]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: replace xfs_mode_to_ftype table with switch statement
authorAmir Goldstein <amir73il@gmail.com>
Thu, 26 Jan 2017 02:02:41 +0000 (20:02 -0600)
committerEric Sandeen <sandeen@redhat.com>
Thu, 26 Jan 2017 02:02:41 +0000 (20:02 -0600)
Source kernel commit: 1fc4d33fed124fb182e8e6c214e973a29389ae83

The size of the xfs_mode_to_ftype[] conversion table
was too small to handle an invalid value of mode=S_IFMT.

Instead of fixing the table size, replace the conversion table
with a conversion helper that uses a switch statement.

Suggested-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_dir2.c
libxfs/xfs_dir2.h
repair/dino_chunks.c
repair/phase6.c

index e86d564466b7636363cedab4e99d92d573c96362..34602de13a960e18d4cad3a142132cd4efccfa02 100644 (file)
 struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR };
 
 /*
- * @mode, if set, indicates that the type field needs to be set up.
- * This uses the transformation from file mode to DT_* as defined in linux/fs.h
- * for file type specification. This will be propagated into the directory
- * structure if appropriate for the given operation and filesystem config.
+ * Convert inode mode to directory entry filetype
  */
-const unsigned char xfs_mode_to_ftype[S_IFMT >> S_SHIFT] = {
-       [0]                     = XFS_DIR3_FT_UNKNOWN,
-       [S_IFREG >> S_SHIFT]    = XFS_DIR3_FT_REG_FILE,
-       [S_IFDIR >> S_SHIFT]    = XFS_DIR3_FT_DIR,
-       [S_IFCHR >> S_SHIFT]    = XFS_DIR3_FT_CHRDEV,
-       [S_IFBLK >> S_SHIFT]    = XFS_DIR3_FT_BLKDEV,
-       [S_IFIFO >> S_SHIFT]    = XFS_DIR3_FT_FIFO,
-       [S_IFSOCK >> S_SHIFT]   = XFS_DIR3_FT_SOCK,
-       [S_IFLNK >> S_SHIFT]    = XFS_DIR3_FT_SYMLINK,
-};
+const unsigned char xfs_mode_to_ftype(int mode)
+{
+       switch (mode & S_IFMT) {
+       case S_IFREG:
+               return XFS_DIR3_FT_REG_FILE;
+       case S_IFDIR:
+               return XFS_DIR3_FT_DIR;
+       case S_IFCHR:
+               return XFS_DIR3_FT_CHRDEV;
+       case S_IFBLK:
+               return XFS_DIR3_FT_BLKDEV;
+       case S_IFIFO:
+               return XFS_DIR3_FT_FIFO;
+       case S_IFSOCK:
+               return XFS_DIR3_FT_SOCK;
+       case S_IFLNK:
+               return XFS_DIR3_FT_SYMLINK;
+       default:
+               return XFS_DIR3_FT_UNKNOWN;
+       }
+}
 
 /*
  * ASCII case-insensitive (ie. A-Z) support for directories that was
index 72df0dc1bd2ad28de5586ab8e798a00f0d2875a2..d4b77ab37a98eb80a78fd41021ef2817ea0040ca 100644 (file)
@@ -35,10 +35,9 @@ struct xfs_dir2_data_unused;
 extern struct xfs_name xfs_name_dotdot;
 
 /*
- * directory filetype conversion tables.
+ * Convert inode mode to directory entry filetype
  */
-#define S_SHIFT 12
-extern const unsigned char xfs_mode_to_ftype[];
+extern const unsigned char xfs_mode_to_ftype(int mode);
 
 /*
  * directory operations vector for encode/decode routines
index 4db9512a2f1520aca8dbf0050d04e7839cd9289d..a3909ac8b1c4d20cf6572f40ed860e8c11a594c5 100644 (file)
@@ -826,8 +826,6 @@ next_readbuf:
                 * we do now, this is where to start.
                 */
                if (is_used)  {
-                       __uint16_t      di_mode;
-
                        if (is_inode_free(ino_rec, irec_offset))  {
                                if (verbose || no_modify)  {
                                        do_warn(
@@ -846,10 +844,8 @@ next_readbuf:
                         * store the on-disk file type for comparing in
                         * phase 6.
                         */
-                       di_mode = be16_to_cpu(dino->di_mode);
-                       di_mode = (di_mode & S_IFMT) >> S_SHIFT;
                        set_inode_ftype(ino_rec, irec_offset,
-                                       xfs_mode_to_ftype[di_mode]);
+                               xfs_mode_to_ftype(be16_to_cpu(dino->di_mode)));
 
                        /*
                         * store on-disk nlink count for comparing in phase 7
index 3eb7cf1eecb15fb97969ef570b546d8cc388fea1..08636dcfcda1697dbe6c46bb3a8036ff5477727f 100644 (file)
@@ -1078,7 +1078,7 @@ mv_orphanage(
        if ((err = -libxfs_iget(mp, NULL, ino, 0, &ino_p)))
                do_error(_("%d - couldn't iget disconnected inode\n"), err);
 
-       xname.type = xfs_mode_to_ftype[(VFS_I(ino_p)->i_mode & S_IFMT)>>S_SHIFT];
+       xname.type = xfs_mode_to_ftype(VFS_I(ino_p)->i_mode);
 
        if (isa_dir)  {
                irec = find_inode_rec(mp, XFS_INO_TO_AGNO(mp, orphanage_ino),