[RFC PATCH 1/3] erofs-utils: fuse: set d_type for readdir

Sheng Yong shengyong at oppo.com
Thu Aug 4 00:22:21 AEST 2022


Set inode mode for libfuse readdir filler so that readdir count get
correct d_type.

Signed-off-by: Sheng Yong <shengyong at oppo.com>
---
 fuse/main.c           |  5 ++++-
 include/erofs/inode.h |  1 +
 lib/inode.c           | 19 +++++++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/fuse/main.c b/fuse/main.c
index 95f939e..345bcb5 100644
--- a/fuse/main.c
+++ b/fuse/main.c
@@ -13,6 +13,7 @@
 #include "erofs/print.h"
 #include "erofs/io.h"
 #include "erofs/dir.h"
+#include "erofs/inode.h"

 struct erofsfuse_dir_context {
        struct erofs_dir_context ctx;
@@ -24,11 +25,13 @@ struct erofsfuse_dir_context {
 static int erofsfuse_fill_dentries(struct erofs_dir_context *ctx)
 {
        struct erofsfuse_dir_context *fusectx = (void *)ctx;
+       struct stat st = {0};
        char dname[EROFS_NAME_LEN + 1];

        strncpy(dname, ctx->dname, ctx->de_namelen);
        dname[ctx->de_namelen] = '\0';
-       fusectx->filler(fusectx->buf, dname, NULL, 0);
+       st.st_mode = erofs_ftype_to_dtype(ctx->de_ftype) << 12;
+       fusectx->filler(fusectx->buf, dname, &st, 0);
        return 0;
 }

diff --git a/include/erofs/inode.h b/include/erofs/inode.h
index 79b39b0..79b8d89 100644
--- a/include/erofs/inode.h
+++ b/include/erofs/inode.h
@@ -16,6 +16,7 @@ extern "C"
 #include "erofs/internal.h"

 unsigned char erofs_mode_to_ftype(umode_t mode);
+unsigned char erofs_ftype_to_dtype(unsigned int filetype);
 void erofs_inode_manager_init(void);
 unsigned int erofs_iput(struct erofs_inode *inode);
 erofs_nid_t erofs_lookupnid(struct erofs_inode *inode);
diff --git a/lib/inode.c b/lib/inode.c
index f192510..ce75014 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -43,6 +43,25 @@ unsigned char erofs_mode_to_ftype(umode_t mode)
        return erofs_ftype_by_mode[(mode & S_IFMT) >> S_SHIFT];
 }

+static const unsigned char erofs_dtype_by_ftype[EROFS_FT_MAX] = {
+       [EROFS_FT_UNKNOWN]      = DT_UNKNOWN,
+       [EROFS_FT_REG_FILE]     = DT_REG,
+       [EROFS_FT_DIR]          = DT_DIR,
+       [EROFS_FT_CHRDEV]       = DT_CHR,
+       [EROFS_FT_BLKDEV]       = DT_BLK,
+       [EROFS_FT_FIFO]         = DT_FIFO,
+       [EROFS_FT_SOCK]         = DT_SOCK,
+       [EROFS_FT_SYMLINK]      = DT_LNK
+};
+
+unsigned char erofs_ftype_to_dtype(unsigned int filetype)
+{
+       if (filetype >= EROFS_FT_MAX)
+               return DT_UNKNOWN;
+
+       return erofs_dtype_by_ftype[filetype];
+}
+
 #define NR_INODE_HASHTABLE     16384

 struct list_head inode_hashtable[NR_INODE_HASHTABLE];
--
2.25.1

________________________________
OPPO

本电子邮件及其附件含有OPPO公司的保密信息,仅限于邮件指明的收件人使用(包含个人及群组)。禁止任何人在未经授权的情况下以任何形式使用。如果您错收了本邮件,请立即以电子邮件通知发件人并删除本邮件及其附件。

This e-mail and its attachments contain confidential information from OPPO, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!


More information about the Linux-erofs mailing list