Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[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 <linux/lustre_lib.h>
9 #include <linux/obd.h>
10
11 int main(int argc, char **argv)
12 {
13     struct obd_ioctl_data data;
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     memset(&data, 0, sizeof(data));
39     data.ioc_version = OBD_IOCTL_VERSION;
40     data.ioc_len = sizeof(data);
41     if (offset >= 0)
42         data.ioc_inlbuf1 = base + offset + 2;
43     else
44         data.ioc_inlbuf1 = base;
45     data.ioc_inllen1 = strlen(data.ioc_inlbuf1) + 1;
46     
47     if (obd_ioctl_pack(&data, &buf, max)) {
48         printf("ioctl_pack failed.\n");
49         exit(1);
50     }
51     
52     rc = ioctl(fd, IOC_MDC_LOOKUP, buf);
53     if (rc < 0) {
54         printf("ioctl(%s/%s) error: %s\n", parent,
55                data.ioc_inlbuf1, strerror(errno));
56         exit(errno);
57     }
58
59     return 0;
60 }