erofs-utils: complete special file support
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/3 erofs-utils: complete special file support
From: Gao Xiang <[email protected]>
Special file was already supported by obsoleted_mkfs, let's complete it for new erofs-utils now.
---
Hi Guifu,
Could you kindly take a look of these patches?
Thanks,
Gao Xiang
configure.ac | 1 + lib/inode.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-)
configure.ac +1 -0
@@ -82,6 +82,7 @@ AC_CHECK_HEADERS(m4_flatten([ string.h sys/ioctl.h sys/stat.h + sys/sysmacros.h sys/time.h unistd.h ]))
lib/inode.c +30 -4
@@ -12,6 +12,7 @@#include <stdlib.h> #include <stdio.h> #include <sys/stat.h> +#include <sys/sysmacros.h> #include <dirent.h> #include "erofs/print.h" #include "erofs/inode.h"
@@ -128,7 +129,6 @@ static int __allocate_inode_bh_data(struct erofs_inode *inode,int ret;if (!nblocks) { - inode->bh_data =NULL ;/* it has only tail-end inlined data */ inode->u.i_blkaddr =NULL_ADDR ;return 0 ;
@@ -302,6 +302,11 @@ int erofs_write_file(struct erofs_inode *inode)unsigned int nblocks, i;int ret, fd; +if (!inode->i_size) { + inode->data_mapping_mode =EROFS_INODE_FLAT_PLAIN ; +return 0 ; + } +if (cfg.c_compr_alg_master &&erofs_file_is_compressible (inode)) { ret =erofs_write_compressed_file (inode);
@@ -573,6 +578,14 @@ out:return 0 ; } +static u32 erofs_new_encode_dev (dev_t dev) +{ +const unsigned int major =major (dev); +const unsigned int minor =minor (dev); + +return (minor &0xff ) | (major <<8 ) | ((minor & ~0xff ) <<12 ); +} +int erofs_fill_inode (struct erofs_inode *inode,struct stat64 *st,const char *path)
@@ -582,10 +595,22 @@ int erofs_fill_inode(struct erofs_inode *inode, inode->i_gid = st->st_gid; inode->i_nlink =1 ;/* fix up later if needed */ -if (!S_ISDIR (inode->i_mode)) - inode->i_size = st->st_size; -else +switch (inode->i_mode &S_IFMT ) { +case S_IFCHR : +case S_IFBLK : +case S_IFIFO : +case S_IFSOCK : + inode->u.i_rdev =erofs_new_encode_dev (st->st_rdev); +case S_IFDIR : inode->i_size =0 ; +break ; +case S_IFREG : +case S_IFLNK : + inode->i_size = st->st_size; +break ; +default : +return -EINVAL ; + }strncpy (inode->i_srcpath, path,sizeof (inode->i_srcpath) -1 ); inode->i_srcpath[sizeof (inode->i_srcpath) -1 ] ='\0' ;
@@ -613,6 +638,7 @@ struct erofs_inode *erofs_new_inode(void) inode->i_count =1 ;init_list_head (&inode->i_subdirs); + inode->idata_size =0 ; inode->xattr_isize =0 ; inode->extent_isize =0 ;
Signature · 1 line
2.17.1
PATCH 2/3 erofs-utils: resize image to the correct size
From: Gao Xiang <[email protected]>
In the end, it's necessary to resize image to
the proper size since buffers could be dropped.
--- include/erofs/io.h | 1 + lib/io.c | 32 +++++++++++++++++++++++++++++++- mkfs/main.c | 11 ++++++++--- 3 files changed, 40 insertions(+), 4 deletions(-)
include/erofs/io.h +1 -0
@@ -21,6 +21,7 @@ void dev_close(void);int dev_write (const void *buf,u64 offset,size_t len);int dev_fillzero (u64 offset,size_t len,bool padding);int dev_fsync (void ); +int dev_resize (erofs_blk_t nblocks);u64 dev_length (void ); static inline int blk_write(const void *buf, erofs_blk_t blkaddr,
lib/io.c +31 -1
@@ -79,6 +79,7 @@ int dev_open(const char *dev)close (fd);return ret; } + erofs_devsz =round_down (erofs_devsz,EROFS_BLKSIZ );break ;case S_IFREG : ret =ftruncate (fd,0 );
@@ -98,7 +99,6 @@ int dev_open(const char *dev) erofs_devname = dev; erofs_devfd = fd; - erofs_devsz =round_down (erofs_devsz,EROFS_BLKSIZ );erofs_info ("successfully to open %s" , dev);return 0 ;
@@ -177,3 +177,33 @@ int dev_fsync(void) }return 0 ; } + +int dev_resize (unsigned int blocks) +{ +int ret; +struct stat st; +u64 length; + +if (cfg.c_dry_run || erofs_devsz !=INT64_MAX ) +return 0 ; + + ret =fstat (erofs_devfd, &st); +if (ret) { +erofs_err ("failed to fstat." ); +return -errno; + } + + length = (u64 )blocks *EROFS_BLKSIZ ; +if (st.st_size == length) +return 0 ; +if (st.st_size > length) +return ftruncate (erofs_devfd, length); + + length = length - st.st_size; +#if defined(HAVE_FALLOCATE ) +if (fallocate (erofs_devfd,0 , st.st_size, length) >=0 ) +return 0 ; +#endif +return dev_fillzero (st.st_size, length, true); +} +
mkfs/main.c +8 -3
@@ -145,7 +145,8 @@ static int mkfs_parse_options_cfg(int argc, char *argv[]) }int erofs_mkfs_update_super_block (struct erofs_buffer_head *bh, -erofs_nid_t root_nid) +erofs_nid_t root_nid, +erofs_blk_t *blocks) {struct erofs_super_block sb = { .magic =cpu_to_le32 (EROFS_SUPER_MAGIC_V1 ),
@@ -166,7 +167,8 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh, sb.build_time_nsec =cpu_to_le32 (t.tv_usec); } - sb.blocks =cpu_to_le32 (erofs_mapbh (NULL , true)); + *blocks =erofs_mapbh (NULL , true); + sb.blocks =cpu_to_le32 (*blocks); sb.root_nid =cpu_to_le16 (root_nid); buf =calloc (sb_blksize,1 );
@@ -189,6 +191,7 @@ int main(int argc, char **argv)struct erofs_inode *root_inode;erofs_nid_t root_nid;struct stat64 st; +erofs_blk_t nblocks;erofs_init_configure ();fprintf (stderr,"%s %s\n" ,basename (argv[0 ]), cfg.c_version);
@@ -250,13 +253,15 @@ int main(int argc, char **argv) root_nid =erofs_lookupnid (root_inode);erofs_iput (root_inode); - err =erofs_mkfs_update_super_block (sb_bh, root_nid); + err =erofs_mkfs_update_super_block (sb_bh, root_nid, &nblocks);if (err) goto exit;/* flush all remaining buffers */ if (!erofs_bflush (NULL )) err = -EIO ; +else + err =dev_resize (nblocks); exit:z_erofs_compress_exit ();dev_close ();
Signature · 1 line
2.17.1
Re: [PATCH 2/3] erofs-utils: resize image to the correct size
Quoted 7 lines · Gao Xiang via Linux-erofs
From: Gao Xiang <[email protected]>
In the end, it's necessary to resize image to
the proper size since buffers could be dropped.Signed-off-by Gao Xiang <[email protected]>---
It looks good.
Thanks,
PATCH 3/3 erofs-utils: keep up with in-kernel ondisk format naming
In reply to Gao Xiang via Linux-erofsFrom: Gao Xiang <[email protected]>
This patch adapts erofs-utils to the latest kernel ondisk definitions, especially the following kernel commits:
4b66eb51d2c4 erofs: remove all the byte offset comments 60a49ba8fee1 erofs: on-disk format should have explicitly assigned numbers b6796abd3cc1 erofs: some macros are much more readable as a function ed34aa4a8a7d erofs: kill __packed for on-disk structures c39747f770be erofs: update erofs_inode_is_data_compressed helper 426a930891cf erofs: use feature_incompat rather than requirements 8a76568225de erofs: better naming for erofs inode related stuffs ea559e7b8451 erofs: update erofs_fs.h comments
--- include/erofs/cache.h | 2 +- include/erofs/internal.h | 6 +- include/erofs_fs.h | 198 ++++++++++++++++++++------------------- lib/compress.c | 9 +- lib/config.c | 2 +- lib/inode.c | 42 ++++----- mkfs/main.c | 5 +- 7 files changed, 137 insertions(+), 127 deletions(-)
include/erofs/cache.h +1 -1
@@ -53,7 +53,7 @@ static inline const int get_alignsize(int type, int *type_ret)if (type ==INODE ) { *type_ret =META ; -return sizeof (struct erofs_inode_v1 ); +return sizeof (struct erofs_inode_compact ); }else if (type ==XATTR ) { *type_ret =META ;return sizeof (struct erofs_xattr_entry );
include/erofs/internal.h +3 -3
@@ -52,7 +52,7 @@ struct erofs_sb_info {erofs_blk_t meta_blkaddr;erofs_blk_t xattr_blkaddr; -u32 requirements; +u32 feature_incompat; };/* global sbi */
@@ -82,7 +82,7 @@ struct erofs_inode {char i_srcpath[PATH_MAX +1 ]; -unsigned char data_mapping_mode; +unsigned char datalayout;unsigned char inode_isize;/* inline tail-end packing size */ unsigned short idata_size;
@@ -100,7 +100,7 @@ struct erofs_inode {static inline bool is_inode_layout_compression (struct erofs_inode *inode) { -return erofs_inode_is_data_compressed (inode->data_mapping_mode); +return erofs_inode_is_data_compressed (inode->datalayout); }#define IS_ROOT (x) ((x) == (x)->i_parent)
include/erofs_fs.h +103 -95
309 lines not on this page · raw message
lib/compress.c +5 -4
@@ -120,7 +120,7 @@ static int write_uncompressed_block(struct z_erofs_vle_compress_ctx *ctx,int ret;unsigned int count; -if (!(sbi.requirements &EROFS_REQUIREMENT_LZ4_0PADDING )) { +if (!(sbi.feature_incompat &EROFS_FEATURE_INCOMPAT_LZ4_0PADDING )) {/* fix up clusterofs to 0 if possable */ if (ctx->head >= ctx->clusterofs) { ctx->head -= ctx->clusterofs;
@@ -184,7 +184,8 @@ nocompression:erofs_dbg ("Writing %u compressed data to block %u" , count, ctx->blkaddr); -if (sbi.requirements &EROFS_REQUIREMENT_LZ4_0PADDING ) +if (sbi.feature_incompat & +EROFS_FEATURE_INCOMPAT_LZ4_0PADDING ) ret =blk_write (dst - (EROFS_BLKSIZ - ret), ctx->blkaddr,1 );else
@@ -382,7 +383,7 @@ int z_erofs_convert_to_compacted_format(struct erofs_inode *inode, 4, logical_clusterbits, true); } inode->extent_isize = out - (u8 *)inode->compressmeta; - inode->data_mapping_mode =EROFS_INODE_FLAT_COMPRESSION ; + inode->datalayout =EROFS_INODE_FLAT_COMPRESSION ;return 0 ; }
@@ -473,7 +474,7 @@ int erofs_write_compressed_file(struct erofs_inode *inode) legacymetasize = ctx.metacur - compressmeta;if (cfg.c_legacy_compress) { inode->extent_isize = legacymetasize; - inode->data_mapping_mode =EROFS_INODE_FLAT_COMPRESSION_LEGACY ; + inode->datalayout =EROFS_INODE_FLAT_COMPRESSION_LEGACY ; }else { ret =z_erofs_convert_to_compacted_format (inode, blkaddr -1 , legacymetasize,12 );
lib/config.c +1 -1
@@ -21,7 +21,7 @@ void erofs_init_configure(void) cfg.c_dry_run = false; cfg.c_legacy_compress = false; cfg.c_compr_level_master =-1 ; - sbi.requirements =EROFS_REQUIREMENT_LZ4_0PADDING ; + sbi.feature_incompat =EROFS_FEATURE_INCOMPAT_LZ4_0PADDING ; }void erofs_show_config (void )
lib/inode.c +21 -21
115 lines not on this page · raw message
mkfs/main.c +3 -2
@@ -69,7 +69,8 @@ static int parse_extended_opts(const char *opts)return -EINVAL ;/* disable compacted indexes and 0padding */ cfg.c_legacy_compress = true; - sbi.requirements &= ~EROFS_REQUIREMENT_LZ4_0PADDING ; + sbi.feature_incompat &= + ~EROFS_FEATURE_INCOMPAT_LZ4_0PADDING ; } }return 0 ;
@@ -155,7 +156,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh, .blocks = 0, .meta_blkaddr = sbi.meta_blkaddr, .xattr_blkaddr = 0, - .requirements = cpu_to_le32(sbi.requirements), + .feature_incompat = cpu_to_le32(sbi.feature_incompat), };const unsigned int sb_blksize =round_up (EROFS_SUPER_END ,EROFS_BLKSIZ );
Signature · 1 line
2.17.1
Re: [PATCH 3/3] erofs-utils: keep up with in-kernel ondisk format naming
Quoted 14 lines · Gao Xiang via Linux-erofs
From: Gao Xiang <[email protected]>
This patch adapts erofs-utils to the latest kernel ondisk definitions, especially the following kernel commits:
4b66eb51d2c4erofs: remove all the byte offset comments60a49ba8fee1erofs: on-disk format should have explicitly assigned numbersb6796abd3cc1erofs: some macros are much more readable as a functioned34aa4a8a7derofs: kill__packedfor on-disk structuresc39747f770beerofs: updateerofs_inode_is_data_compressedhelper426a930891cferofs: usefeature_incompatrather than requirements8a76568225deerofs: better naming for erofs inode related stuffsea559e7b8451erofs: updateerofs_fs.hcomments
Quoted 2 lines
Signed-off-by Gao Xiang <[email protected]>---
It looks good.
Thanks,
Quoted 7 lines · Gao Xiang via Linux-erofs
From: Gao Xiang <[email protected]>
Special file was already supported by
obsoleted_mkfs, let's complete it for new erofs-utils now.Signed-off-by Gao Xiang <[email protected]>
It looks good.
Thanks,