From: Darrick J. Wong <djwong@xxxxxxxxxx> Teach the path command to traverse the metadata directory tree by passing a '\' as the first letter in the path. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- db/namei.c | 43 +++++++++++++++++++++++++++++++++++++------ man/man8/xfs_db.8 | 11 +++++++++-- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/db/namei.c b/db/namei.c index dc3cbbeda38..a3d917db5c6 100644 --- a/db/namei.c +++ b/db/namei.c @@ -139,11 +139,11 @@ path_navigate( /* Walk a directory path to an inode and set the io cursor to that inode. */ static int path_walk( + xfs_ino_t rootino, char *path) { struct dirpath *dirpath; char *p = path; - xfs_ino_t rootino = mp->m_sb.sb_rootino; int error = 0; if (*p == '/') { @@ -173,6 +173,9 @@ path_help(void) dbprintf(_( "\n" " Navigate to an inode via directory path.\n" +"\n" +" Options:\n" +" -m -- Walk an absolute path down the metadata directory tree.\n" )); } @@ -181,18 +184,34 @@ path_f( int argc, char **argv) { + xfs_ino_t rootino = mp->m_sb.sb_rootino; int c; int error; - while ((c = getopt(argc, argv, "")) != -1) { + while ((c = getopt(argc, argv, "m")) != -1) { switch (c) { + case 'm': + /* Absolute path, start from metadata rootdir. */ + if (!xfs_has_metadir(mp)) { + dbprintf( + _("filesystem does not support metadata directories.\n")); + exitcode = 1; + return 0; + } + rootino = mp->m_sb.sb_metadirino; + break; default: path_help(); return 0; } } - error = path_walk(argv[optind]); + if (argc == optind || argc > optind + 1) { + dbprintf(_("Only supply one path.\n")); + return -1; + } + + error = path_walk(rootino, argv[optind]); if (error) { dbprintf("%s: %s\n", argv[optind], strerror(error)); exitcode = 1; @@ -206,7 +225,7 @@ static struct cmdinfo path_cmd = { .altname = NULL, .cfunc = path_f, .argmin = 1, - .argmax = 1, + .argmax = -1, .canpush = 0, .args = "", .help = path_help, @@ -521,6 +540,7 @@ ls_help(void) " Options:\n" " -i -- Resolve the given paths to their corresponding inode numbers.\n" " If no paths are given, display the current inode number.\n" +" -m -- Walk an absolute path down the metadata directory tree.\n" "\n" " Directory contents will be listed in the format:\n" " dir_cookie inode_number type hash name_length name\n" @@ -532,15 +552,26 @@ ls_f( int argc, char **argv) { + xfs_ino_t rootino = mp->m_sb.sb_rootino; bool inum_only = false; int c; int error = 0; - while ((c = getopt(argc, argv, "i")) != -1) { + while ((c = getopt(argc, argv, "im")) != -1) { switch (c) { case 'i': inum_only = true; break; + case 'm': + /* Absolute path, start from metadata rootdir. */ + if (!xfs_has_metadir(mp)) { + dbprintf( + _("filesystem does not support metadata directories.\n")); + exitcode = 1; + return 0; + } + rootino = mp->m_sb.sb_metadirino; + break; default: ls_help(); return 0; @@ -563,7 +594,7 @@ ls_f( for (c = optind; c < argc; c++) { push_cur(); - error = path_walk(argv[c]); + error = path_walk(rootino, argv[c]); if (error) goto err_cur; diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 43c7db5e225..a7e42e1a333 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -835,7 +835,7 @@ This makes it easier to find discrepancies in the reservation calculations between xfsprogs and the kernel, which will help when diagnosing minimum log size calculation errors. .TP -.BI "ls [\-i] [" paths "]..." +.BI "ls [\-im] [" paths "]..." List the contents of a directory. If a path resolves to a directory, the directory will be listed. If no paths are supplied and the IO cursor points at a directory inode, @@ -849,6 +849,9 @@ directory cookie, inode number, file type, hash, name length, name. Resolve each of the given paths to an inode number and print that number. If no paths are given and the IO cursor points to an inode, print the inode number. +.TP +.B \-m +Absolute paths should be walked from the root of the metadata directory tree. .RE .TP .BI "metadump [\-egow] " filename @@ -876,9 +879,13 @@ See the .B print command. .TP -.BI "path " dir_path +.BI "path [\-m] " dir_path Walk the directory tree to an inode using the supplied path. Absolute and relative paths are supported. +The +.B \-m +option causes absolute paths to be walked from the root of the metadata +directory tree. .TP .B pop Pop location from the stack.