[PATCH v2 4/5] erofs-utils: dump: add support for showing file extents.

Gao Xiang hsiangkao at linux.alibaba.com
Thu Oct 28 22:32:35 AEDT 2021


On Thu, Oct 28, 2021 at 07:27:05PM +0800, Gao Xiang wrote:
> On Thu, Oct 28, 2021 at 06:57:47PM +0800, Guo Xuenan wrote:
> > Add option -e to show file extents info, this option needs
> > specify nid as well. (eg. dump.erofs --nid # -e erofs.img)
> > 
> > Signed-off-by: Guo Xuenan <guoxuenan at huawei.com>
> > Signed-off-by: Wang Qi <mpiglet at outlook.com>
> > ---
> >  dump/main.c              | 77 ++++++++++++++++++++++++++++++++++------
> >  include/erofs/internal.h |  2 ++
> >  lib/data.c               |  4 +--
> >  3 files changed, 71 insertions(+), 12 deletions(-)
> > 
> > diff --git a/dump/main.c b/dump/main.c
> > index d1aa017..58ecf93 100644
> > --- a/dump/main.c
> > +++ b/dump/main.c
> > @@ -18,6 +18,7 @@
> >  struct erofsdump_cfg {
> >  	unsigned int totalshow;
> >  	bool show_inode;
> > +	bool show_extent;
> >  	bool show_superblock;
> >  	bool show_statistics;
> >  	erofs_nid_t nid;
> > @@ -94,6 +95,7 @@ static void usage(void)
> >  	fputs("usage: [options] IMAGE\n\n"
> >  	      "Dump erofs layout from IMAGE, and [options] are:\n"
> >  	      " -V      print the version number of dump.erofs and exit.\n"
> > +	      " -e      show extent info (require --nid #)\n"
> 
> 	      " -e      show extent info (require --nid set)\n"
> 
> >  	      " -s      show information about superblock\n"
> >  	      " -S      show statistic information of the image\n"
> >  	      " --nid=# show the target inode info of nid #\n"
> > @@ -110,9 +112,13 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
> >  {
> >  	int opt;
> >  
> > -	while ((opt = getopt_long(argc, argv, "SV:s",
> > +	while ((opt = getopt_long(argc, argv, "SVes",
> >  				  long_options, NULL)) != -1) {
> >  		switch (opt) {
> > +		case 'e':
> > +			dumpcfg.show_extent = true;
> > +			++dumpcfg.totalshow;
> > +			break;
> >  		case 's':
> >  			dumpcfg.show_superblock = true;
> >  			++dumpcfg.totalshow;
> > @@ -407,7 +413,28 @@ static int erofs_get_pathname(erofs_nid_t nid, erofs_nid_t parent_nid,
> >  	return -1;
> >  }
> >  
> > -static void erofsdump_show_fileinfo(void)
> > +static int erofsdump_map_blocks_helper(struct erofs_inode *inode,
> > +		struct erofs_map_blocks *map, int flags)
> > +{
> > +	int err = 0;
> > +
> 
> Let's add a generic entry in lib/zmap.c:

Oh, since erofs_map_blocks is already taken for now, I'm fine with the
old name erofsdump_map_blocks() for now....

Thanks,
Gao Xiang

> 
> int erofs_map_blocks(struct inode *inode,
> 		     struct erofs_map_blocks *map, int flags)
> {
> 	if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout))
> 		return z_erofs_map_blocks_iter(inode, map, flags);
> 	return erofs_map_blocks_flatmode(inode, map, flags);
> }
> 
> > +	switch (inode->datalayout) {
> > +	case EROFS_INODE_FLAT_PLAIN:
> > +	case EROFS_INODE_FLAT_INLINE:
> > +	case EROFS_INODE_CHUNK_BASED:
> > +		err = erofs_map_blocks(inode, map, flags);
> > +		break;
> > +	case EROFS_INODE_FLAT_COMPRESSION_LEGACY:
> > +	case EROFS_INODE_FLAT_COMPRESSION:
> > +		err = z_erofs_map_blocks_iter(inode, map, flags);
> > +		break;
> > +	default:
> 
> 		err = -EOPNOTSUPP;
> 
> > +		break;
> > +	}
> > +	return err;
> > +}
> > +
> > +static void erofsdump_show_fileinfo(bool show_extent)
> >  {
> >  	int err;
> >  	erofs_off_t size;
> > @@ -418,6 +445,11 @@ static void erofsdump_show_fileinfo(void)
> >  	char path[PATH_MAX + 1] = {0};
> >  	char access_mode_str[] = "rwxrwxrwx";
> >  	char timebuf[128] = {0};
> > +	unsigned int extent_count = 0;
> > +	struct erofs_map_blocks map = {
> > +		.index = UINT_MAX,
> > +		.m_la = 0,
> > +	};
> >  
> >  	err = erofs_read_inode_from_disk(&inode);
> >  	if (err) {
> > @@ -437,6 +469,14 @@ static void erofsdump_show_fileinfo(void)
> >  		return;
> >  	}
> >  
> > +	t = inode.i_ctime;
> > +	strftime(timebuf, sizeof(timebuf),
> > +			"%Y-%m-%d %H:%M:%S", localtime(&t));
> > +	access_mode = inode.i_mode & 0777;
> > +	for (int i = 8; i >= 0; i--) {
> > +		if (((access_mode >> i) & 1) == 0)
> > +			access_mode_str[8 - i] = '-';
> > +	}
> 
> Why we need to move this part?
> 
> Thanks,
> Gao Xiang


More information about the Linux-erofs mailing list