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
11static const char *sample;
12
13static long
14call_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
20int
21main(int ac, char **av)
22{
23	unsigned long dev = (unsigned long) 0xdeadbeefbadc0dedULL;
24	sample = av[0];
25
26	long rc = call_mknod(0, dev);
27	printf("mknod(\"%s\", 000) = %ld %s (%m)\n",
28	       sample, rc, errno2name());
29
30	rc = call_mknod(0xffff, dev);
31	printf("mknod(\"%s\", %#03ho) = %ld %s (%m)\n",
32	       sample, (unsigned short) -1, rc, errno2name());
33
34	rc = call_mknod(S_IFREG, 0);
35	printf("mknod(\"%s\", S_IFREG|000) = %ld %s (%m)\n",
36	       sample, rc, errno2name());
37
38	rc = call_mknod(S_IFDIR | 06, 0);
39	printf("mknod(\"%s\", S_IFDIR|006) = %ld %s (%m)\n",
40	       sample, rc, errno2name());
41
42	rc = call_mknod(S_IFLNK | 060, 0);
43	printf("mknod(\"%s\", S_IFLNK|060) = %ld %s (%m)\n",
44	       sample, rc, errno2name());
45
46	rc = call_mknod(S_IFIFO | 0600, 0);
47	printf("mknod(\"%s\", S_IFIFO|0600) = %ld %s (%m)\n",
48	       sample, rc, errno2name());
49
50	dev = (unsigned long) 0xdeadbeef00000000ULL | makedev(1, 7);
51
52	rc = call_mknod(S_IFCHR | 024, dev);
53	printf("mknod(\"%s\", S_IFCHR|024, makedev(1, 7)) = %ld %s (%m)\n",
54	       sample, rc, errno2name());
55
56	const unsigned short mode = (0xffff & ~S_IFMT) | S_IFBLK;
57	dev = (unsigned long) 0xdeadbeefbadc0dedULL;
58
59	rc = call_mknod(mode, dev);
60	printf("mknod(\"%s\", S_IFBLK|S_ISUID|S_ISGID|S_ISVTX|%#03ho"
61	       ", makedev(%u, %u)) = %ld %s (%m)\n",
62	       sample, mode & ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX),
63	       major((unsigned) dev), minor((unsigned) dev),
64	       rc, errno2name());
65
66	puts("+++ exited with 0 +++");
67	return 0;
68}
69
70#else
71
72SKIP_MAIN_UNDEFINED("__NR_mknod")
73
74#endif
75