patch-2.1.71 linux/fs/ufs/ufs_dir.c

Next file: linux/fs/ufs/ufs_file.c
Previous file: linux/fs/ufs/Makefile
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.70/linux/fs/ufs/ufs_dir.c linux/fs/ufs/ufs_dir.c
@@ -6,12 +6,13 @@
  * Laboratory for Computer Science Research Computing Facility
  * Rutgers, The State University of New Jersey
  *
- * $Id: ufs_dir.c,v 1.10 1997/06/05 01:29:06 davem Exp $
+ * swab support by Francois-Rene Rideau <rideau@ens.fr> 19970406
  *
  */
 
 #include <linux/fs.h>
-#include <linux/ufs_fs.h>
+
+#include "ufs_swab.h"
 
 /*
  * This is blatantly stolen from ext2fs
@@ -26,12 +27,18 @@
 	struct buffer_head * bh;
 	struct ufs_direct * de;
 	struct super_block * sb;
+	int de_reclen;
+	__u32 s_flags, bytesex;
 
+	/* Isn't that already done but the upper layer??? */
 	if (!inode || !S_ISDIR(inode->i_mode))
 		return -EBADF;
+
 	sb = inode->i_sb;
+        s_flags = sb->u.ufs_sb.s_flags;
+        bytesex = s_flags & UFS_BYTESEX;
 
-	if (inode->i_sb->u.ufs_sb.s_flags & UFS_DEBUG) {
+	if (s_flags & UFS_DEBUG) {
 	        printk("ufs_readdir: ino %lu  f_pos %lu\n",
 	               inode->i_ino, (unsigned long) filp->f_pos);
 	        ufs_print_inode(inode);
@@ -48,7 +55,8 @@
 		bh = bread (sb->s_dev, blk, sb->s_blocksize);
 		if (!bh) {
 	                /* XXX - error - skip to the next block */
-	                printk("ufs_readdir: dir inode %lu has a hole at offset %lu\n",
+	                printk("ufs_readdir: "
+			       "dir inode %lu has a hole at offset %lu\n",
 	                       inode->i_ino, (unsigned long int)filp->f_pos);
 			filp->f_pos += sb->s_blocksize - offset;
 			continue;
@@ -61,7 +69,7 @@
 		 * to make sure. */
 		if (filp->f_version != inode->i_version) {
 			for (i = 0; i < sb->s_blocksize && i < offset; ) {
-				de = (struct ufs_direct *) 
+				de = (struct ufs_direct *)
 					(bh->b_data + i);
 				/* It's too expensive to do a full
 				 * dirent test each time round this
@@ -69,28 +77,30 @@
 				 * least that it is non-zero.  A
 				 * failure will be detected in the
 				 * dirent test below. */
-				if (ufs_swab16(de->d_reclen) < 1)
+				de_reclen = SWAB16(de->d_reclen);
+				if (de_reclen < 1)
 					break;
-				i += ufs_swab16(de->d_reclen);
+				i += de_reclen;
 			}
 			offset = i;
 			filp->f_pos = (filp->f_pos & ~(sb->s_blocksize - 1))
 				| offset;
 			filp->f_version = inode->i_version;
 		}
-		
-		while (!error && filp->f_pos < inode->i_size 
+
+		while (!error && filp->f_pos < inode->i_size
 		       && offset < sb->s_blocksize) {
 			de = (struct ufs_direct *) (bh->b_data + offset);
 	                /* XXX - put in a real ufs_check_dir_entry() */
-	                if ((ufs_swab16(de->d_reclen) == 0)
-                             || (ufs_swab16(de->d_namlen) == 0)) {
+	                if ((de->d_reclen == 0) || (de->d_namlen == 0)) {
+			/* SWAB16() was unneeded -- compare to 0 */
 	                        filp->f_pos = (filp->f_pos & (sb->s_blocksize - 1)) + sb->s_blocksize;
 	                        brelse(bh);
 	                        return stored;
 	                }
 #if 0
 			if (!ext2_check_dir_entry ("ext2_readdir", inode, de,
+			/* XXX - beware about de having to be swabped somehow */
 						   bh, offset)) {
 				/* On error, skip the f_pos to the
 	                           next block. */
@@ -100,8 +110,9 @@
 				return stored;
 			}
 #endif /* XXX */
-			offset += ufs_swab16(de->d_reclen);
-			if (ufs_swab32(de->d_ino)) {
+			offset += SWAB16(de->d_reclen);
+			if (de->d_ino) {
+			/* SWAB16() was unneeded -- compare to 0 */
 				/* We might block in the next section
 				 * if the data destination is
 				 * currently swapped out.  So, use a
@@ -110,18 +121,18 @@
 				 * during the copy operation. */
 				unsigned long version = inode->i_version;
 
-	                        if (inode->i_sb->u.ufs_sb.s_flags & UFS_DEBUG) {
+	                        if (s_flags & UFS_DEBUG) {
 	                                printk("ufs_readdir: filldir(%s,%u)\n",
-	                                       de->d_name, ufs_swab32(de->d_ino));
+	                                       de->d_name, SWAB32(de->d_ino));
 	                        }
-				error = filldir(dirent, de->d_name, ufs_swab16(de->d_namlen), filp->f_pos, ufs_swab32(de->d_ino));
+				error = filldir(dirent, de->d_name, SWAB16(de->d_namlen), filp->f_pos, SWAB32(de->d_ino));
 				if (error)
 					break;
 				if (version != inode->i_version)
 					goto revalidate;
 				stored ++;
 			}
-			filp->f_pos += ufs_swab16(de->d_reclen);
+			filp->f_pos += SWAB16(de->d_reclen);
 		}
 		offset = 0;
 		brelse (bh);
@@ -140,7 +151,7 @@
 	NULL,			/* read */
 	NULL,			/* write */
 	ufs_readdir,		/* readdir */
-	NULL,			/* poll */
+	NULL,			/* select */
 	NULL,			/* ioctl */
 	NULL,			/* mmap */
 	NULL,			/* open */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov