4 * Copyright (C) 1995, 1996 by Volker Lendecke
5 * Modified for big endian by J.F. Chadima and David S. Miller
6 * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
7 * Modified 1998, 1999 Wolfram Pienkoss for NLS
8 * Modified 1999 Wolfram Pienkoss for directory caching
9 * Modified 2000 Ben Harris, University of Cambridge for NFS NS meta-info
14 #include <linux/time.h>
15 #include <linux/errno.h>
16 #include <linux/stat.h>
17 #include <linux/kernel.h>
18 #include <linux/vmalloc.h>
20 #include <asm/uaccess.h>
21 #include <asm/byteorder.h>
22 #include <linux/smp_lock.h>
24 #include <linux/ncp_fs.h>
26 #include "ncplib_kernel.h"
28 static void ncp_read_volume_list(struct file *, void *, filldir_t,
29 struct ncp_cache_control *);
30 static void ncp_do_readdir(struct file *, void *, filldir_t,
31 struct ncp_cache_control *);
33 static int ncp_readdir(struct file *, void *, filldir_t);
35 static int ncp_create(struct inode *, struct dentry *, int, struct nameidata *);
36 static struct dentry *ncp_lookup(struct inode *, struct dentry *, struct nameidata *);
37 static int ncp_unlink(struct inode *, struct dentry *);
38 static int ncp_mkdir(struct inode *, struct dentry *, int);
39 static int ncp_rmdir(struct inode *, struct dentry *);
40 static int ncp_rename(struct inode *, struct dentry *,
41 struct inode *, struct dentry *);
42 static int ncp_mknod(struct inode * dir, struct dentry *dentry,
43 int mode, dev_t rdev);
44 #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
45 extern int ncp_symlink(struct inode *, struct dentry *, const char *);
47 #define ncp_symlink NULL
50 const struct file_operations ncp_dir_operations =
52 .read = generic_read_dir,
53 .readdir = ncp_readdir,
56 .compat_ioctl = ncp_compat_ioctl,
60 const struct inode_operations ncp_dir_inode_operations =
65 .symlink = ncp_symlink,
70 .setattr = ncp_notify_change,
74 * Dentry operations routines
76 static int ncp_lookup_validate(struct dentry *, struct nameidata *);
77 static int ncp_hash_dentry(struct dentry *, struct qstr *);
78 static int ncp_compare_dentry (struct dentry *, struct qstr *, struct qstr *);
79 static int ncp_delete_dentry(struct dentry *);
81 static const struct dentry_operations ncp_dentry_operations =
83 .d_revalidate = ncp_lookup_validate,
84 .d_hash = ncp_hash_dentry,
85 .d_compare = ncp_compare_dentry,
86 .d_delete = ncp_delete_dentry,
89 const struct dentry_operations ncp_root_dentry_operations =
91 .d_hash = ncp_hash_dentry,
92 .d_compare = ncp_compare_dentry,
93 .d_delete = ncp_delete_dentry,
98 * Note: leave the hash unchanged if the directory
102 ncp_hash_dentry(struct dentry *dentry, struct qstr *this)
108 t = NCP_IO_TABLE(dentry);
110 if (!ncp_case_sensitive(dentry->d_inode)) {
111 hash = init_name_hash();
112 for (i=0; i<this->len ; i++)
113 hash = partial_name_hash(ncp_tolower(t, this->name[i]),
115 this->hash = end_name_hash(hash);
121 ncp_compare_dentry(struct dentry *dentry, struct qstr *a, struct qstr *b)
123 if (a->len != b->len)
126 if (ncp_case_sensitive(dentry->d_inode))
127 return strncmp(a->name, b->name, a->len);
129 return ncp_strnicmp(NCP_IO_TABLE(dentry), a->name, b->name, a->len);
133 * This is the callback from dput() when d_count is going to 0.
134 * We use this to unhash dentries with bad inodes.
135 * Closing files can be safely postponed until iput() - it's done there anyway.
138 ncp_delete_dentry(struct dentry * dentry)
140 struct inode *inode = dentry->d_inode;
143 if (is_bad_inode(inode))
147 /* N.B. Unhash negative dentries? */
153 ncp_single_volume(struct ncp_server *server)
155 return (server->m.mounted_vol[0] != '\0');
158 static inline int ncp_is_server_root(struct inode *inode)
160 return (!ncp_single_volume(NCP_SERVER(inode)) &&
161 inode == inode->i_sb->s_root->d_inode);
166 * This is the callback when the dcache has a lookup hit.
170 #ifdef CONFIG_NCPFS_STRONG
171 /* try to delete a readonly file (NW R bit set) */
174 ncp_force_unlink(struct inode *dir, struct dentry* dentry)
177 struct nw_modify_dos_info info;
181 memset(&info, 0, sizeof(info));
183 /* remove the Read-Only flag on the NW server */
184 inode = dentry->d_inode;
186 old_nwattr = NCP_FINFO(inode)->nwattr;
187 info.attributes = old_nwattr & ~(aRONLY|aDELETEINHIBIT|aRENAMEINHIBIT);
188 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(inode), inode, NULL, DM_ATTRIBUTES, &info);
192 /* now try again the delete operation */
193 res = ncp_del_file_or_subdir2(NCP_SERVER(dir), dentry);
195 if (res) /* delete failed, set R bit again */
197 info.attributes = old_nwattr;
198 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(inode), inode, NULL, DM_ATTRIBUTES, &info);
205 #endif /* CONFIG_NCPFS_STRONG */
207 #ifdef CONFIG_NCPFS_STRONG
209 ncp_force_rename(struct inode *old_dir, struct dentry* old_dentry, char *_old_name,
210 struct inode *new_dir, struct dentry* new_dentry, char *_new_name)
212 struct nw_modify_dos_info info;
214 struct inode *old_inode = old_dentry->d_inode;
215 __le32 old_nwattr = NCP_FINFO(old_inode)->nwattr;
216 __le32 new_nwattr = 0; /* shut compiler warning */
217 int old_nwattr_changed = 0;
218 int new_nwattr_changed = 0;
220 memset(&info, 0, sizeof(info));
222 /* remove the Read-Only flag on the NW server */
224 info.attributes = old_nwattr & ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
225 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(old_inode), old_inode, NULL, DM_ATTRIBUTES, &info);
227 old_nwattr_changed = 1;
228 if (new_dentry && new_dentry->d_inode) {
229 new_nwattr = NCP_FINFO(new_dentry->d_inode)->nwattr;
230 info.attributes = new_nwattr & ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
231 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(new_dir), new_dir, _new_name, DM_ATTRIBUTES, &info);
233 new_nwattr_changed = 1;
235 /* now try again the rename operation */
236 /* but only if something really happened */
237 if (new_nwattr_changed || old_nwattr_changed) {
238 res = ncp_ren_or_mov_file_or_subdir(NCP_SERVER(old_dir),
244 /* file was successfully renamed, so:
245 do not set attributes on old file - it no longer exists
246 copy attributes from old file to new */
247 new_nwattr_changed = old_nwattr_changed;
248 new_nwattr = old_nwattr;
249 old_nwattr_changed = 0;
252 if (old_nwattr_changed) {
253 info.attributes = old_nwattr;
254 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(old_inode), old_inode, NULL, DM_ATTRIBUTES, &info);
257 if (new_nwattr_changed) {
258 info.attributes = new_nwattr;
259 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(new_dir), new_dir, _new_name, DM_ATTRIBUTES, &info);
264 #endif /* CONFIG_NCPFS_STRONG */
268 __ncp_lookup_validate(struct dentry *dentry)
270 struct ncp_server *server;
271 struct dentry *parent;
273 struct ncp_entry_info finfo;
274 int res, val = 0, len;
275 __u8 __name[NCP_MAXPATHLEN + 1];
277 parent = dget_parent(dentry);
278 dir = parent->d_inode;
280 if (!dentry->d_inode)
283 server = NCP_SERVER(dir);
285 if (!ncp_conn_valid(server))
290 * The default validation is based on dentry age:
291 * We set the max age at mount time. (But each
292 * successful server lookup renews the timestamp.)
294 val = NCP_TEST_AGE(server, dentry);
298 DDPRINTK("ncp_lookup_validate: %s/%s not valid, age=%ld, server lookup\n",
299 dentry->d_parent->d_name.name, dentry->d_name.name,
300 NCP_GET_AGE(dentry));
302 len = sizeof(__name);
303 if (ncp_is_server_root(dir)) {
304 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
305 dentry->d_name.len, 1);
307 res = ncp_lookup_volume(server, __name, &(finfo.i));
309 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
310 dentry->d_name.len, !ncp_preserve_case(dir));
312 res = ncp_obtain_info(server, dir, __name, &(finfo.i));
314 finfo.volume = finfo.i.volNumber;
315 DDPRINTK("ncp_lookup_validate: looked for %s/%s, res=%d\n",
316 dentry->d_parent->d_name.name, __name, res);
318 * If we didn't find it, or if it has a different dirEntNum to
319 * what we remember, it's not valid any more.
322 if (finfo.i.dirEntNum == NCP_FINFO(dentry->d_inode)->dirEntNum) {
323 ncp_new_dentry(dentry);
326 DDPRINTK("ncp_lookup_validate: found, but dirEntNum changed\n");
328 ncp_update_inode2(dentry->d_inode, &finfo);
332 DDPRINTK("ncp_lookup_validate: result=%d\n", val);
338 ncp_lookup_validate(struct dentry * dentry, struct nameidata *nd)
342 res = __ncp_lookup_validate(dentry);
347 static struct dentry *
348 ncp_dget_fpos(struct dentry *dentry, struct dentry *parent, unsigned long fpos)
350 struct dentry *dent = dentry;
351 struct list_head *next;
353 if (d_validate(dent, parent)) {
354 if (dent->d_name.len <= NCP_MAXPATHLEN &&
355 (unsigned long)dent->d_fsdata == fpos) {
356 if (!dent->d_inode) {
365 /* If a pointer is invalid, we search the dentry. */
366 spin_lock(&dcache_lock);
367 next = parent->d_subdirs.next;
368 while (next != &parent->d_subdirs) {
369 dent = list_entry(next, struct dentry, d_u.d_child);
370 if ((unsigned long)dent->d_fsdata == fpos) {
375 spin_unlock(&dcache_lock);
380 spin_unlock(&dcache_lock);
387 static time_t ncp_obtain_mtime(struct dentry *dentry)
389 struct inode *inode = dentry->d_inode;
390 struct ncp_server *server = NCP_SERVER(inode);
391 struct nw_info_struct i;
393 if (!ncp_conn_valid(server) || ncp_is_server_root(inode))
396 if (ncp_obtain_info(server, inode, NULL, &i))
399 return ncp_date_dos2unix(i.modifyTime, i.modifyDate);
402 static int ncp_readdir(struct file *filp, void *dirent, filldir_t filldir)
404 struct dentry *dentry = filp->f_path.dentry;
405 struct inode *inode = dentry->d_inode;
406 struct page *page = NULL;
407 struct ncp_server *server = NCP_SERVER(inode);
408 union ncp_dir_cache *cache = NULL;
409 struct ncp_cache_control ctl;
410 int result, mtime_valid = 0;
418 DDPRINTK("ncp_readdir: reading %s/%s, pos=%d\n",
419 dentry->d_parent->d_name.name, dentry->d_name.name,
423 if (!ncp_conn_valid(server))
427 if (filp->f_pos == 0) {
428 if (filldir(dirent, ".", 1, 0, inode->i_ino, DT_DIR))
432 if (filp->f_pos == 1) {
433 if (filldir(dirent, "..", 2, 1, parent_ino(dentry), DT_DIR))
438 page = grab_cache_page(&inode->i_data, 0);
442 ctl.cache = cache = kmap(page);
443 ctl.head = cache->head;
445 if (!PageUptodate(page) || !ctl.head.eof)
448 if (filp->f_pos == 2) {
449 if (jiffies - ctl.head.time >= NCP_MAX_AGE(server))
452 mtime = ncp_obtain_mtime(dentry);
454 if ((!mtime) || (mtime != ctl.head.mtime))
458 if (filp->f_pos > ctl.head.end)
461 ctl.fpos = filp->f_pos + (NCP_DIRCACHE_START - 2);
462 ctl.ofs = ctl.fpos / NCP_DIRCACHE_SIZE;
463 ctl.idx = ctl.fpos % NCP_DIRCACHE_SIZE;
467 ctl.page = find_lock_page(&inode->i_data, ctl.ofs);
470 ctl.cache = kmap(ctl.page);
471 if (!PageUptodate(ctl.page))
474 while (ctl.idx < NCP_DIRCACHE_SIZE) {
478 dent = ncp_dget_fpos(ctl.cache->dentry[ctl.idx],
479 dentry, filp->f_pos);
482 res = filldir(dirent, dent->d_name.name,
483 dent->d_name.len, filp->f_pos,
484 dent->d_inode->i_ino, DT_UNKNOWN);
490 if (filp->f_pos > ctl.head.end)
495 SetPageUptodate(ctl.page);
496 unlock_page(ctl.page);
497 page_cache_release(ctl.page);
506 unlock_page(ctl.page);
507 page_cache_release(ctl.page);
512 ncp_invalidate_dircache_entries(dentry);
514 mtime = ncp_obtain_mtime(dentry);
517 ctl.head.mtime = mtime;
518 ctl.head.time = jiffies;
522 ctl.idx = NCP_DIRCACHE_START;
526 if (ncp_is_server_root(inode)) {
527 ncp_read_volume_list(filp, dirent, filldir, &ctl);
529 ncp_do_readdir(filp, dirent, filldir, &ctl);
531 ctl.head.end = ctl.fpos - 1;
532 ctl.head.eof = ctl.valid;
535 cache->head = ctl.head;
537 SetPageUptodate(page);
539 page_cache_release(page);
543 SetPageUptodate(ctl.page);
544 unlock_page(ctl.page);
545 page_cache_release(ctl.page);
553 ncp_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
554 struct ncp_cache_control *ctrl, struct ncp_entry_info *entry)
556 struct dentry *newdent, *dentry = filp->f_path.dentry;
557 struct inode *newino, *inode = dentry->d_inode;
558 struct ncp_cache_control ctl = *ctrl;
563 __u8 __name[NCP_MAXPATHLEN + 1];
565 qname.len = sizeof(__name);
566 if (ncp_vol2io(NCP_SERVER(inode), __name, &qname.len,
567 entry->i.entryName, entry->i.nameLen,
568 !ncp_preserve_entry_case(inode, entry->i.NSCreator)))
569 return 1; /* I'm not sure */
572 qname.hash = full_name_hash(qname.name, qname.len);
574 if (dentry->d_op && dentry->d_op->d_hash)
575 if (dentry->d_op->d_hash(dentry, &qname) != 0)
578 newdent = d_lookup(dentry, &qname);
581 newdent = d_alloc(dentry, &qname);
586 memcpy((char *) newdent->d_name.name, qname.name,
587 newdent->d_name.len);
590 if (!newdent->d_inode) {
592 entry->ino = iunique(inode->i_sb, 2);
593 newino = ncp_iget(inode->i_sb, entry);
595 newdent->d_op = &ncp_dentry_operations;
596 d_instantiate(newdent, newino);
601 ncp_update_inode2(newdent->d_inode, entry);
603 if (newdent->d_inode) {
604 ino = newdent->d_inode->i_ino;
605 newdent->d_fsdata = (void *) ctl.fpos;
606 ncp_new_dentry(newdent);
609 if (ctl.idx >= NCP_DIRCACHE_SIZE) {
612 SetPageUptodate(ctl.page);
613 unlock_page(ctl.page);
614 page_cache_release(ctl.page);
617 ctl.idx -= NCP_DIRCACHE_SIZE;
619 ctl.page = grab_cache_page(&inode->i_data, ctl.ofs);
621 ctl.cache = kmap(ctl.page);
624 ctl.cache->dentry[ctl.idx] = newdent;
631 if (!ctl.filled && (ctl.fpos == filp->f_pos)) {
633 ino = find_inode_number(dentry, &qname);
635 ino = iunique(inode->i_sb, 2);
636 ctl.filled = filldir(dirent, qname.name, qname.len,
637 filp->f_pos, ino, DT_UNKNOWN);
644 return (ctl.valid || !ctl.filled);
648 ncp_read_volume_list(struct file *filp, void *dirent, filldir_t filldir,
649 struct ncp_cache_control *ctl)
651 struct dentry *dentry = filp->f_path.dentry;
652 struct inode *inode = dentry->d_inode;
653 struct ncp_server *server = NCP_SERVER(inode);
654 struct ncp_volume_info info;
655 struct ncp_entry_info entry;
658 DPRINTK("ncp_read_volume_list: pos=%ld\n",
659 (unsigned long) filp->f_pos);
661 for (i = 0; i < NCP_NUMBER_OF_VOLUMES; i++) {
663 if (ncp_get_volume_info_with_number(server, i, &info) != 0)
665 if (!strlen(info.volume_name))
668 DPRINTK("ncp_read_volume_list: found vol: %s\n",
671 if (ncp_lookup_volume(server, info.volume_name,
673 DPRINTK("ncpfs: could not lookup vol %s\n",
677 entry.volume = entry.i.volNumber;
678 if (!ncp_fill_cache(filp, dirent, filldir, ctl, &entry))
684 ncp_do_readdir(struct file *filp, void *dirent, filldir_t filldir,
685 struct ncp_cache_control *ctl)
687 struct dentry *dentry = filp->f_path.dentry;
688 struct inode *dir = dentry->d_inode;
689 struct ncp_server *server = NCP_SERVER(dir);
690 struct nw_search_sequence seq;
691 struct ncp_entry_info entry;
697 DPRINTK("ncp_do_readdir: %s/%s, fpos=%ld\n",
698 dentry->d_parent->d_name.name, dentry->d_name.name,
699 (unsigned long) filp->f_pos);
700 PPRINTK("ncp_do_readdir: init %s, volnum=%d, dirent=%u\n",
701 dentry->d_name.name, NCP_FINFO(dir)->volNumber,
702 NCP_FINFO(dir)->dirEntNum);
704 err = ncp_initialize_search(server, dir, &seq);
706 DPRINTK("ncp_do_readdir: init failed, err=%d\n", err);
709 /* We MUST NOT use server->buffer_size handshaked with server if we are
710 using UDP, as for UDP server uses max. buffer size determined by
711 MTU, and for TCP server uses hardwired value 65KB (== 66560 bytes).
712 So we use 128KB, just to be sure, as there is no way how to know
713 this value in advance. */
715 buf = vmalloc(bufsize);
723 err = ncp_search_for_fileset(server, &seq, &more, &cnt, buf, bufsize, &rpl, &rpls);
726 if (!cnt) /* prevent endless loop */
731 if (rpls < offsetof(struct nw_info_struct, entryName))
732 break; /* short packet */
733 ncp_extract_file_info(rpl, &entry.i);
734 onerpl = offsetof(struct nw_info_struct, entryName) + entry.i.nameLen;
736 break; /* short packet */
737 (void)ncp_obtain_nfs_info(server, &entry.i);
740 entry.volume = entry.i.volNumber;
741 if (!ncp_fill_cache(filp, dirent, filldir, ctl, &entry))
749 int ncp_conn_logged_in(struct super_block *sb)
751 struct ncp_server* server = NCP_SBP(sb);
754 if (ncp_single_volume(server)) {
760 __u8 __name[NCP_MAXPATHLEN + 1];
762 len = sizeof(__name);
763 result = ncp_io2vol(server, __name, &len, server->m.mounted_vol,
764 strlen(server->m.mounted_vol), 1);
768 if (ncp_get_volume_root(server, __name, &volNumber, &dirEntNum, &DosDirNum)) {
769 PPRINTK("ncp_conn_logged_in: %s not found\n",
770 server->m.mounted_vol);
775 struct inode* ino = dent->d_inode;
777 NCP_FINFO(ino)->volNumber = volNumber;
778 NCP_FINFO(ino)->dirEntNum = dirEntNum;
779 NCP_FINFO(ino)->DosDirNum = DosDirNum;
781 DPRINTK("ncpfs: sb->s_root->d_inode == NULL!\n");
784 DPRINTK("ncpfs: sb->s_root == NULL!\n");
793 static struct dentry *ncp_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
795 struct ncp_server *server = NCP_SERVER(dir);
796 struct inode *inode = NULL;
797 struct ncp_entry_info finfo;
799 __u8 __name[NCP_MAXPATHLEN + 1];
803 if (!ncp_conn_valid(server))
806 PPRINTK("ncp_lookup: server lookup for %s/%s\n",
807 dentry->d_parent->d_name.name, dentry->d_name.name);
809 len = sizeof(__name);
810 if (ncp_is_server_root(dir)) {
811 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
812 dentry->d_name.len, 1);
814 res = ncp_lookup_volume(server, __name, &(finfo.i));
816 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
817 dentry->d_name.len, !ncp_preserve_case(dir));
819 res = ncp_obtain_info(server, dir, __name, &(finfo.i));
821 PPRINTK("ncp_lookup: looked for %s/%s, res=%d\n",
822 dentry->d_parent->d_name.name, __name, res);
824 * If we didn't find an entry, make a negative dentry.
830 * Create an inode for the entry.
833 finfo.ino = iunique(dir->i_sb, 2);
834 finfo.volume = finfo.i.volNumber;
836 inode = ncp_iget(dir->i_sb, &finfo);
839 ncp_new_dentry(dentry);
841 dentry->d_op = &ncp_dentry_operations;
842 d_add(dentry, inode);
847 PPRINTK("ncp_lookup: result=%d\n", error);
849 return ERR_PTR(error);
853 * This code is common to create, mkdir, and mknod.
855 static int ncp_instantiate(struct inode *dir, struct dentry *dentry,
856 struct ncp_entry_info *finfo)
861 finfo->ino = iunique(dir->i_sb, 2);
862 inode = ncp_iget(dir->i_sb, finfo);
865 d_instantiate(dentry,inode);
871 PPRINTK("ncp_instantiate: %s/%s failed, closing file\n",
872 dentry->d_parent->d_name.name, dentry->d_name.name);
873 ncp_close_file(NCP_SERVER(dir), finfo->file_handle);
877 int ncp_create_new(struct inode *dir, struct dentry *dentry, int mode,
878 dev_t rdev, __le32 attributes)
880 struct ncp_server *server = NCP_SERVER(dir);
881 struct ncp_entry_info finfo;
882 int error, result, len;
884 __u8 __name[NCP_MAXPATHLEN + 1];
886 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
887 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
891 if (!ncp_conn_valid(server))
894 ncp_age_dentry(server, dentry);
895 len = sizeof(__name);
896 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
897 dentry->d_name.len, !ncp_preserve_case(dir));
904 (server->m.flags & NCP_MOUNT_EXTRAS) &&
906 attributes |= aSYSTEM | aSHARED;
908 result = ncp_open_create_file_or_subdir(server, dir, __name,
909 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
910 attributes, AR_READ | AR_WRITE, &finfo);
913 result = ncp_open_create_file_or_subdir(server, dir, __name,
914 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
915 attributes, AR_WRITE, &finfo);
918 error = -ENAMETOOLONG;
919 DPRINTK("ncp_create: %s/%s failed\n",
920 dentry->d_parent->d_name.name, dentry->d_name.name);
925 finfo.access = opmode;
926 if (ncp_is_nfs_extras(server, finfo.volume)) {
927 finfo.i.nfs.mode = mode;
928 finfo.i.nfs.rdev = new_encode_dev(rdev);
929 if (ncp_modify_nfs_info(server, finfo.volume,
931 mode, new_encode_dev(rdev)) != 0)
935 error = ncp_instantiate(dir, dentry, &finfo);
941 static int ncp_create(struct inode *dir, struct dentry *dentry, int mode,
942 struct nameidata *nd)
944 return ncp_create_new(dir, dentry, mode, 0, 0);
947 static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
949 struct ncp_entry_info finfo;
950 struct ncp_server *server = NCP_SERVER(dir);
952 __u8 __name[NCP_MAXPATHLEN + 1];
954 DPRINTK("ncp_mkdir: making %s/%s\n",
955 dentry->d_parent->d_name.name, dentry->d_name.name);
959 if (!ncp_conn_valid(server))
962 ncp_age_dentry(server, dentry);
963 len = sizeof(__name);
964 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
965 dentry->d_name.len, !ncp_preserve_case(dir));
970 if (ncp_open_create_file_or_subdir(server, dir, __name,
971 OC_MODE_CREATE, aDIR,
975 if (ncp_is_nfs_extras(server, finfo.volume)) {
977 finfo.i.nfs.mode = mode;
978 if (ncp_modify_nfs_info(server,
984 error = ncp_instantiate(dir, dentry, &finfo);
991 static int ncp_rmdir(struct inode *dir, struct dentry *dentry)
993 struct ncp_server *server = NCP_SERVER(dir);
994 int error, result, len;
995 __u8 __name[NCP_MAXPATHLEN + 1];
997 DPRINTK("ncp_rmdir: removing %s/%s\n",
998 dentry->d_parent->d_name.name, dentry->d_name.name);
1002 if (!ncp_conn_valid(server))
1006 if (!d_unhashed(dentry))
1009 len = sizeof(__name);
1010 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
1011 dentry->d_name.len, !ncp_preserve_case(dir));
1015 result = ncp_del_file_or_subdir(server, dir, __name);
1020 case 0x85: /* unauthorized to delete file */
1021 case 0x8A: /* unauthorized to delete file */
1025 case 0x90: /* read only */
1028 case 0x9F: /* in use by another client */
1031 case 0xA0: /* directory not empty */
1034 case 0xFF: /* someone deleted file */
1046 static int ncp_unlink(struct inode *dir, struct dentry *dentry)
1048 struct inode *inode = dentry->d_inode;
1049 struct ncp_server *server;
1053 server = NCP_SERVER(dir);
1054 DPRINTK("ncp_unlink: unlinking %s/%s\n",
1055 dentry->d_parent->d_name.name, dentry->d_name.name);
1058 if (!ncp_conn_valid(server))
1062 * Check whether to close the file ...
1065 PPRINTK("ncp_unlink: closing file\n");
1066 ncp_make_closed(inode);
1069 error = ncp_del_file_or_subdir2(server, dentry);
1070 #ifdef CONFIG_NCPFS_STRONG
1071 /* 9C is Invalid path.. It should be 8F, 90 - read only, but
1073 if ((error == 0x9C || error == 0x90) && server->m.flags & NCP_MOUNT_STRONG) { /* R/O */
1074 error = ncp_force_unlink(dir, dentry);
1079 DPRINTK("ncp: removed %s/%s\n",
1080 dentry->d_parent->d_name.name, dentry->d_name.name);
1086 case 0x8D: /* some files in use */
1087 case 0x8E: /* all files in use */
1090 case 0x8F: /* some read only */
1091 case 0x90: /* all read only */
1092 case 0x9C: /* !!! returned when in-use or read-only by NW4 */
1108 static int ncp_rename(struct inode *old_dir, struct dentry *old_dentry,
1109 struct inode *new_dir, struct dentry *new_dentry)
1111 struct ncp_server *server = NCP_SERVER(old_dir);
1113 int old_len, new_len;
1114 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
1116 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
1117 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
1118 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
1122 if (!ncp_conn_valid(server))
1125 ncp_age_dentry(server, old_dentry);
1126 ncp_age_dentry(server, new_dentry);
1128 old_len = sizeof(__old_name);
1129 error = ncp_io2vol(server, __old_name, &old_len,
1130 old_dentry->d_name.name, old_dentry->d_name.len,
1131 !ncp_preserve_case(old_dir));
1135 new_len = sizeof(__new_name);
1136 error = ncp_io2vol(server, __new_name, &new_len,
1137 new_dentry->d_name.name, new_dentry->d_name.len,
1138 !ncp_preserve_case(new_dir));
1142 error = ncp_ren_or_mov_file_or_subdir(server, old_dir, __old_name,
1143 new_dir, __new_name);
1144 #ifdef CONFIG_NCPFS_STRONG
1145 if ((error == 0x90 || error == 0x8B || error == -EACCES) &&
1146 server->m.flags & NCP_MOUNT_STRONG) { /* RO */
1147 error = ncp_force_rename(old_dir, old_dentry, __old_name,
1148 new_dir, new_dentry, __new_name);
1153 DPRINTK("ncp renamed %s -> %s.\n",
1154 old_dentry->d_name.name,new_dentry->d_name.name);
1157 error = -ENAMETOOLONG;
1171 static int ncp_mknod(struct inode * dir, struct dentry *dentry,
1172 int mode, dev_t rdev)
1174 if (!new_valid_dev(rdev))
1176 if (ncp_is_nfs_extras(NCP_SERVER(dir), NCP_FINFO(dir)->volNumber)) {
1177 DPRINTK(KERN_DEBUG "ncp_mknod: mode = 0%o\n", mode);
1178 return ncp_create_new(dir, dentry, mode, rdev, 0);
1180 return -EPERM; /* Strange, but true */
1183 /* The following routines are taken directly from msdos-fs */
1185 /* Linear day numbers of the respective 1sts in non-leap years. */
1187 static int day_n[] =
1188 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0, 0};
1189 /* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */
1192 extern struct timezone sys_tz;
1194 static int utc2local(int time)
1196 return time - sys_tz.tz_minuteswest * 60;
1199 static int local2utc(int time)
1201 return time + sys_tz.tz_minuteswest * 60;
1204 /* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70). */
1206 ncp_date_dos2unix(__le16 t, __le16 d)
1208 unsigned short time = le16_to_cpu(t), date = le16_to_cpu(d);
1209 int month, year, secs;
1211 /* first subtract and mask after that... Otherwise, if
1212 date == 0, bad things happen */
1213 month = ((date >> 5) - 1) & 15;
1215 secs = (time & 31) * 2 + 60 * ((time >> 5) & 63) + (time >> 11) * 3600 +
1216 86400 * ((date & 31) - 1 + day_n[month] + (year / 4) +
1217 year * 365 - ((year & 3) == 0 && month < 2 ? 1 : 0) + 3653);
1218 /* days since 1.1.70 plus 80's leap day */
1219 return local2utc(secs);
1223 /* Convert linear UNIX date to a MS-DOS time/date pair. */
1225 ncp_date_unix2dos(int unix_date, __le16 *time, __le16 *date)
1227 int day, year, nl_day, month;
1229 unix_date = utc2local(unix_date);
1230 *time = cpu_to_le16(
1231 (unix_date % 60) / 2 + (((unix_date / 60) % 60) << 5) +
1232 (((unix_date / 3600) % 24) << 11));
1233 day = unix_date / 86400 - 3652;
1235 if ((year + 3) / 4 + 365 * year > day)
1237 day -= (year + 3) / 4 + 365 * year;
1238 if (day == 59 && !(year & 3)) {
1242 nl_day = (year & 3) || day <= 59 ? day : day - 1;
1243 for (month = 1; month < 12; month++)
1244 if (day_n[month] > nl_day)
1247 *date = cpu_to_le16(nl_day - day_n[month - 1] + 1 + (month << 5) + (year << 9));