[PATCH v4] Implement decoding of ustat syscall
Dmitry V. Levin
ldv at altlinux.org
Tue Jan 10 18:08:00 UTC 2017
On Mon, Jan 09, 2017 at 09:40:19PM +0800, JingPiao Chen wrote:
[...]
> +#include "tests.h"
> +#include <asm/unistd.h>
> +
> +#ifdef __NR_ustat
> +
> +# include <stdio.h>
> +# include <sys/stat.h>
> +# include <sys/sysmacros.h>
> +# include <unistd.h>
> +# include <ustat.h>
> +
> +int
> +main(void)
> +{
> + kernel_ulong_t magic = (kernel_ulong_t) 0xfacefeedffffffff;
> + unsigned int dev = (unsigned int) magic;
> + struct ustat *ust = tail_alloc(sizeof(*ust));
> + struct stat st;
> +
> + long rc = syscall(__NR_ustat, magic, 0);
> + printf("ustat(makedev(%u, %u), NULL) = %s\n", major(dev),
> + minor(dev), sprintrc(rc));
It'd look nicer if you wrapped the line after the first argument, e.g.
printf("ustat(makedev(%u, %u), NULL) = %s\n",
major(dev), minor(dev), sprintrc(rc));
> +
> + rc = syscall(__NR_ustat, magic, ust);
> + printf("ustat(makedev(%u, %u), %p) = %s\n", major(dev), minor(dev),
> + ust, sprintrc(rc));
Likewise.
> +
> + if (stat("/", &st) == -1)
> + perror_msg_and_fail("stat");
> + rc = syscall(__NR_ustat, st.st_dev, ust);
Please note that sizeof(st.st_dev) might be greater than sizeof(dev).
If this is the case, the value of st.st_dev might not be a valid argument
for ustat. I suggest assigning st.st_dev to dev with a check that both
are equal. If it is the case, you can pass dev on to ustat.
> + printf("ustat(makedev(%u, %u), {f_tfree=%llu, f_tinode=%llu}) = %s\n",
> + major(st.st_dev), minor(st.st_dev), (unsigned long long) ust->f_tfree,
> + (unsigned long long) ust->f_tinode, sprintrc(rc));
Please note that ustat might be not implemented by the kernel,
so one cannot assume that a ustat call succeeds.
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170110/d89609ea/attachment.bin>
More information about the Strace-devel
mailing list