src/t_dir_type: support filtering by inode number
authorAmir Goldstein <amir73il@gmail.com>
Thu, 11 May 2017 06:55:07 +0000 (09:55 +0300)
committerEryu Guan <eguan@redhat.com>
Fri, 12 May 2017 13:13:19 +0000 (21:13 +0800)
usage: t_dir_type <dir> <inode number>

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
doc/auxiliary-programs.txt
src/t_dir_type.c

index 2e2060a0cec65fd6d79bea81783b53e28f114ecb..21ef118596b6c4c967c9e39b438dcdc98ff33871 100644 (file)
@@ -18,6 +18,7 @@ Contents:
  - af_unix             -- Create an AF_UNIX socket
  - open_by_handle      -- open_by_handle_at syscall exercise
  - stat_test           -- statx syscall exercise
+ - t_dir_type          -- print directory entries and their file type
  - xfs_io              -- General I/O operation exercise
 
 
@@ -48,6 +49,12 @@ stat_test
                _require_statx
 
 
+t_dir_type
+
+       The t_dir_type program exercises the getdents64() system call.
+       It prints directory entry names returned from getdents64() and
+       thier d_type, optionally filtered by type or by inode number.
+
 xfs_io
 
        The xfs_io program can be found in the xfsprogs package and can be used
index 344bef89460854b755c60df3562b8f0abb78c05c..76aaa9bb4b731d47523385286dd0a6f43a7df14a 100644 (file)
 /*
  * t_dir_type
  *
- * print directory entries, optionally filtered by d_type
+ * print directory entries and their file type, optionally filtered by d_type
+ * or by inode number.
  *
- * ./t_dir_type <path> [u|f|d|c|b|l|p|s|w]
+ * ./t_dir_type <path> [u|f|d|c|b|l|p|s|w|<ino>]
  */
 
 #include <fcntl.h>
@@ -67,6 +68,7 @@ main(int argc, char *argv[])
        struct linux_dirent64 *d;
        int bpos;
        int type = -1; /* -1 means all types */
+       uint64_t ino = 0;
        int ret = 1;
 
        fd = open(argv[1], O_RDONLY | O_DIRECTORY);
@@ -82,6 +84,8 @@ main(int argc, char *argv[])
                        if (DT_CHAR(type) == t)
                                break;
                /* no match ends up with type = -1 */
+               if (type < 0)
+                       ino = atoll(argv[2]);
        }
 
        for ( ; ; ) {
@@ -96,7 +100,8 @@ main(int argc, char *argv[])
 
                for (bpos = 0; bpos < nread;) {
                        d = (struct linux_dirent64 *) (buf + bpos);
-                       if (type < 0 || type == (int)d->d_type) {
+                       if ((type < 0 || type == (int)d->d_type) &&
+                           (!ino || ino == d->d_ino)) {
                                ret = 0;
                                printf("%s %c\n", d->d_name, DT_CHAR(d->d_type));
                        }