diff options
author | Ralf Baechle <ralf@linux-mips.org> | 1997-12-06 23:51:34 +0000 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 1997-12-06 23:51:34 +0000 |
commit | 230e5ab6a084ed50470f101934782dbf54b0d06b (patch) | |
tree | 5dd821c8d33f450470588e7a543f74bf74306e9e /fs/ncpfs/dir.c | |
parent | c9b1c8a64c6444d189856f1e26bdcb8b4cd0113a (diff) |
Merge with Linux 2.1.67.
Diffstat (limited to 'fs/ncpfs/dir.c')
-rw-r--r-- | fs/ncpfs/dir.c | 1314 |
1 files changed, 662 insertions, 652 deletions
diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c index 58e1bd187..005431485 100644 --- a/fs/ncpfs/dir.c +++ b/fs/ncpfs/dir.c @@ -3,6 +3,7 @@ * * Copyright (C) 1995, 1996 by Volker Lendecke * Modified for big endian by J.F. Chadima and David S. Miller + * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache * */ @@ -13,13 +14,18 @@ #include <linux/malloc.h> #include <linux/vmalloc.h> #include <linux/mm.h> -#include <linux/ncp_fs.h> #include <asm/uaccess.h> #include <asm/byteorder.h> #include <linux/errno.h> #include <linux/locks.h> + +#include <linux/ncp_fs.h> #include "ncplib_kernel.h" +#ifndef shrink_dcache_parent +#define shrink_dcache_parent(dentry) shrink_dcache_sb((dentry)->d_sb) +#endif + struct ncp_dirent { struct nw_info_struct i; @@ -27,79 +33,30 @@ struct ncp_dirent { unsigned long f_pos; }; -static long - ncp_dir_read(struct inode *inode, struct file *filp, char *buf, unsigned long count); - -static int - ncp_readdir(struct file *filp, - void *dirent, filldir_t filldir); - -static int - ncp_read_volume_list(struct ncp_server *server, int start_with, - int cache_size); - -static int - ncp_do_readdir(struct ncp_server *server, struct inode *dir, int fpos, - int cache_size, struct ncp_dirent *entry); - -static struct inode * - ncp_iget(struct inode *dir, struct nw_file_info *finfo); - -static struct ncp_inode_info * - ncp_find_dir_inode(struct inode *dir, const char *name); - -static int - ncp_lookup(struct inode *dir, const char *__name, - int len, struct inode **result); - -static int - ncp_create(struct inode *dir, const char *name, int len, int mode, - struct inode **result); - -static int - ncp_mkdir(struct inode *dir, const char *name, int len, int mode); - -static int - ncp_rmdir(struct inode *dir, const char *name, int len); - -static int - ncp_unlink(struct inode *dir, const char *name, int len); +static kdev_t c_dev = 0; +static unsigned long c_ino = 0; +static int c_size; +static int c_seen_eof; +static int c_last_returned_index; +static struct ncp_dirent *c_entry = NULL; +static int c_lock = 0; +static struct wait_queue *c_wait = NULL; -static int - ncp_rename(struct inode *old_dir, const char *old_name, int old_len, - struct inode *new_dir, const char *new_name, int new_len); +static int ncp_read_volume_list(struct ncp_server *, int, int, + struct ncp_dirent *); +static int ncp_do_readdir(struct ncp_server *, struct dentry *, int, int, + struct ncp_dirent *); -static inline void str_upper(char *name) -{ - while (*name) { - if (*name >= 'a' && *name <= 'z') { - *name -= ('a' - 'A'); - } - name++; - } -} - -static inline void str_lower(char *name) -{ - while (*name) { - if (*name >= 'A' && *name <= 'Z') { - *name += ('a' - 'A'); - } - name++; - } -} +static ssize_t ncp_dir_read(struct file *, char *, size_t, loff_t *); +static int ncp_readdir(struct file *, void *, filldir_t); -static inline int ncp_namespace(struct inode *i) -{ - struct ncp_server *server = NCP_SERVER(i); - struct nw_info_struct *info = NCP_ISTRUCT(i); - return server->name_space[info->volNumber]; -} - -static inline int ncp_preserve_case(struct inode *i) -{ - return (ncp_namespace(i) == NW_NS_OS2); -} +static int ncp_create(struct inode *, struct dentry *, int); +static int ncp_lookup(struct inode *, struct dentry *); +static int ncp_unlink(struct inode *, struct dentry *); +static int ncp_mkdir(struct inode *, struct dentry *, int); +static int ncp_rmdir(struct inode *, struct dentry *); +static int ncp_rename(struct inode *, struct dentry *, + struct inode *, struct dentry *); static struct file_operations ncp_dir_operations = { @@ -128,74 +85,173 @@ struct inode_operations ncp_dir_inode_operations = NULL, /* mknod */ ncp_rename, /* rename */ NULL, /* readlink */ + NULL, /* follow link */ + NULL, /* readpage */ + NULL, /* writepage */ NULL, /* bmap */ NULL, /* truncate */ NULL, /* permission */ - NULL /* smap */ + NULL, /* smap */ + NULL, /* updatepage */ + NULL, /* revalidate */ }; +static ssize_t +ncp_dir_read(struct file *filp, char *buf, size_t count, loff_t *ppos) +{ + return -EISDIR; +} -/* Here we encapsulate the inode number handling that depends upon the - * mount mode: When we mount a complete server, the memory address of - * the ncp_inode_info is used as the inode number. When only a single - * volume is mounted, then the dirEntNum is used as the inode - * number. As this is unique for the complete volume, this should - * enable the NFS exportability of a ncpfs-mounted volume. +/* + * Dentry operations routines */ +static int ncp_lookup_validate(struct dentry *); +static void ncp_delete_dentry(struct dentry *); +static int ncp_hash_dentry(struct dentry *, struct qstr *); +static int ncp_compare_dentry (struct dentry *, struct qstr *, struct qstr *); -static inline int ncp_single_volume(struct ncp_server *server) +static struct dentry_operations ncp_dentry_operations = { - return (server->m.mounted_vol[0] != '\0'); -} + ncp_lookup_validate, /* d_validate(struct dentry *) */ + ncp_hash_dentry, /* d_hash */ + ncp_compare_dentry, /* d_compare */ + ncp_delete_dentry /* d_delete(struct dentry *) */ +}; + + +/* + * XXX: It would be better to use the tolower from linux/ctype.h, + * but _ctype is needed and it is not exported. + */ +#define tolower(c) (((c) >= 'A' && (c) <= 'Z') ? (c)-('A'-'a') : (c)) + -inline ino_t - ncp_info_ino(struct ncp_server * server, struct ncp_inode_info * info) +static int +ncp_hash_dentry(struct dentry *dentry, struct qstr *this) { - return ncp_single_volume(server) - ? info->finfo.i.dirEntNum : (ino_t) info; + unsigned long hash; + int i; + + hash = init_name_hash(); + for (i=0; i<this->len ; i++) + hash = partial_name_hash(tolower(this->name[i]),hash); + this->hash = end_name_hash(hash); + + return 0; } -static inline int ncp_is_server_root(struct inode *inode) +static int +ncp_compare_dentry(struct dentry *dentry, struct qstr *a, struct qstr *b) { - struct ncp_server *s = NCP_SERVER(inode); + int i; + + if (a->len != b->len) return 1; + + if (ncp_case_sensitive(dentry->d_inode)) + return strncmp(a->name, b->name, a->len); + + for (i=0; i<a->len; i++) + if (tolower(a->name[i]) != tolower(b->name[i])) + return 1; - return ((!ncp_single_volume(s)) - && (inode->i_ino == ncp_info_ino(s, &(s->root)))); + return 0; } -struct ncp_inode_info * - ncp_find_inode(struct inode *inode) +/* + * This is the callback from dput() when d_count is going to 0. + * We use this to unhash dentries with bad inodes and close files. + */ +static void +ncp_delete_dentry(struct dentry * dentry) { - struct ncp_server *server = NCP_SERVER(inode); - struct ncp_inode_info *root = &(server->root); - struct ncp_inode_info *this = root; - - ino_t ino = inode->i_ino; + struct inode *inode = dentry->d_inode; - do { - if (ino == ncp_info_ino(server, this)) { - return this; + if (inode) + { + if (is_bad_inode(inode)) + { + d_drop(dentry); } - this = this->next; + /* + * Lock the superblock, then recheck the dentry count. + * (Somebody might have used it again ...) + */ + if (dentry->d_count == 1 && NCP_FINFO(inode)->opened) { +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_delete_dentry: closing file %s/%s\n", +dentry->d_parent->d_name.name, dentry->d_name.name); +#endif + ncp_make_closed(inode); + } + } else + { + /* N.B. Unhash negative dentries? */ + } +} + +/* Here we encapsulate the inode number handling that depends upon the + * mount mode: When we mount a complete server, the memory address of + * the ncp_inode_info is used as the inode number. When only a single + * volume is mounted, then the dirEntNum is used as the inode + * number. As this is unique for the complete volume, this should + * enable the NFS exportability of a ncpfs-mounted volume. + */ + +/* + * Generate a unique inode number. + */ +ino_t ncp_invent_inos(unsigned long n) +{ + static ino_t ino = 1; + + if (ino + 2*n < ino) + { + /* wrap around */ + ino += n; } - while (this != root); + ino += n; + return ino; +} - return NULL; +/* + * Check whether a dentry already exists for the given name, + * and return the inode number if it has an inode. This is + * needed to keep getcwd() working. + */ +static ino_t +find_inode_number(struct dentry *dir, struct qstr *name) +{ + unsigned long hash; + int i; + struct dentry * dentry; + ino_t ino = 0; + + hash = init_name_hash(); + for (i=0; i<name->len ; i++) + hash = partial_name_hash(tolower(name->name[i]),hash); + name->hash = end_name_hash(hash); + + dentry = d_lookup(dir, name); + if (dentry) + { + if (dentry->d_inode) + ino = dentry->d_inode->i_ino; + dput(dentry); + } + return ino; } -static long ncp_dir_read(struct inode *inode, struct file *filp, char *buf, unsigned long count) +static inline int +ncp_single_volume(struct ncp_server *server) { - return -EISDIR; + return (server->m.mounted_vol[0] != '\0'); } -static kdev_t c_dev = 0; -static unsigned long c_ino = 0; -static int c_size; -static int c_seen_eof; -static int c_last_returned_index; -static struct ncp_dirent *c_entry = NULL; -static int c_lock = 0; -static struct wait_queue *c_wait = NULL; +static inline int ncp_is_server_root(struct inode *inode) +{ + return (!ncp_single_volume(NCP_SERVER(inode)) && + inode == inode->i_sb->s_root->d_inode); +} static inline void ncp_lock_dircache(void) { @@ -210,54 +266,146 @@ static inline void ncp_unlock_dircache(void) wake_up(&c_wait); } -static int ncp_readdir(struct file *filp, - void *dirent, filldir_t filldir) + +/* + * This is the callback when the dcache has a lookup hit. + */ + +static int +ncp_lookup_validate(struct dentry * dentry) { - int result = 0; - int i = 0; - int index = 0; - struct inode *inode = file->f_dentry->d_inode; - struct ncp_dirent *entry = NULL; + struct ncp_server *server; + struct inode *dir = dentry->d_parent->d_inode; + int down_case = 0; + int val = 0,res; + int len = dentry->d_name.len; + struct ncpfs_inode_info finfo; + __u8 __name[dentry->d_name.len + 1]; + + if (!dentry->d_inode) { + DPRINTK(KERN_DEBUG "ncp_lookup_validate: called with dentry->d_inode already NULL.\n"); + return 0; + } + + if (!dir || !S_ISDIR(dir->i_mode)) { + printk(KERN_WARNING "ncp_lookup_validate: inode is NULL or not a directory.\n"); + goto finished; + } + server = NCP_SERVER(dir); + + if (!ncp_conn_valid(server)) + goto finished; + + strncpy(__name, dentry->d_name.name, len); + __name[len] = '\0'; +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_lookup_validate: %s, len %d\n", __name, len); +#endif + + if (!ncp_preserve_case(dir)) { + str_lower(__name); + down_case = 1; + } + + /* If the file is in the dir cache, we do not have to ask the + server. */ + +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_lookup_validate: server lookup for %s/%s\n", +dentry->d_parent->d_name.name, __name); +#endif + if (ncp_is_server_root(dir)) + { + str_upper(__name); + down_case = 1; + res = ncp_lookup_volume(server, __name, + &(finfo.nw_info.i)); + } else + { + if (!ncp_preserve_case(dir)) + { + str_upper(__name); + down_case = 1; + } + res = ncp_obtain_info(server, dir, __name, + &(finfo.nw_info.i)); + } +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_lookup_validate: looked for %s/%s, res=%d\n", +dentry->d_parent->d_name.name, __name, res); +#endif + /* + * If we didn't find it, or if it has a different dirEntNum to + * what we remember, it's not valid any more. + */ + if (!res) + if (finfo.nw_info.i.dirEntNum == NCP_FINFO(dentry->d_inode)->dirEntNum) + val=1; +#ifdef NCPFS_PARANOIA + else + printk(KERN_DEBUG "ncp_lookup_validate: found, but dirEntNum changed\n"); +#endif + if (!val) ncp_invalid_dir_cache(dir); + +finished: +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_lookup_validate: result=%d\n", val); +#endif + + return val; +} + + +static int ncp_readdir(struct file *filp, void *dirent, filldir_t filldir) +{ + struct dentry *dentry = filp->f_dentry; + struct inode *inode = dentry->d_inode; struct ncp_server *server = NCP_SERVER(inode); - struct ncp_inode_info *dir = NCP_INOP(inode); + struct ncp_dirent *entry = NULL; + int result, i, index = 0; - DDPRINTK("ncp_readdir: filp->f_pos = %d\n", (int) filp->f_pos); - DDPRINTK("ncp_readdir: inode->i_ino = %ld, c_ino = %ld\n", + DDPRINTK(KERN_DEBUG "ncp_readdir: reading %s/%s, pos=%d\n", + dentry->d_parent->d_name.name, dentry->d_name.name, + (int) filp->f_pos); + DDPRINTK(KERN_DEBUG "ncp_readdir: inode->i_ino = %ld, c_ino = %ld\n", inode->i_ino, c_ino); + result = -EBADF; if (!inode || !S_ISDIR(inode->i_mode)) { - printk("ncp_readdir: inode is NULL or not a directory\n"); - return -EBADF; - } - if (!ncp_conn_valid(server)) { - return -EIO; + printk(KERN_WARNING "ncp_readdir: inode is NULL or not a directory\n"); + goto out; } - ncp_lock_dircache(); + result = -EIO; + if (!ncp_conn_valid(server)) + goto out; + ncp_lock_dircache(); + result = -ENOMEM; if (c_entry == NULL) { i = sizeof(struct ncp_dirent) * NCP_READDIR_CACHE_SIZE; c_entry = (struct ncp_dirent *) vmalloc(i); if (c_entry == NULL) { - printk("ncp_readdir: no MEMORY for cache\n"); - result = -ENOMEM; + printk(KERN_WARNING "ncp_readdir: no MEMORY for cache\n"); goto finished; } } + + result = 0; if (filp->f_pos == 0) { ncp_invalid_dir_cache(inode); - if (filldir(dirent, ".", 1, filp->f_pos, - ncp_info_ino(server, dir)) < 0) { + if (filldir(dirent, ".", 1, 0, inode->i_ino) < 0) { goto finished; } - filp->f_pos += 1; + filp->f_pos = 1; } if (filp->f_pos == 1) { - if (filldir(dirent, "..", 2, filp->f_pos, - ncp_info_ino(server, dir->dir)) < 0) { + if (filldir(dirent, "..", 2, 1, + dentry->d_parent->d_inode->i_ino) < 0) { goto finished; } - filp->f_pos += 1; + filp->f_pos = 2; } + if ((inode->i_dev == c_dev) && (inode->i_ino == c_ino)) { for (i = 0; i < c_size; i++) { if (filp->f_pos == c_entry[i].f_pos) { @@ -273,18 +421,17 @@ static int ncp_readdir(struct file *filp, } if (entry == NULL) { int entries; - DDPRINTK("ncp_readdir: Not found in cache.\n"); + DDPRINTK(KERN_DEBUG "ncp_readdir: Not found in cache.\n"); if (ncp_is_server_root(inode)) { entries = ncp_read_volume_list(server, filp->f_pos, - NCP_READDIR_CACHE_SIZE); - DPRINTK("ncp_read_volume_list returned %d\n", entries); + NCP_READDIR_CACHE_SIZE, c_entry); + DPRINTK(KERN_DEBUG "ncp_read_volume_list returned %d\n", entries); } else { - entries = ncp_do_readdir(server, inode, filp->f_pos, - NCP_READDIR_CACHE_SIZE, - c_entry); - DPRINTK("ncp_readdir returned %d\n", entries); + entries = ncp_do_readdir(server, dentry, filp->f_pos, + NCP_READDIR_CACHE_SIZE, c_entry); + DPRINTK(KERN_DEBUG "ncp_readdir: returned %d\n", entries); } if (entries < 0) { @@ -313,31 +460,24 @@ static int ncp_readdir(struct file *filp, /* Nothing found, even from a ncp call */ goto finished; } + while (index < c_size) { ino_t ino; - - if (ncp_single_volume(server)) { - ino = (ino_t) (entry->i.dirEntNum); - } else { - /* For getwd() we have to return the correct - * inode in d_ino if the inode is currently in - * use. Otherwise the inode number does not - * matter. (You can argue a lot about this..) */ - struct ncp_inode_info *ino_info; - ino_info = ncp_find_dir_inode(inode, - entry->i.entryName); - - /* Some programs seem to be confused about a - * zero inode number, so we set it to one. - * Thanks to Gordon Chaffee for this one. */ - if (ino_info == NULL) { - ino_info = (struct ncp_inode_info *) 1; - } - ino = (ino_t) (ino_info); - } - - DDPRINTK("ncp_readdir: entry->path= %s\n", entry->i.entryName); - DDPRINTK("ncp_readdir: entry->f_pos = %ld\n", entry->f_pos); + struct qstr qname; + + DDPRINTK(KERN_DEBUG "ncp_readdir: entry->path= %s\n", entry->i.entryName); + DDPRINTK(KERN_DEBUG "ncp_readdir: entry->f_pos = %ld\n", entry->f_pos); + + /* For getwd() we have to return the correct + * inode in d_ino if the inode is currently in + * use. Otherwise the inode number does not + * matter. (You can argue a lot about this..) + */ + qname.name = entry->i.entryName; + qname.len = entry->i.nameLen; + ino = find_inode_number(dentry, &qname); + if (!ino) + ino = ncp_invent_inos(1); if (filldir(dirent, entry->i.entryName, entry->i.nameLen, entry->f_pos, ino) < 0) { @@ -356,103 +496,114 @@ static int ncp_readdir(struct file *filp, } finished: ncp_unlock_dircache(); +out: return result; } -static int ncp_read_volume_list(struct ncp_server *server, int fpos, int cache_size) +static int +ncp_read_volume_list(struct ncp_server *server, int fpos, + int cache_size, struct ncp_dirent *entry) { - struct ncp_dirent *entry = c_entry; - - int total_count = 2; - int i; + int i, total_count = 2; + struct ncp_volume_info info; + DPRINTK(KERN_DEBUG "ncp_read_volume_list: pos=%d\n", fpos); #if 1 if (fpos < 2) { - printk("OOPS, we expect fpos >= 2"); + printk(KERN_ERR "OOPS, we expect fpos >= 2"); fpos = 2; } #endif for (i = 0; i < NCP_NUMBER_OF_VOLUMES; i++) { - struct ncp_volume_info info; - if (ncp_get_volume_info_with_number(server, i, &info) != 0) { - return (total_count - fpos); - } - if (strlen(info.volume_name) > 0) { - if (total_count < fpos) { - DPRINTK("ncp_read_volumes: skipped vol: %s\n", - info.volume_name); - } else if (total_count >= fpos + cache_size) { - return (total_count - fpos); - } else { - DPRINTK("ncp_read_volumes: found vol: %s\n", - info.volume_name); + if (ncp_get_volume_info_with_number(server, i, &info) != 0) + goto out; + if (!strlen(info.volume_name)) + continue; - if (ncp_lookup_volume(server, - info.volume_name, - &(entry->i)) != 0) { - DPRINTK("ncpfs: could not lookup vol " - "%s\n", info.volume_name); - continue; - } - entry->f_pos = total_count; - entry += 1; + if (total_count < fpos) { + DPRINTK(KERN_DEBUG "ncp_read_volume_list: skipped vol: %s\n", + info.volume_name); + } else if (total_count >= fpos + cache_size) { + goto out; + } else { + DPRINTK(KERN_DEBUG "ncp_read_volume_list: found vol: %s\n", + info.volume_name); + + if (ncp_lookup_volume(server, info.volume_name, + &(entry->i)) != 0) { + DPRINTK(KERN_DEBUG "ncpfs: could not lookup vol %s\n", + info.volume_name); + continue; } - total_count += 1; + entry->f_pos = total_count; + entry += 1; } + total_count += 1; } +out: return (total_count - fpos); } -static int ncp_do_readdir(struct ncp_server *server, struct inode *dir, int fpos, - int cache_size, struct ncp_dirent *entry) +static int ncp_do_readdir(struct ncp_server *server, struct dentry *dentry, + int fpos, int cache_size, struct ncp_dirent *entry) { - static struct nw_search_sequence seq; + struct inode *dir = dentry->d_inode; static struct inode *last_dir; static int total_count; + static struct nw_search_sequence seq; + int err; #if 1 if (fpos < 2) { - printk("OOPS, we expect fpos >= 2"); + printk(KERN_ERR "OOPS, we expect fpos >= 2"); fpos = 2; } #endif - DPRINTK("ncp_do_readdir: fpos = %d\n", fpos); + DPRINTK(KERN_DEBUG "ncp_do_readdir: %s/%s, fpos=%d\n", + dentry->d_parent->d_name.name, dentry->d_name.name, fpos); if (fpos == 2) { last_dir = NULL; total_count = 2; } - if ((fpos != total_count) || (dir != last_dir)) { + if ((fpos != total_count) || (dir != last_dir)) + { total_count = 2; last_dir = dir; - - DPRINTK("ncp_do_readdir: re-used seq for %s\n", - NCP_ISTRUCT(dir)->entryName); - - if (ncp_initialize_search(server, NCP_ISTRUCT(dir), &seq) != 0) { - DPRINTK("ncp_init_search failed\n"); - return total_count - fpos; + +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_do_readdir: init %s, volnum=%d, dirent=%u\n", +dentry->d_name.name, NCP_FINFO(dir)->volNumber, NCP_FINFO(dir)->dirEntNum); +#endif + err = ncp_initialize_search(server, dir, &seq); + if (err) + { + DPRINTK(KERN_DEBUG "ncp_do_readdir: init failed, err=%d\n", err); + goto out; } } + while (total_count < fpos + cache_size) { - if (ncp_search_for_file_or_subdir(server, &seq, - &(entry->i)) != 0) { - return total_count - fpos; + err = ncp_search_for_file_or_subdir(server, &seq, &(entry->i)); + if (err) { + DPRINTK(KERN_DEBUG "ncp_do_readdir: search failed, err=%d\n", err); + goto out; } if (total_count < fpos) { - DPRINTK("ncp_do_readdir: skipped file: %s\n", - entry->i.entryName); + DPRINTK(KERN_DEBUG "ncp_do_readdir: skipped file: %s/%s\n", + dentry->d_name.name, entry->i.entryName); } else { - DDPRINTK("ncp_do_r: file: %s, f_pos=%d,total_count=%d", - entry->i.entryName, fpos, total_count); + DDPRINTK(KERN_DEBUG "ncp_do_r: file: %s, f_pos=%d,total_count=%d", + entry->i.entryName, fpos, total_count); entry->s = seq; entry->f_pos = total_count; entry += 1; } total_count += 1; } +out: return (total_count - fpos); } @@ -474,7 +625,7 @@ void ncp_invalid_dir_cache(struct inode *ino) void ncp_free_dir_cache(void) { - DPRINTK("ncp_free_dir_cache: enter\n"); + DPRINTK(KERN_DEBUG "ncp_free_dir_cache: enter\n"); if (c_entry == NULL) { return; @@ -482,540 +633,398 @@ void ncp_free_dir_cache(void) vfree(c_entry); c_entry = NULL; - DPRINTK("ncp_free_dir_cache: exit\n"); -} - - -static struct inode * - ncp_iget(struct inode *dir, struct nw_file_info *finfo) -{ - struct inode *inode; - struct ncp_inode_info *new_inode_info; - struct ncp_inode_info *root; - - if (dir == NULL) { - printk("ncp_iget: dir is NULL\n"); - return NULL; - } - if (finfo == NULL) { - printk("ncp_iget: finfo is NULL\n"); - return NULL; - } - new_inode_info = ncp_kmalloc(sizeof(struct ncp_inode_info), - GFP_KERNEL); - - if (new_inode_info == NULL) { - printk("ncp_iget: could not alloc mem for %s\n", - finfo->i.entryName); - return NULL; - } - new_inode_info->state = NCP_INODE_LOOKED_UP; - new_inode_info->nused = 0; - new_inode_info->dir = NCP_INOP(dir); - new_inode_info->finfo = *finfo; - - NCP_INOP(dir)->nused += 1; - - /* We have to link the new inode_info into the doubly linked - list of inode_infos to make a complete linear search - possible. */ - - root = &(NCP_SERVER(dir)->root); - - new_inode_info->prev = root; - new_inode_info->next = root->next; - root->next->prev = new_inode_info; - root->next = new_inode_info; - - if (!(inode = iget(dir->i_sb, ncp_info_ino(NCP_SERVER(dir), - new_inode_info)))) { - printk("ncp_iget: iget failed!"); - return NULL; - } - return inode; -} - -void ncp_free_inode_info(struct ncp_inode_info *i) -{ - if (i == NULL) { - printk("ncp_free_inode: i == NULL\n"); - return; - } - i->state = NCP_INODE_CACHED; - while ((i->nused == 0) && (i->state == NCP_INODE_CACHED)) { - struct ncp_inode_info *dir = i->dir; - - i->next->prev = i->prev; - i->prev->next = i->next; - - DDPRINTK("ncp_free_inode_info: freeing %s\n", - i->finfo.i.entryName); - - ncp_kfree_s(i, sizeof(struct ncp_inode_info)); - - if (dir == i) - return; - - (dir->nused)--; - i = dir; - } -} - -void ncp_init_root(struct ncp_server *server) -{ - struct ncp_inode_info *root = &(server->root); - struct nw_info_struct *i = &(root->finfo.i); - unsigned short dummy; - - DPRINTK("ncp_init_root: i = %x\n", (int) i); - - root->finfo.opened = 0; - i->attributes = aDIR; - i->dataStreamSize = 1024; - i->dirEntNum = i->DosDirNum = 0; - i->volNumber = NCP_NUMBER_OF_VOLUMES + 1; /* illegal volnum */ - ncp_date_unix2dos(0, &(i->creationTime), &(i->creationDate)); - ncp_date_unix2dos(0, &(i->modifyTime), &(i->modifyDate)); - ncp_date_unix2dos(0, &dummy, &(i->lastAccessDate)); - i->creationTime = le16_to_cpu(i->creationTime); - i->creationDate = le16_to_cpu(i->creationDate); - i->modifyTime = le16_to_cpu(i->modifyTime); - i->modifyDate = le16_to_cpu(i->modifyDate); - i->lastAccessDate = le16_to_cpu(i->lastAccessDate); - i->nameLen = 0; - i->entryName[0] = '\0'; - - root->state = NCP_INODE_LOOKED_UP; - root->nused = 1; - root->dir = root; - root->next = root->prev = root; - return; + DPRINTK(KERN_DEBUG "ncp_free_dir_cache: exit\n"); } int ncp_conn_logged_in(struct ncp_server *server) { - if (server->m.mounted_vol[0] == '\0') { - return 0; - } - str_upper(server->m.mounted_vol); - if (ncp_lookup_volume(server, server->m.mounted_vol, - &(server->root.finfo.i)) != 0) { - return -ENOENT; - } - str_lower(server->root.finfo.i.entryName); - - return 0; -} - -void ncp_free_all_inodes(struct ncp_server *server) -{ - /* Here nothing should be to do. I do not know whether it's - better to leave some memory allocated or be stuck in an - endless loop */ -#if 1 - struct ncp_inode_info *root = &(server->root); - - if (root->next != root) { - printk("ncp_free_all_inodes: INODES LEFT!!!\n"); - } - while (root->next != root) { - printk("ncp_free_all_inodes: freeing inode\n"); - ncp_free_inode_info(root->next); - /* In case we have an endless loop.. */ - schedule(); - } + int result; + + if (ncp_single_volume(server)) { + result = -ENOENT; + str_upper(server->m.mounted_vol); + if (ncp_lookup_volume(server, server->m.mounted_vol, + &(server->root.finfo.i)) != 0) { +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_conn_logged_in: %s not found\n", server->m.mounted_vol); #endif - - return; -} - -/* We will search the inode that belongs to this name, currently by a - complete linear search through the inodes belonging to this - filesystem. This has to be fixed. */ -static struct ncp_inode_info * - ncp_find_dir_inode(struct inode *dir, const char *name) -{ - struct ncp_server *server = NCP_SERVER(dir); - struct nw_info_struct *dir_info = NCP_ISTRUCT(dir); - struct ncp_inode_info *result = &(server->root); - - if (name == NULL) { - return NULL; - } - do { - if ((result->dir->finfo.i.dirEntNum == dir_info->dirEntNum) - && (result->dir->finfo.i.volNumber == dir_info->volNumber) - && (strcmp(result->finfo.i.entryName, name) == 0) - /* The root dir is never looked up using this - * routine. Without the following test a root - * directory 'sys' in a volume named 'sys' could - * never be looked up, because - * server->root->dir==server->root. */ - && (result != &(server->root))) { - return result; + goto out; } - result = result->next; - + str_lower(server->root.finfo.i.entryName); } - while (result != &(server->root)); + result = 0; - return NULL; +out: + return result; } -static int ncp_lookup(struct inode *dir, const char *__name, int len, - struct inode **result) +static int ncp_lookup(struct inode *dir, struct dentry *dentry) { - struct nw_file_info finfo; struct ncp_server *server; - struct ncp_inode_info *result_info; - int found_in_cache; - int down_case = 0; - char name[len + 1]; - - *result = NULL; - + struct inode *inode = NULL; + int found_in_cache, down_case = 0; + int error; + int len = dentry->d_name.len; + struct ncpfs_inode_info finfo; + __u8 __name[dentry->d_name.len + 1]; + + error = -ENOENT; if (!dir || !S_ISDIR(dir->i_mode)) { - printk("ncp_lookup: inode is NULL or not a directory.\n"); - iput(dir); - return -ENOENT; + printk(KERN_WARNING "ncp_lookup: inode is NULL or not a directory.\n"); + goto finished; } server = NCP_SERVER(dir); - if (!ncp_conn_valid(server)) { - iput(dir); - return -EIO; - } - DPRINTK("ncp_lookup: %s, len %d\n", __name, len); - - /* Fast cheat for . */ - if (len == 0 || (len == 1 && __name[0] == '.')) { - *result = dir; - return 0; - } - /* ..and for .. */ - if (len == 2 && __name[0] == '.' && __name[1] == '.') { - struct ncp_inode_info *parent = NCP_INOP(dir)->dir; - - if (parent->state == NCP_INODE_CACHED) { - parent->state = NCP_INODE_LOOKED_UP; - } - *result = iget(dir->i_sb, ncp_info_ino(server, parent)); - iput(dir); - if (*result == 0) { - return -EACCES; - } else { - return 0; - } - } - memcpy(name, __name, len); - name[len] = 0; - lock_super(dir->i_sb); - result_info = ncp_find_dir_inode(dir, name); - - if (result_info != 0) { - if (result_info->state == NCP_INODE_CACHED) { - result_info->state = NCP_INODE_LOOKED_UP; - } - /* Here we convert the inode_info address into an - inode number */ + error = -EIO; + if (!ncp_conn_valid(server)) + goto finished; - *result = iget(dir->i_sb, ncp_info_ino(server, result_info)); - unlock_super(dir->i_sb); - iput(dir); + strncpy(__name, dentry->d_name.name, len); + __name[len] = '\0'; +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_lookup: %s, len %d\n", __name, len); +#endif - if (*result == NULL) { - return -EACCES; - } - return 0; + if (!ncp_preserve_case(dir)) { + str_lower(__name); + down_case = 1; } + /* If the file is in the dir cache, we do not have to ask the server. */ found_in_cache = 0; ncp_lock_dircache(); - if ((dir->i_dev == c_dev) && (dir->i_ino == c_ino)) { + if ((dir->i_dev == c_dev) && (dir->i_ino == c_ino)) + { int first = c_last_returned_index; int i; - + i = first; do { - DDPRINTK("ncp_lookup: trying index: %d, name: %s\n", - i, c_entry[i].i.entryName); - - if (strcmp(c_entry[i].i.entryName, name) == 0) { - DPRINTK("ncp_lookup: found in cache!\n"); - finfo.i = c_entry[i].i; +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_lookup: trying index: %d, name: %s\n", i, c_entry[i].i.entryName); +#endif + if (strcmp(c_entry[i].i.entryName, __name) == 0) { +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_lookup: found in cache!\n"); +#endif + finfo.nw_info.i = c_entry[i].i; found_in_cache = 1; break; } i = (i + 1) % c_size; - } - while (i != first); + } while (i != first); } ncp_unlock_dircache(); - if (found_in_cache == 0) { + if (found_in_cache == 0) + { int res; - - DDPRINTK("ncp_lookup: do_lookup on %s/%s\n", - NCP_ISTRUCT(dir)->entryName, name); - - if (ncp_is_server_root(dir)) { - str_upper(name); + +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_lookup: server lookup for %s/%s\n", +dentry->d_parent->d_name.name, __name); +#endif + if (ncp_is_server_root(dir)) + { + str_upper(__name); down_case = 1; - res = ncp_lookup_volume(server, name, &(finfo.i)); - } else { - if (!ncp_preserve_case(dir)) { - str_upper(name); + res = ncp_lookup_volume(server, __name, + &(finfo.nw_info.i)); + } else + { + if (!ncp_preserve_case(dir)) + { + str_upper(__name); down_case = 1; } - res = ncp_obtain_info(server, - NCP_ISTRUCT(dir)->volNumber, - NCP_ISTRUCT(dir)->dirEntNum, - name, &(finfo.i)); - } - if (res != 0) { - unlock_super(dir->i_sb); - iput(dir); - return -ENOENT; + res = ncp_obtain_info(server, dir, __name, + &(finfo.nw_info.i)); } +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_lookup: looked for %s/%s, res=%d\n", +dentry->d_parent->d_name.name, __name, res); +#endif + /* + * If we didn't find an entry, make a negative dentry. + */ + if (res != 0) + goto add_entry; + } + + /* + * Create an inode for the entry. + */ + finfo.nw_info.opened = 0; + finfo.ino = ncp_invent_inos(1); + error = -EACCES; + inode = ncp_iget(dir->i_sb, &finfo); + if (inode) + { + add_entry: + dentry->d_op = &ncp_dentry_operations; + d_add(dentry, inode); + error = 0; } - finfo.opened = 0; - if (down_case != 0) { - str_lower(finfo.i.entryName); - } - if (!(*result = ncp_iget(dir, &finfo))) { - unlock_super(dir->i_sb); - iput(dir); - return -EACCES; - } - unlock_super(dir->i_sb); - iput(dir); - return 0; +finished: +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_lookup: result=%d\n", error); +#endif + return error; } -static int ncp_create(struct inode *dir, const char *name, int len, int mode, - struct inode **result) +/* + * This code is common to create, mkdir, and mknod. + */ +static int ncp_instantiate(struct inode *dir, struct dentry *dentry, + struct ncpfs_inode_info *finfo) { - struct nw_file_info finfo; - __u8 _name[len + 1]; + struct inode *inode; + int error = -EINVAL; + + ncp_invalid_dir_cache(dir); + + finfo->ino = ncp_invent_inos(1); + inode = ncp_iget(dir->i_sb, finfo); + if (!inode) + goto out_close; + d_instantiate(dentry,inode); + error = 0; +out: + return error; - *result = NULL; +out_close: +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_instantiate: %s/%s failed, closing file\n", +dentry->d_parent->d_name.name, dentry->d_name.name); +#endif + ncp_close_file(NCP_SERVER(dir), finfo->nw_info.file_handle); + goto out; +} +static int ncp_create(struct inode *dir, struct dentry *dentry, int mode) +{ + int error, result; + struct ncpfs_inode_info finfo; + __u8 _name[dentry->d_name.len + 1]; + +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_create: creating %s/%s, mode=%x\n", +dentry->d_parent->d_name.name, dentry->d_name.name, mode); +#endif if (!dir || !S_ISDIR(dir->i_mode)) { - printk("ncp_create: inode is NULL or not a directory\n"); - iput(dir); + printk(KERN_WARNING "ncp_create: inode is NULL or not a directory\n"); return -ENOENT; } - if (!ncp_conn_valid(NCP_SERVER(dir))) { - iput(dir); - return -EIO; - } - strncpy(_name, name, len); - _name[len] = '\0'; + error = -EIO; + if (!ncp_conn_valid(NCP_SERVER(dir))) + goto out; + + strncpy(_name, dentry->d_name.name, dentry->d_name.len); + _name[dentry->d_name.len] = '\0'; if (!ncp_preserve_case(dir)) { str_upper(_name); } - lock_super(dir->i_sb); - if (ncp_open_create_file_or_subdir(NCP_SERVER(dir), - NCP_ISTRUCT(dir), _name, - OC_MODE_CREATE | OC_MODE_OPEN | - OC_MODE_REPLACE, - 0, AR_READ | AR_WRITE, - &finfo) != 0) { - unlock_super(dir->i_sb); - iput(dir); - return -EACCES; - } - ncp_invalid_dir_cache(dir); - if (!ncp_preserve_case(dir)) { - str_lower(finfo.i.entryName); + error = -EACCES; + result = ncp_open_create_file_or_subdir(NCP_SERVER(dir), dir, _name, + OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE, + 0, AR_READ | AR_WRITE, &finfo.nw_info); + if (!result) { + finfo.nw_info.access = O_RDWR; + error = ncp_instantiate(dir, dentry, &finfo); + } else { + DPRINTK(KERN_DEBUG "ncp_create: %s/%s failed\n", + dentry->d_parent->d_name.name, dentry->d_name.name); } - finfo.access = O_RDWR; - if (!(*result = ncp_iget(dir, &finfo)) < 0) { - ncp_close_file(NCP_SERVER(dir), finfo.file_handle); - unlock_super(dir->i_sb); - iput(dir); - return -EINVAL; - } - unlock_super(dir->i_sb); - iput(dir); - return 0; +out: + return error; } -static int ncp_mkdir(struct inode *dir, const char *name, int len, int mode) +static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode) { int error; - struct nw_file_info new_dir; - __u8 _name[len + 1]; - - if ((name[0] == '.') - && ((len == 1) - || ((len == 2) - && (name[1] == '.')))) { - iput(dir); - return -EEXIST; + struct ncpfs_inode_info finfo; + __u8 _name[dentry->d_name.len + 1]; + + DPRINTK(KERN_DEBUG "ncp_mkdir: making %s/%s\n", + dentry->d_parent->d_name.name, dentry->d_name.name); + error = -ENOTDIR; + if (!dir || !S_ISDIR(dir->i_mode)) { + printk(KERN_WARNING "ncp_mkdir: inode is NULL or not a directory\n"); + goto out; } - strncpy(_name, name, len); - _name[len] = '\0'; + error = -EIO; + if (!ncp_conn_valid(NCP_SERVER(dir))) + goto out; + strncpy(_name, dentry->d_name.name, dentry->d_name.len); + _name[dentry->d_name.len] = '\0'; if (!ncp_preserve_case(dir)) { str_upper(_name); } - if (!dir || !S_ISDIR(dir->i_mode)) { - printk("ncp_mkdir: inode is NULL or not a directory\n"); - iput(dir); - return -ENOENT; - } - if (!ncp_conn_valid(NCP_SERVER(dir))) { - iput(dir); - return -EIO; - } - if (ncp_open_create_file_or_subdir(NCP_SERVER(dir), - NCP_ISTRUCT(dir), _name, + + error = -EACCES; + if (ncp_open_create_file_or_subdir(NCP_SERVER(dir), dir, _name, OC_MODE_CREATE, aDIR, 0xffff, - &new_dir) != 0) { - error = -EACCES; - } else { - error = 0; - ncp_invalid_dir_cache(dir); + &finfo.nw_info) == 0) + { + error = ncp_instantiate(dir, dentry, &finfo); } - - iput(dir); +out: return error; } -static int ncp_rmdir(struct inode *dir, const char *name, int len) +static int ncp_rmdir(struct inode *dir, struct dentry *dentry) { - int error; - __u8 _name[len + 1]; - - if (!dir || !S_ISDIR(dir->i_mode)) { - printk("ncp_rmdir: inode is NULL or not a directory\n"); - iput(dir); - return -ENOENT; - } - if (!ncp_conn_valid(NCP_SERVER(dir))) { - iput(dir); - return -EIO; - } - if (ncp_find_dir_inode(dir, name) != NULL) { - iput(dir); + int error, result; + __u8 _name[dentry->d_name.len + 1]; + + DPRINTK(KERN_DEBUG "ncp_rmdir: removing %s/%s\n", + dentry->d_parent->d_name.name, dentry->d_name.name); + + error = -ENOENT; + if (!dir || !S_ISDIR(dir->i_mode)) + { + printk(KERN_WARNING "ncp_rmdir: inode is NULL or not a directory\n"); + goto out; + } + error = -EIO; + if (!ncp_conn_valid(NCP_SERVER(dir))) + goto out; + + if (dentry->d_count > 1) + { + shrink_dcache_parent(dentry); error = -EBUSY; - } else { - - strncpy(_name, name, len); - _name[len] = '\0'; + if (dentry->d_count > 1) + goto out; + } - if (!ncp_preserve_case(dir)) { - str_upper(_name); - } - if ((error = ncp_del_file_or_subdir(NCP_SERVER(dir), - NCP_ISTRUCT(dir), - _name)) == 0) { - ncp_invalid_dir_cache(dir); - } else { - error = -EACCES; - } + strncpy(_name, dentry->d_name.name, dentry->d_name.len); + _name[dentry->d_name.len] = '\0'; + + if (!ncp_preserve_case(dir)) + { + str_upper(_name); } - iput(dir); + error = -EACCES; + result = ncp_del_file_or_subdir(NCP_SERVER(dir), dir, _name); + if (!result) + { + ncp_invalid_dir_cache(dir); + d_delete(dentry); + error = 0; + } +out: return error; } -static int ncp_unlink(struct inode *dir, const char *name, int len) +static int ncp_unlink(struct inode *dir, struct dentry *dentry) { - int error; - __u8 _name[len + 1]; - + struct inode *inode = dentry->d_inode; + int error, result; + __u8 _name[dentry->d_name.len + 1]; + + DPRINTK(KERN_DEBUG "ncp_unlink: unlinking %s/%s\n", + dentry->d_parent->d_name.name, dentry->d_name.name); + + error = -ENOTDIR; if (!dir || !S_ISDIR(dir->i_mode)) { - printk("ncp_unlink: inode is NULL or not a directory\n"); - iput(dir); - return -ENOENT; - } - if (!ncp_conn_valid(NCP_SERVER(dir))) { - iput(dir); - return -EIO; + printk(KERN_WARNING "ncp_unlink: inode is NULL or not a directory\n"); + goto out; + } + error = -EIO; + if (!ncp_conn_valid(NCP_SERVER(dir))) + goto out; + + /* + * Check whether to close the file ... + */ + if (inode && NCP_FINFO(inode)->opened) { +#ifdef NCPFS_PARANOIA +printk(KERN_DEBUG "ncp_unlink: closing file\n"); +#endif + ncp_make_closed(inode); } - if (ncp_find_dir_inode(dir, name) != NULL) { - iput(dir); - error = -EBUSY; - } else { - strncpy(_name, name, len); - _name[len] = '\0'; - if (!ncp_preserve_case(dir)) { - str_upper(_name); - } - if ((error = ncp_del_file_or_subdir(NCP_SERVER(dir), - NCP_ISTRUCT(dir), - _name)) == 0) { - ncp_invalid_dir_cache(dir); - } else { - error = -EACCES; - } + strncpy(_name, dentry->d_name.name, dentry->d_name.len); + _name[dentry->d_name.len] = '\0'; + if (!ncp_preserve_case(dir)) + { + str_upper(_name); + } + error = -EACCES; + result = ncp_del_file_or_subdir(NCP_SERVER(dir), dir, _name); + if (!result) { + DPRINTK(KERN_DEBUG "ncp: removed %s/%s\n", + dentry->d_parent->d_name.name, dentry->d_name.name); + ncp_invalid_dir_cache(dir); + d_delete(dentry); + error = 0; } - iput(dir); +out: return error; } -static int ncp_rename(struct inode *old_dir, const char *old_name, int old_len, - struct inode *new_dir, const char *new_name, int new_len) +static int ncp_rename(struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry) { - int res; - char _old_name[old_len + 1]; - char _new_name[new_len + 1]; + int old_len = old_dentry->d_name.len; + int new_len = new_dentry->d_name.len; + int error, result; + char _old_name[old_dentry->d_name.len + 1]; + char _new_name[new_dentry->d_name.len + 1]; + + DPRINTK(KERN_DEBUG "ncp_rename: %s/%s to %s/%s\n", + old_dentry->d_parent->d_name.name, old_dentry->d_name.name, + new_dentry->d_parent->d_name.name, new_dentry->d_name.name); + error = -ENOTDIR; if (!old_dir || !S_ISDIR(old_dir->i_mode)) { - printk("ncp_rename: old inode is NULL or not a directory\n"); - res = -ENOENT; - goto finished; - } - if (!ncp_conn_valid(NCP_SERVER(old_dir))) { - res = -EIO; - goto finished; + printk(KERN_WARNING "ncp_rename: old inode is NULL or not a directory\n"); + goto out; } if (!new_dir || !S_ISDIR(new_dir->i_mode)) { - printk("ncp_rename: new inode is NULL or not a directory\n"); - res = -ENOENT; - goto finished; - } - if ((ncp_find_dir_inode(old_dir, old_name) != NULL) - || (ncp_find_dir_inode(new_dir, new_name) != NULL)) { - res = -EBUSY; - goto finished; + printk(KERN_WARNING "ncp_rename: new inode is NULL or not a directory\n"); + goto out; } - strncpy(_old_name, old_name, old_len); - _old_name[old_len] = '\0'; + error = -EIO; + if (!ncp_conn_valid(NCP_SERVER(old_dir))) + goto out; + strncpy(_old_name, old_dentry->d_name.name, old_len); + _old_name[old_len] = '\0'; if (!ncp_preserve_case(old_dir)) { str_upper(_old_name); } - strncpy(_new_name, new_name, new_len); - _new_name[new_len] = '\0'; + strncpy(_new_name, new_dentry->d_name.name, new_len); + _new_name[new_len] = '\0'; if (!ncp_preserve_case(new_dir)) { str_upper(_new_name); } - res = ncp_ren_or_mov_file_or_subdir(NCP_SERVER(old_dir), - NCP_ISTRUCT(old_dir), _old_name, - NCP_ISTRUCT(new_dir), _new_name); - if (res == 0) { + error = -EACCES; + result = ncp_ren_or_mov_file_or_subdir(NCP_SERVER(old_dir), + old_dir, _old_name, + new_dir, _new_name); + if (result == 0) + { + DPRINTK(KERN_DEBUG "ncp renamed %s -> %s.\n", + old_dentry->d_name.name,new_dentry->d_name.name); ncp_invalid_dir_cache(old_dir); ncp_invalid_dir_cache(new_dir); - } else { - res = -EACCES; + d_move(old_dentry,new_dentry); + error = 0; } - - finished: - iput(old_dir); - iput(new_dir); - return res; +out: + return error; } /* The following routines are taken directly from msdos-fs */ @@ -1024,7 +1033,7 @@ static int ncp_rename(struct inode *old_dir, const char *old_name, int old_len, static int day_n[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0, 0, 0, 0}; - /* JanFebMarApr May Jun Jul Aug Sep Oct Nov Dec */ +/* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */ extern struct timezone sys_tz; @@ -1042,23 +1051,24 @@ static int local2utc(int time) } /* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70). */ - -int ncp_date_dos2unix(unsigned short time, unsigned short date) +int +ncp_date_dos2unix(unsigned short time, unsigned short date) { int month, year, secs; month = ((date >> 5) & 15) - 1; year = date >> 9; - secs = (time & 31) * 2 + 60 * ((time >> 5) & 63) + (time >> 11) * 3600 + 86400 * - ((date & 31) - 1 + day_n[month] + (year / 4) + year * 365 - ((year & 3) == 0 && - month < 2 ? 1 : 0) + 3653); + secs = (time & 31) * 2 + 60 * ((time >> 5) & 63) + (time >> 11) * 3600 + + 86400 * ((date & 31) - 1 + day_n[month] + (year / 4) + + year * 365 - ((year & 3) == 0 && month < 2 ? 1 : 0) + 3653); /* days since 1.1.70 plus 80's leap day */ return local2utc(secs); } /* Convert linear UNIX date to a MS-DOS time/date pair. */ -void ncp_date_unix2dos(int unix_date, unsigned short *time, unsigned short *date) +void +ncp_date_unix2dos(int unix_date, unsigned short *time, unsigned short *date) { int day, year, nl_day, month; |