331
325
execute_command ("blocklist", n, args);
332
326
grub_printf ("\n");
337
329
for (i = 0; i < num_disks; i++)
339
grub_free (loop_name);
340
333
loop_name = grub_xasprintf ("loop%d", i);
343
grub_free (host_file);
344
grub_util_error (grub_errmsg);
335
grub_util_error (grub_errmsg);
347
340
execute_command ("loopback", 2, argv);
342
grub_free (loop_name);
350
grub_free (loop_name);
351
grub_free (host_file);
354
static struct option options[] = {
355
{"root", required_argument, 0, 'r'},
356
{"skip", required_argument, 0, 's'},
357
{"length", required_argument, 0, 'n'},
358
{"diskcount", required_argument, 0, 'c'},
359
{"debug", required_argument, 0, 'd'},
360
{"help", no_argument, 0, 'h'},
361
{"version", no_argument, 0, 'V'},
362
{"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)
370
fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
373
Usage: %s [OPTION]... IMAGE_PATH COMMANDS\n\
375
Debug tool for filesystem driver.\n\
377
ls PATH list files in PATH\n\
378
cp FILE LOCAL copy FILE to local file LOCAL\n\
379
cmp FILE LOCAL compare FILE with local file LOCAL\n\
380
hex FILE Hex dump FILE\n\
381
crc FILE Get crc32 checksum of FILE\n\
382
blocklist FILE display blocklist of FILE\n\
384
-r, --root=DEVICE_NAME set root device\n\
385
-s, --skip=N skip N bytes from output file\n\
386
-n, --length=N handle N bytes in output file\n\
387
-c, --diskcount=N N input files\n\
388
-d, --debug=S Set debug environment variable\n\
389
-h, --help display this message and exit\n\
390
-V, --version print version information and exit\n\
391
-v, --verbose print verbose messages\n\
393
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;
399
main (int argc, char *argv[])
373
argp_parser (int key, char *arg, struct argp_state *state)
401
char *debug_str = NULL, *root = NULL, *default_root, *alloc_root;
402
int i, cmd, num_opts, image_index, num_disks = 1;
404
set_program_name (argv[0]);
406
grub_util_init_nls ();
408
/* Find the first non option entry. */
409
for (num_opts = 1; num_opts < argc; num_opts++)
410
if (argv[num_opts][0] == '-')
412
if ((argv[num_opts][2] == 0) && (num_opts < argc - 1) &&
413
((argv[num_opts][1] == 'r') ||
414
(argv[num_opts][1] == 's') ||
415
(argv[num_opts][1] == 'n') ||
416
(argv[num_opts][1] == 'c') ||
417
(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"));
423
/* Check for options. */
426
int c = getopt_long (num_opts, argv, "r:s:n:c:d:hVv", options, 0);
439
skip = grub_strtoul (optarg, &p, 0);
441
skip <<= GRUB_DISK_SECTOR_BITS;
445
leng = grub_strtoul (optarg, &p, 0);
447
leng <<= GRUB_DISK_SECTOR_BITS;
451
num_disks = grub_strtoul (optarg, NULL, 0);
454
fprintf (stderr, "Invalid disk count.\n");
468
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
482
if (optind + num_disks - 1 >= argc)
484
fprintf (stderr, "Not enough pathname.\n");
488
image_index = optind;
489
for (i = 0; i < num_disks; i++, optind++)
490
if (argv[optind][0] != '/')
492
fprintf (stderr, "Must use absolute path.\n");
501
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"))
505
else if (!grub_strcmp (argv[optind], "cp"))
457
else if (!grub_strcmp (arg, "cp"))
510
else if (!grub_strcmp (argv[optind], "cmp"))
462
else if (!grub_strcmp (arg, "cmp"))
515
else if (!grub_strcmp (argv[optind], "hex"))
467
else if (!grub_strcmp (arg, "hex"))
520
else if (!grub_strcmp (argv[optind], "crc"))
472
else if (!grub_strcmp (arg, "crc"))
525
else if (!grub_strcmp (argv[optind], "blocklist"))
477
else if (!grub_strcmp (arg, "blocklist"))
527
479
cmd = CMD_BLOCKLIST;
532
fprintf (stderr, "Invalid command %s.\n", argv[optind]);
536
if (optind + 1 + nparm > argc)
538
fprintf (stderr, "Invalid parameter for command %s.\n",
547
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);
551
515
/* Initialize all modules. */
552
516
grub_init_all ();