xfs: replace xfs_mode_to_ftype table with switch statement

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>
This commit is contained in:
Amir Goldstein 2017-01-17 11:41:43 -08:00 committed by Darrick J. Wong
parent b597dd5373
commit 1fc4d33fed
3 changed files with 25 additions and 18 deletions

View File

@ -36,21 +36,29 @@
struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR }; 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. * Convert inode mode to directory entry filetype
* 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.
*/ */
const unsigned char xfs_mode_to_ftype[S_IFMT >> S_SHIFT] = { const unsigned char xfs_mode_to_ftype(int mode)
[0] = XFS_DIR3_FT_UNKNOWN, {
[S_IFREG >> S_SHIFT] = XFS_DIR3_FT_REG_FILE, switch (mode & S_IFMT) {
[S_IFDIR >> S_SHIFT] = XFS_DIR3_FT_DIR, case S_IFREG:
[S_IFCHR >> S_SHIFT] = XFS_DIR3_FT_CHRDEV, return XFS_DIR3_FT_REG_FILE;
[S_IFBLK >> S_SHIFT] = XFS_DIR3_FT_BLKDEV, case S_IFDIR:
[S_IFIFO >> S_SHIFT] = XFS_DIR3_FT_FIFO, return XFS_DIR3_FT_DIR;
[S_IFSOCK >> S_SHIFT] = XFS_DIR3_FT_SOCK, case S_IFCHR:
[S_IFLNK >> S_SHIFT] = XFS_DIR3_FT_SYMLINK, 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 * ASCII case-insensitive (ie. A-Z) support for directories that was

View File

@ -35,10 +35,9 @@ struct xfs_dir2_data_unused;
extern struct xfs_name xfs_name_dotdot; 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(int mode);
extern const unsigned char xfs_mode_to_ftype[];
/* /*
* directory operations vector for encode/decode routines * directory operations vector for encode/decode routines

View File

@ -103,7 +103,7 @@ xfs_dentry_to_name(
{ {
namep->name = dentry->d_name.name; namep->name = dentry->d_name.name;
namep->len = dentry->d_name.len; namep->len = dentry->d_name.len;
namep->type = xfs_mode_to_ftype[(mode & S_IFMT) >> S_SHIFT]; namep->type = xfs_mode_to_ftype(mode);
} }
STATIC void STATIC void