-
-static int jt_destroy(int argc, char **argv)
-{
- struct obd_ioctl_data data;
- int rc;
-
- IOCINIT(data);
- if (argc < 1) {
- printf("usage %s id\n", argv[0]);
- }
-
- data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
-
- rc = ioctl(fd, OBD_IOC_DESTROY , &data);
- if (rc < 0) {
- printf("setattr: %x %s\n", OBD_IOC_DESTROY, strerror(errno));
- }
- return rc;
-}
-
-static int jt_multi_getattr(int argc, char **argv)
-{
- struct obd_ioctl_data data;
- int count, i;
- int rc;
-
- IOCINIT(data);
- if (argc == 2) {
- count = strtoul(argv[1], NULL, 0);
- data.ioc_obdo1.o_valid = 0xffffffff;
- data.ioc_obdo1.o_id = 2;
- printf("getting %d attrs (testing only)\n", count);
- } else {
- printf("usage %s id\n", argv[0]);
- return 0;
- }
-
- for (i = 0 ; i < count; i++) {
- rc = ioctl(fd, OBD_IOC_GETATTR , &data);
- if (rc) {
- printf("Error: %s on i=%d\n", strerror(rc), i);
- break;
- } else {
- printf("attr number %d\n", i);
- }
- }
- return 0;
-}
-
-static int jt_getattr(int argc, char **argv)
-{
- struct obd_ioctl_data data;
- int rc;
-
- IOCINIT(data);
- if (argc == 2) {
- data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
- data.ioc_obdo1.o_valid = 0xffffffff;
- printf("getting attr for %Ld\n", data.ioc_obdo1.o_id);
- } else {
- printf("usage %s id\n", argv[0]);
- return 0;
- }
-
- rc = ioctl(fd, OBD_IOC_GETATTR , &data);
- if (rc) {
- printf("Error: %s\n", strerror(rc));
- } else {
- printf("attr obdo %Ld, mode %o\n", data.ioc_obdo1.o_id,
- data.ioc_obdo1.o_mode);
- }
- return 0;
-}
-
-command_t list[] = {
- {"device", jt_device, 0, "set current device (args device no)"},
- {"attach", jt_attach, 0, "name the typed of device (args: type data"},
- {"setup", jt_setup, 0, "setup device (args: blkdev, data"},
- {"detach", jt_detach, 0, "detach the current device (arg: )"},
- {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
- {"create", jt_create, 0, "create [count [mode [silent]]]"},
- {"destroy", jt_destroy, 0, "destroy id"},
- {"test_getattr", jt_multi_getattr, 0, "test_getattr count [silent]"},
- {"getattr", jt_getattr, 0, "getattr id"},
- {"setattr", jt_setattr, 0, "setattr id mode"},
- {"connect", jt_connect, 0, "connect - get a connection to device"},
- {"disconnect", jt_disconnect, 0, "disconnect - break connection to device"},
- {"help", Parser_help, 0, "help"},
- {"exit", Parser_quit, 0, "quit"},
- {"quit", Parser_quit, 0, "quit"},
- { 0, 0, 0, NULL }
-};
-
-
-static void signal_server(int sig)
-{
- if (sig == SIGINT) {
- printf("Disconnecting existing connection");
- do_disconnect();
- }
-}
-
-int main(int argc, char **argv)
-{
- struct sigaction sigact;
- sigact.sa_handler = signal_server;
- sigfillset(&sigact.sa_mask);
- sigact.sa_flags = SA_RESTART;
- sigaction(SIGINT, &sigact, NULL);
-
- if (argc > 1) {
- return Parser_execarg(argc - 1, &argv[1], list);
- }
-
- Parser_init("obdctl > ", list);
- Parser_commands();
-
- return 0;
-}
-