1 #include "tests.h"
2 #include <asm/unistd.h>
3
4 #ifdef __NR_mknod
5
6 # include <stdio.h>
7 # include <sys/stat.h>
8 # include <sys/sysmacros.h>
9 # include <unistd.h>
10
11 static const char sample[] = "mknod";
12
13 static long
call_mknod(unsigned short mode,unsigned long dev)14 call_mknod(unsigned short mode, unsigned long dev)
15 {
16 unsigned long lmode = (unsigned long) 0xffffffffffff0000ULL | mode;
17 return syscall(__NR_mknod, sample, lmode, dev);
18 }
19
20 int
main(void)21 main(void)
22 {
23 unsigned long dev = (unsigned long) 0xdeadbeefbadc0dedULL;
24
25 long rc = call_mknod(0, dev);
26 printf("mknod(\"%s\", 000) = %ld %s (%m)\n",
27 sample, rc, errno2name());
28
29 rc = call_mknod(0xffff, dev);
30 printf("mknod(\"%s\", %#03ho) = %ld %s (%m)\n",
31 sample, (unsigned short) -1, rc, errno2name());
32
33 rc = call_mknod(S_IFREG, 0);
34 printf("mknod(\"%s\", S_IFREG|000) = %ld %s (%m)\n",
35 sample, rc, errno2name());
36
37 rc = call_mknod(S_IFDIR | 06, 0);
38 printf("mknod(\"%s\", S_IFDIR|006) = %ld %s (%m)\n",
39 sample, rc, errno2name());
40
41 rc = call_mknod(S_IFLNK | 060, 0);
42 printf("mknod(\"%s\", S_IFLNK|060) = %ld %s (%m)\n",
43 sample, rc, errno2name());
44
45 rc = call_mknod(S_IFIFO | 0600, 0);
46 printf("mknod(\"%s\", S_IFIFO|0600) = %ld %s (%m)\n",
47 sample, rc, errno2name());
48
49 dev = (unsigned long) 0xdeadbeef00000000ULL | makedev(1, 7);
50
51 rc = call_mknod(S_IFCHR | 024, dev);
52 printf("mknod(\"%s\", S_IFCHR|024, makedev(1, 7)) = %ld %s (%m)\n",
53 sample, rc, errno2name());
54
55 const unsigned short mode = (0xffff & ~S_IFMT) | S_IFBLK;
56 dev = (unsigned long) 0xdeadbeefbadc0dedULL;
57
58 rc = call_mknod(mode, dev);
59 printf("mknod(\"%s\", S_IFBLK|S_ISUID|S_ISGID|S_ISVTX|%#03ho"
60 ", makedev(%u, %u)) = %ld %s (%m)\n",
61 sample, mode & ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX),
62 major((unsigned) dev), minor((unsigned) dev),
63 rc, errno2name());
64
65 puts("+++ exited with 0 +++");
66 return 0;
67 }
68
69 #else
70
71 SKIP_MAIN_UNDEFINED("__NR_mknod")
72
73 #endif
74