]> git.hungrycats.org Git - linux/commitdiff
JFS: Limit readdir offset to signed integer.
authorDave Kleikamp <shaggy@kleikamp.austin.ibm.com>
Wed, 6 Mar 2002 08:52:43 +0000 (02:52 -0600)
committerDave Kleikamp <shaggy@kleikamp.austin.ibm.com>
Wed, 6 Mar 2002 08:52:43 +0000 (02:52 -0600)
NFSv2 does not like negative values for the offset.

Submitted by Christoph Hellwig.

fs/jfs/jfs_dtree.c
fs/jfs/jfs_dtree.h

index 42e1b280ca12228de9f5f139dcfd922ef5f87131..725c1f20ac7db87bacd55364d1f8e3a196f75f9b 100644 (file)
@@ -798,7 +798,7 @@ int dtInsert(tid_t tid, struct inode *ip,
         *      insert entry for new key
         */
        if (DO_INDEX(ip)) {
-               if (JFS_IP(ip)->next_index == -1) {
+               if (JFS_IP(ip)->next_index == DIREND) {
                        DT_PUTPAGE(mp);
                        return EMLINK;
                }
@@ -2885,7 +2885,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
        int do_index = 0;
        uint loop_count = 0;
 
-       if (filp->f_pos == -1)
+       if (filp->f_pos == DIREND)
                return 0;
 
        if (DO_INDEX(ip)) {
@@ -2904,25 +2904,25 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
                        dir_table_slot_t dirtab_slot;
 
                        if (dtEmpty(ip)) {
-                               filp->f_pos = -1;
+                               filp->f_pos = DIREND;
                                return 0;
                        }
                      repeat:
                        rc = get_index(ip, dir_index, &dirtab_slot);
                        if (rc) {
-                               filp->f_pos = -1;
+                               filp->f_pos = DIREND;
                                return rc;
                        }
                        if (dirtab_slot.flag == DIR_INDEX_FREE) {
                                if (loop_count++ > JFS_IP(ip)->next_index) {
                                        jERROR(1, ("jfs_readdir detected "
                                                   "infinite loop!\n"));
-                                       filp->f_pos = -1;
+                                       filp->f_pos = DIREND;
                                        return 0;
                                }
                                dir_index = le32_to_cpu(dirtab_slot.addr2);
                                if (dir_index == -1) {
-                                       filp->f_pos = -1;
+                                       filp->f_pos = DIREND;
                                        return 0;
                                }
                                goto repeat;
@@ -2931,7 +2931,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
                        index = dirtab_slot.slot;
                        DT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
                        if (rc) {
-                               filp->f_pos = -1;
+                               filp->f_pos = DIREND;
                                return 0;
                        }
                        if (p->header.flag & BT_INTERNAL) {
@@ -2968,7 +2968,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
                         * Find first entry of left-most leaf
                         */
                        if (dtEmpty(ip)) {
-                               filp->f_pos = -1;
+                               filp->f_pos = DIREND;
                                return 0;
                        }
 
@@ -3013,7 +3013,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
                }
 
                if (dtEmpty(ip)) {
-                       filp->f_pos = -1;
+                       filp->f_pos = DIREND;
                        return 0;
                }
 
@@ -3021,7 +3021,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
                        jERROR(1,
                               ("jfs_readdir: unexpected rc = %d from dtReadNext\n",
                                rc));
-                       filp->f_pos = -1;
+                       filp->f_pos = DIREND;
                        return 0;
                }
                /* get start leaf page and index */
@@ -3029,7 +3029,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
 
                /* offset beyond directory eof ? */
                if (bn < 0) {
-                       filp->f_pos = -1;
+                       filp->f_pos = DIREND;
                        return 0;
                }
        }
@@ -3038,7 +3038,7 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
        if (d_name == NULL) {
                DT_PUTPAGE(mp);
                jERROR(1, ("jfs_readdir: kmalloc failed!\n"));
-               filp->f_pos = -1;
+               filp->f_pos = DIREND;
                return 0;
        }
        while (1) {
@@ -3087,13 +3087,13 @@ int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
                 */
 
                if (p->header.flag & BT_ROOT) {
-                       filp->f_pos = -1;
+                       filp->f_pos = DIREND;
                        break;
                }
 
                bn = le64_to_cpu(p->header.next);
                if (bn == 0) {
-                       filp->f_pos = -1;
+                       filp->f_pos = DIREND;
                        break;
                }
 
index 5ea922aeeb28d9cea15874d96fc742e357dba0af..06a928b87460d47881e6af4334e6d135b7609dc2 100644 (file)
@@ -252,6 +252,10 @@ typedef union {
 #define DIRENTSIZ(namlen) \
     ( (sizeof(struct dirent) - 2*(JFS_NAME_MAX+1) + 2*((namlen)+1) + 3) &~ 3 )
 
+/*
+ * Maximum file offset for directories.
+ */
+#define DIREND INT_MAX
 
 /*
  *     external declarations