From: Abhinav Jain <jain.abhinav177@gmail.com>
To: dushistov@mail.ru, linux-kernel@vger.kernel.org
Cc: skhan@linuxfoundation.org, javier.carrasco.cruz@gmail.com,
jain.abhinav177@gmail.com
Subject: [PATCH] ufs: Add table lookup to set d_type based on mode & S_IFMT
Date: Thu, 13 Jun 2024 20:26:50 +0000 [thread overview]
Message-ID: <20240613202650.39739-1-jain.abhinav177@gmail.com> (raw)
Add usf_de_type_mapping structure to map file mode masks to dir entries.
Add a static ufs_type_table array to map file mode to dir entries.
Remove switch and add a table based lookup for the mapping.
Add ARRAY_SIZE macro on ufs_type_table to eliminate checkpatch warning.
Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
---
fs/ufs/util.h | 57 +++++++++++++++++++++++++++++----------------------
1 file changed, 32 insertions(+), 25 deletions(-)
diff --git a/fs/ufs/util.h b/fs/ufs/util.h
index 0ecd2ed792f5..8a941d69270a 100644
--- a/fs/ufs/util.h
+++ b/fs/ufs/util.h
@@ -9,7 +9,28 @@
#include <linux/buffer_head.h>
#include <linux/fs.h>
+#include <linux/types.h>
#include "swab.h"
+#include "ufs_fs.h"
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
+struct ufs_de_type_mapping {
+ umode_t mode_mask;
+ unsigned char d_type;
+};
+
+static const struct ufs_de_type_mapping ufs_type_table[] = {
+ { S_IFSOCK, DT_SOCK },
+ { S_IFLNK, DT_LNK },
+ { S_IFREG, DT_REG },
+ { S_IFBLK, DT_BLK },
+ { S_IFDIR, DT_DIR },
+ { S_IFCHR, DT_CHR },
+ { S_IFIFO, DT_FIFO },
+};
/*
* functions used for retyping
@@ -153,32 +174,18 @@ ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode)
return;
/*
- * TODO turn this into a table lookup
+ * Table lookup to set d_type based on mode & S_IFMT
*/
- 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;
+
+ size_t i;
+ /* Default to DT_UNKNOWN if not found */
+ de->d_u.d_44.d_type = DT_UNKNOWN;
+
+ for (i = 0; i < ARRAY_SIZE(ufs_type_table); i++) {
+ if ((mode & S_IFMT) == ufs_type_table[i].mode_mask) {
+ de->d_u.d_44.d_type = ufs_type_table[i].d_type;
+ break;
+ }
}
}
--
2.34.1
next reply other threads:[~2024-06-13 20:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-13 20:26 Abhinav Jain [this message]
2024-06-13 20:40 ` [PATCH] ufs: Add table lookup to set d_type based on mode & S_IFMT Al Viro
2024-06-13 23:17 ` Al Viro
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=20240613202650.39739-1-jain.abhinav177@gmail.com \
--to=jain.abhinav177@gmail.com \
--cc=dushistov@mail.ru \
--cc=javier.carrasco.cruz@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=skhan@linuxfoundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.