From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Lulza-0000jl-GS for mharc-grub-devel@gnu.org; Fri, 17 Apr 2009 07:12:22 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LulzY-0000iv-Ly for grub-devel@gnu.org; Fri, 17 Apr 2009 07:12:20 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LulzU-0000f3-Fz for grub-devel@gnu.org; Fri, 17 Apr 2009 07:12:20 -0400 Received: from [199.232.76.173] (port=41795 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LulzU-0000es-92 for grub-devel@gnu.org; Fri, 17 Apr 2009 07:12:16 -0400 Received: from fg-out-1718.google.com ([72.14.220.159]:45411) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LulzT-0005GW-Jw for grub-devel@gnu.org; Fri, 17 Apr 2009 07:12:16 -0400 Received: by fg-out-1718.google.com with SMTP id 19so267369fgg.7 for ; Fri, 17 Apr 2009 04:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type; bh=1teAUNzJyK5zE4vhRLO5YBakOnGAl5qR69YYs0U7mbE=; b=hNI7Zx67mfUjYX9Y+xClnzpwyciU0J5JEKwyKR/6YQ9JOAX8rYCEb9bLfrkIu/6rQR cIcgw0Oa8oLPNASMH1EaDpFzi+zUGj76CjYePPRiyA3W+C/+PTr9Qe2B++s+Dzwnqlzu gO+dTVV4bNu7t90D6YamzeYODlNOTuHNfRjrw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; b=FdNizMOnpdi6oVDzJ3ZGGdnhF3SsJoCLf1vfs86EvCH0N+OzxIc6CMHNCAG/ZfWVn0 OVCdjRa0/EYDTgJcYOb3AyfxK6ozZqzroQSTvmCnpMcxLD9ltpstos0CRMze1poCO98Z FIYNCT0G0QfGREISG6ghUy4bKX3X1zryEheTU= Received: by 10.86.86.2 with SMTP id j2mr1914151fgb.74.1239966734681; Fri, 17 Apr 2009 04:12:14 -0700 (PDT) Received: from ?192.168.1.100? (147-69.203-62.cust.bluewin.ch [62.203.69.147]) by mx.google.com with ESMTPS id 4sm802427fge.13.2009.04.17.04.12.12 (version=SSLv3 cipher=RC4-MD5); Fri, 17 Apr 2009 04:12:13 -0700 (PDT) Message-ID: <49E8640B.50407@gmail.com> Date: Fri, 17 Apr 2009 13:12:11 +0200 From: phcoder User-Agent: Thunderbird 2.0.0.21 (X11/20090409) MIME-Version: 1.0 To: The development of GRUB 2 References: <49AEEF72.5050000@gmail.com> <49C3EF85.5080908@gmail.com> <49D726DF.4010601@gmail.com> <200904052348.15540.okuji@enbug.org> <49D9D0E6.5090706@gmail.com> <1239033183.8986.30.camel@mj> <49DA263E.7060803@gmail.com> <1239034857.8986.36.camel@mj> <49DA2CEF.3050404@gmail.com> <1239035609.8986.42.camel@mj> <49DC6FCC.2020909@gmail.com> <1239222271.2948.22.camel@mj> In-Reply-To: <1239222271.2948.22.camel@mj> Content-Type: multipart/mixed; boundary="------------030002060200000301090504" X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: [PATCH] parttool X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Apr 2009 11:12:20 -0000 This is a multi-part message in MIME format. --------------030002060200000301090504 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Thank you for the testing > Please remove one space after "list". done > > I've tested the command quickly. A few notes. > > We need a command to list the partition table, as "ls" doesn't show the > partition types. The easiest way is to add an info string to partmap structure. This, however pollutes the partmap modules. The question is whether this info is useful enough to put it in partmap modules. I think no. I will code an additional command for this > > It would be nice to have some feedback, e.g. > parttool (hd0,1) hidden+ > Setting partition type to 0x92 > > "hidden" should work like "hidden+". Done > The "hidden" attribute doesn't apply to all partition types. There is > no such thing as a hidden Linux swap partition. > I know, however I don't have an exhaustive list when this feature is useful, so I let the user to always use this feature and rely on his/her good sense > "parttool PARTITION" should work like "parttool PARTITION help" or maybe > it should give information about the partition. > Done > Modules for the partition (like "pcpart") should be loaded automatically > for any commands including "help". If that module is missing and cannot > be loaded, all commands should report is, not just "help". > Done -- Regards Vladimir 'phcoder' Serbinenko --------------030002060200000301090504 Content-Type: text/x-diff; name="parttoolimp.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="parttoolimp.diff" diff --git a/ChangeLog b/ChangeLog index 0c50854..60aa9e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2009-04-17 Vladimir Serbinenko + + Parttool autoloading and improvements + + * Makefile.in (pkglib_DATA): add parttool.lst + (parttool.lst): new target + * genmk.rb: generate parttool-* + (CLEANFILES): add #{parttool} + (PARTTOOLFILES): new variable + * genparttoollist.sh: new file + * parttool/pcpart.c (grub_pcpart_boot): more feedback + (grub_pcpart_type): likewise + * commands/parttool.c (helpmsg): new variable + (grub_cmd_parttool): output help if not enough arguments are supplied + autoload modules + (GRUB_MOD_INIT(parttool)): use helpmsg + 2009-04-16 Bean * commands/efi/loadbios.c (grub_cmd_fakebios): Add missing return diff --git a/Makefile.in b/Makefile.in index b24ee2e..f73192e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -139,7 +139,7 @@ include $(srcdir)/conf/$(target_cpu)-$(platform).mk ### General targets. CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA) -pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst handler.lst +pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep.awk cat $(DEFSYMFILES) /dev/null \ | $(AWK) -f $(srcdir)/genmoddep.awk $(UNDSYMFILES) > $@ \ @@ -157,6 +157,9 @@ partmap.lst: $(PARTMAPFILES) handler.lst: $(HANDLERFILES) cat $^ /dev/null | sort > $@ +parttool.lst: $(PARTTOOLFILES) + cat $^ /dev/null | sort | uniq > $@ + ifeq (, $(UNIFONT_BDF)) else diff --git a/commands/parttool.c b/commands/parttool.c index 6eec13b..b09a2ba 100644 --- a/commands/parttool.c +++ b/commands/parttool.c @@ -33,6 +33,10 @@ static struct grub_parttool *parts = 0; static int curhandle = 0; static grub_dl_t mymod; +static char helpmsg[] = + "perform COMMANDS on partition.\n" + "Use \"parttool PARTITION help\" for the list " + "of available commands"; int grub_parttool_register(const char *part_name, @@ -101,8 +105,53 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), int i, j; grub_err_t err = GRUB_ERR_NONE; - if (argc < 2) - return grub_error (GRUB_ERR_BAD_ARGUMENT, "too few arguments"); + auto grub_err_t show_help (void); + grub_err_t show_help (void) + { + int found = 0; + for (cur = parts; cur; cur = cur->next) + if (grub_strcmp (dev->disk->partition->partmap->name, cur->name) == 0) + { + struct grub_parttool_argdesc *curarg; + found = 1; + for (curarg = cur->args; curarg->name; curarg++) + { + int spacing = 20; + + spacing -= grub_strlen (curarg->name); + grub_printf ("%s", curarg->name); + + switch (curarg->type) + { + case GRUB_PARTTOOL_ARG_BOOL: + grub_printf ("+/-"); + spacing -= 3; + break; + + case GRUB_PARTTOOL_ARG_VAL: + grub_printf ("=VAL"); + spacing -= 4; + break; + + case GRUB_PARTTOOL_ARG_END: + break; + } + while (spacing-- > 0) + grub_printf (" "); + grub_printf ("%s\n", curarg->desc); + } + } + if (! found) + grub_printf ("Sorry no parttool is available for %s\n", + dev->disk->partition->partmap->name); + return GRUB_ERR_NONE; + } + + if (argc < 1) + { + grub_printf ("%s\n", helpmsg); + return grub_error (GRUB_ERR_BAD_ARGUMENT, "too few arguments"); + } if (args[0][0] == '(' && args[0][grub_strlen (args[0]) - 1] == ')') { @@ -128,50 +177,77 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a partition"); } - parsed = (int *) grub_malloc (argc * sizeof (int)); - grub_memset (parsed, 0, argc * sizeof (int)); - - for (i = 1; i < argc; i++) - if (!grub_strcmp (args[i], "help")) + /* Load modules. */ +#ifndef GRUB_UTIL + { + const char *prefix; + prefix = grub_env_get ("prefix"); + if (prefix) { - int found = 0; - for (cur = parts; cur; cur = cur->next) - if (! grub_strcmp (dev->disk->partition->partmap->name, cur->name)) - { - struct grub_parttool_argdesc *curarg; - found = 1; - for (curarg = cur->args; curarg->name; curarg++) - { - int spacing = 20; - - spacing -= grub_strlen (curarg->name); - grub_printf ("%s", curarg->name); + char *filename; - switch (curarg->type) - { - case GRUB_PARTTOOL_ARG_BOOL: - grub_printf ("+/-"); - spacing -= 3; - break; + filename = grub_malloc (grub_strlen (prefix) + sizeof ("/parttool.lst")); + if (filename) + { + grub_file_t file; + + grub_sprintf (filename, "%s/parttool.lst", prefix); + file = grub_file_open (filename); + if (file) + { + char *buf = 0; + for (;; grub_free(buf)) + { + char *p, *name; - case GRUB_PARTTOOL_ARG_VAL: - grub_printf ("=VAL"); - spacing -= 4; + buf = grub_file_getline (file); + + if (! buf) break; + + name = buf; - case GRUB_PARTTOOL_ARG_END: - break; - } - while (spacing-- > 0) - grub_printf (" "); - grub_printf ("%s\n", curarg->desc); - } - } - if (! found) - grub_printf ("Sorry no parttool is available for %s\n", - dev->disk->partition->partmap->name); - return GRUB_ERR_NONE; + if (! grub_isgraph (name[0])) + continue; + + p = grub_strchr (name, ':'); + if (! p) + continue; + + *p = '\0'; + while (*++p == ' ') + ; + + if (! grub_isgraph (*p)) + continue; + + if (grub_strcmp (name, dev->disk->partition->partmap->name) + != 0) + continue; + + grub_dl_load (p); + } + + grub_file_close (file); + } + + grub_free (filename); + } } + /* Ignore errors. */ + grub_errno = GRUB_ERR_NONE; + } +#endif + + if (argc == 1) + return show_help (); + + for (i = 1; i < argc; i++) + if (grub_strcmp (args[i], "help") == 0) + return show_help (); + + parsed = (int *) grub_malloc (argc * sizeof (int)); + grub_memset (parsed, 0, argc * sizeof (int)); for (i = 1; i < argc; i++) if (! parsed[i]) @@ -179,14 +255,15 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), struct grub_parttool_argdesc *curarg; struct grub_parttool_args *pargs; for (cur = parts; cur; cur = cur->next) - if (! grub_strcmp (dev->disk->partition->partmap->name, cur->name)) + if (grub_strcmp (dev->disk->partition->partmap->name, cur->name) == 0) { for (curarg = cur->args; curarg->name; curarg++) - if (!grub_strncmp (curarg->name, args[i], - grub_strlen (curarg->name)) + if (grub_strncmp (curarg->name, args[i], + grub_strlen (curarg->name)) == 0 && ((curarg->type == GRUB_PARTTOOL_ARG_BOOL && (args[i][grub_strlen (curarg->name)] == '+' - || args[i][grub_strlen (curarg->name)] == '-')) + || args[i][grub_strlen (curarg->name)] == '-' + || args[i][grub_strlen (curarg->name)] == 0)) || (curarg->type == GRUB_PARTTOOL_ARG_VAL && args[i][grub_strlen (curarg->name)] == '='))) @@ -203,14 +280,15 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), grub_memset (pargs, 0, ptool->nargs * sizeof (struct grub_parttool_args)); for (j = i; j < argc; j++) - if (!parsed[j]) + if (! parsed[j]) { for (curarg = ptool->args; curarg->name; curarg++) - if (!grub_strncmp (curarg->name, args[i], - grub_strlen (curarg->name)) + if (grub_strncmp (curarg->name, args[i], + grub_strlen (curarg->name)) == 0 && ((curarg->type == GRUB_PARTTOOL_ARG_BOOL && (args[j][grub_strlen (curarg->name)] == '+' - || args[j][grub_strlen (curarg->name)] == '-')) + || args[j][grub_strlen (curarg->name)] == '-' + || args[j][grub_strlen (curarg->name)] == 0)) || (curarg->type == GRUB_PARTTOOL_ARG_VAL && args[j][grub_strlen (curarg->name)] == '='))) { @@ -240,6 +318,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), break; } + grub_free (parsed); grub_device_close (dev); return err; } @@ -252,9 +331,7 @@ GRUB_MOD_INIT(parttool) mymod = mod; cmd = grub_register_command ("parttool", grub_cmd_parttool, "parttool PARTITION COMMANDS", - "perform COMMANDS on partition." - " use parttool PARTITION help for the list " - " of available commands"); + helpmsg); } GRUB_MOD_FINI(parttool) diff --git a/genmk.rb b/genmk.rb index b619421..3532cd8 100644 --- a/genmk.rb +++ b/genmk.rb @@ -144,6 +144,7 @@ endif fs = 'fs-' + obj.suffix('lst') partmap = 'partmap-' + obj.suffix('lst') handler = 'handler-' + obj.suffix('lst') + parttool = 'parttool-' + obj.suffix('lst') dep = deps[i] flag = if /\.c$/ =~ src then 'CFLAGS' else 'ASFLAGS' end extra_flags = if /\.S$/ =~ src then '-DASM_FILE=1' else '' end @@ -153,9 +154,10 @@ endif $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $< -include #{dep} -CLEANFILES += #{command} #{fs} #{partmap} #{handler} +CLEANFILES += #{command} #{fs} #{partmap} #{handler} #{parttool} COMMANDFILES += #{command} FSFILES += #{fs} +PARTTOOLFILES += #{parttool} PARTMAPFILES += #{partmap} HANDLERFILES += #{handler} @@ -169,6 +171,11 @@ HANDLERFILES += #{handler} $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \ | sh $(srcdir)/genfslist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1) +#{parttool}: #{src} $(#{src}_DEPENDENCIES) genparttoollist.sh + set -e; \ + $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \ + | sh $(srcdir)/genparttoollist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1) + #{partmap}: #{src} $(#{src}_DEPENDENCIES) genpartmaplist.sh set -e; \ $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \ diff --git a/genparttoollist.sh b/genparttoollist.sh new file mode 100644 index 0000000..2424b8a --- /dev/null +++ b/genparttoollist.sh @@ -0,0 +1,19 @@ +#! /bin/sh +# +# Copyright (C) 2009 Free Software Foundation, Inc. +# +# This gensymlist.sh is free software; the author +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +# Read source code from stdin and detect command names. + +module=$1 + +grep -v "^#" | sed -n \ + -e "/grub_parttool_register *( *\"/{s/.*( *\"\([^\"]*\)\".*/\1: $module/;p;}" \ No newline at end of file diff --git a/parttool/pcpart.c b/parttool/pcpart.c index 59f24ba..a2b9452 100644 --- a/parttool/pcpart.c +++ b/parttool/pcpart.c @@ -63,9 +63,13 @@ static grub_err_t grub_pcpart_boot (const grub_device_t dev, for (i = 0; i < 4; i++) mbr.entries[i].flag = 0x0; mbr.entries[index].flag = 0x80; + grub_printf ("Partition %d is active now. \n", index); } else - mbr.entries[index].flag = 0x0; + { + mbr.entries[index].flag = 0x0; + grub_printf ("Cleared active flag on %d. \n", index); + } /* Write the MBR. */ grub_disk_write (dev->disk, 0, 0, sizeof (mbr), (char *) &mbr); @@ -123,6 +127,7 @@ static grub_err_t grub_pcpart_type (const grub_device_t dev, } mbr.entries[index].type = type; + grub_printf ("Setting partition type to 0x%x\n", type); /* Write the parttable. */ grub_disk_write (dev->disk, part->offset, 0, --------------030002060200000301090504--