Whamcloud - gitweb
land b1_5 onto HEAD
[fs/lustre-release.git] / lustre / tests / statone.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6
7 #include <liblustre.h>
8 #include <lustre_lib.h>
9 #include <obd.h>
10
11 int main(int argc, char **argv)
12 {
13     struct obd_ioctl_data data = { 0 };
14     char rawbuf[8192], parent[4096], *buf = rawbuf, *base, *t;
15     int max = sizeof(rawbuf), fd, offset, rc;
16
17     if (argc != 2) {
18         printf("usage: %s filename\n", argv[0]);
19         return 1;
20     }
21
22     base = argv[1];
23     t = strrchr(base, '/');
24     if (!t) {
25         strcpy(parent, ".");
26         offset = -1;
27     } else {
28         strncpy(parent, base, t - base);
29         offset = t - base - 1;
30     }
31
32     fd = open(parent, O_RDONLY);
33     if (fd < 0) {
34         printf("open(%s) error: %s\n", parent, strerror(errno));
35         exit(errno);
36     }
37
38     data.ioc_version = OBD_IOCTL_VERSION;
39     data.ioc_len = sizeof(data);
40     if (offset >= 0)
41         data.ioc_inlbuf1 = base + offset + 2;
42     else
43         data.ioc_inlbuf1 = base;
44     data.ioc_inllen1 = strlen(data.ioc_inlbuf1) + 1;
45     
46     if (obd_ioctl_pack(&data, &buf, max)) {
47         printf("ioctl_pack failed.\n");
48         exit(1);
49     }
50     
51     rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
52     if (rc < 0) {
53         printf("ioctl(%s/%s) error: %s\n", parent,
54                data.ioc_inlbuf1, strerror(errno));
55         exit(errno);
56     }
57
58     return 0;
59 }