[PATCH v2] erofs-utils: fuse: set d_type for readdir
Sheng Yong
shengyong2021 at gmail.com
Sun Aug 7 18:08:35 AEST 2022
From: Sheng Yong <shengyong at oppo.com>
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
More information about the Linux-erofs
mailing list