Re: [PATCH 1/2] xfs_db: add a directory path lookup command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 20, 2021 at 06:05:35PM +0530, Chandan Babu R wrote:
> 
> On 16 Jan 2021 at 06:54, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@xxxxxxxxxx>
> >
> > Add a command to xfs_db so that we can navigate to inodes by path.
> >
> > Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx>
> > ---
> >  db/Makefile       |    3 -
> >  db/command.c      |    1
> >  db/command.h      |    1
> >  db/namei.c        |  223 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  man/man8/xfs_db.8 |    4 +
> >  5 files changed, 231 insertions(+), 1 deletion(-)
> >  create mode 100644 db/namei.c
> >
> >
> > diff --git a/db/Makefile b/db/Makefile
> > index 9d502bf0..beafb105 100644
> > --- a/db/Makefile
> > +++ b/db/Makefile
> > @@ -14,7 +14,8 @@ HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \
> >  	io.h logformat.h malloc.h metadump.h output.h print.h quit.h sb.h \
> >  	sig.h strvec.h text.h type.h write.h attrset.h symlink.h fsmap.h \
> >  	fuzz.h
> > -CFILES = $(HFILES:.h=.c) btdump.c btheight.c convert.c info.c timelimit.c
> > +CFILES = $(HFILES:.h=.c) btdump.c btheight.c convert.c info.c namei.c \
> > +	timelimit.c
> >  LSRCFILES = xfs_admin.sh xfs_ncheck.sh xfs_metadump.sh
> >
> >  LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
> > diff --git a/db/command.c b/db/command.c
> > index 43828369..02f778b9 100644
> > --- a/db/command.c
> > +++ b/db/command.c
> > @@ -131,6 +131,7 @@ init_commands(void)
> >  	logformat_init();
> >  	io_init();
> >  	metadump_init();
> > +	namei_init();
> >  	output_init();
> >  	print_init();
> >  	quit_init();
> > diff --git a/db/command.h b/db/command.h
> > index 6913c817..498983ff 100644
> > --- a/db/command.h
> > +++ b/db/command.h
> > @@ -33,3 +33,4 @@ extern void		btdump_init(void);
> >  extern void		info_init(void);
> >  extern void		btheight_init(void);
> >  extern void		timelimit_init(void);
> > +extern void		namei_init(void);
> > diff --git a/db/namei.c b/db/namei.c
> > new file mode 100644
> > index 00000000..eebebe15
> > --- /dev/null
> > +++ b/db/namei.c
> > @@ -0,0 +1,223 @@

<snip some of this out>

> > +/* Walk a directory path to an inode and set the io cursor to that inode. */
> > +static int
> > +path_walk(
> > +	char		*path)
> > +{
> > +	struct dirpath	*dirpath;
> > +	char		*p = path;
> > +	xfs_ino_t	rootino = mp->m_sb.sb_rootino;
> > +	int		error = 0;
> > +
> > +	if (*p == '/') {
> > +		/* Absolute path, start from the root inode. */
> > +		p++;
> > +	} else {
> > +		/* Relative path, start from current dir. */
> > +		if (iocur_top->typ != &typtab[TYP_INODE] ||
> > +		    !S_ISDIR(iocur_top->mode))
> > +			return ENOTDIR;
> > +
> > +		rootino = iocur_top->ino;
> > +	}
> > +
> > +	dirpath = path_parse(p);
> > +	if (!dirpath)
> > +		return ENOMEM;
> > +
> > +	error = path_navigate(mp, rootino, dirpath);
> > +	if (error)
> > +		return error;
> 
> Memory pointed by dirpath (and its members) is not freed if the call to
> path_navigate() returns a non-zero error value.

Good catch, thanks!

--D



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux