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
12 #include <linux/config.h>
14 #include <linux/sched.h>
15 #include <linux/errno.h>
16 #include <linux/stat.h>
17 #include <linux/kernel.h>
18 #include <linux/slab.h>
19 #include <linux/vmalloc.h>
21 #include <asm/uaccess.h>
22 #include <asm/byteorder.h>
23 #include <linux/locks.h>
24 #include <linux/smp_lock.h>
26 #include <linux/ncp_fs.h>
28 #include "ncplib_kernel.h"
30 static void ncp_read_volume_list(struct file *, void *, filldir_t,
31 struct ncp_cache_control *);
32 static void ncp_do_readdir(struct file *, void *, filldir_t,
33 struct ncp_cache_control *);
35 static int ncp_readdir(struct file *, void *, filldir_t);
37 static int ncp_create(struct inode *, struct dentry *, int);
38 static struct dentry *ncp_lookup(struct inode *, struct dentry *);
39 static int ncp_unlink(struct inode *, struct dentry *);
40 static int ncp_mkdir(struct inode *, struct dentry *, int);
41 static int ncp_rmdir(struct inode *, struct dentry *);
42 static int ncp_rename(struct inode *, struct dentry *,
43 struct inode *, struct dentry *);
44 #ifdef CONFIG_NCPFS_EXTRAS
45 extern int ncp_symlink(struct inode *, struct dentry *, const char *);
48 struct file_operations ncp_dir_operations =
50 read: generic_read_dir,
55 struct inode_operations ncp_dir_inode_operations =
60 #ifdef CONFIG_NCPFS_EXTRAS
66 setattr: ncp_notify_change,
70 * Dentry operations routines
72 static int ncp_lookup_validate(struct dentry *, int);
73 static int ncp_hash_dentry(struct dentry *, struct qstr *);
74 static int ncp_compare_dentry (struct dentry *, struct qstr *, struct qstr *);
75 static int ncp_delete_dentry(struct dentry *);
77 static struct dentry_operations ncp_dentry_operations =
79 d_revalidate: ncp_lookup_validate,
80 d_hash: ncp_hash_dentry,
81 d_compare: ncp_compare_dentry,
82 d_delete: ncp_delete_dentry,
85 struct dentry_operations ncp_root_dentry_operations =
87 d_hash: ncp_hash_dentry,
88 d_compare: ncp_compare_dentry,
89 d_delete: ncp_delete_dentry,
94 * Note: leave the hash unchanged if the directory
98 ncp_hash_dentry(struct dentry *dentry, struct qstr *this)
104 t = NCP_IO_TABLE(dentry);
106 if (!ncp_case_sensitive(dentry->d_inode)) {
107 hash = init_name_hash();
108 for (i=0; i<this->len ; i++)
109 hash = partial_name_hash(ncp_tolower(t, this->name[i]),
111 this->hash = end_name_hash(hash);
117 ncp_compare_dentry(struct dentry *dentry, struct qstr *a, struct qstr *b)
119 if (a->len != b->len)
122 if (ncp_case_sensitive(dentry->d_inode))
123 return strncmp(a->name, b->name, a->len);
125 return ncp_strnicmp(NCP_IO_TABLE(dentry), a->name, b->name, a->len);
129 * This is the callback from dput() when d_count is going to 0.
130 * We use this to unhash dentries with bad inodes.
131 * Closing files can be safely postponed until iput() - it's done there anyway.
134 ncp_delete_dentry(struct dentry * dentry)
136 struct inode *inode = dentry->d_inode;
139 if (is_bad_inode(inode))
143 /* N.B. Unhash negative dentries? */
149 ncp_single_volume(struct ncp_server *server)
151 return (server->m.mounted_vol[0] != '\0');
154 static inline int ncp_is_server_root(struct inode *inode)
156 return (!ncp_single_volume(NCP_SERVER(inode)) &&
157 inode == inode->i_sb->s_root->d_inode);
162 * This is the callback when the dcache has a lookup hit.
166 #ifdef CONFIG_NCPFS_STRONG
167 /* try to delete a readonly file (NW R bit set) */
170 ncp_force_unlink(struct inode *dir, struct dentry* dentry)
173 struct nw_modify_dos_info info;
177 memset(&info, 0, sizeof(info));
179 /* remove the Read-Only flag on the NW server */
180 inode = dentry->d_inode;
182 old_nwattr = NCP_FINFO(inode)->nwattr;
183 info.attributes = old_nwattr & ~(aRONLY|aDELETEINHIBIT|aRENAMEINHIBIT);
184 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(inode), inode, NULL, DM_ATTRIBUTES, &info);
188 /* now try again the delete operation */
189 res = ncp_del_file_or_subdir2(NCP_SERVER(dir), dentry);
191 if (res) /* delete failed, set R bit again */
193 info.attributes = old_nwattr;
194 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(inode), inode, NULL, DM_ATTRIBUTES, &info);
201 #endif /* CONFIG_NCPFS_STRONG */
203 #ifdef CONFIG_NCPFS_STRONG
205 ncp_force_rename(struct inode *old_dir, struct dentry* old_dentry, char *_old_name,
206 struct inode *new_dir, struct dentry* new_dentry, char *_new_name)
208 struct nw_modify_dos_info info;
210 struct inode *old_inode = old_dentry->d_inode;
211 __u32 old_nwattr = NCP_FINFO(old_inode)->nwattr;
212 __u32 new_nwattr = 0; /* shut compiler warning */
213 int old_nwattr_changed = 0;
214 int new_nwattr_changed = 0;
216 memset(&info, 0, sizeof(info));
218 /* remove the Read-Only flag on the NW server */
220 info.attributes = old_nwattr & ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
221 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(old_inode), old_inode, NULL, DM_ATTRIBUTES, &info);
223 old_nwattr_changed = 1;
224 if (new_dentry && new_dentry->d_inode) {
225 new_nwattr = NCP_FINFO(new_dentry->d_inode)->nwattr;
226 info.attributes = new_nwattr & ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
227 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(new_dir), new_dir, _new_name, DM_ATTRIBUTES, &info);
229 new_nwattr_changed = 1;
231 /* now try again the rename operation */
232 /* but only if something really happened */
233 if (new_nwattr_changed || old_nwattr_changed) {
234 res = ncp_ren_or_mov_file_or_subdir(NCP_SERVER(old_dir),
240 /* file was successfully renamed, so:
241 do not set attributes on old file - it no longer exists
242 copy attributes from old file to new */
243 new_nwattr_changed = old_nwattr_changed;
244 new_nwattr = old_nwattr;
245 old_nwattr_changed = 0;
248 if (old_nwattr_changed) {
249 info.attributes = old_nwattr;
250 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(old_inode), old_inode, NULL, DM_ATTRIBUTES, &info);
253 if (new_nwattr_changed) {
254 info.attributes = new_nwattr;
255 res2 = ncp_modify_file_or_subdir_dos_info_path(NCP_SERVER(new_dir), new_dir, _new_name, DM_ATTRIBUTES, &info);
260 #endif /* CONFIG_NCPFS_STRONG */
264 __ncp_lookup_validate(struct dentry * dentry, int flags)
266 struct ncp_server *server;
267 struct inode *dir = dentry->d_parent->d_inode;
268 struct ncp_entry_info finfo;
269 int res, val = 0, len;
270 __u8 __name[NCP_MAXPATHLEN + 1];
272 if (!dentry->d_inode || !dir)
275 server = NCP_SERVER(dir);
277 if (!ncp_conn_valid(server))
282 * The default validation is based on dentry age:
283 * We set the max age at mount time. (But each
284 * successful server lookup renews the timestamp.)
286 val = NCP_TEST_AGE(server, dentry);
290 DDPRINTK("ncp_lookup_validate: %s/%s not valid, age=%ld, server lookup\n",
291 dentry->d_parent->d_name.name, dentry->d_name.name,
292 NCP_GET_AGE(dentry));
294 len = sizeof(__name);
295 if (ncp_is_server_root(dir)) {
296 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
297 dentry->d_name.len, 1);
299 res = ncp_lookup_volume(server, __name, &(finfo.i));
301 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
302 dentry->d_name.len, !ncp_preserve_case(dir));
304 res = ncp_obtain_info(server, dir, __name, &(finfo.i));
306 DDPRINTK("ncp_lookup_validate: looked for %s/%s, res=%d\n",
307 dentry->d_parent->d_name.name, __name, res);
309 * If we didn't find it, or if it has a different dirEntNum to
310 * what we remember, it's not valid any more.
313 if (finfo.i.dirEntNum == NCP_FINFO(dentry->d_inode)->dirEntNum) {
314 ncp_new_dentry(dentry);
317 DDPRINTK("ncp_lookup_validate: found, but dirEntNum changed\n");
319 ncp_update_inode2(dentry->d_inode, &finfo);
323 DDPRINTK("ncp_lookup_validate: result=%d\n", val);
328 ncp_lookup_validate(struct dentry * dentry, int flags)
332 res = __ncp_lookup_validate(dentry, flags);
337 static struct dentry *
338 ncp_dget_fpos(struct dentry *dentry, struct dentry *parent, unsigned long fpos)
340 struct dentry *dent = dentry;
341 struct list_head *next;
343 if (d_validate(dent, parent)) {
344 if (dent->d_name.len <= NCP_MAXPATHLEN &&
345 (unsigned long)dent->d_fsdata == fpos) {
346 if (!dent->d_inode) {
355 /* If a pointer is invalid, we search the dentry. */
356 spin_lock(&dcache_lock);
357 next = parent->d_subdirs.next;
358 while (next != &parent->d_subdirs) {
359 dent = list_entry(next, struct dentry, d_child);
360 if ((unsigned long)dent->d_fsdata == fpos) {
365 spin_unlock(&dcache_lock);
370 spin_unlock(&dcache_lock);
377 static time_t ncp_obtain_mtime(struct dentry *dentry)
379 struct inode *inode = dentry->d_inode;
380 struct ncp_server *server = NCP_SERVER(inode);
381 struct nw_info_struct i;
383 if (!ncp_conn_valid(server) || ncp_is_server_root(inode))
386 if (ncp_obtain_info(server, inode, NULL, &i))
389 return ncp_date_dos2unix(le16_to_cpu(i.modifyTime),
390 le16_to_cpu(i.modifyDate));
393 static int ncp_readdir(struct file *filp, void *dirent, filldir_t filldir)
395 struct dentry *dentry = filp->f_dentry;
396 struct inode *inode = dentry->d_inode;
397 struct page *page = NULL;
398 struct ncp_server *server = NCP_SERVER(inode);
399 union ncp_dir_cache *cache = NULL;
400 struct ncp_cache_control ctl;
401 int result, mtime_valid = 0;
407 DDPRINTK("ncp_readdir: reading %s/%s, pos=%d\n",
408 dentry->d_parent->d_name.name, dentry->d_name.name,
412 if (!ncp_conn_valid(server))
416 if (filp->f_pos == 0) {
417 if (filldir(dirent, ".", 1, 0, inode->i_ino, DT_DIR))
421 if (filp->f_pos == 1) {
422 if (filldir(dirent, "..", 2, 1,
423 dentry->d_parent->d_inode->i_ino, DT_DIR))
428 page = grab_cache_page(&inode->i_data, 0);
432 ctl.cache = cache = kmap(page);
433 ctl.head = cache->head;
435 if (!Page_Uptodate(page) || !ctl.head.eof)
438 if (filp->f_pos == 2) {
439 if (jiffies - ctl.head.time >= NCP_MAX_AGE(server))
442 mtime = ncp_obtain_mtime(dentry);
444 if ((!mtime) || (mtime != ctl.head.mtime))
448 if (filp->f_pos > ctl.head.end)
451 ctl.fpos = filp->f_pos + (NCP_DIRCACHE_START - 2);
452 ctl.ofs = ctl.fpos / NCP_DIRCACHE_SIZE;
453 ctl.idx = ctl.fpos % NCP_DIRCACHE_SIZE;
457 ctl.page = find_lock_page(&inode->i_data, ctl.ofs);
460 ctl.cache = kmap(ctl.page);
461 if (!Page_Uptodate(ctl.page))
464 while (ctl.idx < NCP_DIRCACHE_SIZE) {
468 dent = ncp_dget_fpos(ctl.cache->dentry[ctl.idx],
469 dentry, filp->f_pos);
472 res = filldir(dirent, dent->d_name.name,
473 dent->d_name.len, filp->f_pos,
474 dent->d_inode->i_ino, DT_UNKNOWN);
480 if (filp->f_pos > ctl.head.end)
485 SetPageUptodate(ctl.page);
486 UnlockPage(ctl.page);
487 page_cache_release(ctl.page);
496 UnlockPage(ctl.page);
497 page_cache_release(ctl.page);
502 ncp_invalidate_dircache_entries(dentry);
504 mtime = ncp_obtain_mtime(dentry);
507 ctl.head.mtime = mtime;
508 ctl.head.time = jiffies;
512 ctl.idx = NCP_DIRCACHE_START;
516 if (ncp_is_server_root(inode)) {
517 ncp_read_volume_list(filp, dirent, filldir, &ctl);
519 ncp_do_readdir(filp, dirent, filldir, &ctl);
521 ctl.head.end = ctl.fpos - 1;
522 ctl.head.eof = ctl.valid;
525 cache->head = ctl.head;
527 SetPageUptodate(page);
529 page_cache_release(page);
533 SetPageUptodate(ctl.page);
534 UnlockPage(ctl.page);
535 page_cache_release(ctl.page);
542 ncp_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
543 struct ncp_cache_control *ctrl, struct ncp_entry_info *entry)
545 struct dentry *newdent, *dentry = filp->f_dentry;
546 struct inode *newino, *inode = dentry->d_inode;
547 struct ncp_cache_control ctl = *ctrl;
552 __u8 __name[NCP_MAXPATHLEN + 1];
554 qname.len = sizeof(__name);
555 if (ncp_vol2io(NCP_SERVER(inode), __name, &qname.len,
556 entry->i.entryName, entry->i.nameLen,
557 !ncp_preserve_entry_case(inode, entry->i.NSCreator)))
558 return 1; /* I'm not sure */
561 qname.hash = full_name_hash(qname.name, qname.len);
563 if (dentry->d_op && dentry->d_op->d_hash)
564 if (dentry->d_op->d_hash(dentry, &qname) != 0)
567 newdent = d_lookup(dentry, &qname);
570 newdent = d_alloc(dentry, &qname);
575 memcpy((char *) newdent->d_name.name, qname.name,
576 newdent->d_name.len);
579 if (!newdent->d_inode) {
581 entry->ino = iunique(inode->i_sb, 2);
582 newino = ncp_iget(inode->i_sb, entry);
584 newdent->d_op = &ncp_dentry_operations;
585 d_instantiate(newdent, newino);
590 ncp_update_inode2(newdent->d_inode, entry);
592 if (newdent->d_inode) {
593 ino = newdent->d_inode->i_ino;
594 newdent->d_fsdata = (void *) ctl.fpos;
595 ncp_new_dentry(newdent);
598 if (ctl.idx >= NCP_DIRCACHE_SIZE) {
601 SetPageUptodate(ctl.page);
602 UnlockPage(ctl.page);
603 page_cache_release(ctl.page);
606 ctl.idx -= NCP_DIRCACHE_SIZE;
608 ctl.page = grab_cache_page(&inode->i_data, ctl.ofs);
610 ctl.cache = kmap(ctl.page);
613 ctl.cache->dentry[ctl.idx] = newdent;
620 if (!ctl.filled && (ctl.fpos == filp->f_pos)) {
622 ino = find_inode_number(dentry, &qname);
624 ino = iunique(inode->i_sb, 2);
625 ctl.filled = filldir(dirent, qname.name, qname.len,
626 filp->f_pos, ino, DT_UNKNOWN);
633 return (ctl.valid || !ctl.filled);
637 ncp_read_volume_list(struct file *filp, void *dirent, filldir_t filldir,
638 struct ncp_cache_control *ctl)
640 struct dentry *dentry = filp->f_dentry;
641 struct inode *inode = dentry->d_inode;
642 struct ncp_server *server = NCP_SERVER(inode);
643 struct ncp_volume_info info;
644 struct ncp_entry_info entry;
647 DPRINTK("ncp_read_volume_list: pos=%ld\n",
648 (unsigned long) filp->f_pos);
650 for (i = 0; i < NCP_NUMBER_OF_VOLUMES; i++) {
652 if (ncp_get_volume_info_with_number(server, i, &info) != 0)
654 if (!strlen(info.volume_name))
657 DPRINTK("ncp_read_volume_list: found vol: %s\n",
660 if (ncp_lookup_volume(server, info.volume_name,
662 DPRINTK("ncpfs: could not lookup vol %s\n",
666 if (!ncp_fill_cache(filp, dirent, filldir, ctl, &entry))
672 ncp_do_readdir(struct file *filp, void *dirent, filldir_t filldir,
673 struct ncp_cache_control *ctl)
675 struct dentry *dentry = filp->f_dentry;
676 struct inode *dir = dentry->d_inode;
677 struct ncp_server *server = NCP_SERVER(dir);
678 struct nw_search_sequence seq;
679 struct ncp_entry_info entry;
682 DPRINTK("ncp_do_readdir: %s/%s, fpos=%ld\n",
683 dentry->d_parent->d_name.name, dentry->d_name.name,
684 (unsigned long) filp->f_pos);
685 PPRINTK("ncp_do_readdir: init %s, volnum=%d, dirent=%u\n",
686 dentry->d_name.name, NCP_FINFO(dir)->volNumber,
687 NCP_FINFO(dir)->dirEntNum);
689 err = ncp_initialize_search(server, dir, &seq);
691 DPRINTK("ncp_do_readdir: init failed, err=%d\n", err);
695 err = ncp_search_for_file_or_subdir(server, &seq, &entry.i);
697 DPRINTK("ncp_do_readdir: search failed, err=%d\n", err);
700 if (!ncp_fill_cache(filp, dirent, filldir, ctl, &entry))
705 int ncp_conn_logged_in(struct super_block *sb)
707 struct ncp_server* server = NCP_SBP(sb);
708 struct nw_info_struct i;
711 if (ncp_single_volume(server)) {
714 __u8 __name[NCP_MAXPATHLEN + 1];
716 len = sizeof(__name);
717 result = ncp_io2vol(server, __name, &len, server->m.mounted_vol,
718 strlen(server->m.mounted_vol), 1);
722 if (ncp_lookup_volume(server, __name, &i)) {
723 PPRINTK("ncp_conn_logged_in: %s not found\n",
724 server->m.mounted_vol);
729 struct inode* ino = dent->d_inode;
731 NCP_FINFO(ino)->volNumber = i.volNumber;
732 NCP_FINFO(ino)->dirEntNum = i.dirEntNum;
733 NCP_FINFO(ino)->DosDirNum = i.DosDirNum;
735 DPRINTK("ncpfs: sb->s_root->d_inode == NULL!\n");
738 DPRINTK("ncpfs: sb->s_root == NULL!\n");
747 static struct dentry *ncp_lookup(struct inode *dir, struct dentry *dentry)
749 struct ncp_server *server = NCP_SERVER(dir);
750 struct inode *inode = NULL;
751 struct ncp_entry_info finfo;
753 __u8 __name[NCP_MAXPATHLEN + 1];
756 if (!ncp_conn_valid(server))
759 PPRINTK("ncp_lookup: server lookup for %s/%s\n",
760 dentry->d_parent->d_name.name, dentry->d_name.name);
762 len = sizeof(__name);
763 if (ncp_is_server_root(dir)) {
764 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
765 dentry->d_name.len, 1);
767 res = ncp_lookup_volume(server, __name, &(finfo.i));
769 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
770 dentry->d_name.len, !ncp_preserve_case(dir));
772 res = ncp_obtain_info(server, dir, __name, &(finfo.i));
774 PPRINTK("ncp_lookup: looked for %s/%s, res=%d\n",
775 dentry->d_parent->d_name.name, __name, res);
777 * If we didn't find an entry, make a negative dentry.
783 * Create an inode for the entry.
786 finfo.ino = iunique(dir->i_sb, 2);
788 inode = ncp_iget(dir->i_sb, &finfo);
791 ncp_new_dentry(dentry);
793 dentry->d_op = &ncp_dentry_operations;
794 d_add(dentry, inode);
799 PPRINTK("ncp_lookup: result=%d\n", error);
800 return ERR_PTR(error);
804 * This code is common to create, mkdir, and mknod.
806 static int ncp_instantiate(struct inode *dir, struct dentry *dentry,
807 struct ncp_entry_info *finfo)
812 finfo->ino = iunique(dir->i_sb, 2);
813 inode = ncp_iget(dir->i_sb, finfo);
816 d_instantiate(dentry,inode);
822 PPRINTK("ncp_instantiate: %s/%s failed, closing file\n",
823 dentry->d_parent->d_name.name, dentry->d_name.name);
824 ncp_close_file(NCP_SERVER(dir), finfo->file_handle);
828 int ncp_create_new(struct inode *dir, struct dentry *dentry, int mode,
831 struct ncp_server *server = NCP_SERVER(dir);
832 struct ncp_entry_info finfo;
833 int error, result, len;
835 __u8 __name[NCP_MAXPATHLEN + 1];
837 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
838 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
840 if (!ncp_conn_valid(server))
843 ncp_age_dentry(server, dentry);
844 len = sizeof(__name);
845 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
846 dentry->d_name.len, !ncp_preserve_case(dir));
853 (server->m.flags & NCP_MOUNT_EXTRAS) &&
855 attributes |= aSYSTEM | aSHARED;
857 result = ncp_open_create_file_or_subdir(server, dir, __name,
858 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
859 attributes, AR_READ | AR_WRITE, &finfo);
862 result = ncp_open_create_file_or_subdir(server, dir, __name,
863 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
864 attributes, AR_WRITE, &finfo);
867 error = -ENAMETOOLONG;
868 DPRINTK("ncp_create: %s/%s failed\n",
869 dentry->d_parent->d_name.name, dentry->d_name.name);
874 finfo.access = opmode;
875 error = ncp_instantiate(dir, dentry, &finfo);
880 static int ncp_create(struct inode *dir, struct dentry *dentry, int mode)
882 return ncp_create_new(dir, dentry, mode, 0);
885 static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
887 struct ncp_entry_info finfo;
888 struct ncp_server *server = NCP_SERVER(dir);
890 __u8 __name[NCP_MAXPATHLEN + 1];
892 DPRINTK("ncp_mkdir: making %s/%s\n",
893 dentry->d_parent->d_name.name, dentry->d_name.name);
895 if (!ncp_conn_valid(server))
898 ncp_age_dentry(server, dentry);
899 len = sizeof(__name);
900 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
901 dentry->d_name.len, !ncp_preserve_case(dir));
906 if (ncp_open_create_file_or_subdir(server, dir, __name,
907 OC_MODE_CREATE, aDIR, 0xffff,
910 error = ncp_instantiate(dir, dentry, &finfo);
916 static int ncp_rmdir(struct inode *dir, struct dentry *dentry)
918 struct ncp_server *server = NCP_SERVER(dir);
919 int error, result, len;
920 __u8 __name[NCP_MAXPATHLEN + 1];
922 DPRINTK("ncp_rmdir: removing %s/%s\n",
923 dentry->d_parent->d_name.name, dentry->d_name.name);
926 if (!ncp_conn_valid(server))
930 if (!d_unhashed(dentry))
933 len = sizeof(__name);
934 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
935 dentry->d_name.len, !ncp_preserve_case(dir));
939 result = ncp_del_file_or_subdir(server, dir, __name);
944 case 0x85: /* unauthorized to delete file */
945 case 0x8A: /* unauthorized to delete file */
949 case 0x90: /* read only */
952 case 0x9F: /* in use by another client */
955 case 0xA0: /* directory not empty */
958 case 0xFF: /* someone deleted file */
969 static int ncp_unlink(struct inode *dir, struct dentry *dentry)
971 struct inode *inode = dentry->d_inode;
972 struct ncp_server *server = NCP_SERVER(dir);
975 DPRINTK("ncp_unlink: unlinking %s/%s\n",
976 dentry->d_parent->d_name.name, dentry->d_name.name);
979 if (!ncp_conn_valid(server))
983 * Check whether to close the file ...
986 PPRINTK("ncp_unlink: closing file\n");
987 ncp_make_closed(inode);
990 error = ncp_del_file_or_subdir2(server, dentry);
991 #ifdef CONFIG_NCPFS_STRONG
992 /* 9C is Invalid path.. It should be 8F, 90 - read only, but
994 if ((error == 0x9C || error == 0x90) && server->m.flags & NCP_MOUNT_STRONG) { /* R/O */
995 error = ncp_force_unlink(dir, dentry);
1000 DPRINTK("ncp: removed %s/%s\n",
1001 dentry->d_parent->d_name.name, dentry->d_name.name);
1007 case 0x8D: /* some files in use */
1008 case 0x8E: /* all files in use */
1011 case 0x8F: /* some read only */
1012 case 0x90: /* all read only */
1013 case 0x9C: /* !!! returned when in-use or read-only by NW4 */
1028 static int ncp_rename(struct inode *old_dir, struct dentry *old_dentry,
1029 struct inode *new_dir, struct dentry *new_dentry)
1031 struct ncp_server *server = NCP_SERVER(old_dir);
1033 int old_len, new_len;
1034 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
1036 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
1037 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
1038 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
1041 if (!ncp_conn_valid(server))
1044 ncp_age_dentry(server, old_dentry);
1045 ncp_age_dentry(server, new_dentry);
1047 old_len = sizeof(__old_name);
1048 error = ncp_io2vol(server, __old_name, &old_len,
1049 old_dentry->d_name.name, old_dentry->d_name.len,
1050 !ncp_preserve_case(old_dir));
1054 new_len = sizeof(__new_name);
1055 error = ncp_io2vol(server, __new_name, &new_len,
1056 new_dentry->d_name.name, new_dentry->d_name.len,
1057 !ncp_preserve_case(new_dir));
1061 error = ncp_ren_or_mov_file_or_subdir(server, old_dir, __old_name,
1062 new_dir, __new_name);
1063 #ifdef CONFIG_NCPFS_STRONG
1064 if ((error == 0x90 || error == 0x8B || error == -EACCES) &&
1065 server->m.flags & NCP_MOUNT_STRONG) { /* RO */
1066 error = ncp_force_rename(old_dir, old_dentry, __old_name,
1067 new_dir, new_dentry, __new_name);
1072 DPRINTK("ncp renamed %s -> %s.\n",
1073 old_dentry->d_name.name,new_dentry->d_name.name);
1076 error = -ENAMETOOLONG;
1089 /* The following routines are taken directly from msdos-fs */
1091 /* Linear day numbers of the respective 1sts in non-leap years. */
1093 static int day_n[] =
1094 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0, 0};
1095 /* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */
1098 extern struct timezone sys_tz;
1100 static int utc2local(int time)
1102 return time - sys_tz.tz_minuteswest * 60;
1105 static int local2utc(int time)
1107 return time + sys_tz.tz_minuteswest * 60;
1110 /* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70). */
1112 ncp_date_dos2unix(unsigned short time, unsigned short date)
1114 int month, year, secs;
1116 /* first subtract and mask after that... Otherwise, if
1117 date == 0, bad things happen */
1118 month = ((date >> 5) - 1) & 15;
1120 secs = (time & 31) * 2 + 60 * ((time >> 5) & 63) + (time >> 11) * 3600 +
1121 86400 * ((date & 31) - 1 + day_n[month] + (year / 4) +
1122 year * 365 - ((year & 3) == 0 && month < 2 ? 1 : 0) + 3653);
1123 /* days since 1.1.70 plus 80's leap day */
1124 return local2utc(secs);
1128 /* Convert linear UNIX date to a MS-DOS time/date pair. */
1130 ncp_date_unix2dos(int unix_date, unsigned short *time, unsigned short *date)
1132 int day, year, nl_day, month;
1134 unix_date = utc2local(unix_date);
1135 *time = (unix_date % 60) / 2 + (((unix_date / 60) % 60) << 5) +
1136 (((unix_date / 3600) % 24) << 11);
1137 day = unix_date / 86400 - 3652;
1139 if ((year + 3) / 4 + 365 * year > day)
1141 day -= (year + 3) / 4 + 365 * year;
1142 if (day == 59 && !(year & 3)) {
1146 nl_day = (year & 3) || day <= 59 ? day : day - 1;
1147 for (month = 0; month < 12; month++)
1148 if (day_n[month] > nl_day)
1151 *date = nl_day - day_n[month - 1] + 1 + (month << 5) + (year << 9);