All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>,
	 Thomas Schmitt <scdbackup@gmx.net>
Subject: Re: About the CLI of both grub-mkrescue versions
Date: Fri, 28 Nov 2014 21:41:03 +0200	[thread overview]
Message-ID: <5478CFCF.9010601@gmail.com> (raw)
In-Reply-To: <1495546211684188288@scdbackup.webframe.org>

[-- Attachment #1: Type: text/plain, Size: 9104 bytes --]

On 01.10.2014 10:25, Thomas Schmitt wrote:
> Hi,
> 
> to substantiate my proposal of renaming young grub-mkrescue.c to
> grub-mkiso.c and to add a built-in emulation of grub-mkrescue(.in),
> here the necessary code which i tested standalone with valgrind.
> 
> The decision which parser to use would be made in main():
> 
I think that old parser is better. The only reason the change happened
is that it's a bug that sneaked in during migration to C. It should be
fixed.
> --------------------------------------------------------------
> 
>   char *cpt;
>   ...
>   /* Get leaf name of argv[0] */
>   for (cpt = argv[0] + strlen (argv[0]) - 1; cpt >= argv[0]; cpt--)
>     if (*cpt == '/')
>       break;
>   cpt++;
>   if (strcmp (cpt, "grub-mkrescue") == 0)
>     {
>       arg_parser_mkrescue (argc, argv);
>     }
>   else
>     {
>       argp_parse (&argp, argc, argv, 0, 0, 0);
>     }
> 
> --------------------------------------------------------------
> 
> The help text is derived from grub-mkrescue.in of GRUB 2.00.
> 
> --------------------------------------------------------------
> 
> static void
> printc (char *line)
> {
>   printf ("%s\n", line);
> }
> 
> static void
> print_mkrescue_help (char *prog_name)
> {
>   printf ("%s %s %s\n", _("Usage:"), prog_name, _("[OPTION] SOURCE..."));
>   printc (_("Make GRUB CD-ROM, disk, pendrive and floppy bootable image."));
>   printc (_("-h, --help"));
>   printc (_("        print this message and exit"));
>   printc (_("-v, --version"));
>   printc (_("        print the version information and exit"));
>   printc (_("-o, --output=FILE"));
>   printc (_("        save output in FILE [required]"));
>   printc (_("--rom-directory=DIR"));
>   printc (_("        save ROM images in DIR [optional]"));
>   printc (_("--xorriso=FILE"));
>   printc (_("        use FILE as xorriso [optional]"));
>   printc (_("Not supported any more are:"));
>   printc (_("        --modules , --grub-mkimage , --override-directory"));
>   printc (_("Other arguments get forwarded to xorriso -as mkisofs"));
>   printc (_("emulation."));
>   printc ("");
>   printf ("%s %s\n", prog_name, _("generates a bootable rescue image"));
>   printc (_("with specified source files, source directories, or mkisofs"));
>   printc (_("options listed by the output of `xorriso -as mkisofs -help'"));
>   printc ("");
>   printc (_("Note: Do not use option \"--\" unless you want to submit"));
>   printc (_("      native xorriso commands instead of file paths or"));
>   printc (_("      mkisofs options. See man xorrisofs and man xorriso."));
>   printc ("");
>   printc (_("Report bugs to <bug-grub@gnu.org>."));
>   printc (_("Mail xorriso support requests to <bug-xorriso@gnu.org>."));
>   printc ("");
>   printc (_("This is program grub-mkiso emulating the option"));
>   printc (_("interpretation of legacy program grub-mkrescue."));
>   printc (_("grub-mkiso in its native mode has more advanced options."));
>   printc (_("But that mode demands to separate grub-mkiso options"));
>   printc (_("and xorriso options by a double dash \"--\", which xorriso"));
>   printc (_("will not get to see."));
> }
> 
> --------------------------------------------------------------
> 
> The parser function implements the promised options and collects
> the xorriso -as mkisofs options into the same char pointer array
> as does the existing parser in the C program.
> In particular it sets the values of these variables:
> 
> static char *rom_directory;
> static int xorriso_tail_argc;
> static int xorriso_tail_arg_alloc;
> static char **xorriso_tail_argv;
> static char *output_image;
> static char *xorriso;
> 
> --------------------------------------------------------------
> 
> static void
> arg_parser_mkrescue (int argc, char *argv[])
> {
>   int i;
> 
>   for (i = 1; i < argc; i++)
>     {
>       if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "--help") == 0)
>         {
>           print_mkrescue_help (argv[0]);
>           exit (0);
>         }
>       else if (strcmp (argv[i], "-v") == 0
>                || strcmp (argv[i], "--version") == 0)
>         {
>           printf ("%s %s %s\n", argv[0], PACKAGE_NAME, PACKAGE_VERSION);
>           exit (0);
>         }
>       else if (strcmp (argv[i], "--modules") == 0)
>         {
>           grub_util_error (_("Option --modules is not supported any more"));
>         }
>       else if (strncmp (argv[i], "--modules=", 10) == 0)
>         {
>           grub_util_error (_("Option --modules= is not supported any more"));
>         }
>       else if (strcmp (argv[i], "-o") == 0
>                || strcmp (argv[i], "--output") == 0)
>         {
>           if (i == argc - 1)
>             grub_util_error (_("option requires an argument -- `%s'"),
>                              argv[i]);
>           i++;
>           free (output_image);
>           output_image = xstrdup (argv[i]);
>         }
>       else if (strncmp (argv[i], "--output=", 9) == 0)
>         {
>           free (output_image);
>           output_image = xstrdup (argv[i] + 9);
>         }
>       else if (strcmp (argv[i], "--rom-directory") == 0)
>         {
>           if (i == argc - 1)
>             grub_util_error (_("option requires an argument -- `%s'"),
>                              argv[i]);
>           i++;
>           free (rom_directory);
>           rom_directory = xstrdup (argv[i]);
>         }
>       else if (strncmp (argv[i], "--rom-directory=", 16) == 0)
>         {
>           free (rom_directory);
>           rom_directory = xstrdup (argv[i] + 16);
>         }
>       else if (strcmp (argv[i], "--override-directory") == 0)
>         {
>           grub_util_error(
>                    _("Option --override-directory is not supported any more"));
>         }
>       else if (strncmp (argv[i], "--override-directory=", 21) == 0)
>         {
>           grub_util_error(
>                   _("Option --override-directory= is not supported any more"));
>         }
>       else if (strcmp (argv[i], "--xorriso") == 0)
>         {
>           if (i == argc - 1)
>             grub_util_error (_("option requires an argument -- `%s'"),
>                              argv[i]);
>           i++;
>           free (xorriso);
>           xorriso = xstrdup (argv[i]);
>         }
>       else if (strncmp (argv[i], "--xorriso=", 10) == 0)
>         {
>           free (xorriso);
>           xorriso = xstrdup (argv[i] + 10);
>         }
>       else
>         {
>           if (xorriso_tail_arg_alloc <= xorriso_tail_argc)
>             {
>               xorriso_tail_arg_alloc = 2 * (4 + xorriso_tail_argc);
>               xorriso_tail_argv = xrealloc (xorriso_tail_argv,
>                                       sizeof (xorriso_tail_argv[0])
>                                       * xorriso_tail_arg_alloc);
>             }
>           xorriso_tail_argv[xorriso_tail_argc++] = xstrdup (argv[i]);
>         }
>     }
> }
> 
> --------------------------------------------------------------
> 
> There remains the incompatibility that i could not find
> equivalents of the following grub-mkrescue.in features:
> 
>   --modules=MODULES
>           pre-load specified modules MODULES
>   --grub-mkimage=FILE
>           use FILE as grub-mkimage
>   --override-directory
>           "Intentionally undocumented"
> 
> --------------------------------------------------------------
> 
> The valgrind test was made with a mock-up of grub-mkiso.c
> consisting of some copied util/grub-*.c functions and a main()
> which prints the content of the variables after parsing.
> 
>   ln -s grub-mkiso grub-mkrescue
>   valgrind ./grub-mkrescue -o output.iso -J --rom-directory=./ROMDIR -P YET_ANOTHER_OS.ORG --md5 --emul-toc ./my_os_payload --xorriso="$HOME"/xorriso-1.3.8/xorriso/xorriso
> 
> yielded:
> 
>   output_image=           'output.iso'
>   rom_directory=          './ROMDIR'
>   xorriso=                '/home/thomas/xorriso-1.3.8/xorriso/xorriso'
>   xorriso_tail_arg_alloc= 8
>   xorriso_tail_argc=      6
>   xorriso_tail_argv[ 0]= '-J'
>   xorriso_tail_argv[ 1]= '-P'
>   xorriso_tail_argv[ 2]= 'YET_ANOTHER_OS.ORG'
>   xorriso_tail_argv[ 3]= '--md5'
>   xorriso_tail_argv[ 4]= '--emul-toc'
>   xorriso_tail_argv[ 5]= './my_os_payload'
>   ==9810== 
>   ==9810== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 1)
>   ...
>   ==9810== LEAK SUMMARY:
>   ==9810==    definitely lost: 0 bytes in 0 blocks.
>   ==9810==      possibly lost: 0 bytes in 0 blocks.
>   ==9810==    still reachable: 185 bytes in 10 blocks.
>   ==9810==         suppressed: 0 bytes in 0 blocks.
> 
> The memory leaks are caused by allocated storage of global
> variables.
> 
> 
> Have a nice day :)
> 
> Thomas
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

  parent reply	other threads:[~2014-11-28 20:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-23  8:12 About the CLI of both grub-mkrescue versions Thomas Schmitt
2014-09-28 16:17 ` Andrei Borzenkov
2014-09-28 16:52   ` Thomas Schmitt
2014-09-28 18:28     ` Thomas Schmitt
2014-09-29  5:04       ` Andrei Borzenkov
2014-09-29  7:07         ` Thomas Schmitt
2014-10-01  7:25           ` Thomas Schmitt
2014-10-10 18:19             ` Andrei Borzenkov
2014-10-10 20:29               ` Thomas Schmitt
2014-11-28 19:41             ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2014-11-29  5:38               ` Andrei Borzenkov
2014-11-29 10:55                 ` Thomas Schmitt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5478CFCF.9010601@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    --cc=scdbackup@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.