352
static struct option options[] = {
353
{"root", required_argument, 0, 'r'},
354
{"skip", required_argument, 0, 's'},
355
{"length", required_argument, 0, 'n'},
356
{"diskcount", required_argument, 0, 'c'},
357
{"debug", required_argument, 0, 'd'},
358
{"help", no_argument, 0, 'h'},
359
{"version", no_argument, 0, 'V'},
360
{"verbose", no_argument, 0, 'v'},
346
static struct argp_option options[] = {
347
{0, 0, 0 , OPTION_DOC, N_("Commands:"), 1},
348
{N_("ls PATH"), 0, 0 , OPTION_DOC, N_("List files in PATH."), 1},
349
{N_("cp FILE LOCAL"), 0, 0, OPTION_DOC, N_("Copy FILE to local file LOCAL."), 1},
350
{N_("cmp FILE LOCAL"), 0, 0, OPTION_DOC, N_("Compare FILE with local file LOCAL."), 1},
351
{N_("hex FILE"), 0, 0 , OPTION_DOC, N_("Hex dump FILE."), 1},
352
{N_("crc FILE"), 0, 0 , OPTION_DOC, N_("Get crc32 checksum of FILE."), 1},
353
{N_("blocklist FILE"), 0, 0, OPTION_DOC, N_("Display blocklist of FILE."), 1},
355
{"root", 'r', N_("DEVICE_NAME"), 0, N_("Set root device."), 2},
356
{"skip", 's', "N", 0, N_("Skip N bytes from output file."), 2},
357
{"length", 'n', "N", 0, N_("Handle N bytes in output file."), 2},
358
{"diskcount", 'c', "N", 0, N_("N input files."), 2},
359
{"debug", 'd', "S", 0, N_("Set debug environment variable."), 2},
360
{"verbose", 'v', NULL, OPTION_ARG_OPTIONAL, N_("Print verbose messages."), 2},
364
/* Print the version information. */
366
print_version (FILE *stream, struct argp_state *state)
368
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
371
Usage: %s [OPTION]... IMAGE_PATH COMMANDS\n\
373
Debug tool for filesystem driver.\n\
375
ls PATH list files in PATH\n\
376
cp FILE LOCAL copy FILE to local file LOCAL\n\
377
cmp FILE LOCAL compare FILE with local file LOCAL\n\
378
hex FILE Hex dump FILE\n\
379
crc FILE Get crc32 checksum of FILE\n\
380
blocklist FILE display blocklist of FILE\n\
382
-r, --root=DEVICE_NAME set root device\n\
383
-s, --skip=N skip N bytes from output file\n\
384
-n, --length=N handle N bytes in output file\n\
385
-c, --diskcount=N N input files\n\
386
-d, --debug=S Set debug environment variable\n\
387
-h, --help display this message and exit\n\
388
-V, --version print version information and exit\n\
389
-v, --verbose print verbose messages\n\
391
Report bugs to <%s>.\n", program_name, PACKAGE_BUGREPORT);
368
fprintf (stream, "%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
370
void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
397
main (int argc, char *argv[])
373
argp_parser (int key, char *arg, struct argp_state *state)
399
char *debug_str = NULL, *root = NULL, *default_root, *alloc_root;
400
int i, cmd, num_opts, image_index, num_disks = 1;
402
set_program_name (argv[0]);
404
grub_util_init_nls ();
406
/* Find the first non option entry. */
407
for (num_opts = 1; num_opts < argc; num_opts++)
408
if (argv[num_opts][0] == '-')
410
if ((argv[num_opts][2] == 0) && (num_opts < argc - 1) &&
411
((argv[num_opts][1] == 'r') ||
412
(argv[num_opts][1] == 's') ||
413
(argv[num_opts][1] == 'n') ||
414
(argv[num_opts][1] == 'c') ||
415
(argv[num_opts][1] == 'd')))
384
skip = grub_strtoul (arg, &p, 0);
386
skip <<= GRUB_DISK_SECTOR_BITS;
390
leng = grub_strtoul (arg, &p, 0);
392
leng <<= GRUB_DISK_SECTOR_BITS;
396
num_disks = grub_strtoul (arg, NULL, 0);
399
fprintf (stderr, "%s", _("Invalid disk count.\n"));
404
fprintf (stderr, "%s", _("Disk count must precede disks list.\n"));
418
if (args_count < num_disks)
420
fprintf (stderr, "%s", _("No command is specified.\n"));
423
if (args_count - 1 - num_disks < nparm)
425
fprintf (stderr, "%s", _("Not enough parameters to command.\n"));
421
/* Check for options. */
424
int c = getopt_long (num_opts, argv, "r:s:n:c:d:hVv", options, 0);
437
skip = grub_strtoul (optarg, &p, 0);
439
skip <<= GRUB_DISK_SECTOR_BITS;
443
leng = grub_strtoul (optarg, &p, 0);
445
leng <<= GRUB_DISK_SECTOR_BITS;
449
num_disks = grub_strtoul (optarg, NULL, 0);
452
fprintf (stderr, "Invalid disk count.\n");
466
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
480
if (optind + num_disks - 1 >= argc)
482
fprintf (stderr, "Not enough pathname.\n");
486
image_index = optind;
487
for (i = 0; i < num_disks; i++, optind++)
488
if (argv[optind][0] != '/')
490
fprintf (stderr, "Must use absolute path.\n");
499
if (!grub_strcmp (argv[optind], "ls"))
434
return ARGP_ERR_UNKNOWN;
437
if (args_count < num_disks)
441
fprintf (stderr, "%s", _("Must use absolute path.\n"));
445
images = xmalloc (num_disks * sizeof (images[0]));
446
images[args_count] = xstrdup (arg);
451
if (args_count == num_disks)
453
if (!grub_strcmp (arg, "ls"))
503
else if (!grub_strcmp (argv[optind], "cp"))
457
else if (!grub_strcmp (arg, "cp"))
508
else if (!grub_strcmp (argv[optind], "cmp"))
462
else if (!grub_strcmp (arg, "cmp"))
513
else if (!grub_strcmp (argv[optind], "hex"))
467
else if (!grub_strcmp (arg, "hex"))
518
else if (!grub_strcmp (argv[optind], "crc"))
472
else if (!grub_strcmp (arg, "crc"))
523
else if (!grub_strcmp (argv[optind], "blocklist"))
477
else if (!grub_strcmp (arg, "blocklist"))
525
479
cmd = CMD_BLOCKLIST;
530
fprintf (stderr, "Invalid command %s.\n", argv[optind]);
534
if (optind + 1 + nparm > argc)
536
fprintf (stderr, "Invalid parameter for command %s.\n",
545
fprintf (stderr, "No command is specified.\n");
484
fprintf (stderr, _("Invalid command %s.\n"), arg);
491
args[args_count - 1 - num_disks] = xstrdup (arg);
497
options, argp_parser, N_("IMAGE_PATH COMMANDS"),
498
N_("Debug tool for filesystem driver."),
503
main (int argc, char *argv[])
505
char *default_root, *alloc_root;
507
set_program_name (argv[0]);
509
grub_util_init_nls ();
511
args = xmalloc (argc * sizeof (args[0]));
513
argp_parse (&argp, argc, argv, 0, 0, 0);
549
515
/* Initialize all modules. */
550
516
grub_init_all ();