patch-2.4.0-test5 linux/fs/smbfs/dir.c

Next file: linux/fs/smbfs/file.c
Previous file: linux/fs/smbfs/cache.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.0-test4/linux/fs/smbfs/dir.c linux/fs/smbfs/dir.c
@@ -4,19 +4,20 @@
  *  Copyright (C) 1995, 1996 by Paal-Kr. Engstad and Volker Lendecke
  *  Copyright (C) 1997 by Volker Lendecke
  *
+ *  Please add a note about your changes to smbfs in the ChangeLog file.
  */
 
 #include <linux/sched.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/smp_lock.h>
+#include <linux/ctype.h>
 
 #include <linux/smb_fs.h>
 #include <linux/smbno.h>
 
-#define SMBFS_PARANOIA 1
-/* #define SMBFS_DEBUG_VERBOSE 1 */
-/* #define pr_debug printk */
+#include "smb_debug.h"
+
 #define SMBFS_MAX_AGE 5*HZ
 
 static int smb_readdir(struct file *, void *, filldir_t);
@@ -58,10 +59,23 @@
 	struct cache_head *cachep;
 	int result;
 
-#ifdef SMBFS_DEBUG_VERBOSE
-printk("smb_readdir: reading %s/%s, f_pos=%d\n",
-dentry->d_parent->d_name.name, dentry->d_name.name, (int) filp->f_pos);
-#endif
+	VERBOSE("reading %s/%s, f_pos=%d\n",
+		DENTRY_PATH(dentry),  (int) filp->f_pos);
+
+	result = 0;
+	switch ((unsigned int) filp->f_pos)
+	{
+	case 0:
+		if (filldir(dirent, ".", 1, 0, dir->i_ino) < 0)
+			goto out;
+		filp->f_pos = 1;
+	case 1:
+		if (filldir(dirent, "..", 2, 1,
+				dentry->d_parent->d_inode->i_ino) < 0)
+			goto out;
+		filp->f_pos = 2;
+	}
+
 	/*
 	 * Make sure our inode is up-to-date.
 	 */
@@ -75,10 +89,16 @@
 	cachep = smb_get_dircache(dentry);
 	if (!cachep)
 		goto out;
+
 	/*
 	 * Make sure the cache is up-to-date.
+	 *
+	 * To detect changes on the server we refill on each "new" access.
+	 *
+	 * Directory mtime would be nice to use for finding changes,
+	 * unfortunately some servers (NT4) doesn't update on local changes.
 	 */
-	if (!cachep->valid)
+	if (!cachep->valid || filp->f_pos == 2)
 	{
 		result = smb_refill_dircache(cachep, dentry);
 		if (result)
@@ -86,18 +106,6 @@
 	}
 
 	result = 0;
-	switch ((unsigned int) filp->f_pos)
-	{
-	case 0:
-		if (filldir(dirent, ".", 1, 0, dir->i_ino) < 0)
-			goto out_free;
-		filp->f_pos = 1;
-	case 1:
-		if (filldir(dirent, "..", 2, 1,
-				dentry->d_parent->d_inode->i_ino) < 0)
-			goto out_free;
-		filp->f_pos = 2;
-	}
 
 	while (1)
 	{
@@ -143,10 +151,10 @@
 	struct dentry *dentry = file->f_dentry;
 	struct smb_sb_info *server;
 	int error = 0;
-#ifdef SMBFS_DEBUG_VERBOSE
-printk("smb_dir_open: (%s/%s)\n", dentry->d_parent->d_name.name, 
-file->f_dentry->d_name.name);
-#endif
+
+	VERBOSE("(%s/%s)\n", dentry->d_parent->d_name.name,
+		file->f_dentry->d_name.name);
+
 	/*
 	 * Directory timestamps in the core protocol aren't updated
 	 * when a file is added, so we give them a very short TTL.
@@ -199,39 +207,27 @@
 	 */
 	valid = (age <= SMBFS_MAX_AGE);
 #ifdef SMBFS_DEBUG_VERBOSE
-if (!valid)
-printk("smb_lookup_validate: %s/%s not valid, age=%lu\n", 
-dentry->d_parent->d_name.name, dentry->d_name.name, age);
+	if (!valid)
+		VERBOSE("%s/%s not valid, age=%lu\n", 
+			DENTRY_PATH(dentry), age);
 #endif
 
-	if (inode)
-	{
+	if (inode) {
 		lock_kernel();
-		if (is_bad_inode(inode))
-		{
-#ifdef SMBFS_PARANOIA
-printk("smb_lookup_validate: %s/%s has dud inode\n", 
-dentry->d_parent->d_name.name, dentry->d_name.name);
-#endif
+		if (is_bad_inode(inode)) {
+			PARANOIA("%s/%s has dud inode\n", DENTRY_PATH(dentry));
 			valid = 0;
 		} else if (!valid)
 			valid = (smb_revalidate_inode(dentry) == 0);
 		unlock_kernel();
-	} else
-	{
-	/*
-	 * What should we do for negative dentries?
-	 */
+	} else {
+		/*
+		 * What should we do for negative dentries?
+		 */
 	}
 	return valid;
 }
 
-/*
- * 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))
-
 static int 
 smb_hash_dentry(struct dentry *dir, struct qstr *this)
 {
@@ -270,19 +266,14 @@
 static int
 smb_delete_dentry(struct dentry * dentry)
 {
-	if (dentry->d_inode)
-	{
-		if (is_bad_inode(dentry->d_inode))
-		{
-#ifdef SMBFS_PARANOIA
-printk("smb_delete_dentry: bad inode, unhashing %s/%s\n", 
-dentry->d_parent->d_name.name, dentry->d_name.name);
-#endif
+	if (dentry->d_inode) {
+		if (is_bad_inode(dentry->d_inode)) {
+			PARANOIA("bad inode, unhashing %s/%s\n",
+				 DENTRY_PATH(dentry));
 			return 1;
 		}
-	} else
-	{
-	/* N.B. Unhash negative dentries? */
+	} else {
+		/* N.B. Unhash negative dentries? */
 	}
 	return 0;
 }
@@ -295,8 +286,7 @@
 void
 smb_renew_times(struct dentry * dentry)
 {
-	for (;;)
-	{
+	for (;;) {
 		dentry->d_time = jiffies;
 		if (IS_ROOT(dentry))
 			break;
@@ -317,9 +307,9 @@
 
 	error = smb_proc_getattr(dentry, &finfo);
 #ifdef SMBFS_PARANOIA
-if (error && error != -ENOENT)
-printk("smb_lookup: find %s/%s failed, error=%d\n",
-dentry->d_parent->d_name.name, dentry->d_name.name, error);
+	if (error && error != -ENOENT)
+		PARANOIA("find %s/%s failed, error=%d\n",
+			 DENTRY_PATH(dentry), error);
 #endif
 
 	inode = NULL;
@@ -354,10 +344,8 @@
 	int error;
 	struct smb_fattr fattr;
 
-#ifdef SMBFS_DEBUG_VERBOSE
-printk("smb_instantiate: file %s/%s, fileid=%u\n",
-dentry->d_parent->d_name.name, dentry->d_name.name, fileid);
-#endif
+	VERBOSE("file %s/%s, fileid=%u\n", DENTRY_PATH(dentry), fileid);
+
 	error = smb_proc_getattr(dentry, &fattr);
 	if (error)
 		goto out_close;
@@ -383,10 +371,8 @@
 out_close:
 	if (have_id)
 	{
-#ifdef SMBFS_PARANOIA
-printk("smb_instantiate: %s/%s failed, error=%d, closing %u\n",
-dentry->d_parent->d_name.name, dentry->d_name.name, error, fileid);
-#endif
+		PARANOIA("%s/%s failed, error=%d, closing %u\n",
+			 DENTRY_PATH(dentry), error, fileid);
 		smb_close_fileid(dentry, fileid);
 	}
 	goto out;
@@ -399,22 +385,15 @@
 	__u16 fileid;
 	int error;
 
-#ifdef SMBFS_DEBUG_VERBOSE
-printk("smb_create: creating %s/%s, mode=%d\n",
-dentry->d_parent->d_name.name, dentry->d_name.name, mode);
-#endif
+	VERBOSE("creating %s/%s, mode=%d\n", DENTRY_PATH(dentry), mode);
 
 	smb_invalid_dir_cache(dir);
 	error = smb_proc_create(dentry, 0, CURRENT_TIME, &fileid);
-	if (!error)
-	{
+	if (!error) {
 		error = smb_instantiate(dentry, fileid, 1);
-	} else
-	{
-#ifdef SMBFS_PARANOIA
-printk("smb_create: %s/%s failed, error=%d\n",
-dentry->d_parent->d_name.name, dentry->d_name.name, error);
-#endif
+	} else {
+		PARANOIA("%s/%s failed, error=%d\n",
+			 DENTRY_PATH(dentry), error);
 	}
 	return error;
 }
@@ -427,8 +406,7 @@
 
 	smb_invalid_dir_cache(dir);
 	error = smb_proc_mkdir(dentry);
-	if (!error)
-	{
+	if (!error) {
 		error = smb_instantiate(dentry, 0, 0);
 	}
 	return error;
@@ -452,7 +430,6 @@
 	if (!d_unhashed(dentry))
 		goto out;
 
-	smb_invalid_dir_cache(dir);
 	error = smb_proc_rmdir(dentry);
 
 out:
@@ -469,7 +446,6 @@
 	 */
 	smb_close(dentry->d_inode);
 
-	smb_invalid_dir_cache(dir);
 	error = smb_proc_unlink(dentry);
 	if (!error)
 		smb_renew_times(dentry);
@@ -494,10 +470,8 @@
 		error = smb_proc_unlink(new_dentry);
 		if (error)
 		{
-#ifdef SMBFS_DEBUG_VERBOSE
-printk("smb_rename: unlink %s/%s, error=%d\n",
-new_dentry->d_parent->d_name.name, new_dentry->d_name.name, error);
-#endif
+			VERBOSE("unlink %s/%s, error=%d\n",
+				DENTRY_PATH(new_dentry), error);
 			goto out;
 		}
 		/* FIXME */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)