4 #include <sys/socket.h>
9 #include <linux/obd_class.h>
13 #include <netinet/in.h>
18 #include <linux/list.h>
30 #define IOCINIT(data) do { memset(&data, 0, sizeof(data)); data.ioc_version = OBD_IOCTL_VERSION; data.ioc_conn1 = connid; data.ioc_len = sizeof(data); if (fd < 0) { printf("No device open, use device\n"); return 1;}} while (0)
33 pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
52 0, 0, # struct list_head
58 char * obdo_print(struct obdo *obd)
62 sprintf(buf, "id: %Ld\ngrp: %Ld\natime: %Ld\nmtime: %Ld\nctime: %Ld\nsize: %Ld\nblocks: %Ld\nblksize: %d\nmode: %o\nuid: %d\ngid: %d\nflags: %x\nobdflags: %x\nnlink: %d,\nvalid %x\n",
82 static int jt_device(int argc, char **argv)
84 struct obd_ioctl_data data;
87 memset(&data, 0, sizeof(data));
89 fprintf(stderr, "Usage: %s devno\n", argv[0]);
93 data.ioc_dev = atoi(argv[1]);
95 if (obd_ioctl_pack(&data, &buf, max)) {
96 printf("invalid ioctl\n");
101 fd = open("/dev/obd", O_RDWR);
103 printf("Opening /dev/obd: %s\n", strerror(errno));
107 rc = ioctl(fd, OBD_IOC_DEVICE , buf);
109 printf("Device: %x %s\n", OBD_IOC_DEVICE, strerror(errno));
116 static int jt_connect(int argc, char **argv)
118 struct obd_ioctl_data data;
124 fprintf(stderr, "Usage: %s\n", argv[0]);
128 rc = ioctl(fd, OBD_IOC_CONNECT , &data);
130 printf("Device: %x %s\n", OBD_IOC_CONNECT, strerror(errno));
133 connid = data.ioc_conn1;
140 static int jt_disconnect(int argc, char **argv)
142 struct obd_ioctl_data data;
148 fprintf(stderr, "Usage: %s\n", argv[0]);
152 rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
154 printf("Device: %x %s\n", OBD_IOC_DISCONNECT, strerror(errno));
163 static int jt_detach(int argc, char **argv)
165 struct obd_ioctl_data data;
171 fprintf(stderr, "Usage: %s\n", argv[0]);
175 if (obd_ioctl_pack(&data, &buf, max)) {
176 printf("invalid ioctl\n");
180 rc = ioctl(fd, OBD_IOC_DETACH , buf);
182 printf("Detach: %s\n", strerror(errno));
188 static int jt_cleanup(int argc, char **argv)
190 struct obd_ioctl_data data;
196 fprintf(stderr, "Usage: %s\n", argv[0]);
200 rc = ioctl(fd, OBD_IOC_CLEANUP , &data);
202 printf("Detach: %s\n", strerror(errno));
208 static int jt_attach(int argc, char **argv)
210 struct obd_ioctl_data data;
215 if ( argc != 2 && argc != 3 ) {
216 fprintf(stderr, "Usage: %s type [data]\n", argv[0]);
220 data.ioc_inllen1 = strlen(argv[1]) + 1;
221 data.ioc_inlbuf1 = argv[1];
223 data.ioc_inllen2 = strlen(argv[2]) + 1;
224 data.ioc_inlbuf2 = argv[2];
227 printf("attach len %d addr %p type %s data %s\n", data.ioc_len, buf,
228 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
230 if (obd_ioctl_pack(&data, &buf, max)) {
231 printf("invalid ioctl\n");
234 printf("attach len %d addr %p raw %p type %s data %s and %s\n", data.ioc_len, buf, rawbuf,
235 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2), &buf[516]);
237 rc = ioctl(fd, OBD_IOC_ATTACH , buf);
239 printf("Attach: %x %s\n", OBD_IOC_ATTACH, strerror(errno));
245 static int jt_setup(int argc, char **argv)
247 struct obd_ioctl_data data;
252 if ( argc != 2 && argc != 3 ) {
253 fprintf(stderr, "Usage: %s device [fstype]\n", argv[0]);
257 data.ioc_inllen1 = strlen(argv[1]) + 1;
258 data.ioc_inlbuf1 = argv[1];
260 data.ioc_inllen2 = strlen(argv[2]) + 1;
261 data.ioc_inlbuf2 = argv[2];
264 printf("attach len %d addr %p type %s data %s\n", data.ioc_len, buf,
265 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2));
267 if (obd_ioctl_pack(&data, &buf, max)) {
268 printf("invalid ioctl\n");
271 printf("attach len %d addr %p raw %p type %s data %s and %s\n", data.ioc_len, buf, rawbuf,
272 MKSTR(data.ioc_inlbuf1), MKSTR(data.ioc_inlbuf2), &buf[516]);
274 rc = ioctl(fd, OBD_IOC_SETUP , buf);
276 printf("Attach: %x %s\n", OBD_IOC_SETUP, strerror(errno));
283 static int jt_create(int argc, char **argv)
285 struct obd_ioctl_data data;
293 num = strtoul(argv[1], NULL, 0);
297 data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
299 data.ioc_obdo1.o_mode = 0100644;
301 data.ioc_obdo1.o_mode = OBD_MD_FLMODE;
304 silent = strtoul(argv[3], NULL, 0);
307 printf("Creating %d obdos\n", num);
309 for (i = 0 ; i<num ; i++) {
310 rc = ioctl(fd, OBD_IOC_CREATE , &data);
312 printf("Create: %x %s\n", OBD_IOC_CREATE,
316 printf("created obdo %Ld\n", data.ioc_obdo1.o_id);
322 {"device", jt_device, 0, "set current device (args device no)"},
323 {"attach", jt_attach, 0, "name the typed of device (args: type data"},
324 {"setup", jt_setup, 0, "setup device (args: blkdev, data"},
325 {"detach", jt_detach, 0, "detach the current device (arg: )"},
326 {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
327 {"create", jt_create, 0, "create [count [mode [silent]]]"},
328 {"connect", jt_connect, 0, "connect - get a connection to device"},
329 {"disconnect", jt_disconnect, 0, "disconnect - break connection to device"},
330 {"help", Parser_help, 0, "help"},
331 {"exit", Parser_quit, 0, "quit"},
332 {"quit", Parser_quit, 0, "quit"},
336 int main(int argc, char **argv)
340 return Parser_execarg(argc - 1, &argv[1], list);
343 Parser_init("obdctl > ", list);