int main(int argc, char **argv) { int readonly = 0; int growable = 0; const char *sopt = "hVc:rsnmgk"; const struct option lopt[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, { "offset", 1, NULL, 'o' }, { "cmd", 1, NULL, 'c' }, { "read-only", 0, NULL, 'r' }, { "snapshot", 0, NULL, 's' }, { "nocache", 0, NULL, 'n' }, { "misalign", 0, NULL, 'm' }, { "growable", 0, NULL, 'g' }, { "native-aio", 0, NULL, 'k' }, { NULL, 0, NULL, 0 } }; int c; int opt_index = 0; int flags = 0; progname = basename(argv[0]); while ((c = getopt_long(argc, argv, sopt, lopt, &opt_index)) != -1) { switch (c) { case 's': flags |= BDRV_O_SNAPSHOT; break; case 'n': flags |= BDRV_O_NOCACHE; break; case 'c': add_user_command(optarg); break; case 'r': readonly = 1; break; case 'm': misalign = 1; break; case 'g': growable = 1; break; case 'k': flags |= BDRV_O_NATIVE_AIO; break; case 'V': printf("%s version %s\n", progname, VERSION); exit(0); case 'h': usage(progname); exit(0); default: usage(progname); exit(1); } } if ((argc - optind) > 1) { usage(progname); exit(1); } bdrv_init(); /* initialize commands */ quit_init(); help_init(); add_command(&open_cmd); add_command(&close_cmd); add_command(&read_cmd); add_command(&readv_cmd); add_command(&write_cmd); add_command(&writev_cmd); add_command(&multiwrite_cmd); add_command(&aio_read_cmd); add_command(&aio_write_cmd); add_command(&aio_flush_cmd); add_command(&flush_cmd); add_command(&truncate_cmd); add_command(&length_cmd); add_command(&info_cmd); add_command(&alloc_cmd); add_args_command(init_args_command); add_check_command(init_check_command); /* open the device */ if (!readonly) { flags |= BDRV_O_RDWR; } if ((argc - optind) == 1) openfile(argv[optind], flags, growable); command_loop(); /* * Make sure all outstanding requests get flushed the program exits. */ qemu_aio_flush(); if (bs) bdrv_close(bs); return 0; }
int main(int argc, char **argv) { int readonly = 0; int growable = 0; const char *sopt = "hVc:d:rsnmgkt:T:"; const struct option lopt[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, { "offset", 1, NULL, 'o' }, { "cmd", 1, NULL, 'c' }, { "read-only", 0, NULL, 'r' }, { "snapshot", 0, NULL, 's' }, { "nocache", 0, NULL, 'n' }, { "misalign", 0, NULL, 'm' }, { "growable", 0, NULL, 'g' }, { "native-aio", 0, NULL, 'k' }, { "discard", 1, NULL, 'd' }, { "cache", 1, NULL, 't' }, { "trace", 1, NULL, 'T' }, { NULL, 0, NULL, 0 } }; int c; int opt_index = 0; int flags = BDRV_O_UNMAP; progname = basename(argv[0]); while ((c = getopt_long(argc, argv, sopt, lopt, &opt_index)) != -1) { switch (c) { case 's': flags |= BDRV_O_SNAPSHOT; break; case 'n': flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; break; case 'd': if (bdrv_parse_discard_flags(optarg, &flags) < 0) { error_report("Invalid discard option: %s", optarg); exit(1); } break; case 'c': add_user_command(optarg); break; case 'r': readonly = 1; break; case 'm': misalign = 1; break; case 'g': growable = 1; break; case 'k': flags |= BDRV_O_NATIVE_AIO; break; case 't': if (bdrv_parse_cache_flags(optarg, &flags) < 0) { error_report("Invalid cache option: %s", optarg); exit(1); } break; case 'T': if (!trace_backend_init(optarg, NULL)) { exit(1); /* error message will have been printed */ } break; case 'V': printf("%s version %s\n", progname, VERSION); exit(0); case 'h': usage(progname); exit(0); default: usage(progname); exit(1); } } if ((argc - optind) > 1) { usage(progname); exit(1); } qemu_init_main_loop(); bdrv_init(); /* initialize commands */ quit_init(); help_init(); add_command(&open_cmd); add_command(&close_cmd); add_command(&read_cmd); add_command(&readv_cmd); add_command(&write_cmd); add_command(&writev_cmd); add_command(&multiwrite_cmd); add_command(&aio_read_cmd); add_command(&aio_write_cmd); add_command(&aio_flush_cmd); add_command(&flush_cmd); add_command(&truncate_cmd); add_command(&length_cmd); add_command(&info_cmd); add_command(&discard_cmd); add_command(&alloc_cmd); add_command(&map_cmd); add_command(&break_cmd); add_command(&resume_cmd); add_command(&wait_break_cmd); add_command(&abort_cmd); add_args_command(init_args_command); add_check_command(init_check_command); /* open the device */ if (!readonly) { flags |= BDRV_O_RDWR; } if ((argc - optind) == 1) { openfile(argv[optind], flags, growable); } command_loop(); /* * Make sure all outstanding requests complete before the program exits. */ bdrv_drain_all(); if (bs) { bdrv_delete(bs); } return 0; }
void init( int argc, char **argv) { int c, flags = 0; char *sp; mode_t mode = 0600; xfs_fsop_geom_t geometry = { 0 }; progname = basename(argv[0]); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); pagesize = getpagesize(); gettimeofday(&stopwatch, NULL); while ((c = getopt(argc, argv, "ac:dFfmp:nrRstVx")) != EOF) { switch (c) { case 'a': flags |= IO_APPEND; break; case 'c': add_user_command(optarg); break; case 'd': flags |= IO_DIRECT; break; case 'F': /* Ignored / deprecated now, handled automatically */ break; case 'f': flags |= IO_CREAT; break; case 'm': mode = strtoul(optarg, &sp, 0); if (!sp || sp == optarg) { fprintf(stderr, _("non-numeric mode -- %s\n"), optarg); exit(1); } break; case 'n': flags |= IO_NONBLOCK; break; case 'p': progname = optarg; break; case 'r': flags |= IO_READONLY; break; case 's': flags |= IO_OSYNC; break; case 't': flags |= IO_TRUNC; break; case 'R': flags |= IO_REALTIME; break; case 'x': expert = 1; break; case 'V': printf(_("%s version %s\n"), progname, VERSION); exit(0); default: usage(); } } while (optind < argc) { if ((c = openfile(argv[optind], &geometry, flags, mode)) < 0) exit(1); if (!platform_test_xfs_fd(c)) flags |= IO_FOREIGN; if (addfile(argv[optind], c, &geometry, flags) < 0) exit(1); optind++; } init_commands(); add_args_command(init_args_command); add_check_command(init_check_command); }