Fei Jie | 0ebe67b | 2016-03-25 17:47:13 +0800 | [diff] [blame] | 1 | #include "tests.h" |
Dmitry V. Levin | 6a2f43c | 2016-08-09 14:38:29 +0000 | [diff] [blame] | 2 | #include <asm/unistd.h> |
Fei Jie | 0ebe67b | 2016-03-25 17:47:13 +0800 | [diff] [blame] | 3 | |
| 4 | #ifdef __NR_mknod |
| 5 | |
Fei Jie | 0ebe67b | 2016-03-25 17:47:13 +0800 | [diff] [blame] | 6 | # include <stdio.h> |
| 7 | # include <sys/stat.h> |
| 8 | # include <unistd.h> |
| 9 | |
Dmitry V. Levin | 9d91928 | 2016-03-25 23:48:48 +0000 | [diff] [blame] | 10 | # 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. Levin | 8d37438 | 2016-08-03 14:05:39 +0000 | [diff] [blame] | 17 | static const char sample[] = "mknod"; |
| 18 | |
| 19 | static long |
| 20 | call_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 Jie | 0ebe67b | 2016-03-25 17:47:13 +0800 | [diff] [blame] | 25 | |
| 26 | int |
| 27 | main(void) |
| 28 | { |
Dmitry V. Levin | 8d37438 | 2016-08-03 14:05:39 +0000 | [diff] [blame] | 29 | unsigned long dev = (unsigned long) 0xdeadbeefbadc0ded; |
Dmitry V. Levin | 7dad3f3 | 2016-04-26 11:00:51 +0000 | [diff] [blame] | 30 | |
Dmitry V. Levin | 8d37438 | 2016-08-03 14:05:39 +0000 | [diff] [blame] | 31 | long rc = call_mknod(0, dev); |
| 32 | printf("mknod(\"%s\", 000) = %ld %s (%m)\n", |
| 33 | sample, rc, errno2name()); |
Dmitry V. Levin | 7dad3f3 | 2016-04-26 11:00:51 +0000 | [diff] [blame] | 34 | |
Dmitry V. Levin | 8d37438 | 2016-08-03 14:05:39 +0000 | [diff] [blame] | 35 | rc = call_mknod(0xffff, dev); |
| 36 | printf("mknod(\"%s\", %#03ho) = %ld %s (%m)\n", |
| 37 | sample, (unsigned short) -1, rc, errno2name()); |
Fei Jie | 0ebe67b | 2016-03-25 17:47:13 +0800 | [diff] [blame] | 38 | |
Dmitry V. Levin | 8d37438 | 2016-08-03 14:05:39 +0000 | [diff] [blame] | 39 | rc = call_mknod(S_IFREG, 0); |
| 40 | printf("mknod(\"%s\", S_IFREG|000) = %ld %s (%m)\n", |
| 41 | sample, rc, errno2name()); |
Dmitry V. Levin | d0652a4 | 2016-04-21 21:04:00 +0000 | [diff] [blame] | 42 | |
Dmitry V. Levin | 8d37438 | 2016-08-03 14:05:39 +0000 | [diff] [blame] | 43 | rc = call_mknod(S_IFDIR | 06, 0); |
| 44 | printf("mknod(\"%s\", S_IFDIR|006) = %ld %s (%m)\n", |
| 45 | sample, rc, errno2name()); |
Dmitry V. Levin | 9d91928 | 2016-03-25 23:48:48 +0000 | [diff] [blame] | 46 | |
Dmitry V. Levin | 8d37438 | 2016-08-03 14:05:39 +0000 | [diff] [blame] | 47 | 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. Levin | 7dad3f3 | 2016-04-26 11:00:51 +0000 | [diff] [blame] | 62 | dev = (unsigned long) 0xdeadbeefbadc0ded; |
| 63 | |
Dmitry V. Levin | 8d37438 | 2016-08-03 14:05:39 +0000 | [diff] [blame] | 64 | rc = call_mknod(mode, dev); |
| 65 | printf("mknod(\"%s\", S_IFBLK|S_ISUID|S_ISGID|S_ISVTX|%#03ho" |
Dmitry V. Levin | 7dad3f3 | 2016-04-26 11:00:51 +0000 | [diff] [blame] | 66 | ", makedev(%u, %u)) = %ld %s (%m)\n", |
Dmitry V. Levin | 8d37438 | 2016-08-03 14:05:39 +0000 | [diff] [blame] | 67 | sample, mode & ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX), |
Dmitry V. Levin | 7dad3f3 | 2016-04-26 11:00:51 +0000 | [diff] [blame] | 68 | major((unsigned) dev), minor((unsigned) dev), |
| 69 | rc, errno2name()); |
| 70 | |
Fei Jie | 0ebe67b | 2016-03-25 17:47:13 +0800 | [diff] [blame] | 71 | puts("+++ exited with 0 +++"); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | #else |
| 76 | |
| 77 | SKIP_MAIN_UNDEFINED("__NR_mknod") |
| 78 | |
| 79 | #endif |