summaryrefslogtreecommitdiffstats
path: root/fs/ncpfs
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>1997-12-06 23:51:34 +0000
committerRalf Baechle <ralf@linux-mips.org>1997-12-06 23:51:34 +0000
commit230e5ab6a084ed50470f101934782dbf54b0d06b (patch)
tree5dd821c8d33f450470588e7a543f74bf74306e9e /fs/ncpfs
parentc9b1c8a64c6444d189856f1e26bdcb8b4cd0113a (diff)
Merge with Linux 2.1.67.
Diffstat (limited to 'fs/ncpfs')
-rw-r--r--fs/ncpfs/dir.c1314
-rw-r--r--fs/ncpfs/file.c196
-rw-r--r--fs/ncpfs/inode.c371
-rw-r--r--fs/ncpfs/ioctl.c23
-rw-r--r--fs/ncpfs/mmap.c7
-rw-r--r--fs/ncpfs/ncplib_kernel.c249
-rw-r--r--fs/ncpfs/ncplib_kernel.h80
-rw-r--r--fs/ncpfs/sock.c132
8 files changed, 1254 insertions, 1118 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;
diff --git a/fs/ncpfs/file.c b/fs/ncpfs/file.c
index 9a2067848..2f22f25d1 100644
--- a/fs/ncpfs/file.c
+++ b/fs/ncpfs/file.c
@@ -2,6 +2,7 @@
* file.c
*
* Copyright (C) 1995, 1996 by Volker Lendecke
+ * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
*
*/
@@ -29,82 +30,113 @@ static int ncp_fsync(struct file *file, struct dentry *dentry)
return 0;
}
-int ncp_make_open(struct inode *i, int right)
+/*
+ * Open a file with the specified read/write mode.
+ */
+int ncp_make_open(struct inode *inode, int right)
{
- struct nw_file_info *finfo;
-
- if (i == NULL) {
- printk("ncp_make_open: got NULL inode\n");
- return -EINVAL;
+ int error, result;
+ int access;
+ struct nw_file_info finfo;
+
+ error = -EINVAL;
+ if (!inode) {
+ printk(KERN_ERR "ncp_make_open: got NULL inode\n");
+ goto out;
}
- finfo = NCP_FINFO(i);
-
- DPRINTK("ncp_make_open: dirent->opened = %d\n", finfo->opened);
- lock_super(i->i_sb);
- if (finfo->opened == 0) {
- finfo->access = -1;
+ DPRINTK(KERN_DEBUG "ncp_make_open: opened=%d, volume # %u, dir entry # %u\n",
+ NCP_FINFO(inode)->opened,
+ NCP_FINFO(inode)->volNumber,
+ NCP_FINFO(inode)->dirEntNum);
+ error = -EACCES;
+ lock_super(inode->i_sb);
+ if (!NCP_FINFO(inode)->opened) {
+ finfo.i.dirEntNum = NCP_FINFO(inode)->dirEntNum;
+ finfo.i.volNumber = NCP_FINFO(inode)->volNumber;
/* tries max. rights */
- if (ncp_open_create_file_or_subdir(NCP_SERVER(i),
- NULL, NULL,
- OC_MODE_OPEN, 0,
- AR_READ | AR_WRITE,
- finfo) == 0) {
- finfo->access = O_RDWR;
- } else if (ncp_open_create_file_or_subdir(NCP_SERVER(i),
- NULL, NULL,
- OC_MODE_OPEN, 0,
- AR_READ,
- finfo) == 0) {
- finfo->access = O_RDONLY;
+ finfo.access = O_RDWR;
+ result = ncp_open_create_file_or_subdir(NCP_SERVER(inode),
+ NULL, NULL, OC_MODE_OPEN,
+ 0, AR_READ | AR_WRITE, &finfo);
+ if (!result)
+ goto update;
+ finfo.access = O_RDONLY;
+ result = ncp_open_create_file_or_subdir(NCP_SERVER(inode),
+ NULL, NULL, OC_MODE_OPEN,
+ 0, AR_READ, &finfo);
+ if (!result) {
+#ifdef NCPFS_PARANOIA
+printk(KERN_DEBUG "ncp_make_open: failed, result=%d\n", result);
+#endif
+ goto out_unlock;
}
+ /*
+ * Update the inode information.
+ */
+ update:
+ ncp_update_inode(inode, &finfo);
}
- unlock_super(i->i_sb);
- if (((right == O_RDONLY) && ((finfo->access == O_RDONLY)
- || (finfo->access == O_RDWR)))
- || ((right == O_WRONLY) && ((finfo->access == O_WRONLY)
- || (finfo->access == O_RDWR)))
- || ((right == O_RDWR) && (finfo->access == O_RDWR)))
- return 0;
-
- return -EACCES;
+ access = NCP_FINFO(inode)->access;
+#ifdef NCPFS_PARANOIA
+printk(KERN_DEBUG "ncp_make_open: file open, access=%x\n", access);
+#endif
+ if (((right == O_RDONLY) && ((access == O_RDONLY)
+ || (access == O_RDWR)))
+ || ((right == O_WRONLY) && ((access == O_WRONLY)
+ || (access == O_RDWR)))
+ || ((right == O_RDWR) && (access == O_RDWR)))
+ error = 0;
+
+out_unlock:
+ unlock_super(inode->i_sb);
+out:
+ return error;
}
-static long ncp_file_read(struct inode *inode, struct file *file, char *buf, unsigned long count)
+static ssize_t
+ncp_file_read(struct file *file, char *buf, size_t count, loff_t *ppos)
{
- int bufsize, already_read;
+ struct dentry *dentry = file->f_dentry;
+ struct inode *inode = dentry->d_inode;
+ size_t already_read = 0;
off_t pos;
- int errno;
+ int bufsize, error;
- DPRINTK("ncp_file_read: enter %s\n", NCP_ISTRUCT(inode)->entryName);
+ DPRINTK(KERN_DEBUG "ncp_file_read: enter %s/%s\n",
+ dentry->d_parent->d_name.name, dentry->d_name.name);
+ error = -EINVAL;
if (inode == NULL) {
- DPRINTK("ncp_file_read: inode = NULL\n");
- return -EINVAL;
- }
- if (!ncp_conn_valid(NCP_SERVER(inode))) {
- return -EIO;
+ DPRINTK(KERN_DEBUG "ncp_file_read: inode = NULL\n");
+ goto out;
}
+ error = -EIO;
+ if (!ncp_conn_valid(NCP_SERVER(inode)))
+ goto out;
+ error = -EINVAL;
if (!S_ISREG(inode->i_mode)) {
- DPRINTK("ncp_file_read: read from non-file, mode %07o\n",
+ DPRINTK(KERN_DEBUG "ncp_file_read: read from non-file, mode %07o\n",
inode->i_mode);
- return -EINVAL;
+ goto out;
}
- pos = file->f_pos;
+ pos = file->f_pos;
if (pos + count > inode->i_size) {
count = inode->i_size - pos;
}
- if (count <= 0) {
- return 0;
- }
- if ((errno = ncp_make_open(inode, O_RDONLY)) != 0) {
- return errno;
+ error = 0;
+ if (!count) /* size_t is never < 0 */
+ goto out;
+
+ error = ncp_make_open(inode, O_RDONLY);
+ if (error) {
+ printk(KERN_ERR "ncp_file_read: open failed, error=%d\n", error);
+ goto out;
}
- bufsize = NCP_SERVER(inode)->buffer_size;
- already_read = 0;
+ bufsize = NCP_SERVER(inode)->buffer_size;
/* First read in as much as possible for each bufsize. */
while (already_read < count) {
@@ -112,9 +144,12 @@ static long ncp_file_read(struct inode *inode, struct file *file, char *buf, uns
int to_read = min(bufsize - (pos % bufsize),
count - already_read);
- if (ncp_read(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle,
- pos, to_read, buf, &read_this_time) != 0) {
- return -EIO; /* This is not exact, i know.. */
+ error = ncp_read(NCP_SERVER(inode),
+ NCP_FINFO(inode)->file_handle,
+ pos, to_read, buf, &read_this_time);
+ if (error) {
+ error = -EIO; /* This is not exact, i know.. */
+ goto out;
}
pos += read_this_time;
buf += read_this_time;
@@ -130,38 +165,43 @@ static long ncp_file_read(struct inode *inode, struct file *file, char *buf, uns
if (!IS_RDONLY(inode)) {
inode->i_atime = CURRENT_TIME;
}
- mark_inode_dirty(inode);
- DPRINTK("ncp_file_read: exit %s\n", NCP_ISTRUCT(inode)->entryName);
-
- return already_read;
+ DPRINTK(KERN_DEBUG "ncp_file_read: exit %s/%s\n",
+ dentry->d_parent->d_name.name, dentry->d_name.name);
+out:
+ return already_read ? already_read : error;
}
-static long ncp_file_write(struct inode *inode, struct file *file, const char *buf,
- unsigned long count)
+static ssize_t
+ncp_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
{
- int bufsize, already_written;
+ struct dentry *dentry = file->f_dentry;
+ struct inode *inode = dentry->d_inode;
+ size_t already_written = 0;
off_t pos;
- int errno;
+ int bufsize, errno;
+ DPRINTK(KERN_DEBUG "ncp_file_write: enter %s/%s\n",
+ dentry->d_parent->d_name.name, dentry->d_name.name);
if (inode == NULL) {
- DPRINTK("ncp_file_write: inode = NULL\n");
+ DPRINTK(KERN_DEBUG "ncp_file_write: inode = NULL\n");
return -EINVAL;
}
- if (!ncp_conn_valid(NCP_SERVER(inode))) {
- return -EIO;
- }
+ errno = -EIO;
+ if (!ncp_conn_valid(NCP_SERVER(inode)))
+ goto out;
if (!S_ISREG(inode->i_mode)) {
- DPRINTK("ncp_file_write: write to non-file, mode %07o\n",
+ DPRINTK(KERN_DEBUG "ncp_file_write: write to non-file, mode %07o\n",
inode->i_mode);
return -EINVAL;
}
- DPRINTK("ncp_file_write: enter %s\n", NCP_ISTRUCT(inode)->entryName);
- if (count <= 0) {
- return 0;
- }
- if ((errno = ncp_make_open(inode, O_RDWR)) != 0) {
+ errno = 0;
+ if (!count)
+ goto out;
+ errno = ncp_make_open(inode, O_RDWR);
+ if (errno) {
+ printk(KERN_ERR "ncp_file_write: open failed, error=%d\n", errno);
return errno;
}
pos = file->f_pos;
@@ -192,17 +232,17 @@ static long ncp_file_write(struct inode *inode, struct file *file, const char *b
}
inode->i_mtime = inode->i_ctime = CURRENT_TIME;
- mark_inode_dirty(inode);
file->f_pos = pos;
if (pos > inode->i_size) {
inode->i_size = pos;
- ncp_invalid_dir_cache(NCP_INOP(inode)->dir->inode);
+ ncp_invalid_dir_cache(dentry->d_parent->d_inode);
}
- DPRINTK("ncp_file_write: exit %s\n", NCP_ISTRUCT(inode)->entryName);
-
- return already_written;
+ DPRINTK(KERN_DEBUG "ncp_file_write: exit %s/%s\n",
+ dentry->d_parent->d_name.name, dentry->d_name.name);
+out:
+ return already_written ? already_written : errno;
}
static struct file_operations ncp_file_operations =
diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
index 2e903151e..61cdd0319 100644
--- a/fs/ncpfs/inode.c
+++ b/fs/ncpfs/inode.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
*
*/
@@ -14,7 +15,6 @@
#include <asm/byteorder.h>
#include <linux/sched.h>
-#include <linux/ncp_fs.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/string.h>
@@ -28,84 +28,108 @@
#ifdef CONFIG_KERNELD
#include <linux/kerneld.h>
#endif
+
+#include <linux/ncp_fs.h>
#include "ncplib_kernel.h"
extern int close_fp(struct file *filp);
-static void ncp_put_inode(struct inode *);
static void ncp_read_inode(struct inode *);
+static void ncp_put_inode(struct inode *);
+static void ncp_delete_inode(struct inode *);
+static int ncp_notify_change(struct inode *, struct iattr *);
static void ncp_put_super(struct super_block *);
-static void ncp_statfs(struct super_block *sb, struct statfs *buf, int bufsiz);
-static int ncp_notify_change(struct inode *inode, struct iattr *attr);
+static int ncp_statfs(struct super_block *, struct statfs *, int);
static struct super_operations ncp_sops =
{
ncp_read_inode, /* read inode */
- ncp_notify_change, /* notify change */
NULL, /* write inode */
ncp_put_inode, /* put inode */
+ ncp_delete_inode, /* delete inode */
+ ncp_notify_change, /* notify change */
ncp_put_super, /* put superblock */
NULL, /* write superblock */
ncp_statfs, /* stat filesystem */
- NULL
+ NULL /* remount */
};
-/* ncp_read_inode: Called from iget, it only traverses the allocated
- ncp_inode_info's and initializes the inode from the data found
- there. It does not allocate or deallocate anything. */
+static struct nw_file_info *read_nwinfo = NULL;
+static struct semaphore read_sem = MUTEX;
-static void ncp_read_inode(struct inode *inode)
+/*
+ * Fill in the ncpfs-specific information in the inode.
+ */
+void ncp_update_inode(struct inode *inode, struct nw_file_info *nwinfo)
{
- /* Our task should be extremely simple here. We only have to
- look up the information somebody else (ncp_iget) put into
- the inode tree. The address of this information is the
- inode->i_ino. Just to make sure everything went well, we
- check it's there. */
-
- struct ncp_inode_info *inode_info = ncp_find_inode(inode);
-
- if (inode_info == NULL) {
- /* Ok, now we're in trouble. The inode info is not there. What
- should we do now??? */
- printk("ncp_read_inode: inode info not found\n");
- return;
- }
- inode_info->state = NCP_INODE_VALID;
+ NCP_FINFO(inode)->DosDirNum = nwinfo->i.DosDirNum;
+ NCP_FINFO(inode)->dirEntNum = nwinfo->i.dirEntNum;
+ NCP_FINFO(inode)->volNumber = nwinfo->i.volNumber;
+
+ NCP_FINFO(inode)->opened = nwinfo->opened;
+ NCP_FINFO(inode)->access = nwinfo->access;
+ NCP_FINFO(inode)->server_file_handle = nwinfo->server_file_handle;
+ memcpy(NCP_FINFO(inode)->file_handle, nwinfo->file_handle,
+ sizeof(nwinfo->file_handle));
+#ifdef NCPFS_DEBUG_VERBOSE
+printk(KERN_DEBUG "ncp_update_inode: updated %s, volnum=%d, dirent=%u\n",
+nwinfo->i.entryName, NCP_FINFO(inode)->volNumber, NCP_FINFO(inode)->dirEntNum);
+#endif
+}
- NCP_INOP(inode) = inode_info;
- inode_info->inode = inode;
+/*
+ * Fill in the inode based on the nw_file_info structure.
+ */
+static void ncp_set_attr(struct inode *inode, struct nw_file_info *nwinfo)
+{
+ struct nw_info_struct *nwi = &nwinfo->i;
+ struct ncp_server *server = NCP_SERVER(inode);
- if (NCP_ISTRUCT(inode)->attributes & aDIR) {
- inode->i_mode = NCP_SERVER(inode)->m.dir_mode;
+ if (nwi->attributes & aDIR) {
+ inode->i_mode = server->m.dir_mode;
/* for directories dataStreamSize seems to be some
Object ID ??? */
inode->i_size = 512;
} else {
- inode->i_mode = NCP_SERVER(inode)->m.file_mode;
- inode->i_size = le32_to_cpu(NCP_ISTRUCT(inode)->dataStreamSize);
+ inode->i_mode = server->m.file_mode;
+ inode->i_size = le32_to_cpu(nwi->dataStreamSize);
}
- DDPRINTK("ncp_read_inode: inode->i_mode = %u\n", inode->i_mode);
+ DDPRINTK(KERN_DEBUG "ncp_read_inode: inode->i_mode = %u\n", inode->i_mode);
inode->i_nlink = 1;
- inode->i_uid = NCP_SERVER(inode)->m.uid;
- inode->i_gid = NCP_SERVER(inode)->m.gid;
+ inode->i_uid = server->m.uid;
+ inode->i_gid = server->m.gid;
inode->i_blksize = 512;
inode->i_rdev = 0;
+ inode->i_blocks = 0;
if ((inode->i_blksize != 0) && (inode->i_size != 0)) {
inode->i_blocks =
(inode->i_size - 1) / inode->i_blksize + 1;
- } else {
- inode->i_blocks = 0;
}
- inode->i_mtime = ncp_date_dos2unix(le16_to_cpu(NCP_ISTRUCT(inode)->modifyTime),
- le16_to_cpu(NCP_ISTRUCT(inode)->modifyDate));
- inode->i_ctime = ncp_date_dos2unix(le16_to_cpu(NCP_ISTRUCT(inode)->creationTime),
- le16_to_cpu(NCP_ISTRUCT(inode)->creationDate));
+ inode->i_mtime = ncp_date_dos2unix(le16_to_cpu(nwi->modifyTime),
+ le16_to_cpu(nwi->modifyDate));
+ inode->i_ctime = ncp_date_dos2unix(le16_to_cpu(nwi->creationTime),
+ le16_to_cpu(nwi->creationDate));
inode->i_atime = ncp_date_dos2unix(0,
- le16_to_cpu(NCP_ISTRUCT(inode)->lastAccessDate));
+ le16_to_cpu(nwi->lastAccessDate));
+ ncp_update_inode(inode, nwinfo);
+}
+
+/*
+ * This is called from iget() with the read semaphore held.
+ * The global ncpfs_file_info structure has been set up by ncp_iget.
+ */
+static void ncp_read_inode(struct inode *inode)
+{
+ if (read_nwinfo == NULL) {
+ printk(KERN_ERR "ncp_read_inode: invalid call\n");
+ return;
+ }
+
+ ncp_set_attr(inode, read_nwinfo);
if (S_ISREG(inode->i_mode)) {
inode->i_op = &ncp_file_inode_operations;
@@ -116,73 +140,103 @@ static void ncp_read_inode(struct inode *inode)
}
}
-static void ncp_put_inode(struct inode *inode)
+/*
+ * Set up the ncpfs_inode_info pointer and get a new inode.
+ */
+struct inode *
+ncp_iget(struct super_block *sb, struct ncpfs_inode_info *info)
{
- struct nw_file_info *finfo = NCP_FINFO(inode);
- struct super_block *sb = inode->i_sb;
+ struct inode *inode;
- lock_super(sb);
- if (finfo->opened != 0) {
- if (ncp_close_file(NCP_SERVER(inode), finfo->file_handle) != 0) {
- /* We can't do anything but complain. */
- printk("ncp_put_inode: could not close\n");
- }
+ if (info == NULL) {
+ printk(KERN_ERR "ncp_iget: info is NULL\n");
+ return NULL;
}
- DDPRINTK("ncp_put_inode: put %s\n",
- finfo->i.entryName);
- ncp_free_inode_info(NCP_INOP(inode));
+ down(&read_sem);
+ read_nwinfo = &info->nw_info;
+ inode = iget(sb, info->ino);
+ read_nwinfo = NULL;
+ up(&read_sem);
+ if (!inode)
+ printk(KERN_ERR "ncp_iget: iget failed!\n");
+ return inode;
+}
+
+static void ncp_put_inode(struct inode *inode)
+{
+ if (inode->i_count == 1)
+ inode->i_nlink = 0;
+}
+static void
+ncp_delete_inode(struct inode *inode)
+{
if (S_ISDIR(inode->i_mode)) {
- DDPRINTK("ncp_put_inode: put directory %ld\n",
- inode->i_ino);
+ DDPRINTK(KERN_DEBUG "ncp_delete_inode: put directory %ld\n", inode->i_ino);
ncp_invalid_dir_cache(inode);
}
+
+ if (NCP_FINFO(inode)->opened && ncp_make_closed(inode) != 0) {
+ /* We can't do anything but complain. */
+ printk(KERN_ERR "ncp_delete_inode: could not close\n");
+ }
clear_inode(inode);
- unlock_super(sb);
+}
+
+static void ncp_init_root(struct ncp_server *server,
+ struct ncpfs_inode_info *info)
+{
+ struct ncp_inode_info *root = &(server->root);
+ struct nw_info_struct *i = &(root->finfo.i);
+ unsigned short dummy;
+
+ DPRINTK(KERN_DEBUG "ncp_init_root: i = %x\n", (int) i);
+
+ i->attributes = aDIR;
+ i->dataStreamSize= 1024;
+ i->dirEntNum = 0;
+ 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->finfo.opened= 0;
+ info->ino = 1;
+ info->nw_info = root->finfo;
}
struct super_block *
- ncp_read_super(struct super_block *sb, void *raw_data, int silent)
+ncp_read_super(struct super_block *sb, void *raw_data, int silent)
{
struct ncp_mount_data *data = (struct ncp_mount_data *) raw_data;
struct ncp_server *server;
struct file *ncp_filp;
+ struct inode *root_inode;
kdev_t dev = sb->s_dev;
int error;
+ struct ncpfs_inode_info finfo;
- if (data == NULL) {
- printk("ncp_read_super: missing data argument\n");
- sb->s_dev = 0;
- return NULL;
- }
- if (data->version != NCP_MOUNT_VERSION) {
- printk("ncp warning: mount version %s than kernel\n",
- (data->version < NCP_MOUNT_VERSION) ?
- "older" : "newer");
- sb->s_dev = 0;
- return NULL;
- }
- if ((data->ncp_fd >= NR_OPEN)
- || ((ncp_filp = current->files->fd[data->ncp_fd]) == NULL)
- || (!S_ISSOCK(ncp_filp->f_dentry->d_inode->i_mode))) {
- printk("ncp_read_super: invalid ncp socket\n");
- sb->s_dev = 0;
- return NULL;
- }
- /* We must malloc our own super-block info */
- server = (struct ncp_server *) ncp_kmalloc(sizeof(struct ncp_server),
- GFP_KERNEL);
-
- if (server == NULL) {
- printk("ncp_read_super: could not alloc ncp_server\n");
- return NULL;
- }
- ncp_filp->f_count++;
+ MOD_INC_USE_COUNT;
+ if (data == NULL)
+ goto out_no_data;
+ if (data->version != NCP_MOUNT_VERSION)
+ goto out_bad_mount;
+ if ((data->ncp_fd >= NR_OPEN) ||
+ ((ncp_filp = current->files->fd[data->ncp_fd]) == NULL) ||
+ !S_ISSOCK(ncp_filp->f_dentry->d_inode->i_mode))
+ goto out_bad_file;
lock_super(sb);
-
- NCP_SBP(sb) = server;
+ ncp_filp->f_count++;
sb->s_blocksize = 1024; /* Eh... Is this correct? */
sb->s_blocksize_bits = 10;
@@ -190,6 +244,13 @@ struct super_block *
sb->s_dev = dev;
sb->s_op = &ncp_sops;
+ /* We must malloc our own super-block info */
+ server = (struct ncp_server *) ncp_kmalloc(sizeof(struct ncp_server),
+ GFP_KERNEL);
+ if (server == NULL)
+ goto out_no_server;
+ NCP_SBP(sb) = server;
+
server->ncp_filp = ncp_filp;
server->lock = 0;
server->wait = NULL;
@@ -202,7 +263,7 @@ struct super_block *
now because of PATH_MAX changes.. */
if (server->m.time_out < 10) {
server->m.time_out = 10;
- printk("You need to recompile your ncpfs utils..\n");
+ printk(KERN_INFO "You need to recompile your ncpfs utils..\n");
}
server->m.file_mode = (server->m.file_mode &
(S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFREG;
@@ -211,54 +272,74 @@ struct super_block *
server->packet_size = NCP_PACKET_SIZE;
server->packet = ncp_kmalloc(NCP_PACKET_SIZE, GFP_KERNEL);
+ if (server->packet == NULL)
+ goto out_no_packet;
- if (server->packet == NULL) {
- printk("ncpfs: could not alloc packet\n");
- error = -ENOMEM;
- unlock_super(sb);
- goto fail;
- }
ncp_lock_server(server);
error = ncp_connect(server);
ncp_unlock_server(server);
- unlock_super(sb);
-
- if (error < 0) {
- sb->s_dev = 0;
- printk("ncp_read_super: Failed connection, bailing out "
- "(error = %d).\n", -error);
- ncp_kfree_s(server->packet, server->packet_size);
- goto fail;
- }
- DPRINTK("ncp_read_super: NCP_SBP(sb) = %x\n", (int) NCP_SBP(sb));
+ if (error < 0)
+ goto out_no_connect;
+ DPRINTK(KERN_DEBUG "ncp_read_super: NCP_SBP(sb) = %x\n", (int) NCP_SBP(sb));
+
+ error = ncp_negotiate_buffersize(server, NCP_DEFAULT_BUFSIZE,
+ &(server->buffer_size));
+ if (error)
+ goto out_no_bufsize;
+ DPRINTK(KERN_DEBUG "ncpfs: bufsize = %d\n", server->buffer_size);
+
+ ncp_init_root(server, &finfo);
+ root_inode = ncp_iget(sb, &finfo);
+ if (!root_inode)
+ goto out_no_root;
+ DPRINTK(KERN_DEBUG "ncp_read_super: root vol=%d\n", NCP_FINFO(root_inode)->volNumber);
+ sb->s_root = d_alloc_root(root_inode, NULL);
+ if (!sb->s_root)
+ goto out_no_root;
- ncp_init_root(server);
-
- if (!(sb->s_root = d_alloc_root(iget(sb,ncp_info_ino(server,
- &(server->root))),NULL))) {
- sb->s_dev = 0;
- printk("ncp_read_super: get root inode failed\n");
- goto disconnect;
- }
- if (ncp_negotiate_buffersize(server, NCP_DEFAULT_BUFSIZE,
- &(server->buffer_size)) != 0) {
- sb->s_dev = 0;
- printk("ncp_read_super: could not get bufsize\n");
- goto disconnect;
- }
- DPRINTK("ncpfs: bufsize = %d\n", server->buffer_size);
-
- MOD_INC_USE_COUNT;
+ unlock_super(sb);
return sb;
- disconnect:
+out_no_root:
+ printk(KERN_ERR "ncp_read_super: get root inode failed\n");
+ iput(root_inode);
+ goto out_disconnect;
+out_no_bufsize:
+ printk(KERN_ERR "ncp_read_super: could not get bufsize\n");
+out_disconnect:
ncp_lock_server(server);
ncp_disconnect(server);
ncp_unlock_server(server);
+ goto out_free_packet;
+out_no_connect:
+ printk(KERN_ERR "ncp_read_super: Failed connection, error=%d\n", error);
+out_free_packet:
ncp_kfree_s(server->packet, server->packet_size);
- fail:
- put_filp(ncp_filp);
+ goto out_free_server;
+out_no_packet:
+ printk(KERN_ERR "ncp_read_super: could not alloc packet\n");
+out_free_server:
ncp_kfree_s(NCP_SBP(sb), sizeof(struct ncp_server));
+ goto out_unlock;
+out_no_server:
+ printk(KERN_ERR "ncp_read_super: could not alloc ncp_server\n");
+out_unlock:
+ put_filp(ncp_filp);
+ unlock_super(sb);
+ goto out;
+
+out_bad_file:
+ printk(KERN_ERR "ncp_read_super: invalid ncp socket\n");
+ goto out;
+out_bad_mount:
+ printk(KERN_INFO "ncp_read_super: kernel requires mount version %d\n",
+ NCP_MOUNT_VERSION);
+ goto out;
+out_no_data:
+ printk(KERN_ERR "ncp_read_super: missing data argument\n");
+out:
+ sb->s_dev = 0;
+ MOD_DEC_USE_COUNT;
return NULL;
}
@@ -275,20 +356,17 @@ static void ncp_put_super(struct super_block *sb)
close_fp(server->ncp_filp);
kill_proc(server->m.wdog_pid, SIGTERM, 0);
- ncp_free_all_inodes(server);
-
ncp_kfree_s(server->packet, server->packet_size);
- sb->s_dev = 0;
ncp_kfree_s(NCP_SBP(sb), sizeof(struct ncp_server));
- NCP_SBP(sb) = NULL;
+ sb->s_dev = 0;
unlock_super(sb);
MOD_DEC_USE_COUNT;
}
-static void ncp_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
+static int ncp_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
{
struct statfs tmp;
@@ -306,7 +384,7 @@ static void ncp_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
tmp.f_files = -1;
tmp.f_ffree = -1;
tmp.f_namelen = 12;
- copy_to_user(buf, &tmp, bufsiz);
+ return copy_to_user(buf, &tmp, bufsiz) ? -EFAULT : 0;
}
static int ncp_notify_change(struct inode *inode, struct iattr *attr)
@@ -359,11 +437,9 @@ static int ncp_notify_change(struct inode *inode, struct iattr *attr)
info.lastAccessDate = le16_to_cpu(info.lastAccessDate);
}
if (info_mask != 0) {
- if ((result =
- ncp_modify_file_or_subdir_dos_info(NCP_SERVER(inode),
- NCP_ISTRUCT(inode),
- info_mask,
- &info)) != 0) {
+ result = ncp_modify_file_or_subdir_dos_info(NCP_SERVER(inode),
+ inode, info_mask, &info);
+ if (result != 0) {
result = -EACCES;
if (info_mask == (DM_CREATE_TIME | DM_CREATE_DATE)) {
@@ -379,8 +455,7 @@ static int ncp_notify_change(struct inode *inode, struct iattr *attr)
if ((attr->ia_valid & ATTR_SIZE) != 0) {
int written;
- DPRINTK("ncpfs: trying to change size of %s to %ld\n",
- NCP_ISTRUCT(inode)->entryName, attr->ia_size);
+ DPRINTK(KERN_DEBUG "ncpfs: trying to change size to %ld\n", attr->ia_size);
if ((result = ncp_make_open(inode, O_RDWR)) < 0) {
return -EACCES;
@@ -390,13 +465,12 @@ static int ncp_notify_change(struct inode *inode, struct iattr *attr)
/* According to ndir, the changes only take effect after
closing the file */
- ncp_close_file(NCP_SERVER(inode),
- NCP_FINFO(inode)->file_handle);
- NCP_FINFO(inode)->opened = 0;
-
- result = 0;
+ result = ncp_make_closed(inode);
}
- ncp_invalid_dir_cache(NCP_INOP(inode)->dir->inode);
+ /*
+ * We need a dentry here ...
+ */
+ /* ncp_invalid_dir_cache(NCP_INOP(inode)->dir->inode); */
return result;
}
@@ -423,7 +497,10 @@ EXPORT_NO_SYMBOLS;
int init_module(void)
{
- DPRINTK("ncpfs: init_module called\n");
+ DPRINTK(KERN_DEBUG "ncpfs: init_module called\n");
+
+ read_sem = MUTEX;
+ read_nwinfo = NULL;
#ifdef DEBUG_NCP_MALLOC
ncp_malloced = 0;
@@ -436,12 +513,12 @@ int init_module(void)
void cleanup_module(void)
{
- DPRINTK("ncpfs: cleanup_module called\n");
+ DPRINTK(KERN_DEBUG "ncpfs: cleanup_module called\n");
ncp_free_dir_cache();
unregister_filesystem(&ncp_fs_type);
#ifdef DEBUG_NCP_MALLOC
- printk("ncp_malloced: %d\n", ncp_malloced);
- printk("ncp_current_malloced: %d\n", ncp_current_malloced);
+ printk(KERN_DEBUG "ncp_malloced: %d\n", ncp_malloced);
+ printk(KERN_DEBUG "ncp_current_malloced: %d\n", ncp_current_malloced);
#endif
}
diff --git a/fs/ncpfs/ioctl.c b/fs/ncpfs/ioctl.c
index 9b88c3c9f..e9f0ca86c 100644
--- a/fs/ncpfs/ioctl.c
+++ b/fs/ncpfs/ioctl.c
@@ -2,25 +2,27 @@
* ioctl.c
*
* Copyright (C) 1995, 1996 by Volker Lendecke
+ * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
*
*/
#include <asm/uaccess.h>
#include <linux/errno.h>
#include <linux/fs.h>
-#include <linux/ncp_fs.h>
#include <linux/ioctl.h>
#include <linux/sched.h>
#include <linux/mm.h>
+
#include <linux/ncp.h>
+#include <linux/ncp_fs.h>
int ncp_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
+ struct ncp_server *server = NCP_SERVER(inode);
int result;
struct ncp_ioctl_request request;
struct ncp_fs_info info;
- struct ncp_server *server = NCP_SERVER(inode);
switch (cmd) {
case NCP_IOC_NCPREQUEST:
@@ -56,7 +58,7 @@ int ncp_ioctl(struct inode *inode, struct file *filp,
ncp_request(server, request.function);
- DPRINTK("ncp_ioctl: copy %d bytes\n",
+ DPRINTK(KERN_DEBUG "ncp_ioctl: copy %d bytes\n",
server->reply_size);
copy_to_user(request.data, server->packet, server->reply_size);
@@ -82,19 +84,18 @@ int ncp_ioctl(struct inode *inode, struct file *filp,
sizeof(info))) != 0) {
return result;
}
- copy_from_user(&info, (struct ncp_fs_info *) arg,
- sizeof(info));
+ copy_from_user(&info, (struct ncp_fs_info *) arg, sizeof(info));
if (info.version != NCP_GET_FS_INFO_VERSION) {
- DPRINTK("info.version invalid: %d\n", info.version);
+ DPRINTK(KERN_DEBUG "info.version invalid: %d\n", info.version);
return -EINVAL;
}
/* TODO: info.addr = server->m.serv_addr; */
- info.mounted_uid = server->m.mounted_uid;
- info.connection = server->connection;
- info.buffer_size = server->buffer_size;
- info.volume_number = NCP_ISTRUCT(inode)->volNumber;
- info.directory_id = NCP_ISTRUCT(inode)->DosDirNum;
+ info.mounted_uid = server->m.mounted_uid;
+ info.connection = server->connection;
+ info.buffer_size = server->buffer_size;
+ info.volume_number = NCP_FINFO(inode)->volNumber;
+ info.directory_id = NCP_FINFO(inode)->DosDirNum;
copy_to_user((struct ncp_fs_info *) arg, &info, sizeof(info));
return 0;
diff --git a/fs/ncpfs/mmap.c b/fs/ncpfs/mmap.c
index 5dfdeb27f..56275034d 100644
--- a/fs/ncpfs/mmap.c
+++ b/fs/ncpfs/mmap.c
@@ -2,6 +2,7 @@
* mmap.c
*
* Copyright (C) 1995, 1996 by Volker Lendecke
+ * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
*
*/
@@ -32,7 +33,8 @@ static inline int min(int a, int b)
static unsigned long ncp_file_mmap_nopage(struct vm_area_struct *area,
unsigned long address, int no_share)
{
- struct inode *inode = area->vm_dentry->d_inode;
+ struct dentry *dentry = area->vm_dentry;
+ struct inode *inode = dentry->d_inode;
unsigned long page;
unsigned int clear;
unsigned long tmp;
@@ -120,7 +122,7 @@ int ncp_mmap(struct file *file, struct vm_area_struct *vma)
{
struct inode *inode = file->f_dentry->d_inode;
- DPRINTK("ncp_mmap: called\n");
+ DPRINTK(KERN_DEBUG "ncp_mmap: called\n");
if (!ncp_conn_valid(NCP_SERVER(inode))) {
return -EIO;
@@ -132,7 +134,6 @@ int ncp_mmap(struct file *file, struct vm_area_struct *vma)
return -EACCES;
if (!IS_RDONLY(inode)) {
inode->i_atime = CURRENT_TIME;
- mark_inode_dirty(inode);
}
vma->vm_dentry = dget(file->f_dentry);
diff --git a/fs/ncpfs/ncplib_kernel.c b/fs/ncpfs/ncplib_kernel.c
index f7d4de4a1..8d60732ef 100644
--- a/fs/ncpfs/ncplib_kernel.c
+++ b/fs/ncpfs/ncplib_kernel.c
@@ -3,9 +3,11 @@
*
* 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
*
*/
+
#include "ncplib_kernel.h"
static inline int min(int a, int b)
@@ -16,7 +18,7 @@ static inline int min(int a, int b)
static void assert_server_locked(struct ncp_server *server)
{
if (server->lock == 0) {
- DPRINTK("ncpfs: server not locked!\n");
+ DPRINTK(KERN_DEBUG "ncpfs: server not locked!\n");
}
}
@@ -65,7 +67,7 @@ static void ncp_add_pstring(struct ncp_server *server, const char *s)
int len = strlen(s);
assert_server_locked(server);
if (len > 255) {
- DPRINTK("ncpfs: string too long: %s\n", s);
+ DPRINTK(KERN_DEBUG "ncpfs: string too long: %s\n", s);
len = 255;
}
ncp_add_byte(server, len);
@@ -115,8 +117,8 @@ static __u32
return get_unaligned((__u32 *) ncp_reply_data(server, offset));
}
-int ncp_negotiate_buffersize(struct ncp_server *server,
- int size, int *target)
+int
+ncp_negotiate_buffersize(struct ncp_server *server, int size, int *target)
{
int result;
@@ -133,7 +135,8 @@ int ncp_negotiate_buffersize(struct ncp_server *server,
return 0;
}
-int ncp_get_volume_info_with_number(struct ncp_server *server, int n,
+int
+ncp_get_volume_info_with_number(struct ncp_server *server, int n,
struct ncp_volume_info *target)
{
int result;
@@ -143,8 +146,7 @@ int ncp_get_volume_info_with_number(struct ncp_server *server, int n,
ncp_add_byte(server, n);
if ((result = ncp_request(server, 22)) != 0) {
- ncp_unlock_server(server);
- return result;
+ goto out;
}
target->total_blocks = ncp_reply_dword(server, 0);
target->free_blocks = ncp_reply_dword(server, 4);
@@ -156,18 +158,21 @@ int ncp_get_volume_info_with_number(struct ncp_server *server, int n,
memset(&(target->volume_name), 0, sizeof(target->volume_name));
+ result = -EIO;
len = ncp_reply_byte(server, 29);
if (len > NCP_VOLNAME_LEN) {
- DPRINTK("ncpfs: volume name too long: %d\n", len);
- ncp_unlock_server(server);
- return -EIO;
+ DPRINTK(KERN_DEBUG "ncpfs: volume name too long: %d\n", len);
+ goto out;
}
memcpy(&(target->volume_name), ncp_reply_data(server, 30), len);
+ result = 0;
+out:
ncp_unlock_server(server);
- return 0;
+ return result;
}
-int ncp_close_file(struct ncp_server *server, const char *file_id)
+int
+ncp_close_file(struct ncp_server *server, const char *file_id)
{
int result;
@@ -180,10 +185,25 @@ int ncp_close_file(struct ncp_server *server, const char *file_id)
return result;
}
-static void ncp_add_handle_path(struct ncp_server *server,
- __u8 vol_num,
- __u32 dir_base, int have_dir_base,
- char *path)
+/*
+ * Called with the superblock locked.
+ */
+int
+ncp_make_closed(struct inode *inode)
+{
+ int err;
+ NCP_FINFO(inode)->opened = 0;
+ err = ncp_close_file(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle);
+#ifdef NCPFS_PARANOIA
+if (!err)
+printk(KERN_DEBUG "ncp_make_closed: volnum=%d, dirent=%u, error=%d\n",
+NCP_FINFO(inode)->volNumber, NCP_FINFO(inode)->dirEntNum, err);
+#endif
+ return err;
+}
+
+static void ncp_add_handle_path(struct ncp_server *server, __u8 vol_num,
+ __u32 dir_base, int have_dir_base, char *path)
{
ncp_add_byte(server, vol_num);
ncp_add_dword(server, dir_base);
@@ -213,34 +233,40 @@ static void ncp_extract_file_info(void *structure, struct nw_info_struct *target
return;
}
-int ncp_obtain_info(struct ncp_server *server,
- __u8 vol_num, __u32 dir_base,
- char *path, /* At most 1 component */
- struct nw_info_struct *target)
+/*
+ * Returns information for a (one-component) name relative to
+ * the specified directory.
+ */
+int ncp_obtain_info(struct ncp_server *server, struct inode *dir, char *path,
+ struct nw_info_struct *target)
{
+ __u8 volnum = NCP_FINFO(dir)->volNumber;
+ __u32 dirent = NCP_FINFO(dir)->dirEntNum;
int result;
if (target == NULL) {
+ printk(KERN_ERR "ncp_obtain_info: invalid call\n");
return -EINVAL;
}
ncp_init_request(server);
ncp_add_byte(server, 6); /* subfunction */
- ncp_add_byte(server, server->name_space[vol_num]);
- ncp_add_byte(server, server->name_space[vol_num]);
+ ncp_add_byte(server, server->name_space[volnum]);
+ ncp_add_byte(server, server->name_space[volnum]); /* N.B. twice ?? */
ncp_add_word(server, htons(0xff00)); /* get all */
ncp_add_dword(server, RIM_ALL);
- ncp_add_handle_path(server, vol_num, dir_base, 1, path);
+ ncp_add_handle_path(server, volnum, dirent, 1, path);
- if ((result = ncp_request(server, 87)) != 0) {
- ncp_unlock_server(server);
- return result;
- }
+ if ((result = ncp_request(server, 87)) != 0)
+ goto out;
ncp_extract_file_info(ncp_reply_data(server, 0), target);
+
+out:
ncp_unlock_server(server);
- return 0;
+ return result;
}
-static inline int ncp_has_os2_namespace(struct ncp_server *server, __u8 volume)
+static inline int
+ncp_has_os2_namespace(struct ncp_server *server, __u8 volume)
{
int result;
__u8 *namespace;
@@ -253,34 +279,36 @@ static inline int ncp_has_os2_namespace(struct ncp_server *server, __u8 volume)
if ((result = ncp_request(server, 87)) != 0) {
ncp_unlock_server(server);
- return 0;
+ return 0; /* not result ?? */
}
no_namespaces = ncp_reply_word(server, 0);
namespace = ncp_reply_data(server, 2);
+ result = 1;
while (no_namespaces > 0) {
- DPRINTK("get_namespaces: found %d on %d\n", *namespace, volume);
+ DPRINTK(KERN_DEBUG "get_namespaces: found %d on %d\n", *namespace, volume);
if (*namespace == 4) {
- DPRINTK("get_namespaces: found OS2\n");
- ncp_unlock_server(server);
- return 1;
+ DPRINTK(KERN_DEBUG "get_namespaces: found OS2\n");
+ goto out;
}
namespace += 1;
no_namespaces -= 1;
}
+ result = 0;
+out:
ncp_unlock_server(server);
- return 0;
+ return result;
}
-int ncp_lookup_volume(struct ncp_server *server,
- char *volname,
+int
+ncp_lookup_volume(struct ncp_server *server, char *volname,
struct nw_info_struct *target)
{
int result;
int volnum;
- DPRINTK("ncp_lookup_volume: looking up vol %s\n", volname);
+ DPRINTK(KERN_DEBUG "ncp_lookup_volume: looking up vol %s\n", volname);
ncp_init_request(server);
ncp_add_byte(server, 22); /* Subfunction: Generate dir handle */
@@ -306,7 +334,7 @@ int ncp_lookup_volume(struct ncp_server *server,
server->name_space[volnum] = ncp_has_os2_namespace(server, volnum) ? 4 : 0;
- DPRINTK("lookup_vol: namespace[%d] = %d\n",
+ DPRINTK(KERN_DEBUG "lookup_vol: namespace[%d] = %d\n",
volnum, server->name_space[volnum]);
target->nameLen = strlen(volname);
@@ -316,22 +344,22 @@ int ncp_lookup_volume(struct ncp_server *server,
}
int ncp_modify_file_or_subdir_dos_info(struct ncp_server *server,
- struct nw_info_struct *file,
- __u32 info_mask,
+ struct inode *dir, __u32 info_mask,
struct nw_modify_dos_info *info)
{
+ __u8 volnum = NCP_FINFO(dir)->volNumber;
+ __u32 dirent = NCP_FINFO(dir)->dirEntNum;
int result;
ncp_init_request(server);
ncp_add_byte(server, 7); /* subfunction */
- ncp_add_byte(server, server->name_space[file->volNumber]);
+ ncp_add_byte(server, server->name_space[volnum]);
ncp_add_byte(server, 0); /* reserved */
ncp_add_word(server, htons(0x0680)); /* search attribs: all */
ncp_add_dword(server, info_mask);
ncp_add_mem(server, info, sizeof(*info));
- ncp_add_handle_path(server, file->volNumber,
- file->dirEntNum, 1, NULL);
+ ncp_add_handle_path(server, volnum, dirent, 1, NULL);
result = ncp_request(server, 87);
ncp_unlock_server(server);
@@ -339,17 +367,18 @@ int ncp_modify_file_or_subdir_dos_info(struct ncp_server *server,
}
int ncp_del_file_or_subdir(struct ncp_server *server,
- struct nw_info_struct *dir, char *name)
+ struct inode *dir, char *name)
{
+ __u8 volnum = NCP_FINFO(dir)->volNumber;
+ __u32 dirent = NCP_FINFO(dir)->dirEntNum;
int result;
ncp_init_request(server);
ncp_add_byte(server, 8); /* subfunction */
- ncp_add_byte(server, server->name_space[dir->volNumber]);
+ ncp_add_byte(server, server->name_space[volnum]);
ncp_add_byte(server, 0); /* reserved */
ncp_add_word(server, ntohs(0x0680)); /* search attribs: all */
- ncp_add_handle_path(server, dir->volNumber,
- dir->dirEntNum, 1, name);
+ ncp_add_handle_path(server, volnum, dirent, 1, name);
result = ncp_request(server, 87);
ncp_unlock_server(server);
@@ -367,22 +396,29 @@ static inline void ConvertToNWfromDWORD(__u32 sfd, __u8 ret[6])
/* If both dir and name are NULL, then in target there's already a
looked-up entry that wants to be opened. */
int ncp_open_create_file_or_subdir(struct ncp_server *server,
- struct nw_info_struct *dir, char *name,
+ struct inode *dir, char *name,
int open_create_mode,
__u32 create_attributes,
int desired_acc_rights,
struct nw_file_info *target)
{
- int result;
__u16 search_attribs = ntohs(0x0600);
- __u8 volume = (dir != NULL) ? dir->volNumber : target->i.volNumber;
+ __u8 volnum = target->i.volNumber;
+ __u32 dirent = target->i.dirEntNum;
+ int result;
+
+ if (dir)
+ {
+ volnum = NCP_FINFO(dir)->volNumber;
+ dirent = NCP_FINFO(dir)->dirEntNum;
+ }
if ((create_attributes & aDIR) != 0) {
search_attribs |= ntohs(0x0080);
}
ncp_init_request(server);
ncp_add_byte(server, 1); /* subfunction */
- ncp_add_byte(server, server->name_space[volume]);
+ ncp_add_byte(server, server->name_space[volnum]);
ncp_add_byte(server, open_create_mode);
ncp_add_word(server, search_attribs);
ncp_add_dword(server, RIM_ALL);
@@ -390,53 +426,47 @@ int ncp_open_create_file_or_subdir(struct ncp_server *server,
/* The desired acc rights seem to be the inherited rights mask
for directories */
ncp_add_word(server, desired_acc_rights);
+ ncp_add_handle_path(server, volnum, dirent, 1, name);
- if (dir != NULL) {
- ncp_add_handle_path(server, volume, dir->dirEntNum, 1, name);
- } else {
- ncp_add_handle_path(server, volume, target->i.dirEntNum,
- 1, NULL);
- }
-
- if ((result = ncp_request(server, 87)) != 0) {
- ncp_unlock_server(server);
- return result;
- }
+ if ((result = ncp_request(server, 87)) != 0)
+ goto out;
target->opened = 1;
target->server_file_handle = ncp_reply_dword(server, 0);
target->open_create_action = ncp_reply_byte(server, 4);
if (dir != NULL) {
/* in target there's a new finfo to fill */
- ncp_extract_file_info(ncp_reply_data(server, 5), &(target->i));
+ ncp_extract_file_info(ncp_reply_data(server, 6), &(target->i));
}
ConvertToNWfromDWORD(target->server_file_handle, target->file_handle);
+out:
ncp_unlock_server(server);
- return 0;
+ return result;
}
-
-int ncp_initialize_search(struct ncp_server *server,
- struct nw_info_struct *dir,
- struct nw_search_sequence *target)
+int
+ncp_initialize_search(struct ncp_server *server, struct inode *dir,
+ struct nw_search_sequence *target)
{
+ __u8 volnum = NCP_FINFO(dir)->volNumber;
+ __u32 dirent = NCP_FINFO(dir)->dirEntNum;
int result;
ncp_init_request(server);
ncp_add_byte(server, 2); /* subfunction */
- ncp_add_byte(server, server->name_space[dir->volNumber]);
+ ncp_add_byte(server, server->name_space[volnum]);
ncp_add_byte(server, 0); /* reserved */
- ncp_add_handle_path(server, dir->volNumber, dir->dirEntNum, 1, NULL);
+ ncp_add_handle_path(server, volnum, dirent, 1, NULL);
- if ((result = ncp_request(server, 87)) != 0) {
- ncp_unlock_server(server);
- return result;
- }
+ result = ncp_request(server, 87);
+ if (result)
+ goto out;
memcpy(target, ncp_reply_data(server, 0), sizeof(*target));
+out:
ncp_unlock_server(server);
- return 0;
+ return result;
}
/* Search for everything */
@@ -457,42 +487,41 @@ int ncp_search_for_file_or_subdir(struct ncp_server *server,
ncp_add_byte(server, 0xff); /* following is a wildcard */
ncp_add_byte(server, '*');
- if ((result = ncp_request(server, 87)) != 0) {
- ncp_unlock_server(server);
- return result;
- }
+ if ((result = ncp_request(server, 87)) != 0)
+ goto out;
memcpy(seq, ncp_reply_data(server, 0), sizeof(*seq));
ncp_extract_file_info(ncp_reply_data(server, 10), target);
+out:
ncp_unlock_server(server);
- return 0;
+ return result;
}
int ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
- struct nw_info_struct *old_dir, char *old_name,
- struct nw_info_struct *new_dir, char *new_name)
+ struct inode *old_dir, char *old_name,
+ struct inode *new_dir, char *new_name)
{
- int result;
+ int result = -EINVAL;
- if ((old_dir == NULL) || (old_name == NULL)
- || (new_dir == NULL) || (new_name == NULL))
- return -EINVAL;
+ if ((old_dir == NULL) || (old_name == NULL) ||
+ (new_dir == NULL) || (new_name == NULL))
+ goto out;
ncp_init_request(server);
ncp_add_byte(server, 4); /* subfunction */
- ncp_add_byte(server, server->name_space[old_dir->volNumber]);
+ ncp_add_byte(server, server->name_space[NCP_FINFO(old_dir)->volNumber]);
ncp_add_byte(server, 1); /* rename flag */
ncp_add_word(server, ntohs(0x0680)); /* search attributes */
/* source Handle Path */
- ncp_add_byte(server, old_dir->volNumber);
- ncp_add_dword(server, old_dir->dirEntNum);
+ ncp_add_byte(server, NCP_FINFO(old_dir)->volNumber);
+ ncp_add_dword(server, NCP_FINFO(old_dir)->dirEntNum);
ncp_add_byte(server, 1);
ncp_add_byte(server, 1); /* 1 source component */
/* dest Handle Path */
- ncp_add_byte(server, new_dir->volNumber);
- ncp_add_dword(server, new_dir->dirEntNum);
+ ncp_add_byte(server, NCP_FINFO(new_dir)->volNumber);
+ ncp_add_dword(server, NCP_FINFO(new_dir)->dirEntNum);
ncp_add_byte(server, 1);
ncp_add_byte(server, 1); /* 1 destination component */
@@ -503,15 +532,17 @@ int ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
result = ncp_request(server, 87);
ncp_unlock_server(server);
+out:
return result;
}
/* We have to transfer to/from user space */
-int ncp_read(struct ncp_server *server, const char *file_id,
- __u32 offset, __u16 to_read,
- char *target, int *bytes_read)
+int
+ncp_read(struct ncp_server *server, const char *file_id,
+ __u32 offset, __u16 to_read, char *target, int *bytes_read)
{
+ char *source;
int result;
ncp_init_request(server);
@@ -521,20 +552,23 @@ int ncp_read(struct ncp_server *server, const char *file_id,
ncp_add_word(server, htons(to_read));
if ((result = ncp_request(server, 72)) != 0) {
- ncp_unlock_server(server);
- return result;
+ goto out;
}
*bytes_read = ntohs(ncp_reply_word(server, 0));
+ source = ncp_reply_data(server, 2 + (offset & 1));
- copy_to_user(target, ncp_reply_data(server, 2 + (offset & 1)), *bytes_read);
-
+ result = -EFAULT;
+ if (!copy_to_user(target, source, *bytes_read))
+ result = 0;
+out:
ncp_unlock_server(server);
- return 0;
+ return result;
}
-int ncp_write(struct ncp_server *server, const char *file_id,
+int
+ncp_write(struct ncp_server *server, const char *file_id,
__u32 offset, __u16 to_write,
- const char *source, int *bytes_written)
+ const char *source, int *bytes_written)
{
int result;
@@ -545,12 +579,11 @@ int ncp_write(struct ncp_server *server, const char *file_id,
ncp_add_word(server, htons(to_write));
ncp_add_mem_fromfs(server, source, to_write);
- if ((result = ncp_request(server, 73)) != 0) {
- ncp_unlock_server(server);
- return result;
- }
+ if ((result = ncp_request(server, 73)) != 0)
+ goto out;
*bytes_written = to_write;
-
+ result = 0;
+out:
ncp_unlock_server(server);
- return 0;
+ return result;
}
diff --git a/fs/ncpfs/ncplib_kernel.h b/fs/ncpfs/ncplib_kernel.h
index 48425adb5..69388576b 100644
--- a/fs/ncpfs/ncplib_kernel.h
+++ b/fs/ncpfs/ncplib_kernel.h
@@ -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
*
*/
@@ -10,9 +11,6 @@
#define _NCPLIB_H
#include <linux/fs.h>
-#include <linux/ncp.h>
-#include <linux/ncp_fs.h>
-#include <linux/ncp_fs_sb.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/malloc.h>
@@ -24,71 +22,35 @@
#include <asm/string.h>
#include <linux/ncp.h>
+#include <linux/ncp_fs.h>
+#include <linux/ncp_fs_sb.h>
-int
-ncp_negotiate_buffersize(struct ncp_server *server, int size,
- int *target);
-int
-ncp_get_volume_info_with_number(struct ncp_server *server, int n,
- struct ncp_volume_info *target);
-
-int
-ncp_close_file(struct ncp_server *server, const char *file_id);
-
-int
-ncp_read(struct ncp_server *server, const char *file_id,
- __u32 offset, __u16 to_read,
- char *target, int *bytes_read);
-
-int
-ncp_write(struct ncp_server *server, const char *file_id,
- __u32 offset, __u16 to_write,
- const char *source, int *bytes_written);
+int ncp_negotiate_buffersize(struct ncp_server *, int, int *);
+int ncp_get_volume_info_with_number(struct ncp_server *, int,
+ struct ncp_volume_info *);
+int ncp_close_file(struct ncp_server *, const char *);
+int ncp_read(struct ncp_server *, const char *, __u32, __u16, char *, int *);
+int ncp_write(struct ncp_server *, const char *, __u32, __u16,
+ const char *, int *);
-int
-ncp_obtain_info(struct ncp_server *server,
- __u8 vol_num, __u32 dir_base,
- char *path, /* At most 1 component */
+int ncp_obtain_info(struct ncp_server *server, struct inode *, char *,
struct nw_info_struct *target);
+int ncp_lookup_volume(struct ncp_server *, char *, struct nw_info_struct *);
+int ncp_modify_file_or_subdir_dos_info(struct ncp_server *, struct inode *,
+ __u32, struct nw_modify_dos_info *info);
-int
-ncp_lookup_volume(struct ncp_server *server,
- char *volname,
- struct nw_info_struct *target);
-
-
-int
-ncp_modify_file_or_subdir_dos_info(struct ncp_server *server,
- struct nw_info_struct *file,
- __u32 info_mask,
- struct nw_modify_dos_info *info);
+int ncp_del_file_or_subdir(struct ncp_server *, struct inode *, char *);
+int ncp_open_create_file_or_subdir(struct ncp_server *, struct inode *, char *,
+ int, __u32, int, struct nw_file_info *);
-int
-ncp_del_file_or_subdir(struct ncp_server *server,
- struct nw_info_struct *dir, char *name);
-
-int
-ncp_open_create_file_or_subdir(struct ncp_server *server,
- struct nw_info_struct *dir, char *name,
- int open_create_mode,
- __u32 create_attributes,
- int desired_acc_rights,
- struct nw_file_info *target);
-
-int
-ncp_initialize_search(struct ncp_server *server,
- struct nw_info_struct *dir,
+int ncp_initialize_search(struct ncp_server *, struct inode *,
struct nw_search_sequence *target);
-
-int
-ncp_search_for_file_or_subdir(struct ncp_server *server,
+int ncp_search_for_file_or_subdir(struct ncp_server *server,
struct nw_search_sequence *seq,
struct nw_info_struct *target);
-int
-ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
- struct nw_info_struct *old_dir, char *old_name,
- struct nw_info_struct *new_dir, char *new_name);
+int ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
+ struct inode *, char *, struct inode *, char *);
#endif /* _NCPLIB_H */
diff --git a/fs/ncpfs/sock.c b/fs/ncpfs/sock.c
index e88176f95..08055ac5e 100644
--- a/fs/ncpfs/sock.c
+++ b/fs/ncpfs/sock.c
@@ -4,11 +4,11 @@
* Copyright (C) 1992, 1993 Rick Sladkey
*
* Modified 1995, 1996 by Volker Lendecke to be usable for ncp
+ * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
*
*/
#include <linux/sched.h>
-#include <linux/ncp_fs.h>
#include <linux/errno.h>
#include <linux/socket.h>
#include <linux/fcntl.h>
@@ -19,13 +19,13 @@
#include <linux/mm.h>
#include <linux/netdevice.h>
#include <net/scm.h>
+#include <net/sock.h>
#include <linux/ipx.h>
+#include <linux/poll.h>
#include <linux/ncp.h>
#include <linux/ncp_fs.h>
#include <linux/ncp_fs_sb.h>
-#include <net/sock.h>
-#include <linux/poll.h>
static int _recv(struct socket *sock, unsigned char *ubuf, int size,
unsigned flags)
@@ -104,10 +104,12 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
file = server->ncp_filp;
inode = file->f_dentry->d_inode;
sock = &inode->u.socket_i;
+ /* N.B. this isn't needed ... check socket type? */
if (!sock) {
- printk("ncp_rpc_call: socki_lookup failed\n");
+ printk(KERN_ERR "ncp_rpc_call: socki_lookup failed\n");
return -EBADF;
}
+
init_timeout = server->m.time_out;
max_timeout = NCP_MAX_RPC_TIMEOUT;
retrans = server->m.retry_count;
@@ -127,7 +129,8 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
fs = get_fs();
set_fs(get_ds());
for (n = 0, timeout = init_timeout;; n++, timeout <<= 1) {
- DDPRINTK("ncpfs: %08lX:%02X%02X%02X%02X%02X%02X:%04X\n",
+ /*
+ DDPRINTK(KERN_DEBUG "ncpfs: %08lX:%02X%02X%02X%02X%02X%02X:%04X\n",
htonl(server->m.serv_addr.sipx_network),
server->m.serv_addr.sipx_node[0],
server->m.serv_addr.sipx_node[1],
@@ -136,17 +139,18 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
server->m.serv_addr.sipx_node[4],
server->m.serv_addr.sipx_node[5],
ntohs(server->m.serv_addr.sipx_port));
- DDPRINTK("ncpfs: req.typ: %04X, con: %d, "
+ */
+ DDPRINTK(KERN_DEBUG "ncpfs: req.typ: %04X, con: %d, "
"seq: %d",
request.type,
(request.conn_high << 8) + request.conn_low,
request.sequence);
- DDPRINTK(" func: %d\n",
+ DDPRINTK(KERN_DEBUG " func: %d\n",
request.function);
result = _send(sock, (void *) start, size);
if (result < 0) {
- printk("ncp_rpc_call: send error = %d\n", result);
+ printk(KERN_ERR "ncp_rpc_call: send error = %d\n", result);
break;
}
re_select:
@@ -159,7 +163,7 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
* This is useful to see if the system is
* hanging */
if (acknowledge_seen == 0) {
- printk("NCP max timeout\n");
+ printk(KERN_WARNING "NCP max timeout\n");
}
timeout = max_timeout;
}
@@ -167,7 +171,7 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
schedule();
remove_wait_queue(entry.wait_address, &entry.wait);
current->state = TASK_RUNNING;
- if (current->signal & ~current->blocked) {
+ if (signal_pending(current)) {
current->timeout = 0;
result = -ERESTARTSYS;
break;
@@ -176,7 +180,7 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
if (n < retrans)
continue;
if (server->m.flags & NCP_MOUNT_SOFT) {
- printk("NCP server not responding\n");
+ printk(KERN_WARNING "NCP server not responding\n");
result = -EIO;
break;
}
@@ -184,7 +188,7 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
timeout = init_timeout;
init_timeout <<= 1;
if (!major_timeout_seen) {
- printk("NCP server not responding\n");
+ printk(KERN_WARNING "NCP server not responding\n");
}
major_timeout_seen = 1;
continue;
@@ -201,15 +205,15 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
MSG_PEEK | MSG_DONTWAIT);
if (result < 0) {
if (result == -EAGAIN) {
- DPRINTK("ncp_rpc_call: bad select ready\n");
+ DDPRINTK(KERN_DEBUG "ncp_rpc_call: bad select ready\n");
goto re_select;
}
if (result == -ECONNREFUSED) {
- DPRINTK("ncp_rpc_call: server playing coy\n");
+ DPRINTK(KERN_WARNING "ncp_rpc_call: server playing coy\n");
goto re_select;
}
if (result != -ERESTARTSYS) {
- printk("ncp_rpc_call: recv error = %d\n",
+ printk(KERN_ERR "ncp_rpc_call: recv error = %d\n",
-result);
}
break;
@@ -217,7 +221,7 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
if ((result == sizeof(reply))
&& (reply.type == NCP_POSITIVE_ACK)) {
/* Throw away the packet */
- DPRINTK("ncp_rpc_call: got positive acknowledge\n");
+ DPRINTK(KERN_DEBUG "ncp_rpc_call: got positive acknowledge\n");
_recv(sock, (void *) &reply, sizeof(reply),
MSG_DONTWAIT);
n = 0;
@@ -225,7 +229,7 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
acknowledge_seen = 1;
goto re_select;
}
- DDPRINTK("ncpfs: rep.typ: %04X, con: %d, tsk: %d,"
+ DDPRINTK(KERN_DEBUG "ncpfs: rep.typ: %04X, con: %d, tsk: %d,"
"seq: %d\n",
reply.type,
(reply.conn_high << 8) + reply.conn_low,
@@ -240,7 +244,7 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
/* seem to get wrong task from NW311 && (reply.task == request.task) */
&& (reply.conn_high == request.conn_high)))) {
if (major_timeout_seen)
- printk("NCP server OK\n");
+ printk(KERN_NOTICE "NCP server OK\n");
break;
}
/* JEJB/JSP 2/7/94
@@ -249,7 +253,7 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
* a null buffer yet. */
_recv(sock, (void *) &reply, sizeof(reply), MSG_DONTWAIT);
- DPRINTK("ncp_rpc_call: reply mismatch\n");
+ DPRINTK(KERN_WARNING "ncp_rpc_call: reply mismatch\n");
goto re_select;
}
/*
@@ -258,11 +262,11 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size)
*/
result = _recv(sock, (void *) start, server->packet_size, MSG_DONTWAIT);
if (result < 0) {
- printk("NCP: notice message: result=%d\n", result);
+ printk(KERN_WARNING "NCP: notice message: result=%d\n", result);
} else if (result < sizeof(struct ncp_reply_header)) {
- printk("NCP: just caught a too small read memory size..., "
+ printk(KERN_ERR "NCP: just caught a too small read memory size..., "
"email to NET channel\n");
- printk("NCP: result=%d\n", result);
+ printk(KERN_ERR "NCP: result=%d\n", result);
result = -EIO;
}
current->blocked = old_mask;
@@ -279,7 +283,7 @@ static int ncp_do_request(struct ncp_server *server, int size)
int result;
if (server->lock == 0) {
- printk("ncpfs: Server not locked!\n");
+ printk(KERN_ERR "ncpfs: Server not locked!\n");
return -EIO;
}
if (!ncp_conn_valid(server)) {
@@ -287,7 +291,7 @@ static int ncp_do_request(struct ncp_server *server, int size)
}
result = do_ncp_rpc_call(server, size);
- DDPRINTK("do_ncp_rpc_call returned %d\n", result);
+ DDPRINTK(KERN_DEBUG "do_ncp_rpc_call returned %d\n", result);
if (result < 0) {
/* There was a problem with I/O, so the connections is
@@ -299,19 +303,17 @@ static int ncp_do_request(struct ncp_server *server, int size)
/* ncp_do_request assures that at least a complete reply header is
* received. It assumes that server->current_size contains the ncp
- * request size */
+ * request size
+ */
int ncp_request(struct ncp_server *server, int function)
{
- struct ncp_request_header *h
- = (struct ncp_request_header *) (server->packet);
- struct ncp_reply_header *reply
- = (struct ncp_reply_header *) (server->packet);
-
+ struct ncp_request_header *h;
+ struct ncp_reply_header *reply;
int request_size = server->current_size
- - sizeof(struct ncp_request_header);
-
+ - sizeof(struct ncp_request_header);
int result;
+ h = (struct ncp_request_header *) (server->packet);
if (server->has_subfunction != 0) {
*(__u16 *) & (h->data[0]) = htons(request_size - 2);
}
@@ -321,13 +323,19 @@ int ncp_request(struct ncp_server *server, int function)
h->sequence = server->sequence;
h->conn_low = (server->connection) & 0xff;
h->conn_high = ((server->connection) & 0xff00) >> 8;
- h->task = (current->pid) & 0xff;
+ /*
+ * The server shouldn't know or care what task is making a
+ * request, so we always use the same task number.
+ */
+ h->task = 2; /* (current->pid) & 0xff; */
h->function = function;
- if ((result = ncp_do_request(server, request_size + sizeof(*h))) < 0) {
- DPRINTK("ncp_request_error: %d\n", result);
- return result;
+ result = ncp_do_request(server, request_size + sizeof(*h));
+ if (result < 0) {
+ DPRINTK(KERN_WARNING "ncp_request_error: %d\n", result);
+ goto out;
}
+ reply = (struct ncp_reply_header *) (server->packet);
server->completion = reply->completion_code;
server->conn_status = reply->connection_state;
server->reply_size = result;
@@ -335,48 +343,52 @@ int ncp_request(struct ncp_server *server, int function)
result = reply->completion_code;
- if (result != 0) {
- DPRINTK("ncp_completion_code: %x\n", result);
- }
+#ifdef NCPFS_PARANOIA
+if (result != 0)
+printk(KERN_DEBUG "ncp_request: completion code=%x\n", result);
+#endif
+out:
return result;
}
int ncp_connect(struct ncp_server *server)
{
- struct ncp_request_header *h
- = (struct ncp_request_header *) (server->packet);
+ struct ncp_request_header *h;
int result;
+ h = (struct ncp_request_header *) (server->packet);
h->type = NCP_ALLOC_SLOT_REQUEST;
server->sequence = 0;
- h->sequence = server->sequence;
- h->conn_low = 0xff;
- h->conn_high = 0xff;
- h->task = (current->pid) & 0xff;
- h->function = 0;
-
- if ((result = ncp_do_request(server, sizeof(*h))) < 0) {
- return result;
- }
+ h->sequence = server->sequence;
+ h->conn_low = 0xff;
+ h->conn_high = 0xff;
+ h->task = 2; /* see above */
+ h->function = 0;
+
+ result = ncp_do_request(server, sizeof(*h));
+ if (result < 0)
+ goto out;
server->sequence = 0;
server->connection = h->conn_low + (h->conn_high * 256);
- return 0;
+ result = 0;
+out:
+ return result;
}
int ncp_disconnect(struct ncp_server *server)
{
- struct ncp_request_header *h
- = (struct ncp_request_header *) (server->packet);
+ struct ncp_request_header *h;
+ h = (struct ncp_request_header *) (server->packet);
h->type = NCP_DEALLOC_SLOT_REQUEST;
server->sequence += 1;
- h->sequence = server->sequence;
- h->conn_low = (server->connection) & 0xff;
- h->conn_high = ((server->connection) & 0xff00) >> 8;
- h->task = (current->pid) & 0xff;
- h->function = 0;
+ h->sequence = server->sequence;
+ h->conn_low = (server->connection) & 0xff;
+ h->conn_high = ((server->connection) & 0xff00) >> 8;
+ h->task = 2; /* see above */
+ h->function = 0;
return ncp_do_request(server, sizeof(*h));
}
@@ -386,7 +398,7 @@ void ncp_lock_server(struct ncp_server *server)
#if 0
/* For testing, only 1 process */
if (server->lock != 0) {
- DPRINTK("ncpfs: server locked!!!\n");
+ DPRINTK(KERN_WARNING "ncpfs: server locked!!!\n");
}
#endif
while (server->lock)
@@ -397,7 +409,7 @@ void ncp_lock_server(struct ncp_server *server)
void ncp_unlock_server(struct ncp_server *server)
{
if (server->lock != 1) {
- printk("ncp_unlock_server: was not locked!\n");
+ printk(KERN_WARNING "ncp_unlock_server: was not locked!\n");
}
server->lock = 0;
wake_up(&server->wait);