2016-03-25 12:47:13 +03:00
# include "tests.h"
2016-08-09 17:38:29 +03:00
# include <asm/unistd.h>
2016-03-25 12:47:13 +03:00
# ifdef __NR_mknod
# include <stdio.h>
# include <sys / stat.h>
# include <unistd.h>
2016-03-26 02:48:48 +03:00
# ifdef MAJOR_IN_SYSMACROS
# include <sys / sysmacros.h>
# endif
# ifdef MAJOR_IN_MKDEV
# include <sys / mkdev.h>
# endif
2016-08-03 17:05:39 +03:00
static const char sample [ ] = " mknod " ;
static long
call_mknod ( unsigned short mode , unsigned long dev )
{
unsigned long lmode = ( unsigned long ) 0xffffffffffff0000 | mode ;
return syscall ( __NR_mknod , sample , lmode , dev ) ;
}
2016-03-25 12:47:13 +03:00
int
main ( void )
{
2016-08-03 17:05:39 +03:00
unsigned long dev = ( unsigned long ) 0xdeadbeefbadc0ded ;
long rc = call_mknod ( 0 , dev ) ;
printf ( " mknod( \" %s \" , 000) = %ld %s (%m) \n " ,
sample , rc , errno2name ( ) ) ;
rc = call_mknod ( 0xffff , dev ) ;
printf ( " mknod( \" %s \" , %#03ho) = %ld %s (%m) \n " ,
sample , ( unsigned short ) - 1 , rc , errno2name ( ) ) ;
rc = call_mknod ( S_IFREG , 0 ) ;
printf ( " mknod( \" %s \" , S_IFREG|000) = %ld %s (%m) \n " ,
sample , rc , errno2name ( ) ) ;
rc = call_mknod ( S_IFDIR | 06 , 0 ) ;
printf ( " mknod( \" %s \" , S_IFDIR|006) = %ld %s (%m) \n " ,
sample , rc , errno2name ( ) ) ;
2016-04-26 14:00:51 +03:00
2016-08-03 17:05:39 +03:00
rc = call_mknod ( S_IFLNK | 060 , 0 ) ;
printf ( " mknod( \" %s \" , S_IFLNK|060) = %ld %s (%m) \n " ,
sample , rc , errno2name ( ) ) ;
2016-04-26 14:00:51 +03:00
2016-08-03 17:05:39 +03:00
rc = call_mknod ( S_IFIFO | 0600 , 0 ) ;
printf ( " mknod( \" %s \" , S_IFIFO|0600) = %ld %s (%m) \n " ,
sample , rc , errno2name ( ) ) ;
2016-03-25 12:47:13 +03:00
2016-08-03 17:05:39 +03:00
dev = ( unsigned long ) 0xdeadbeef00000000 | makedev ( 1 , 7 ) ;
2016-04-22 00:04:00 +03:00
2016-08-03 17:05:39 +03:00
rc = call_mknod ( S_IFCHR | 024 , dev ) ;
printf ( " mknod( \" %s \" , S_IFCHR|024, makedev(1, 7)) = %ld %s (%m) \n " ,
sample , rc , errno2name ( ) ) ;
2016-03-26 02:48:48 +03:00
2016-08-03 17:05:39 +03:00
const unsigned short mode = ( 0xffff & ~ S_IFMT ) | S_IFBLK ;
2016-04-26 14:00:51 +03:00
dev = ( unsigned long ) 0xdeadbeefbadc0ded ;
2016-08-03 17:05:39 +03:00
rc = call_mknod ( mode , dev ) ;
printf ( " mknod( \" %s \" , S_IFBLK|S_ISUID|S_ISGID|S_ISVTX|%#03ho "
2016-04-26 14:00:51 +03:00
" , makedev(%u, %u)) = %ld %s (%m) \n " ,
2016-08-03 17:05:39 +03:00
sample , mode & ~ ( S_IFMT | S_ISUID | S_ISGID | S_ISVTX ) ,
2016-04-26 14:00:51 +03:00
major ( ( unsigned ) dev ) , minor ( ( unsigned ) dev ) ,
rc , errno2name ( ) ) ;
2016-03-25 12:47:13 +03:00
puts ( " +++ exited with 0 +++ " ) ;
return 0 ;
}
# else
SKIP_MAIN_UNDEFINED ( " __NR_mknod " )
# endif