From 8207f12d6a61bbeaafbc180a97b8a1ebb07a4fed Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 23 Jun 2017 18:06:46 +0000 Subject: [PATCH] Decode FreeBSD 11 compat stat, fstat and lstat calls. --- usr.bin/truss/syscall.h | 3 ++- usr.bin/truss/syscalls.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/usr.bin/truss/syscall.h b/usr.bin/truss/syscall.h index 86f0411ba47..8510be5d3e9 100644 --- a/usr.bin/truss/syscall.h +++ b/usr.bin/truss/syscall.h @@ -10,6 +10,7 @@ * BinString -- pointer to an array of chars, printed via strvisx(). * Ptr -- pointer to some unspecified structure. Just print as hex for now. * Stat -- a pointer to a stat buffer. Prints a couple fields. + * Stat11 -- a pointer to a freebsd 11 stat buffer. Prints a couple fields. * StatFs -- a pointer to a statfs buffer. Prints a few fields. * Ioctl -- an ioctl command. Woefully limited. * Quad -- a double-word value. e.g., lseek(int, offset_t, int) @@ -38,7 +39,7 @@ * $FreeBSD$ */ -enum Argtype { None = 1, Hex, Octal, Int, UInt, LongHex, Name, Ptr, Stat, Ioctl, +enum Argtype { None = 1, Hex, Octal, Int, UInt, LongHex, Name, Ptr, Stat, Stat11, Ioctl, Quad, Signal, Sockaddr, StringArray, Timespec, Timeval, Itimerval, Pollfd, Fd_set, Sigaction, Fcntl, Mprot, Mmapflags, Whence, Readlinkres, Sigset, Sigprocmask, StatFs, Kevent, Sockdomain, Socktype, Open, diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index c804ba2051f..80547f4a83c 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#define _WANT_FREEBSD11_STAT #include #include #include @@ -215,6 +216,14 @@ static struct syscall decoded_syscalls[] = { .args = { { Int, 0 }, { Fcntl, 1 }, { Fcntlflag, 2 } } }, { .name = "flock", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Flockop, 1 } } }, + { .name = "compat11.fstat", .ret_type = 1, .nargs = 2, + .args = { { Int, 0 }, { Stat11 | OUT, 1 } } }, + { .name = "compat11.lstat", .ret_type = 1, .nargs = 2, + .args = { { Name | IN, 0 }, { Stat11 | OUT, 1 } } }, + { .name = "compat11.stat", .ret_type = 1, .nargs = 2, + .args = { { Name | IN, 0 }, { Stat11 | OUT, 1 } } }, + { .name = "compat11.stat", .ret_type = 1, .nargs = 2, + .args = { { Name | IN, 0 }, { Stat11 | OUT, 1 } } }, { .name = "fstat", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Stat | OUT, 1 } } }, { .name = "fstatat", .ret_type = 1, .nargs = 4, @@ -1885,6 +1894,23 @@ print_arg(struct syscall_args *sc, unsigned long *args, long *retval, } break; } + case Stat11: { + struct freebsd11_stat st; + + if (get_struct(pid, (void *)args[sc->offset], &st, sizeof(st)) + != -1) { + char mode[12]; + + strmode(st.st_mode, mode); + fprintf(fp, + "{ mode=%s,inode=%ju,size=%jd,blksize=%ld }", mode, + (uintmax_t)st.st_ino, (intmax_t)st.st_size, + (long)st.st_blksize); + } else { + fprintf(fp, "0x%lx", args[sc->offset]); + } + break; + } case StatFs: { unsigned int i; struct statfs buf;