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 = dentry->d_name.len + 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 if (ncp_is_server_root(dir)) {
295 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
298 res = ncp_lookup_volume(server, __name, &(finfo.i));
300 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
301 len-1, !ncp_preserve_case(dir));
303 res = ncp_obtain_info(server, dir, __name, &(finfo.i));
305 DDPRINTK("ncp_lookup_validate: looked for %s/%s, res=%d\n",
306 dentry->d_parent->d_name.name, __name, res);
308 * If we didn't find it, or if it has a different dirEntNum to
309 * what we remember, it's not valid any more.
312 if (finfo.i.dirEntNum == NCP_FINFO(dentry->d_inode)->dirEntNum) {
313 ncp_new_dentry(dentry);
316 DDPRINTK("ncp_lookup_validate: found, but dirEntNum changed\n");
318 ncp_update_inode2(dentry->d_inode, &finfo);
322 DDPRINTK("ncp_lookup_validate: result=%d\n", val);
327 ncp_lookup_validate(struct dentry * dentry, int flags)
331 res = __ncp_lookup_validate(dentry, flags);
336 static struct dentry *
337 ncp_dget_fpos(struct dentry *dentry, struct dentry *parent, unsigned long fpos)
339 struct dentry *dent = dentry;
340 struct list_head *next;
342 if (d_validate(dent, parent)) {
343 if (dent->d_name.len <= NCP_MAXPATHLEN &&
344 (unsigned long)dent->d_fsdata == fpos) {
345 if (!dent->d_inode) {
354 /* If a pointer is invalid, we search the dentry. */
355 spin_lock(&dcache_lock);
356 next = parent->d_subdirs.next;
357 while (next != &parent->d_subdirs) {
358 dent = list_entry(next, struct dentry, d_child);
359 if ((unsigned long)dent->d_fsdata == fpos) {
364 spin_unlock(&dcache_lock);
369 spin_unlock(&dcache_lock);
376 static time_t ncp_obtain_mtime(struct dentry *dentry)
378 struct inode *inode = dentry->d_inode;
379 struct ncp_server *server = NCP_SERVER(inode);
380 struct nw_info_struct i;
382 if (!ncp_conn_valid(server) || ncp_is_server_root(inode))
385 if (ncp_obtain_info(server, inode, NULL, &i))
388 return ncp_date_dos2unix(le16_to_cpu(i.modifyTime),
389 le16_to_cpu(i.modifyDate));
392 static int ncp_readdir(struct file *filp, void *dirent, filldir_t filldir)
394 struct dentry *dentry = filp->f_dentry;
395 struct inode *inode = dentry->d_inode;
396 struct page *page = NULL;
397 struct ncp_server *server = NCP_SERVER(inode);
398 union ncp_dir_cache *cache = NULL;
399 struct ncp_cache_control ctl;
400 int result, mtime_valid = 0;
406 DDPRINTK("ncp_readdir: reading %s/%s, pos=%d\n",
407 dentry->d_parent->d_name.name, dentry->d_name.name,
411 if (!ncp_conn_valid(server))
415 if (filp->f_pos == 0) {
416 if (filldir(dirent, ".", 1, 0, inode->i_ino, DT_DIR))
420 if (filp->f_pos == 1) {
421 if (filldir(dirent, "..", 2, 1,
422 dentry->d_parent->d_inode->i_ino, DT_DIR))
427 page = grab_cache_page(&inode->i_data, 0);
431 ctl.cache = cache = kmap(page);
432 ctl.head = cache->head;
434 if (!Page_Uptodate(page) || !ctl.head.eof)
437 if (filp->f_pos == 2) {
438 if (jiffies - ctl.head.time >= NCP_MAX_AGE(server))
441 mtime = ncp_obtain_mtime(dentry);
443 if ((!mtime) || (mtime != ctl.head.mtime))
447 if (filp->f_pos > ctl.head.end)
450 ctl.fpos = filp->f_pos + (NCP_DIRCACHE_START - 2);
451 ctl.ofs = ctl.fpos / NCP_DIRCACHE_SIZE;
452 ctl.idx = ctl.fpos % NCP_DIRCACHE_SIZE;
456 ctl.page = find_lock_page(&inode->i_data, ctl.ofs);
459 ctl.cache = kmap(ctl.page);
460 if (!Page_Uptodate(ctl.page))
463 while (ctl.idx < NCP_DIRCACHE_SIZE) {
467 dent = ncp_dget_fpos(ctl.cache->dentry[ctl.idx],
468 dentry, filp->f_pos);
471 res = filldir(dirent, dent->d_name.name,
472 dent->d_name.len, filp->f_pos,
473 dent->d_inode->i_ino, DT_UNKNOWN);
479 if (filp->f_pos > ctl.head.end)
484 SetPageUptodate(ctl.page);
485 UnlockPage(ctl.page);
486 page_cache_release(ctl.page);
495 UnlockPage(ctl.page);
496 page_cache_release(ctl.page);
501 ncp_invalidate_dircache_entries(dentry);
503 mtime = ncp_obtain_mtime(dentry);
506 ctl.head.mtime = mtime;
507 ctl.head.time = jiffies;
511 ctl.idx = NCP_DIRCACHE_START;
515 if (ncp_is_server_root(inode)) {
516 ncp_read_volume_list(filp, dirent, filldir, &ctl);
518 ncp_do_readdir(filp, dirent, filldir, &ctl);
520 ctl.head.end = ctl.fpos - 1;
521 ctl.head.eof = ctl.valid;
524 cache->head = ctl.head;
526 SetPageUptodate(page);
528 page_cache_release(page);
532 SetPageUptodate(ctl.page);
533 UnlockPage(ctl.page);
534 page_cache_release(ctl.page);
541 ncp_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
542 struct ncp_cache_control *ctrl, struct ncp_entry_info *entry)
544 struct dentry *newdent, *dentry = filp->f_dentry;
545 struct inode *newino, *inode = dentry->d_inode;
546 struct ncp_cache_control ctl = *ctrl;
554 if (ncp_vol2io(NCP_SERVER(inode), __name, &qname.len,
555 entry->i.entryName, entry->i.nameLen,
556 !ncp_preserve_entry_case(inode, entry->i.NSCreator)))
557 return 1; /* I'm not sure */
560 qname.hash = full_name_hash(qname.name, qname.len);
562 if (dentry->d_op && dentry->d_op->d_hash)
563 if (dentry->d_op->d_hash(dentry, &qname) != 0)
566 newdent = d_lookup(dentry, &qname);
569 newdent = d_alloc(dentry, &qname);
574 memcpy((char *) newdent->d_name.name, qname.name,
575 newdent->d_name.len);
578 if (!newdent->d_inode) {
580 entry->ino = iunique(inode->i_sb, 2);
581 newino = ncp_iget(inode->i_sb, entry);
583 newdent->d_op = &ncp_dentry_operations;
584 d_instantiate(newdent, newino);
589 ncp_update_inode2(newdent->d_inode, entry);
591 if (newdent->d_inode) {
592 ino = newdent->d_inode->i_ino;
593 newdent->d_fsdata = (void *) ctl.fpos;
594 ncp_new_dentry(newdent);
597 if (ctl.idx >= NCP_DIRCACHE_SIZE) {
600 SetPageUptodate(ctl.page);
601 UnlockPage(ctl.page);
602 page_cache_release(ctl.page);
605 ctl.idx -= NCP_DIRCACHE_SIZE;
607 ctl.page = grab_cache_page(&inode->i_data, ctl.ofs);
609 ctl.cache = kmap(ctl.page);
612 ctl.cache->dentry[ctl.idx] = newdent;
619 if (!ctl.filled && (ctl.fpos == filp->f_pos)) {
621 ino = find_inode_number(dentry, &qname);
623 ino = iunique(inode->i_sb, 2);
624 ctl.filled = filldir(dirent, qname.name, qname.len,
625 filp->f_pos, ino, DT_UNKNOWN);
632 return (ctl.valid || !ctl.filled);
636 ncp_read_volume_list(struct file *filp, void *dirent, filldir_t filldir,
637 struct ncp_cache_control *ctl)
639 struct dentry *dentry = filp->f_dentry;
640 struct inode *inode = dentry->d_inode;
641 struct ncp_server *server = NCP_SERVER(inode);
642 struct ncp_volume_info info;
643 struct ncp_entry_info entry;
646 DPRINTK("ncp_read_volume_list: pos=%ld\n",
647 (unsigned long) filp->f_pos);
649 for (i = 0; i < NCP_NUMBER_OF_VOLUMES; i++) {
651 if (ncp_get_volume_info_with_number(server, i, &info) != 0)
653 if (!strlen(info.volume_name))
656 DPRINTK("ncp_read_volume_list: found vol: %s\n",
659 if (ncp_lookup_volume(server, info.volume_name,
661 DPRINTK("ncpfs: could not lookup vol %s\n",
665 if (!ncp_fill_cache(filp, dirent, filldir, ctl, &entry))
671 ncp_do_readdir(struct file *filp, void *dirent, filldir_t filldir,
672 struct ncp_cache_control *ctl)
674 struct dentry *dentry = filp->f_dentry;
675 struct inode *dir = dentry->d_inode;
676 struct ncp_server *server = NCP_SERVER(dir);
677 struct nw_search_sequence seq;
678 struct ncp_entry_info entry;
681 DPRINTK("ncp_do_readdir: %s/%s, fpos=%ld\n",
682 dentry->d_parent->d_name.name, dentry->d_name.name,
683 (unsigned long) filp->f_pos);
684 PPRINTK("ncp_do_readdir: init %s, volnum=%d, dirent=%u\n",
685 dentry->d_name.name, NCP_FINFO(dir)->volNumber,
686 NCP_FINFO(dir)->dirEntNum);
688 err = ncp_initialize_search(server, dir, &seq);
690 DPRINTK("ncp_do_readdir: init failed, err=%d\n", err);
694 err = ncp_search_for_file_or_subdir(server, &seq, &entry.i);
696 DPRINTK("ncp_do_readdir: search failed, err=%d\n", err);
699 if (!ncp_fill_cache(filp, dirent, filldir, ctl, &entry))
704 int ncp_conn_logged_in(struct super_block *sb)
706 struct ncp_server* server = NCP_SBP(sb);
707 struct nw_info_struct i;
708 int result, len = strlen(server->m.mounted_vol) + 1;
711 if (ncp_single_volume(server)) {
715 if (ncp_io2vol(server, __name, &len, server->m.mounted_vol,
718 if (ncp_lookup_volume(server, __name, &i)) {
719 PPRINTK("ncp_conn_logged_in: %s not found\n",
720 server->m.mounted_vol);
725 struct inode* ino = dent->d_inode;
727 NCP_FINFO(ino)->volNumber = i.volNumber;
728 NCP_FINFO(ino)->dirEntNum = i.dirEntNum;
729 NCP_FINFO(ino)->DosDirNum = i.DosDirNum;
731 DPRINTK("ncpfs: sb->s_root->d_inode == NULL!\n");
734 DPRINTK("ncpfs: sb->s_root == NULL!\n");
743 static struct dentry *ncp_lookup(struct inode *dir, struct dentry *dentry)
745 struct ncp_server *server = NCP_SERVER(dir);
746 struct inode *inode = NULL;
747 struct ncp_entry_info finfo;
748 int error, res, len = dentry->d_name.len + 1;
752 if (!ncp_conn_valid(server))
755 PPRINTK("ncp_lookup: server lookup for %s/%s\n",
756 dentry->d_parent->d_name.name, dentry->d_name.name);
758 if (ncp_is_server_root(dir)) {
759 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
762 res = ncp_lookup_volume(server, __name, &(finfo.i));
764 res = ncp_io2vol(server, __name, &len, dentry->d_name.name,
765 len-1, !ncp_preserve_case(dir));
767 res = ncp_obtain_info(server, dir, __name, &(finfo.i));
769 PPRINTK("ncp_lookup: looked for %s/%s, res=%d\n",
770 dentry->d_parent->d_name.name, __name, res);
772 * If we didn't find an entry, make a negative dentry.
778 * Create an inode for the entry.
781 finfo.ino = iunique(dir->i_sb, 2);
783 inode = ncp_iget(dir->i_sb, &finfo);
786 ncp_new_dentry(dentry);
788 dentry->d_op = &ncp_dentry_operations;
789 d_add(dentry, inode);
794 PPRINTK("ncp_lookup: result=%d\n", error);
795 return ERR_PTR(error);
799 * This code is common to create, mkdir, and mknod.
801 static int ncp_instantiate(struct inode *dir, struct dentry *dentry,
802 struct ncp_entry_info *finfo)
807 finfo->ino = iunique(dir->i_sb, 2);
808 inode = ncp_iget(dir->i_sb, finfo);
811 d_instantiate(dentry,inode);
817 PPRINTK("ncp_instantiate: %s/%s failed, closing file\n",
818 dentry->d_parent->d_name.name, dentry->d_name.name);
819 ncp_close_file(NCP_SERVER(dir), finfo->file_handle);
823 int ncp_create_new(struct inode *dir, struct dentry *dentry, int mode,
826 struct ncp_server *server = NCP_SERVER(dir);
827 struct ncp_entry_info finfo;
828 int error, result, len = dentry->d_name.len + 1;
832 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
833 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
835 if (!ncp_conn_valid(server))
838 ncp_age_dentry(server, dentry);
839 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
840 len-1, !ncp_preserve_case(dir));
847 (server->m.flags & NCP_MOUNT_EXTRAS) &&
849 attributes |= aSYSTEM | aSHARED;
851 result = ncp_open_create_file_or_subdir(server, dir, __name,
852 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
853 attributes, AR_READ | AR_WRITE, &finfo);
856 result = ncp_open_create_file_or_subdir(server, dir, __name,
857 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
858 attributes, AR_WRITE, &finfo);
861 error = -ENAMETOOLONG;
862 DPRINTK("ncp_create: %s/%s failed\n",
863 dentry->d_parent->d_name.name, dentry->d_name.name);
868 finfo.access = opmode;
869 error = ncp_instantiate(dir, dentry, &finfo);
874 static int ncp_create(struct inode *dir, struct dentry *dentry, int mode)
876 return ncp_create_new(dir, dentry, mode, 0);
879 static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
881 struct ncp_entry_info finfo;
882 struct ncp_server *server = NCP_SERVER(dir);
883 int error, len = dentry->d_name.len + 1;
886 DPRINTK("ncp_mkdir: making %s/%s\n",
887 dentry->d_parent->d_name.name, dentry->d_name.name);
889 if (!ncp_conn_valid(server))
892 ncp_age_dentry(server, dentry);
893 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
894 len-1, !ncp_preserve_case(dir));
899 if (ncp_open_create_file_or_subdir(server, dir, __name,
900 OC_MODE_CREATE, aDIR, 0xffff,
903 error = ncp_instantiate(dir, dentry, &finfo);
909 static int ncp_rmdir(struct inode *dir, struct dentry *dentry)
911 struct ncp_server *server = NCP_SERVER(dir);
912 int error, result, len = dentry->d_name.len + 1;
915 DPRINTK("ncp_rmdir: removing %s/%s\n",
916 dentry->d_parent->d_name.name, dentry->d_name.name);
919 if (!ncp_conn_valid(server))
923 if (!d_unhashed(dentry))
926 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
927 len-1, !ncp_preserve_case(dir));
931 result = ncp_del_file_or_subdir(server, dir, __name);
936 case 0x85: /* unauthorized to delete file */
937 case 0x8A: /* unauthorized to delete file */
941 case 0x90: /* read only */
944 case 0x9F: /* in use by another client */
947 case 0xA0: /* directory not empty */
950 case 0xFF: /* someone deleted file */
961 static int ncp_unlink(struct inode *dir, struct dentry *dentry)
963 struct inode *inode = dentry->d_inode;
964 struct ncp_server *server = NCP_SERVER(dir);
967 DPRINTK("ncp_unlink: unlinking %s/%s\n",
968 dentry->d_parent->d_name.name, dentry->d_name.name);
971 if (!ncp_conn_valid(server))
975 * Check whether to close the file ...
978 PPRINTK("ncp_unlink: closing file\n");
979 ncp_make_closed(inode);
982 error = ncp_del_file_or_subdir2(server, dentry);
983 #ifdef CONFIG_NCPFS_STRONG
984 /* 9C is Invalid path.. It should be 8F, 90 - read only, but
986 if ((error == 0x9C || error == 0x90) && server->m.flags & NCP_MOUNT_STRONG) { /* R/O */
987 error = ncp_force_unlink(dir, dentry);
992 DPRINTK("ncp: removed %s/%s\n",
993 dentry->d_parent->d_name.name, dentry->d_name.name);
999 case 0x8D: /* some files in use */
1000 case 0x8E: /* all files in use */
1003 case 0x8F: /* some read only */
1004 case 0x90: /* all read only */
1005 case 0x9C: /* !!! returned when in-use or read-only by NW4 */
1020 static int ncp_rename(struct inode *old_dir, struct dentry *old_dentry,
1021 struct inode *new_dir, struct dentry *new_dentry)
1023 struct ncp_server *server = NCP_SERVER(old_dir);
1025 int old_len = old_dentry->d_name.len + 1;
1026 int new_len = new_dentry->d_name.len + 1;
1027 __u8 __old_name[old_len], __new_name[new_len];
1029 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
1030 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
1031 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
1034 if (!ncp_conn_valid(server))
1037 ncp_age_dentry(server, old_dentry);
1038 ncp_age_dentry(server, new_dentry);
1040 error = ncp_io2vol(server, __old_name, &old_len,
1041 old_dentry->d_name.name, old_len-1,
1042 !ncp_preserve_case(old_dir));
1046 error = ncp_io2vol(server, __new_name, &new_len,
1047 new_dentry->d_name.name, new_len-1,
1048 !ncp_preserve_case(new_dir));
1052 error = ncp_ren_or_mov_file_or_subdir(server, old_dir, __old_name,
1053 new_dir, __new_name);
1054 #ifdef CONFIG_NCPFS_STRONG
1055 if ((error == 0x90 || error == 0x8B || error == -EACCES) &&
1056 server->m.flags & NCP_MOUNT_STRONG) { /* RO */
1057 error = ncp_force_rename(old_dir, old_dentry, __old_name,
1058 new_dir, new_dentry, __new_name);
1063 DPRINTK("ncp renamed %s -> %s.\n",
1064 old_dentry->d_name.name,new_dentry->d_name.name);
1067 error = -ENAMETOOLONG;
1080 /* The following routines are taken directly from msdos-fs */
1082 /* Linear day numbers of the respective 1sts in non-leap years. */
1084 static int day_n[] =
1085 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0, 0};
1086 /* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */
1089 extern struct timezone sys_tz;
1091 static int utc2local(int time)
1093 return time - sys_tz.tz_minuteswest * 60;
1096 static int local2utc(int time)
1098 return time + sys_tz.tz_minuteswest * 60;
1101 /* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70). */
1103 ncp_date_dos2unix(unsigned short time, unsigned short date)
1105 int month, year, secs;
1107 /* first subtract and mask after that... Otherwise, if
1108 date == 0, bad things happen */
1109 month = ((date >> 5) - 1) & 15;
1111 secs = (time & 31) * 2 + 60 * ((time >> 5) & 63) + (time >> 11) * 3600 +
1112 86400 * ((date & 31) - 1 + day_n[month] + (year / 4) +
1113 year * 365 - ((year & 3) == 0 && month < 2 ? 1 : 0) + 3653);
1114 /* days since 1.1.70 plus 80's leap day */
1115 return local2utc(secs);
1119 /* Convert linear UNIX date to a MS-DOS time/date pair. */
1121 ncp_date_unix2dos(int unix_date, unsigned short *time, unsigned short *date)
1123 int day, year, nl_day, month;
1125 unix_date = utc2local(unix_date);
1126 *time = (unix_date % 60) / 2 + (((unix_date / 60) % 60) << 5) +
1127 (((unix_date / 3600) % 24) << 11);
1128 day = unix_date / 86400 - 3652;
1130 if ((year + 3) / 4 + 365 * year > day)
1132 day -= (year + 3) / 4 + 365 * year;
1133 if (day == 59 && !(year & 3)) {
1137 nl_day = (year & 3) || day <= 59 ? day : day - 1;
1138 for (month = 0; month < 12; month++)
1139 if (day_n[month] > nl_day)
1142 *date = nl_day - day_n[month - 1] + 1 + (month << 5) + (year << 9);