From: Phillip Potter <phil@philpotter.co.uk>
To: dushistov@mail.ru
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] fs: ufs: Convert ufs_set_de_type to use lookup table
Date: Sun, 18 Mar 2018 20:56:35 +0000 [thread overview]
Message-ID: <20180318205635.GA31421@pathfinder> (raw)
Modify ufs_set_de_type function in fs/ufs/util.h to use a lookup
table rather than a switch statement, as per the TODO comment.
Signed-off-by: Phillip Potter <phil@philpotter.co.uk>
---
fs/ufs/util.h | 50 ++++++++++++++++++++++----------------------------
1 file changed, 22 insertions(+), 28 deletions(-)
diff --git a/fs/ufs/util.h b/fs/ufs/util.h
index 1907be6d5808..1edf4c6454e3 100644
--- a/fs/ufs/util.h
+++ b/fs/ufs/util.h
@@ -155,37 +155,31 @@ ufs_set_de_namlen(struct super_block *sb, struct ufs_dir_entry *de, u16 value)
static inline void
ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode)
{
+ /* type lookup table, DT_UNKNOWN is default type if no case holds */
+ const int mode_table[] = {
+ DT_UNKNOWN,
+ DT_FIFO, /* mode & S_IFMT == S_IFIFO case */
+ DT_CHR, /* mode & S_IFMT == S_IFCHR case */
+ DT_UNKNOWN,
+ DT_DIR, /* mode & S_IFMT == S_IFDIR case */
+ DT_UNKNOWN,
+ DT_BLK, /* mode & S_IFMT == S_IFBLK case */
+ DT_UNKNOWN,
+ DT_REG, /* mode & S_IFMT == S_IFREG case */
+ DT_UNKNOWN,
+ DT_LNK, /* mode & S_IFMT == S_IFLNK case */
+ DT_UNKNOWN,
+ DT_SOCK, /* mode & S_IFMT == S_IFSOCK case */
+ DT_UNKNOWN,
+ DT_UNKNOWN,
+ DT_UNKNOWN
+ };
+
if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) != UFS_DE_44BSD)
return;
- /*
- * TODO turn this into a table lookup
- */
- switch (mode & S_IFMT) {
- case S_IFSOCK:
- de->d_u.d_44.d_type = DT_SOCK;
- break;
- case S_IFLNK:
- de->d_u.d_44.d_type = DT_LNK;
- break;
- case S_IFREG:
- de->d_u.d_44.d_type = DT_REG;
- break;
- case S_IFBLK:
- de->d_u.d_44.d_type = DT_BLK;
- break;
- case S_IFDIR:
- de->d_u.d_44.d_type = DT_DIR;
- break;
- case S_IFCHR:
- de->d_u.d_44.d_type = DT_CHR;
- break;
- case S_IFIFO:
- de->d_u.d_44.d_type = DT_FIFO;
- break;
- default:
- de->d_u.d_44.d_type = DT_UNKNOWN;
- }
+ /* shift (mode & S_IFMT) right 12 bits to index into table */
+ de->d_u.d_44.d_type = mode_table[(mode & S_IFMT) >> 12];
}
static inline u32
--
2.14.3
next reply other threads:[~2018-03-18 20:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-18 20:56 Phillip Potter [this message]
2018-04-03 8:59 [PATCH] fs: ufs: Convert ufs_set_de_type to use lookup table Phillip Potter
2018-10-01 15:33 Phillip Potter
2018-10-02 2:28 ` Al Viro
2018-10-02 8:31 ` Phillip Potter
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=20180318205635.GA31421@pathfinder \
--to=phil@philpotter.co.uk \
--cc=dushistov@mail.ru \
--cc=linux-kernel@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;
as well as URLs for NNTP newsgroup(s).