]> granicus.if.org Git - strace/commitdiff
print_dev_t: add xlat styles support
authorShankara Pailoor <shankarapailoor@gmail.com>
Sat, 8 Dec 2018 22:12:42 +0000 (14:12 -0800)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 10 Dec 2018 23:45:11 +0000 (23:45 +0000)
* print_dev_t.c (print_dev_t): Respect xlat_verbosity.
* tests/btrfs.c (sprint_makedev): New function.
(btrfs_print_balance_args, btrfs_test_dev_info_ioctl,
btrfs_test_dev_replace_ioctl, btrfs_test_get_dev_stats_ioctl,
btrfs_test_scrub_ioctls): Use it to update expected output.
* tests/xstatx.c (print_st_mode, sprint_makedev): New functions.
(print_stat): Use them.
* tests/fstat-Xabbrev.c: New file.
* tests/fstat-Xraw.c: Likewise.
* tests/fstat-Xverbose.c: Likewise.
* tests/fstat64-Xabbrev.c: Likewise.
* tests/fstat64-Xraw.c: Likewise.
* tests/fstat64-Xverbose.c: Likewise.
* tests/gen_tests.in (fstat-Xabbrev, fstat-Xraw, fstat-Xverbose,
fstat64-Xabbrev, fstat64-Xraw, fstat64-Xverbose): New entries.
* tests/trace_fstat.in: Likewise.
* tests/trace_stat_like.in: Likewise.
* tests/pure_executables.list: Add fstat-Xabbrev, fstat-Xraw,
fstat-Xverbose, fstat64-Xabbrev, fstat64-Xraw, and fstat64-Xverbose.
* tests/.gitignore: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
14 files changed:
print_dev_t.c
tests/.gitignore
tests/btrfs.c
tests/fstat-Xabbrev.c [new file with mode: 0644]
tests/fstat-Xraw.c [new file with mode: 0644]
tests/fstat-Xverbose.c [new file with mode: 0644]
tests/fstat64-Xabbrev.c [new file with mode: 0644]
tests/fstat64-Xraw.c [new file with mode: 0644]
tests/fstat64-Xverbose.c [new file with mode: 0644]
tests/gen_tests.in
tests/pure_executables.list
tests/trace_fstat.in
tests/trace_stat_like.in
tests/xstatx.c

index 56476bc33ddee6bc8e0514db5ef27ebb07932ddf..0a0354b24073cd3edaec6248c0a47df0a2f82834 100644 (file)
 void
 print_dev_t(const unsigned long long dev)
 {
+       if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
+               tprintf("%#llx", dev);
+
+       if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
+               return;
+
+       if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
+               tprints(" /* ");
+
        tprintf("makedev(%#x, %#x)", major(dev), minor(dev));
+
+       if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
+               tprints(" */");
 }
index 58729054761ffc28e2587d847bb803fceb6485a1..c8609c39a73907fd61fc20de5dcdef021c7399da 100644 (file)
@@ -89,7 +89,13 @@ finit_module
 flock
 fork-f
 fstat
+fstat-Xabbrev
+fstat-Xraw
+fstat-Xverbose
 fstat64
+fstat64-Xabbrev
+fstat64-Xraw
+fstat64-Xverbose
 fstatat64
 fstatfs
 fstatfs64
index 5a60304ae01ceb7979bf378b953825a4017785cb..9367995ef91949afa7400817301960a920dcaf04 100644 (file)
@@ -187,6 +187,28 @@ sprint_xlat_(uint32_t val, const char *xlat)
        return xlat;
 }
 
+static const char *
+sprint_makedev(unsigned long long val)
+{
+       static char devid[256];
+       int ret;
+
+       if (verbose_xlat)
+               ret = snprintf(devid, sizeof(devid),
+                               "%#llx /* makedev(%#x, %#x) */",
+                               val, major(val), minor(val));
+       else
+               ret = snprintf(devid, sizeof(devid),
+                               "makedev(%#x, %#x)", major(val), minor(val));
+
+       if (ret < 0)
+               perror_msg_and_fail("sprint_makedev(%llx)", val);
+       if ((unsigned) ret >= sizeof(devid))
+               error_msg_and_fail("sprint_makedev(%llx): buffer "
+                                          "overflow", val);
+       return devid;
+}
+
 #define ioc(x_) sprint_xlat_(x_, #x_)
 
 void
@@ -556,8 +578,7 @@ btrfs_print_balance_args(struct btrfs_balance_args *args)
        prfl_btrfs(btrfs_space_info_flags, args->profiles,
                   "BTRFS_BLOCK_GROUP_???");
        print_uint64(", usage=", args->usage);
-       printf(", devid=makedev(%#x, %#x)",
-              major(args->devid), minor(args->devid));
+       printf(", devid=%s", sprint_makedev(args->devid));
        print_uint64(", pstart=", args->pstart);
        print_uint64(", pend=", args->pend);
        print_uint64(", vstart=", args->vstart);
@@ -1212,8 +1233,8 @@ btrfs_test_scrub_ioctls(void)
        ioctl(-1, BTRFS_IOC_SCRUB_CANCEL, NULL);
        printf("ioctl(-1, %s) = -1 EBADF (%m)\n", ioc(BTRFS_IOC_SCRUB_CANCEL));
 
-       printf("ioctl(-1, %s, {devid=makedev(%#x, %#x)",
-              ioc(BTRFS_IOC_SCRUB), major(args.devid), minor(args.devid));
+       printf("ioctl(-1, %s, {devid=%s",
+              ioc(BTRFS_IOC_SCRUB), sprint_makedev(args.devid));
        print_uint64(", start=", args.start);
        print_uint64(", end=", args.end);
        printf(", flags=");
@@ -1226,9 +1247,9 @@ btrfs_test_scrub_ioctls(void)
               ioc(BTRFS_IOC_SCRUB_PROGRESS));
 
        ioctl(-1, BTRFS_IOC_SCRUB_PROGRESS, &args);
-       printf("ioctl(-1, %s, {devid=makedev(%#x, %#x)}) = -1 EBADF (%m)\n",
+       printf("ioctl(-1, %s, {devid=%s}) = -1 EBADF (%m)\n",
               ioc(BTRFS_IOC_SCRUB_PROGRESS),
-              major(args.devid), minor(args.devid));
+              sprint_makedev(args.devid));
 }
 
 /*
@@ -1249,8 +1270,8 @@ btrfs_test_dev_info_ioctl(void)
 
        ioctl(-1, BTRFS_IOC_DEV_INFO, &args);
        printf("ioctl(-1, %s, "
-              "{devid=makedev(%#x, %#x), uuid=%s}) = -1 EBADF (%m)\n",
-              ioc(BTRFS_IOC_DEV_INFO), major(args.devid), minor(args.devid),
+              "{devid=%s, uuid=%s}) = -1 EBADF (%m)\n",
+              ioc(BTRFS_IOC_DEV_INFO), sprint_makedev(args.devid),
               uuid_reference_string);
 }
 
@@ -1699,14 +1720,13 @@ btrfs_test_get_dev_stats_ioctl(void)
                .nr_items = 5,
                .flags = max_flags_plus_one(0),
        };
-
        ioctl(-1, BTRFS_IOC_GET_DEV_STATS, NULL);
        printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", ioc(BTRFS_IOC_GET_DEV_STATS));
 
-       printf("ioctl(-1, %s, {devid=makedev(%#x, %#x)"
+       printf("ioctl(-1, %s, {devid=%s"
               ", nr_items=%" PRI__u64 ", flags=",
               ioc(BTRFS_IOC_GET_DEV_STATS),
-              major(args.devid), minor(args.devid), args.nr_items);
+              sprint_makedev(args.devid), args.nr_items);
        prfl_btrfs(btrfs_dev_stats_flags, args.flags,
                     "BTRFS_DEV_STATS_???");
        ioctl(-1, BTRFS_IOC_GET_DEV_STATS, &args);
@@ -1715,10 +1735,10 @@ btrfs_test_get_dev_stats_ioctl(void)
        if (write_ok) {
                unsigned int i;
                args.flags = BTRFS_DEV_STATS_RESET;
-               printf("ioctl(%d, %s, {devid=makedev(%#x, %#x)"
+               printf("ioctl(%d, %s, {devid=%s"
                        ", nr_items=%" PRI__u64 ", flags=",
                        btrfs_test_dir_fd, ioc(BTRFS_IOC_GET_DEV_STATS),
-                       major(args.devid), minor(args.devid), args.nr_items);
+                       sprint_makedev(args.devid), args.nr_items);
                prfl_btrfs(btrfs_dev_stats_flags, args.flags,
                             "BTRFS_DEV_STATS_???");
                ioctl(btrfs_test_dir_fd, BTRFS_IOC_GET_DEV_STATS, &args);
@@ -1775,11 +1795,12 @@ btrfs_test_dev_replace_ioctl(void)
                saved_errno = errno;
                printf("ioctl(-1, %s, "
                       "{cmd=%sBTRFS_IOCTL_DEV_REPLACE_CMD_START%s"
-                      ", start={srcdevid=makedev(%#x, %#x)"
+                      ", start={srcdevid=%s"
                       ", cont_reading_from_srcdev_mode=",
                       ioc(BTRFS_IOC_DEV_REPLACE),
                       verbose_xlat ? "0 /* " : "", verbose_xlat ? " */" : "",
-                      major(args.start.srcdevid), minor(args.start.srcdevid));
+                      sprint_makedev(args.start.srcdevid)
+                      );
                prxval_btrfs(btrfs_cont_reading_from_srcdev_mode,
                             args.start.cont_reading_from_srcdev_mode,
                             "BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV"
diff --git a/tests/fstat-Xabbrev.c b/tests/fstat-Xabbrev.c
new file mode 100644 (file)
index 0000000..3fb61e0
--- /dev/null
@@ -0,0 +1 @@
+#include "fstat.c"
diff --git a/tests/fstat-Xraw.c b/tests/fstat-Xraw.c
new file mode 100644 (file)
index 0000000..0428461
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_RAW 1
+#include "fstat.c"
diff --git a/tests/fstat-Xverbose.c b/tests/fstat-Xverbose.c
new file mode 100644 (file)
index 0000000..e2b2042
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_VERBOSE 1
+#include "fstat.c"
diff --git a/tests/fstat64-Xabbrev.c b/tests/fstat64-Xabbrev.c
new file mode 100644 (file)
index 0000000..dc44b3d
--- /dev/null
@@ -0,0 +1 @@
+#include "fstat64.c"
diff --git a/tests/fstat64-Xraw.c b/tests/fstat64-Xraw.c
new file mode 100644 (file)
index 0000000..f8930d7
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_RAW 1
+#include "fstat64.c"
diff --git a/tests/fstat64-Xverbose.c b/tests/fstat64-Xverbose.c
new file mode 100644 (file)
index 0000000..61e33ae
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_VERBOSE 1
+#include "fstat64.c"
index 7374add8d1803e5e6fd4537cf6461de5445fe5fc..f50b53a80ec58cf60a86bd47f9d40afb8bc7902d 100644 (file)
@@ -89,7 +89,13 @@ finit_module -a25
 flock  -a19
 fork-f -a26 -qq -f -e signal=none -e trace=chdir
 fstat  -a15 -v -P stat.sample
+fstat-Xabbrev -a15 -v -Xabbrev -P stat.sample -e trace=fstat
+fstat-Xraw -a15 -v -Xraw -P stat.sample -e trace=fstat
+fstat-Xverbose -a15 -v -Xverbose -P stat.sample -e trace=fstat
 fstat64        -a17 -v -P stat.sample
+fstat64-Xabbrev -a17 -Xabbrev -v -P stat.sample -e trace=fstat64
+fstat64-Xraw -a17 -Xraw -v -P stat.sample -e trace=fstat64
+fstat64-Xverbose -a17 -Xverbose -v -P stat.sample -e trace=fstat64
 fstatat64      -a32 -v -P stat.sample -P /dev/full
 fstatfs        -a18
 fstatfs64      -a24
index a4e9020a072d7c7e911cf2a61d7e79fdfd6add00..c6c1b0b52edac4bfb5ba47e1ae1775fbd37c156b 100755 (executable)
@@ -65,7 +65,13 @@ file_ioctl
 finit_module
 flock
 fstat
+fstat-Xabbrev
+fstat-Xraw
+fstat-Xverbose
 fstat64
+fstat64-Xabbrev
+fstat64-Xraw
+fstat64-Xverbose
 fstatat64
 fstatfs
 fstatfs64
index 34cfa7e63a850d33727ee593421ae0dcbb531e7b..3fde131dd17d6c39495d7bf09a1c6b13373fecca 100644 (file)
@@ -1,5 +1,11 @@
 fstat  -a15
+fstat-Xabbrev -a15 -Xabbrev
+fstat-Xraw -a15 -Xraw
+fstat-Xverbose -a15 -Xverbose
 fstat64        -a17
+fstat64-Xabbrev        -a17 -Xabbrev
+fstat64-Xraw   -a17 -Xraw
+fstat64-Xverbose       -a17 -Xverbose
 fstatat64      -a32
 newfstatat     -a32
 oldfstat       -a21
index 22bd7f27c4519325dedaa4c1af67b72963ce5752..c48addbf45a085c66ad17432a3e657f1d25635ad 100644 (file)
@@ -1,5 +1,11 @@
 fstat  -a15
+fstat-Xabbrev  -a15 -Xabbrev
+fstat-Xraw     -a15 -Xraw
+fstat-Xverbose -a15 -Xverbose
 fstat64        -a17
+fstat64-Xabbrev        -a17 -Xabbrev
+fstat64-Xraw   -a17 -Xraw
+fstat64-Xverbose       -a17 -Xverbose
 fstatat64      -a32
 lstat  -a32
 lstat64        -a32
index 546b8024461d2d76662b5b778cc06d1d1aa52143..b18157d4dcfebe0ade1a21d87a3ae8a934422e0e 100644 (file)
@@ -121,6 +121,7 @@ typedef off_t libc_off_t;
 #  define IS_STATX 0
 # endif
 
+#if !XLAT_RAW /* Fixes -Wunused warning */
 static void
 print_ftype(const unsigned int mode)
 {
@@ -141,20 +142,66 @@ print_perms(const unsigned int mode)
 {
        printf("%#o", mode & ~S_IFMT);
 }
+#endif
+
+static void
+print_st_mode(const unsigned int mode)
+{
+#if XLAT_RAW
+       printf("%#o", mode);
+#elif XLAT_VERBOSE
+       printf("%#o /* ", mode);
+       print_ftype(mode);
+       printf("|");
+       print_perms(mode);
+       printf(" */");
+#else
+       print_ftype(mode);
+       printf("|");
+       print_perms(mode);
+#endif
+}
 
 # if !IS_STATX
 
+static const char *
+sprint_makedev(const unsigned long long val)
+{
+       static char devid[256];
+       int ret;
+
+#if XLAT_RAW
+       ret = snprintf(devid, sizeof(devid),
+                       "%#llx", val);
+#elif XLAT_VERBOSE
+       ret = snprintf(devid, sizeof(devid),
+                       "%#llx /* makedev(%#x, %#x) */",
+                       val, major(val), minor(val));
+#else /* XLAT_ABBREV */
+       ret = snprintf(devid, sizeof(devid),
+                       "makedev(%#x, %#x)",
+                       major(val), minor(val));
+#endif
+       if (ret < 0)
+               perror_msg_and_fail("sprint_makedev(%llx)", val);
+       if ((unsigned) ret >= sizeof(devid))
+               error_msg_and_fail("sprint_makedev(%llx): buffer "
+                                          "overflow", val);
+       return devid;
+}
+
+
 static void
 print_stat(const STRUCT_STAT *st)
 {
-       printf("{st_dev=makedev(%#x, %#x)",
-              (unsigned int) major(zero_extend_signed_to_ull(st->st_dev)),
-              (unsigned int) minor(zero_extend_signed_to_ull(st->st_dev)));
+       unsigned long long dev, rdev;
+
+       dev = zero_extend_signed_to_ull(st->st_dev);
+       rdev = zero_extend_signed_to_ull(st->st_rdev);
+       printf("{st_dev=%s", sprint_makedev(dev));
        printf(", st_ino=%llu", zero_extend_signed_to_ull(st->st_ino));
        printf(", st_mode=");
-       print_ftype(st->st_mode);
-       printf("|");
-       print_perms(st->st_mode);
+       print_st_mode(st->st_mode);
        printf(", st_nlink=%llu", zero_extend_signed_to_ull(st->st_nlink));
        printf(", st_uid=%llu", zero_extend_signed_to_ull(st->st_uid));
        printf(", st_gid=%llu", zero_extend_signed_to_ull(st->st_gid));
@@ -167,9 +214,7 @@ print_stat(const STRUCT_STAT *st)
 
        switch (st->st_mode & S_IFMT) {
        case S_IFCHR: case S_IFBLK:
-               printf(", st_rdev=makedev(%#x, %#x)",
-                      (unsigned int) major(zero_extend_signed_to_ull(st->st_rdev)),
-                      (unsigned int) minor(zero_extend_signed_to_ull(st->st_rdev)));
+               printf(", st_rdev=%s", sprint_makedev(rdev));
                break;
        default:
                printf(", st_size=%llu", zero_extend_signed_to_ull(st->st_size));
@@ -237,9 +282,7 @@ print_stat(const STRUCT_STAT *st)
        PRINT_FIELD_U32_UID(stx_gid);
 
        printf(", stx_mode=");
-       print_ftype(st->stx_mode);
-       printf("|");
-       print_perms(st->stx_mode);
+       print_st_mode(st->stx_mode);
 
        PRINT_FIELD_U(", ", *st, stx_ino);
        PRINT_FIELD_U(", ", *st, stx_size);