erofs-utils: fix up nlink for d_type unsupported fses
PATCH 1/2 erofs-utils: fix up nlink for d_type unsupported fses
i_mode should be used instead for some old random fs.
Signed-off-by Gao Xiang <[email protected]>
--- lib/inode.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
lib/inode.c +13 -19
@@ -182,7 +182,7 @@ static int comp_subdir(const void *a, const void *b)int erofs_prepare_dir_file (struct erofs_inode *dir,unsigned int nr_subdirs) {struct erofs_dentry *d, *n, **sorted_d; -unsigned int d_size, i_nlink, i; +unsigned int d_size, i;/* dot is pointed to the current dir inode */ d =erofs_d_alloc (dir,"." );
@@ -216,26 +216,14 @@ int erofs_prepare_dir_file(struct erofs_inode *dir, unsigned int nr_subdirs)/* let's calculate dir size and update i_nlink */ d_size =0 ; - i_nlink =0 ;list_for_each_entry (d, &dir->i_subdirs, d_child) {int len =strlen (d->name) +sizeof (struct erofs_dirent );if ((d_size & (erofs_blksiz () -1 )) + len >erofs_blksiz ()) d_size =round_up (d_size,erofs_blksiz ()); d_size += len; - - i_nlink += (d->type ==EROFS_FT_DIR ); } dir->i_size = d_size; -/* -* if there're too many subdirs as compact form, set nlink=1 -* rather than upgrade to use extented form instead. -*/ -if (i_nlink >USHRT_MAX && - dir->inode_isize ==sizeof (struct erofs_inode_compact )) - dir->i_nlink =1 ; -else - dir->i_nlink = i_nlink;/* no compression for all dirs */ dir->datalayout =EROFS_INODE_FLAT_INLINE ;
@@ -1039,7 +1027,7 @@ static int erofs_mkfs_build_tree(struct erofs_inode *dir, struct list_head *dirsDIR *_dir;struct dirent *dp;struct erofs_dentry *d; -unsigned int nr_subdirs; +unsigned int nr_subdirs, i_nlink; ret =erofs_prepare_xattr_ibody (dir);if (ret <0 )
@@ -1100,10 +1088,6 @@ static int erofs_mkfs_build_tree(struct erofs_inode *dir, struct list_head *dirs goto err_closedir; } nr_subdirs++; - -/* to count i_nlink for directories */ - d->type = (dp->d_type ==DT_DIR ? -EROFS_FT_DIR :EROFS_FT_UNKNOWN ); }if (errno) {
@@ -1124,6 +1108,7 @@ static int erofs_mkfs_build_tree(struct erofs_inode *dir, struct list_head *dirsif (IS_ROOT (dir))erofs_fixup_meta_blkaddr (dir); + i_nlink =0 ;list_for_each_entry (d, &dir->i_subdirs, d_child) {char buf[PATH_MAX ];unsigned char ftype;
@@ -1159,12 +1144,21 @@ fail: ++dir->subdirs_queued; } ftype =erofs_mode_to_ftype (inode->i_mode); -DBG_BUGON (ftype ==EROFS_FT_DIR && d->type != ftype); + i_nlink += (ftype ==EROFS_FT_DIR ); d->inode = inode; d->type = ftype;erofs_info ("file %s/%s dumped (type %u)" , dir->i_srcpath, d->name, d->type); } +/* +* if there're too many subdirs as compact form, set nlink=1 +* rather than upgrade to use extented form instead. +*/ +if (i_nlink >USHRT_MAX && + dir->inode_isize ==sizeof (struct erofs_inode_compact )) + dir->i_nlink =1 ; +else + dir->i_nlink = i_nlink;return 0 ; err_closedir:
Signature · 1 line
2.24.4
PATCH 2/2 erofs-utils: lazy write directory data
Signed-off-by Gao Xiang <[email protected]>
--- include/erofs/cache.h | 11 ++++++----- lib/inode.c | 9 +++++---- 2 files changed, 11 insertions(+), 9 deletions(-)
include/erofs/cache.h +6 -5
@@ -19,13 +19,14 @@ struct erofs_buffer_head;struct erofs_buffer_block ;#define DATA 0 -#define META 1 +#define DIRA 1 +#define META 2/* including inline xattrs, extent */ -#define INODE 2 +#define INODE 3/* shared xattrs */ -#define XATTR 3 +#define XATTR 4/* device table */ -#define DEVT 4 +#define DEVT 5struct erofs_bhops {bool (*preflush)(struct erofs_buffer_head *bh);
@@ -54,7 +55,7 @@ struct erofs_buffer_block {static inline const int get_alignsize (int type,int *type_ret) { -if (type ==DATA ) +if (type ==DATA || type ==DIRA )return erofs_blksiz ();if (type ==INODE ) {
lib/inode.c +5 -4
@@ -142,7 +142,8 @@ struct erofs_dentry *erofs_d_alloc(struct erofs_inode *parent,/* allocate main data for a inode */ static int __allocate_inode_bh_data (struct erofs_inode *inode, -unsigned long nblocks) +unsigned long nblocks, +int type) {struct erofs_buffer_head *bh;int ret;
@@ -305,7 +306,7 @@ static int erofs_write_dir_file(struct erofs_inode *dir) q = used = blkno =0 ;/* allocate dir main data */ - ret =__allocate_inode_bh_data (dir,erofs_blknr (dir->i_size)); + ret =__allocate_inode_bh_data (dir,erofs_blknr (dir->i_size),DIRA );if (ret)return ret;
@@ -353,7 +354,7 @@ static int erofs_write_file_from_buffer(struct erofs_inode *inode, char *buf) inode->datalayout =EROFS_INODE_FLAT_INLINE ; - ret =__allocate_inode_bh_data (inode, nblocks); + ret =__allocate_inode_bh_data (inode, nblocks,DATA );if (ret)return ret;
@@ -386,7 +387,7 @@ static int write_uncompressed_file_from_fd(struct erofs_inode *inode, int fd) inode->datalayout =EROFS_INODE_FLAT_INLINE ; nblocks = inode->i_size /erofs_blksiz (); - ret =__allocate_inode_bh_data (inode, nblocks); + ret =__allocate_inode_bh_data (inode, nblocks,DATA );if (ret)return ret;
Signature · 1 line
2.24.4