StudyingUnixInterface/4/fileDirectory/dev.c

27 lines
456 B
C
Raw Normal View History

2020-12-08 03:33:48 +00:00
#include <sys/stat.h>
#include <stdio.h>
#include <sys/types.h>
int main(void) {
struct stat buf;
if(stat("/dev/sda", &buf) < 0){
printf("stat error for /dev/sda\n");
return -1;
}
printf("dev = %ld\nrdev = %ld\n", buf.st_dev, buf.st_rdev);
if(S_ISCHR(buf.st_mode)){
printf("character device\n");
}
else if (S_ISBLK(buf.st_mode)){
printf("block device\n");
}
else {
printf("unkonwn device\n");
}
return 0;
}