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 | |
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')
-rw-r--r-- | fs/xfs/libxfs/xfs_dir2.c | 36 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_dir2.h | 5 | ||||
-rw-r--r-- | fs/xfs/xfs_iops.c | 2 |
3 files changed, 25 insertions, 18 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 |
diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index 6a3fe31d4bc2..0051a34b8c3f 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h | |||
@@ -35,10 +35,9 @@ struct xfs_dir2_data_unused; | |||
35 | extern struct xfs_name xfs_name_dotdot; | 35 | extern struct xfs_name xfs_name_dotdot; |
36 | 36 | ||
37 | /* | 37 | /* |
38 | * directory filetype conversion tables. | 38 | * Convert inode mode to directory entry filetype |
39 | */ | 39 | */ |
40 | #define S_SHIFT 12 | 40 | extern const unsigned char xfs_mode_to_ftype(int mode); |
41 | extern const unsigned char xfs_mode_to_ftype[]; | ||
42 | 41 | ||
43 | /* | 42 | /* |
44 | * directory operations vector for encode/decode routines | 43 | * directory operations vector for encode/decode routines |
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 405a65cd9d6b..1abe71918734 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c | |||
@@ -103,7 +103,7 @@ xfs_dentry_to_name( | |||
103 | { | 103 | { |
104 | namep->name = dentry->d_name.name; | 104 | namep->name = dentry->d_name.name; |
105 | namep->len = dentry->d_name.len; | 105 | namep->len = dentry->d_name.len; |
106 | namep->type = xfs_mode_to_ftype[(mode & S_IFMT) >> S_SHIFT]; | 106 | namep->type = xfs_mode_to_ftype(mode); |
107 | } | 107 | } |
108 | 108 | ||
109 | STATIC void | 109 | STATIC void |