print_dev_t: add xlat styles support

* 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>
This commit is contained in:
Shankara Pailoor 2018-12-08 14:12:42 -08:00 committed by Dmitry V. Levin
parent c40270dd87
commit e1f15583e0
14 changed files with 143 additions and 27 deletions

View File

@ -33,5 +33,17 @@
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(" */");
}

6
tests/.gitignore vendored
View 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

View 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"

1
tests/fstat-Xabbrev.c Normal file
View File

@ -0,0 +1 @@
#include "fstat.c"

2
tests/fstat-Xraw.c Normal file
View File

@ -0,0 +1,2 @@
#define XLAT_RAW 1
#include "fstat.c"

2
tests/fstat-Xverbose.c Normal file
View File

@ -0,0 +1,2 @@
#define XLAT_VERBOSE 1
#include "fstat.c"

1
tests/fstat64-Xabbrev.c Normal file
View File

@ -0,0 +1 @@
#include "fstat64.c"

2
tests/fstat64-Xraw.c Normal file
View File

@ -0,0 +1,2 @@
#define XLAT_RAW 1
#include "fstat64.c"

2
tests/fstat64-Xverbose.c Normal file
View File

@ -0,0 +1,2 @@
#define XLAT_VERBOSE 1
#include "fstat64.c"

View 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

View File

@ -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

View 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

View 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

View 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);