~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to util/grub-fstest.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include <config.h>
21
21
#include <grub/types.h>
 
22
#include <grub/emu/misc.h>
22
23
#include <grub/util/misc.h>
23
24
#include <grub/misc.h>
24
25
#include <grub/device.h>
29
30
#include <grub/term.h>
30
31
#include <grub/mm.h>
31
32
#include <grub/lib/hexdump.h>
32
 
#include <grub/lib/crc.h>
 
33
#include <grub/crypto.h>
33
34
#include <grub/command.h>
34
35
#include <grub/i18n.h>
35
36
 
36
 
#include <grub_fstest_init.h>
37
 
 
38
37
#include <stdio.h>
39
38
#include <unistd.h>
40
39
#include <string.h>
41
40
#include <stdlib.h>
42
 
#include <getopt.h>
43
41
 
44
42
#include "progname.h"
45
 
 
46
 
void 
47
 
grub_xputs_real (const char *str)
48
 
{
49
 
  fputs (str, stdout);
50
 
}
51
 
 
52
 
void (*grub_xputs) (const char *str) = grub_xputs_real;
53
 
 
54
 
int
55
 
grub_getkey (void)
56
 
{
57
 
  return -1;
58
 
}
59
 
 
60
 
void
61
 
grub_refresh (void)
62
 
{
63
 
  fflush (stdout);
64
 
}
 
43
#include "argp.h"
65
44
 
66
45
static grub_err_t
67
46
execute_command (char *name, int n, char **args)
70
49
 
71
50
  cmd = grub_command_find (name);
72
51
  if (! cmd)
73
 
    grub_util_error ("can\'t find command %s", name);
 
52
    grub_util_error (_("can\'t find command %s"), name);
74
53
 
75
54
  return (cmd->func) (cmd, n, args);
76
55
}
99
78
 
100
79
      dev = grub_device_open (0);
101
80
      if ((! dev) || (! dev->disk))
102
 
        grub_util_error ("can\'t open device");
 
81
        grub_util_error (_("can\'t open device"));
103
82
 
104
83
      grub_util_info ("total sectors : %lld",
105
84
                      (unsigned long long) dev->disk->total_sectors);
114
93
          len = (leng > BUF_SIZE) ? BUF_SIZE : leng;
115
94
 
116
95
          if (grub_disk_read (dev->disk, 0, skip, len, buf))
117
 
            grub_util_error ("disk read fails at offset %lld, length %d",
 
96
            grub_util_error (_("disk read fails at offset %lld, length %d"),
118
97
                             skip, len);
119
98
 
120
99
          if (hook (skip, buf, len))
128
107
      return;
129
108
    }
130
109
 
 
110
  grub_file_filter_disable_compression ();
131
111
  file = grub_file_open (pathname);
132
112
  if (!file)
133
113
    {
134
 
      grub_util_error ("cannot open file %s", pathname);
 
114
      grub_util_error (_("cannot open file %s"), pathname);
135
115
      return;
136
116
    }
137
117
 
139
119
 
140
120
  if (skip > file->size)
141
121
    {
142
 
      grub_util_error ("invalid skip value %lld", (unsigned long long) skip);
 
122
      grub_util_error (_("invalid skip value %lld"), (unsigned long long) skip);
143
123
      return;
144
124
    }
145
125
 
157
137
      sz = grub_file_read (file, buf, (len > BUF_SIZE) ? BUF_SIZE : len);
158
138
      if (sz < 0)
159
139
        {
160
 
          grub_util_error ("read error at offset %llu", ofs);
 
140
          grub_util_error (_("read error at offset %llu: %s"), ofs,
 
141
                           grub_errmsg);
161
142
          break;
162
143
        }
163
144
 
183
164
 
184
165
    if ((int) fwrite (buf, 1, len, ff) != len)
185
166
      {
186
 
        grub_util_error ("write error");
 
167
        grub_util_error (_("write error"));
187
168
        return 1;
188
169
      }
189
170
 
193
174
  ff = fopen (dest, "wb");
194
175
  if (ff == NULL)
195
176
    {
196
 
      grub_util_error ("open error");
 
177
      grub_util_error (_("open error"));
197
178
      return;
198
179
    }
199
180
  read_file (src, cp_hook);
211
192
  {
212
193
    if ((int) fread (buf_1, 1, len, ff) != len)
213
194
      {
214
 
        grub_util_error ("read error at offset %llu", ofs);
 
195
        grub_util_error (_("read error at offset %llu: %s"), ofs, grub_errmsg);
215
196
        return 1;
216
197
      }
217
198
 
222
203
        for (i = 0; i < len; i++, ofs++)
223
204
          if (buf_1[i] != buf[i])
224
205
            {
225
 
              grub_util_error ("compare fail at offset %llu", ofs);
 
206
              grub_util_error (_("compare fail at offset %llu"), ofs);
226
207
              return 1;
227
208
            }
228
209
      }
232
213
  ff = fopen (dest, "rb");
233
214
  if (ff == NULL)
234
215
    {
235
 
      grub_util_error ("open error");
 
216
      grub_util_error (_("open error"));
236
217
      return;
237
218
    }
238
219
 
239
220
  if ((skip) && (fseeko (ff, skip, SEEK_SET)))
240
 
    grub_util_error ("seek error");
 
221
    grub_util_error (_("seek error"));
241
222
 
242
223
  read_file (src, cmp_hook);
243
224
  fclose (ff);
259
240
static void
260
241
cmd_crc (char *pathname)
261
242
{
262
 
  grub_uint32_t crc = 0;
 
243
  grub_uint8_t crc32_context[GRUB_MD_CRC32->contextsize];
 
244
  GRUB_MD_CRC32->init(crc32_context);
263
245
 
264
246
  auto int crc_hook (grub_off_t ofs, char *buf, int len);
265
247
  int crc_hook (grub_off_t ofs, char *buf, int len)
266
248
  {
267
249
    (void) ofs;
268
250
 
269
 
    crc = grub_getcrc32 (crc, buf, len);
 
251
    GRUB_MD_CRC32->write(crc32_context, buf, len);
270
252
    return 0;
271
253
  }
272
254
 
273
255
  read_file (pathname, crc_hook);
274
 
  printf ("%08x\n", crc);
 
256
  GRUB_MD_CRC32->final(crc32_context);
 
257
  printf ("%08x\n",
 
258
      grub_be_to_cpu32(*(grub_uint32_t*)GRUB_MD_CRC32->read(crc32_context)));
275
259
}
276
260
 
 
261
static char *root = NULL;
 
262
static int args_count = 0;
 
263
static int nparm = 0;
 
264
static int num_disks = 1;
 
265
static char **images = NULL;
 
266
static int cmd = 0;
 
267
static char *debug_str = NULL;
 
268
static char **args = NULL;
 
269
 
277
270
static void
278
 
fstest (char **images, int num_disks, int cmd, int n, char **args)
 
271
fstest (int n, char **args)
279
272
{
280
273
  char *host_file;
281
274
  char *loop_name;
282
 
  char *argv[3];
283
275
  int i;
284
276
 
285
 
  argv[0] = "-p";
286
 
 
287
277
  for (i = 0; i < num_disks; i++)
288
278
    {
 
279
      char *argv[2];
289
280
      loop_name = grub_xasprintf ("loop%d", i);
290
281
      if (!loop_name)
291
282
        grub_util_error (grub_errmsg);
294
285
      if (!host_file)
295
286
        grub_util_error (grub_errmsg);
296
287
 
297
 
      argv[1] = loop_name;
298
 
      argv[2] = host_file;
 
288
      argv[0] = loop_name;
 
289
      argv[1] = host_file;
299
290
 
300
 
      if (execute_command ("loopback", 3, argv))
301
 
        grub_util_error ("loopback command fails");
 
291
      if (execute_command ("loopback", 2, argv))
 
292
        grub_util_error (_("loopback command fails"));
302
293
 
303
294
      grub_free (loop_name);
304
295
      grub_free (host_file);
305
296
    }
306
297
 
307
298
  grub_lvm_fini ();
308
 
  grub_mdraid_fini ();
 
299
  grub_mdraid09_fini ();
 
300
  grub_mdraid1x_fini ();
309
301
  grub_raid_fini ();
310
302
  grub_raid_init ();
311
 
  grub_mdraid_init ();
 
303
  grub_mdraid09_init ();
 
304
  grub_mdraid1x_init ();
312
305
  grub_lvm_init ();
313
306
 
314
307
  switch (cmd)
332
325
      execute_command ("blocklist", n, args);
333
326
      grub_printf ("\n");
334
327
    }
335
 
 
336
 
  argv[0] = "-d";
337
 
 
 
328
    
338
329
  for (i = 0; i < num_disks; i++)
339
330
    {
 
331
      char *argv[2];
 
332
 
340
333
      loop_name = grub_xasprintf ("loop%d", i);
341
334
      if (!loop_name)
342
335
        grub_util_error (grub_errmsg);
343
336
 
 
337
      argv[0] = "-d";      
344
338
      argv[1] = loop_name;
345
339
 
346
340
      execute_command ("loopback", 2, argv);
349
343
    }
350
344
}
351
345
 
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'},
361
 
  {0, 0, 0, 0}
 
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},
 
354
  
 
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},
 
361
  {0, 0, 0, 0, 0, 0}
362
362
};
363
363
 
 
364
/* Print the version information.  */
364
365
static void
365
 
usage (int status)
 
366
print_version (FILE *stream, struct argp_state *state)
366
367
{
367
 
  if (status)
368
 
    fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
369
 
  else
370
 
    printf ("\
371
 
Usage: %s [OPTION]... IMAGE_PATH COMMANDS\n\
372
 
\n\
373
 
Debug tool for filesystem driver.\n\
374
 
\nCommands:\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\
381
 
\nOptions:\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\
390
 
\n\
391
 
Report bugs to <%s>.\n", program_name, PACKAGE_BUGREPORT);
392
 
 
393
 
  exit (status);
 
368
  fprintf (stream, "%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
394
369
}
 
370
void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
395
371
 
396
 
int
397
 
main (int argc, char *argv[])
 
372
error_t 
 
373
argp_parser (int key, char *arg, struct argp_state *state)
398
374
{
399
 
  char *debug_str = NULL, *root = NULL, *default_root, *alloc_root;
400
 
  int i, cmd, num_opts, image_index, num_disks = 1;
401
 
 
402
 
  set_program_name (argv[0]);
403
 
 
404
 
  grub_util_init_nls ();
405
 
 
406
 
  /* Find the first non option entry.  */
407
 
  for (num_opts = 1; num_opts < argc; num_opts++)
408
 
    if (argv[num_opts][0] == '-')
409
 
      {
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')))
416
 
            num_opts++;
417
 
      }
418
 
    else
 
375
  char *p;
 
376
 
 
377
  switch (key)
 
378
    {
 
379
    case 'r':
 
380
      root = arg;
 
381
      return 0;
 
382
 
 
383
    case 's':
 
384
      skip = grub_strtoul (arg, &p, 0);
 
385
      if (*p == 's')
 
386
        skip <<= GRUB_DISK_SECTOR_BITS;
 
387
      return 0;
 
388
 
 
389
    case 'n':
 
390
      leng = grub_strtoul (arg, &p, 0);
 
391
      if (*p == 's')
 
392
        leng <<= GRUB_DISK_SECTOR_BITS;
 
393
      return 0;
 
394
 
 
395
    case 'c':
 
396
      num_disks = grub_strtoul (arg, NULL, 0);
 
397
      if (num_disks < 1)
 
398
        {
 
399
          fprintf (stderr, "%s", _("Invalid disk count.\n"));
 
400
          argp_usage (state);
 
401
        }
 
402
      if (args_count != 0)
 
403
        {
 
404
          fprintf (stderr, "%s", _("Disk count must precede disks list.\n"));
 
405
          argp_usage (state);
 
406
        }
 
407
      return 0;
 
408
 
 
409
    case 'd':
 
410
      debug_str = arg;
 
411
      return 0;
 
412
 
 
413
    case 'v':
 
414
      verbosity++;
 
415
      return 0;
 
416
 
 
417
    case ARGP_KEY_END:
 
418
      if (args_count < num_disks)
 
419
        {
 
420
          fprintf (stderr, "%s", _("No command is specified.\n"));
 
421
          argp_usage (state);
 
422
        }
 
423
      if (args_count - 1 - num_disks < nparm)
 
424
        {
 
425
          fprintf (stderr, "%s", _("Not enough parameters to command.\n"));
 
426
          argp_usage (state);
 
427
        }
 
428
      return 0;
 
429
 
 
430
    case ARGP_KEY_ARG:
419
431
      break;
420
432
 
421
 
  /* Check for options.  */
422
 
  while (1)
423
 
    {
424
 
      int c = getopt_long (num_opts, argv, "r:s:n:c:d:hVv", options, 0);
425
 
      char *p;
426
 
 
427
 
      if (c == -1)
428
 
        break;
429
 
      else
430
 
        switch (c)
431
 
          {
432
 
          case 'r':
433
 
            root = optarg;
434
 
            break;
435
 
 
436
 
          case 's':
437
 
            skip = grub_strtoul (optarg, &p, 0);
438
 
            if (*p == 's')
439
 
              skip <<= GRUB_DISK_SECTOR_BITS;
440
 
            break;
441
 
 
442
 
          case 'n':
443
 
            leng = grub_strtoul (optarg, &p, 0);
444
 
            if (*p == 's')
445
 
              leng <<= GRUB_DISK_SECTOR_BITS;
446
 
            break;
447
 
 
448
 
          case 'c':
449
 
            num_disks = grub_strtoul (optarg, NULL, 0);
450
 
            if (num_disks < 1)
451
 
              {
452
 
                fprintf (stderr, "Invalid disk count.\n");
453
 
                usage (1);
454
 
              }
455
 
            break;
456
 
 
457
 
          case 'd':
458
 
            debug_str = optarg;
459
 
            break;
460
 
 
461
 
          case 'h':
462
 
            usage (0);
463
 
            break;
464
 
 
465
 
          case 'V':
466
 
            printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
467
 
            return 0;
468
 
 
469
 
          case 'v':
470
 
            verbosity++;
471
 
            break;
472
 
 
473
 
          default:
474
 
            usage (1);
475
 
            break;
476
 
          }
477
 
    }
478
 
 
479
 
  /* Obtain PATH.  */
480
 
  if (optind + num_disks - 1 >= argc)
481
 
    {
482
 
      fprintf (stderr, "Not enough pathname.\n");
483
 
      usage (1);
484
 
    }
485
 
 
486
 
  image_index = optind;
487
 
  for (i = 0; i < num_disks; i++, optind++)
488
 
    if (argv[optind][0] != '/')
489
 
      {
490
 
        fprintf (stderr, "Must use absolute path.\n");
491
 
        usage (1);
492
 
      }
493
 
 
494
 
  cmd = 0;
495
 
  if (optind < argc)
496
 
    {
497
 
      int nparm = 0;
498
 
 
499
 
      if (!grub_strcmp (argv[optind], "ls"))
 
433
    default:
 
434
      return ARGP_ERR_UNKNOWN;
 
435
    }
 
436
 
 
437
  if (args_count < num_disks)
 
438
    {
 
439
      if (arg[0] != '/')
 
440
        {
 
441
          fprintf (stderr, "%s", _("Must use absolute path.\n"));
 
442
          argp_usage (state);
 
443
        }
 
444
      if (args_count == 0)
 
445
        images = xmalloc (num_disks * sizeof (images[0]));
 
446
      images[args_count] = xstrdup (arg);
 
447
      args_count++;
 
448
      return 0;
 
449
    }
 
450
 
 
451
  if (args_count == num_disks)
 
452
    {
 
453
      if (!grub_strcmp (arg, "ls"))
500
454
        {
501
455
          cmd = CMD_LS;
502
456
        }
503
 
      else if (!grub_strcmp (argv[optind], "cp"))
 
457
      else if (!grub_strcmp (arg, "cp"))
504
458
        {
505
459
          cmd = CMD_CP;
506
460
          nparm = 2;
507
461
        }
508
 
      else if (!grub_strcmp (argv[optind], "cmp"))
 
462
      else if (!grub_strcmp (arg, "cmp"))
509
463
        {
510
464
          cmd = CMD_CMP;
511
465
          nparm = 2;
512
466
        }
513
 
      else if (!grub_strcmp (argv[optind], "hex"))
 
467
      else if (!grub_strcmp (arg, "hex"))
514
468
        {
515
469
          cmd = CMD_HEX;
516
470
          nparm = 1;
517
471
        }
518
 
      else if (!grub_strcmp (argv[optind], "crc"))
 
472
      else if (!grub_strcmp (arg, "crc"))
519
473
        {
520
474
          cmd = CMD_CRC;
521
475
          nparm = 1;
522
476
        }
523
 
      else if (!grub_strcmp (argv[optind], "blocklist"))
 
477
      else if (!grub_strcmp (arg, "blocklist"))
524
478
        {
525
479
          cmd = CMD_BLOCKLIST;
526
480
          nparm = 1;
527
481
        }
528
482
      else
529
483
        {
530
 
          fprintf (stderr, "Invalid command %s.\n", argv[optind]);
531
 
          usage (1);
532
 
        }
533
 
 
534
 
      if (optind + 1 + nparm > argc)
535
 
        {
536
 
          fprintf (stderr, "Invalid parameter for command %s.\n",
537
 
                   argv[optind]);
538
 
          usage (1);
539
 
        }
540
 
 
541
 
      optind++;
542
 
    }
543
 
  else
544
 
    {
545
 
      fprintf (stderr, "No command is specified.\n");
546
 
      usage (1);
547
 
    }
 
484
          fprintf (stderr, _("Invalid command %s.\n"), arg);
 
485
          argp_usage (state);
 
486
        }
 
487
      args_count++;
 
488
      return 0;
 
489
    }
 
490
 
 
491
  args[args_count - 1 - num_disks] = xstrdup (arg);
 
492
  args_count++;
 
493
  return 0;
 
494
}
 
495
 
 
496
struct argp argp = {
 
497
  options, argp_parser, N_("IMAGE_PATH COMMANDS"),
 
498
  N_("Debug tool for filesystem driver."), 
 
499
  NULL, NULL, NULL
 
500
};
 
501
 
 
502
int
 
503
main (int argc, char *argv[])
 
504
{
 
505
  char *default_root, *alloc_root;
 
506
 
 
507
  set_program_name (argv[0]);
 
508
 
 
509
  grub_util_init_nls ();
 
510
 
 
511
  args = xmalloc (argc * sizeof (args[0]));
 
512
 
 
513
  argp_parse (&argp, argc, argv, 0, 0, 0);
548
514
 
549
515
  /* Initialize all modules. */
550
516
  grub_init_all ();
573
539
    free (alloc_root);
574
540
 
575
541
  /* Do it.  */
576
 
  fstest (argv + image_index, num_disks, cmd, argc - optind, argv + optind);
 
542
  fstest (args_count - 1 - num_disks, args);
577
543
 
578
544
  /* Free resources.  */
579
545
  grub_fini_all ();