diff options
author | Amir Goldstein <amir73il@gmail.com> | 2017-02-02 02:56:01 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-02-04 03:47:12 -0500 |
commit | b5f68e24cc7bc3492ebc5c70f3ef6babcbd4188b (patch) | |
tree | 1d649f96a2455dd0597fb3886cead8d7d74a3a4d /fs/xfs/libxfs/xfs_dir2.c | |
parent | 4fac84ba1da7aa62dea520dcedd4f6de117d8f2b (diff) |
xfs: replace xfs_mode_to_ftype table with switch statement
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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/xfs/libxfs/xfs_dir2.c')
-rw-r--r-- | fs/xfs/libxfs/xfs_dir2.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index ec326d272efb..1a978bd9d506 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c | |||
@@ -36,21 +36,29 @@ | |||
36 | struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR }; | 36 | struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR }; |
37 | 37 | ||
38 | /* | 38 | /* |
39 | * @mode, if set, indicates that the type field needs to be set up. | 39 | * Convert inode mode to directory entry filetype |
40 | * This uses the transformation from file mode to DT_* as defined in linux/fs.h | ||
41 | * for file type specification. This will be propagated into the directory | ||
42 | * structure if appropriate for the given operation and filesystem config. | ||
43 | */ | 40 | */ |
44 | const unsigned char xfs_mode_to_ftype[S_IFMT >> S_SHIFT] = { | 41 | const unsigned char xfs_mode_to_ftype(int mode) |
45 | [0] = XFS_DIR3_FT_UNKNOWN, | 42 | { |
46 | [S_IFREG >> S_SHIFT] = XFS_DIR3_FT_REG_FILE, | 43 | switch (mode & S_IFMT) { |
47 | [S_IFDIR >> S_SHIFT] = XFS_DIR3_FT_DIR, | 44 | case S_IFREG: |
48 | [S_IFCHR >> S_SHIFT] = XFS_DIR3_FT_CHRDEV, | 45 | return XFS_DIR3_FT_REG_FILE; |
49 | [S_IFBLK >> S_SHIFT] = XFS_DIR3_FT_BLKDEV, | 46 | case S_IFDIR: |
50 | [S_IFIFO >> S_SHIFT] = XFS_DIR3_FT_FIFO, | 47 | return XFS_DIR3_FT_DIR; |
51 | [S_IFSOCK >> S_SHIFT] = XFS_DIR3_FT_SOCK, | 48 | case S_IFCHR: |
52 | [S_IFLNK >> S_SHIFT] = XFS_DIR3_FT_SYMLINK, | 49 | return XFS_DIR3_FT_CHRDEV; |
53 | }; | 50 | case S_IFBLK: |
51 | return XFS_DIR3_FT_BLKDEV; | ||
52 | case S_IFIFO: | ||
53 | return XFS_DIR3_FT_FIFO; | ||
54 | case S_IFSOCK: | ||
55 | return XFS_DIR3_FT_SOCK; | ||
56 | case S_IFLNK: | ||
57 | return XFS_DIR3_FT_SYMLINK; | ||
58 | default: | ||
59 | return XFS_DIR3_FT_UNKNOWN; | ||
60 | } | ||
61 | } | ||
54 | 62 | ||
55 | /* | 63 | /* |
56 | * ASCII case-insensitive (ie. A-Z) support for directories that was | 64 | * ASCII case-insensitive (ie. A-Z) support for directories that was |