1#include "tests.h" 2#include <asm/unistd.h> 3 4#ifdef __NR_mknodat 5 6# include <stdio.h> 7# include <sys/stat.h> 8# include <sys/sysmacros.h> 9# include <unistd.h> 10 11static const char sample[] = "mknodat_sample"; 12static const long int fd = (long int) 0xdeadbeefffffffffULL; 13 14static long 15call_mknodat(unsigned short mode, unsigned long dev) 16{ 17 unsigned long lmode = (unsigned long) 0xffffffffffff0000ULL | mode; 18 return syscall(__NR_mknodat, fd, sample, lmode, dev); 19} 20 21int 22main(void) 23{ 24 unsigned long dev = (unsigned long) 0xdeadbeefbadc0dedULL; 25 26 long rc = call_mknodat(0, dev); 27 printf("mknodat(-1, \"%s\", 000) = %ld %s (%m)\n", 28 sample, rc, errno2name()); 29 30 rc = call_mknodat(0xffff, dev); 31 printf("mknodat(-1, \"%s\", %#03ho) = %ld %s (%m)\n", 32 sample, (unsigned short) -1, rc, errno2name()); 33 34 rc = call_mknodat(S_IFREG, 0); 35 printf("mknodat(-1, \"%s\", S_IFREG|000) = %ld %s (%m)\n", 36 sample, rc, errno2name()); 37 38 rc = call_mknodat(S_IFDIR | 06, 0); 39 printf("mknodat(-1, \"%s\", S_IFDIR|006) = %ld %s (%m)\n", 40 sample, rc, errno2name()); 41 42 rc = call_mknodat(S_IFLNK | 060, 0); 43 printf("mknodat(-1, \"%s\", S_IFLNK|060) = %ld %s (%m)\n", 44 sample, rc, errno2name()); 45 46 rc = call_mknodat(S_IFIFO | 0600, 0); 47 printf("mknodat(-1, \"%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_mknodat(S_IFCHR | 024, dev); 53 printf("mknodat(-1, \"%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_mknodat(mode, dev); 60 printf("mknodat(-1, \"%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_mknodat") 73 74#endif 75