]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
debugfs: Add -p option to ls subcommand.
authorTheodore Ts'o <tytso@mit.edu>
Fri, 4 Jan 2008 20:28:51 +0000 (15:28 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 4 Jan 2008 20:28:51 +0000 (15:28 -0500)
Originally submitted by Jason Pyeron:

While working with a compromized system (suckit root kit) hidden files
were viewable by debugfs but not any other utility.  When spaces and
tabs were put into the directory names defugfs did not "show" them.

"ls -p" quotes the output so is can be parsed easily.

Addresses-Red-Hat-Bugzilla: #149480
Addresses-Sourceforge-Feature-Request: #1201667

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debugfs/debugfs.8.in
debugfs/ls.c

index b9de2341dc24b1eb61fcce3df005c3bcacdbbb2f..74d8756c5d28c8582a7fc7facab97cdb20f20024 100644 (file)
@@ -306,7 +306,7 @@ and
 .I \-b
 options.
 .TP
-.I ls [-l] [-d] filespec
+.I ls [-l] [-d] [-p] filespec
 Print a listing of the files in the directory
 .IR filespec .
 The 
@@ -315,6 +315,11 @@ flag will list files using a more verbose format.
 The
 .I \-d
 flag will list deleted entries in the directory.
+The 
+.I \-p
+flag will list the files in a format which is more easily parsable by
+scripts, as well as making it more clear when there are spaces or other
+non-prinitng characters at the end of filenames.
 .TP
 .I modify_inode filespec
 Modify the contents of the inode structure in the inode
index 52c7e34bac466cb0e135f18b30fe17ce588b505c..1ceeb1be49982d57d3f3646468ae0f808aed7899 100644 (file)
@@ -30,6 +30,7 @@ extern char *optarg;
 
 #define LONG_OPT       0x0001
 #define DELETED_OPT    0x0002
+#define PARSE_OPT      0x0004
 
 struct list_dir_struct {
        FILE    *f;
@@ -72,7 +73,16 @@ static int list_dir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)),
        } else {
                lbr = rbr = ' ';
        }
-       if (ls->options & LONG_OPT) {
+       if (ls->options & PARSE_OPT) {
+               if (ino && debugfs_read_inode(ino, &inode, name)) return 0;
+               fprintf(ls->f,"/%u/%06o/%d/%d/%s/",ino,inode.i_mode,inode.i_uid, inode.i_gid,name);
+               if (LINUX_S_ISDIR(inode.i_mode))
+                       fprintf(ls->f, "/");
+               else
+                       fprintf(ls->f, "%lld/", inode.i_size | ((__u64)inode.i_size_high << 32));
+               fprintf(ls->f, "\n");
+       }
+       else if (ls->options & LONG_OPT) {
                if (ino) {
                        if (debugfs_read_inode(ino, &inode, name))
                                return 0;
@@ -123,7 +133,7 @@ void do_list_dir(int argc, char *argv[])
                return;
 
        reset_getopt();
-       while ((c = getopt (argc, argv, "dl")) != EOF) {
+       while ((c = getopt (argc, argv, "dlp")) != EOF) {
                switch (c) {
                case 'l':
                        ls.options |= LONG_OPT;
@@ -131,6 +141,9 @@ void do_list_dir(int argc, char *argv[])
                case 'd':
                        ls.options |= DELETED_OPT;
                        break;
+               case 'p':
+                       ls.options |= PARSE_OPT;
+                       break;
                default:
                        goto print_usage;
                }
@@ -138,7 +151,7 @@ void do_list_dir(int argc, char *argv[])
 
        if (argc > optind+1) {
        print_usage:
-               com_err(0, 0, "Usage: ls [-l] [-d] file");
+               com_err(0, 0, "Usage: ls [-l] [-d] [-p] file");
                return;
        }