]> granicus.if.org Git - strace/blob - tests/ustat.c
strace: terminate itself if interrupted by a signal
[strace] / tests / ustat.c
1 /*
2  * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  */
7
8 #include "tests.h"
9 #include <asm/unistd.h>
10
11 #ifdef __NR_ustat
12
13 # include <stdio.h>
14 # include <sys/stat.h>
15 # include <sys/sysmacros.h>
16 # include <unistd.h>
17 # ifdef HAVE_USTAT_H
18 #  include <ustat.h>
19 # endif
20
21 int
22 main(void)
23 {
24         const kernel_ulong_t magic = (kernel_ulong_t) 0xfacefeedffffffff;
25         unsigned long long buf[4];
26         unsigned int dev;
27         long rc;
28
29 # ifdef HAVE_USTAT_H
30         TAIL_ALLOC_OBJECT_CONST_PTR(struct ustat, ust);
31         struct stat st;
32         if (stat(".", &st))
33                 perror_msg_and_fail("stat");
34
35         dev = (unsigned int) st.st_dev;
36         rc = syscall(__NR_ustat, dev, ust);
37         if (rc)
38                 printf("ustat(makedev(%#x, %#x), %p) = %s\n",
39                        major(dev), minor(dev), ust, sprintrc(rc));
40         else
41                 printf("ustat(makedev(%#x, %#x)"
42                        ", {f_tfree=%llu, f_tinode=%llu}) = 0\n",
43                        major(dev), minor(dev),
44                        zero_extend_signed_to_ull(ust->f_tfree),
45                        zero_extend_signed_to_ull(ust->f_tinode));
46 # endif /* HAVE_USTAT_H */
47
48         dev = (unsigned int) magic;
49         rc = syscall(__NR_ustat, magic, 0);
50         printf("ustat(makedev(%#x, %#x), NULL) = %s\n",
51                major(dev), minor(dev), sprintrc(rc));
52
53         rc = syscall(__NR_ustat, magic, buf);
54         printf("ustat(makedev(%#x, %#x), %p) = %s\n",
55                major(dev), minor(dev), buf, sprintrc(rc));
56
57         puts("+++ exited with 0 +++");
58         return 0;
59 }
60
61 #else
62
63 SKIP_MAIN_UNDEFINED("__NR_ustat")
64
65 #endif