blob: 98712e196a4fa213fb6e5aa724d497cd2b10b4ed [file] [log] [blame]
Fei Jie0ebe67b2016-03-25 17:47:13 +08001#include "tests.h"
Dmitry V. Levin6a2f43c2016-08-09 14:38:29 +00002#include <asm/unistd.h>
Fei Jie0ebe67b2016-03-25 17:47:13 +08003
4#ifdef __NR_mknod
5
Fei Jie0ebe67b2016-03-25 17:47:13 +08006# include <stdio.h>
7# include <sys/stat.h>
8# include <unistd.h>
9
Dmitry V. Levin9d919282016-03-25 23:48:48 +000010# ifdef MAJOR_IN_SYSMACROS
11# include <sys/sysmacros.h>
12# endif
13# ifdef MAJOR_IN_MKDEV
14# include <sys/mkdev.h>
15# endif
16
Dmitry V. Levin8d374382016-08-03 14:05:39 +000017static const char sample[] = "mknod";
18
19static long
20call_mknod(unsigned short mode, unsigned long dev)
21{
22 unsigned long lmode = (unsigned long) 0xffffffffffff0000 | mode;
23 return syscall(__NR_mknod, sample, lmode, dev);
24}
Fei Jie0ebe67b2016-03-25 17:47:13 +080025
26int
27main(void)
28{
Dmitry V. Levin8d374382016-08-03 14:05:39 +000029 unsigned long dev = (unsigned long) 0xdeadbeefbadc0ded;
Dmitry V. Levin7dad3f32016-04-26 11:00:51 +000030
Dmitry V. Levin8d374382016-08-03 14:05:39 +000031 long rc = call_mknod(0, dev);
32 printf("mknod(\"%s\", 000) = %ld %s (%m)\n",
33 sample, rc, errno2name());
Dmitry V. Levin7dad3f32016-04-26 11:00:51 +000034
Dmitry V. Levin8d374382016-08-03 14:05:39 +000035 rc = call_mknod(0xffff, dev);
36 printf("mknod(\"%s\", %#03ho) = %ld %s (%m)\n",
37 sample, (unsigned short) -1, rc, errno2name());
Fei Jie0ebe67b2016-03-25 17:47:13 +080038
Dmitry V. Levin8d374382016-08-03 14:05:39 +000039 rc = call_mknod(S_IFREG, 0);
40 printf("mknod(\"%s\", S_IFREG|000) = %ld %s (%m)\n",
41 sample, rc, errno2name());
Dmitry V. Levind0652a42016-04-21 21:04:00 +000042
Dmitry V. Levin8d374382016-08-03 14:05:39 +000043 rc = call_mknod(S_IFDIR | 06, 0);
44 printf("mknod(\"%s\", S_IFDIR|006) = %ld %s (%m)\n",
45 sample, rc, errno2name());
Dmitry V. Levin9d919282016-03-25 23:48:48 +000046
Dmitry V. Levin8d374382016-08-03 14:05:39 +000047 rc = call_mknod(S_IFLNK | 060, 0);
48 printf("mknod(\"%s\", S_IFLNK|060) = %ld %s (%m)\n",
49 sample, rc, errno2name());
50
51 rc = call_mknod(S_IFIFO | 0600, 0);
52 printf("mknod(\"%s\", S_IFIFO|0600) = %ld %s (%m)\n",
53 sample, rc, errno2name());
54
55 dev = (unsigned long) 0xdeadbeef00000000 | makedev(1, 7);
56
57 rc = call_mknod(S_IFCHR | 024, dev);
58 printf("mknod(\"%s\", S_IFCHR|024, makedev(1, 7)) = %ld %s (%m)\n",
59 sample, rc, errno2name());
60
61 const unsigned short mode = (0xffff & ~S_IFMT) | S_IFBLK;
Dmitry V. Levin7dad3f32016-04-26 11:00:51 +000062 dev = (unsigned long) 0xdeadbeefbadc0ded;
63
Dmitry V. Levin8d374382016-08-03 14:05:39 +000064 rc = call_mknod(mode, dev);
65 printf("mknod(\"%s\", S_IFBLK|S_ISUID|S_ISGID|S_ISVTX|%#03ho"
Dmitry V. Levin7dad3f32016-04-26 11:00:51 +000066 ", makedev(%u, %u)) = %ld %s (%m)\n",
Dmitry V. Levin8d374382016-08-03 14:05:39 +000067 sample, mode & ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX),
Dmitry V. Levin7dad3f32016-04-26 11:00:51 +000068 major((unsigned) dev), minor((unsigned) dev),
69 rc, errno2name());
70
Fei Jie0ebe67b2016-03-25 17:47:13 +080071 puts("+++ exited with 0 +++");
72 return 0;
73}
74
75#else
76
77SKIP_MAIN_UNDEFINED("__NR_mknod")
78
79#endif