From: Amir Goldstein <amir73il@gmail.com>
To: "Darrick J . Wong" <darrick.wong@oracle.com>
Cc: Brian Foster <bfoster@redhat.com>, linux-xfs@vger.kernel.org
Subject: [PATCH v6 1/3] xfs: fix the size of xfs_mode_to_ftype table
Date: Mon, 9 Jan 2017 15:06:27 +0200 [thread overview]
Message-ID: <1483967189-27313-2-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1483967189-27313-1-git-send-email-amir73il@gmail.com>
Fix the size of the xfs_mode_to_ftype conversion table,
which was too small to handle an invalid value of mode=S_IFMT.
Use a convenience macro S_DT(mode) to convert from
mode to dirent file type and change the name of the table
to xfs_dtype_to_ftype to correctly describe its index values.
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/xfs/libxfs/xfs_dir2.c | 18 +++++++++---------
fs/xfs/libxfs/xfs_dir2.h | 4 +++-
fs/xfs/xfs_iops.c | 2 +-
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c
index c58d72c..48d7c45 100644
--- a/fs/xfs/libxfs/xfs_dir2.c
+++ b/fs/xfs/libxfs/xfs_dir2.c
@@ -41,15 +41,15 @@ struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR };
* 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] = {
- [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_dtype_to_ftype[S_DT_MAX+1] = {
+ [0] = XFS_DIR3_FT_UNKNOWN,
+ [S_DT(S_IFREG)] = XFS_DIR3_FT_REG_FILE,
+ [S_DT(S_IFDIR)] = XFS_DIR3_FT_DIR,
+ [S_DT(S_IFCHR)] = XFS_DIR3_FT_CHRDEV,
+ [S_DT(S_IFBLK)] = XFS_DIR3_FT_BLKDEV,
+ [S_DT(S_IFIFO)] = XFS_DIR3_FT_FIFO,
+ [S_DT(S_IFSOCK)] = XFS_DIR3_FT_SOCK,
+ [S_DT(S_IFLNK)] = XFS_DIR3_FT_SYMLINK,
};
/*
diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h
index 0197590..4934d38 100644
--- a/fs/xfs/libxfs/xfs_dir2.h
+++ b/fs/xfs/libxfs/xfs_dir2.h
@@ -35,7 +35,9 @@ extern struct xfs_name xfs_name_dotdot;
* directory filetype conversion tables.
*/
#define S_SHIFT 12
-extern const unsigned char xfs_mode_to_ftype[];
+#define S_DT(mode) (((mode) & S_IFMT) >> S_SHIFT)
+#define S_DT_MAX S_DT(S_IFMT)
+extern const unsigned char xfs_dtype_to_ftype[];
/*
* directory operations vector for encode/decode routines
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index 308bebb..d2da9ca 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -103,7 +103,7 @@ xfs_dentry_to_name(
{
namep->name = dentry->d_name.name;
namep->len = dentry->d_name.len;
- namep->type = xfs_mode_to_ftype[(mode & S_IFMT) >> S_SHIFT];
+ namep->type = xfs_dtype_to_ftype[S_DT(mode)];
}
STATIC void
--
2.7.4
next prev parent reply other threads:[~2017-01-09 13:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-09 13:06 [PATCH v6 0/3] xfs: fixes for malformed on-disk i_mode Amir Goldstein
2017-01-09 13:06 ` Amir Goldstein [this message]
2017-01-09 15:51 ` [PATCH v6 1/3] xfs: fix the size of xfs_mode_to_ftype table Christoph Hellwig
2017-01-09 17:21 ` Amir Goldstein
2017-01-09 21:17 ` Darrick J. Wong
2017-01-10 7:54 ` Amir Goldstein
2017-01-09 13:06 ` [PATCH v6 2/3] xfs: sanity check directory inode di_size Amir Goldstein
2017-01-09 15:52 ` Christoph Hellwig
2017-01-09 13:06 ` [PATCH v6 3/3] xfs: make the ASSERT() condition likely Amir Goldstein
2017-01-09 15:53 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1483967189-27313-2-git-send-email-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=bfoster@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox