-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_stat_test.c
43 lines (34 loc) · 902 Bytes
/
get_stat_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <sys/stat.h>
#include <linux/major.h>
int is_resides_on_scsi_disk(const char *file_path)
{
int ret, major;
struct stat stat_buf;
if (!file_path)
return 0;
ret = stat(file_path, &stat_buf);
if (-1 == ret) {
return 0;
}
major = stat_buf.st_dev >> 8;
if (major == SCSI_DISK0_MAJOR)
return 1;
if (major >= SCSI_DISK1_MAJOR && major <= SCSI_DISK7_MAJOR)
return 1;
if (major >= SCSI_DISK8_MAJOR && major <= SCSI_DISK15_MAJOR)
return 1;
return 0;
}
int main(int argc, char **argv)
{
struct stat s;
int ret;
if (argc != 2) {
printf("%s <file>\n", argv[0]);
return -1;
}
ret = is_resides_on_scsi_disk(argv[1]);
printf("%s %s residing on scsi disk\n", argv[1], ret?"is":"isn't") ;
return ret;
}