Whamcloud - gitweb
e2fsck: add support for dirdata feature
[tools/e2fsprogs.git] / debugfs / ls.c
index ae8b2d3..9b3a7c1 100644 (file)
@@ -24,6 +24,7 @@ extern char *optarg;
 #endif
 
 #include "debugfs.h"
+#include "ext2fs/lfsck.h"
 
 /*
  * list directory
@@ -32,6 +33,7 @@ extern char *optarg;
 #define LONG_OPT       0x0001
 #define PARSE_OPT      0x0002
 #define RAW_OPT                0x0004
+#define DIRDATA_OPT    0x0008
 #define ENCRYPT_OPT    0x8000
 
 struct list_dir_struct {
@@ -44,6 +46,41 @@ struct list_dir_struct {
 static const char *monstr[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                                "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
 
+static void list_dirdata(struct list_dir_struct *ls,
+                        struct ext2_dir_entry *dirent)
+{
+       unsigned char   *data;
+       int             dlen;
+       __u8            dirdata_mask;
+       __u8            file_type = dirent->name_len >> 8;
+
+       data = (unsigned char *)dirent->name +
+               (dirent->name_len & EXT2_NAME_LEN) + 1;
+
+       for (dirdata_mask = EXT2_FT_MASK + 1;
+            dirdata_mask != 0; dirdata_mask <<= 1) {
+               if ((dirdata_mask & file_type) == 0)
+                       continue;
+
+               dlen = data[0];
+
+               if (dirdata_mask == EXT2_DIRENT_LUFID) {
+                       struct lu_fid *fid = (struct lu_fid *)(data + 1);
+
+                       fid_be_to_cpu(fid, fid);
+                       fprintf(ls->f, "fid:"DFID, PFID(fid));
+               } else {
+                       int i;
+
+                       for (i = 1; i < dlen; i++)
+                               fprintf(ls->f, "%02x", data[i]);
+               }
+
+               fprintf(ls->f, " ");
+               data += dlen;
+       }
+}
+
 static int print_filename(FILE *f, struct ext2_dir_entry *dirent, int options)
 {
        unsigned char   ch;
@@ -114,11 +151,12 @@ static int list_dir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)),
                } else
                        memset(&inode, 0, sizeof(struct ext2_inode));
                fprintf(ls->f,"/%u/%06o/%d/%d/%.*s/", ino, inode.i_mode,
-                       inode.i_uid, inode.i_gid, thislen, dirent->name);
+                       inode_uid(inode), inode_gid(inode), thislen, dirent->name);
                if (LINUX_S_ISDIR(inode.i_mode))
                        fprintf(ls->f, "/");
                else
-                       fprintf(ls->f, "%lld/", EXT2_I_SIZE(&inode));
+                       fprintf(ls->f, "%llu/",
+                               (unsigned long long) EXT2_I_SIZE(&inode));
                fprintf(ls->f, "\n");
        } else if (options & LONG_OPT) {
                if (ino) {
@@ -143,8 +181,11 @@ static int list_dir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)),
                fprintf(ls->f, "(%d)  %5d  %5d   ",
                        ext2fs_dirent_file_type(dirent),
                        inode_uid(inode), inode_gid(inode));
-                       fprintf(ls->f, "%5llu", EXT2_I_SIZE(&inode));
+                       fprintf(ls->f, "%5llu",
+                               (unsigned long long) EXT2_I_SIZE(&inode));
                fprintf(ls->f, " %s ", datestr);
+               if ((ls->options & DIRDATA_OPT) != 0)
+                       list_dirdata(ls, dirent);
                print_filename(ls->f, dirent, options);
                fputc('\n', ls->f);
        } else {
@@ -193,7 +234,7 @@ void do_list_dir(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                return;
 
        reset_getopt();
-       while ((c = getopt (argc, argv, "cdlpr")) != EOF) {
+       while ((c = getopt(argc, argv, "cdDlpr")) != EOF) {
                switch (c) {
                case 'c':
                        flags |= DIRENT_FLAG_INCLUDE_CSUM;
@@ -201,6 +242,9 @@ void do_list_dir(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                case 'l':
                        ls.options |= LONG_OPT;
                        break;
+               case 'D':
+                       ls.options |= DIRDATA_OPT;
+                       break;
                case 'd':
                        flags |= DIRENT_FLAG_INCLUDE_REMOVED;
                        break;
@@ -217,7 +261,7 @@ void do_list_dir(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
 
        if (argc > optind+1) {
        print_usage:
-               com_err(0, 0, "Usage: ls [-c] [-d] [-l] [-p] [-r] file");
+               com_err(0, 0, "Usage: ls [-c] [-d] [-l] [-p] [-r] [-D] file");
                return;
        }