Skip to contentSkip to conversation

parttool

PATCH In review phcoder 3 participants 15 messages Mar 4, 2009 – Apr 25, 2009 Kbuild

lore
Share & tools
lore

phcoder

author
#0 lore raw

PATCH 1/1 parttool

Hello here is the implementation of parttool with the syntax I proposed earlier and equivalent of parttype, makeactive and hide/unhide

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
common.rmk +11 -1
Index: conf/common.rmk
===================================================================
@@ -334,7 +340,7 @@
 	cmp.mod cat.mod help.mod search.mod					\
 	loopback.mod fs_uuid.mod configfile.mod echo.mod	\
 	terminfo.mod test.mod blocklist.mod hexdump.mod		\
-	read.mod sleep.mod loadenv.mod crc.mod
+	read.mod sleep.mod loadenv.mod crc.mod parttool.mod pcpart.mod
 
 # For hello.mod.
 hello_mod_SOURCES = hello/hello.c
@@ -346,6 +352,16 @@
 boot_mod_CFLAGS = $(COMMON_CFLAGS)
 boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For parttool.mod.
+parttool_mod_SOURCES = commands/parttool.c
+parttool_mod_CFLAGS = $(COMMON_CFLAGS)
+parttool_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For pcpart.mod.
+pcpart_mod_SOURCES = parttool/pcpart.c
+pcpart_mod_CFLAGS = $(COMMON_CFLAGS)
+pcpart_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # For handler.mod.
 handler_mod_SOURCES = commands/handler.c
 handler_mod_CFLAGS = $(COMMON_CFLAGS)
i386-coreboot.rmk +1 -0
Index: conf/i386-coreboot.rmk
===================================================================
@@ -87,6 +89,7 @@
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
+	commands/parttool.c parttool/pcpart.c				\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
i386-efi.rmk +1 -0
Index: conf/i386-efi.rmk
===================================================================
@@ -65,6 +66,7 @@
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
+	commands/parttool.c parttool/pcpart.c				\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
i386-ieee1275.rmk +1 -0
Index: conf/i386-ieee1275.rmk
===================================================================
@@ -87,6 +89,7 @@
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
+	commands/parttool.c parttool/pcpart.c				\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
i386-pc.rmk +1 -0
Index: conf/i386-pc.rmk
===================================================================
@@ -146,3 +147,4 @@
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
+	commands/parttool.c parttool/pcpart.c				\

grub_emu_init.c

grub_emu_LDFLAGS = $(LIBCURSES)

powerpc-ieee1275.rmk +1 -0
Index: conf/powerpc-ieee1275.rmk
===================================================================
@@ -70,6 +70,7 @@
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
+	commands/parttool.c parttool/pcpart.c				\
 	grub_script.tab.c grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
sparc64-ieee1275.rmk +1 -0
Index: conf/sparc64-ieee1275.rmk
===================================================================
@@ -66,6 +67,7 @@
 #	partmap/acorn.c							\
 #	util/console.c util/grub-emu.c util/misc.c			\
 #	util/hostdisk.c util/getroot.c					\
+#	commands/parttool.c parttool/pcpart.c				\
 #	util/sparc64/ieee1275/misc.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
x86_64-efi.rmk +1 -0
Index: conf/x86_64-efi.rmk
===================================================================
@@ -67,6 +68,7 @@
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
+	commands/parttool.c parttool/pcpart.c				\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
parttool.c +248 -0

248 lines not on this page · raw message

pcpart.c +152 -0

152 lines not on this page · raw message

author
#1 lore raw

Sorry I forgot include/grub/parttool.h

Quoted 2 lines · phcoder

Hello here is the implementation of parttool with the syntax I proposed earlier and equivalent of parttype, makeactive and hide/unhide

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko

/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc. *

 *  GRUB is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  GRUB is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.

*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef GRUB_PARTTOOL_HEADER
#define GRUB_PARTTOOL_HEADER 1

struct grub_parttool_argdesc
{
char *name;
char *desc;
enum {GRUB_PARTTOOL_ARG_END, GRUB_PARTTOOL_ARG_BOOL, GRUB_PARTTOOL_ARG_VAL}

    type;
};

struct grub_parttool_args
{
int set;
union

  {
    int bool;
    char *str;

};
};

typedef grub_err_t (*grub_parttool_function_t) (const grub_device_t dev,

						const struct grub_parttool_args *args);

struct grub_parttool
{
struct grub_parttool *next;
char *name;
int handle;
int nargs;
struct grub_parttool_argdesc *args;
grub_parttool_function_t func;
};

int grub_parttool_register(const char *part_name,

			   const grub_parttool_function_t func,
			   const struct grub_parttool_argdesc *args);

void grub_parttool_unregister (int handle);

#endif /* ! GRUB_PARTTOOL_HEADER*/

author
#2 lore raw

Update

Quoted 7 lines · phcoder

Sorry I forgot include/grub/parttool.h

Quoted 2 lines · phcoder

Hello here is the implementation of parttool with the syntax I proposed earlier and equivalent of parttype, makeactive and hide/unhide

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
ChangeLog +16 -0
index e3ac3ac..5fc3e37 100644
@@ -1,4 +1,20 @@
 2009-03-15  Vladimir Serbinenko  <[email protected]>
+
+	Parttool
+
+	* parttool/pcpart.c: new file
+	* commands/parttool.c: likewise
+	* conf/common.rmk: Added parttool.mod and pcpart.mod
+	* conf/i386-coreboot.rmk: added commands/parttool.c 
+	and parttool/pcpart.c to grub-emu
+	* conf/i386-efi.rmk: likewise
+	* conf/i386-ieee1275.rmk: likewise
+	* conf/i386-pc.rmk: likewise
+	* conf/powerpc-ieee1275.rmk: likewise
+	* conf/sparc64-ieee1275.rmk: likewise
+	* conf/x86_64-ieee1275.rmk: likewise
+
+2009-03-15  Vladimir Serbinenko  <[email protected]>
  
 	Efiemu
  
commands/parttool.c new file +261 -0

261 lines not on this page · raw message

conf/common.rmk +11 -1
index 857d8b8..100fae7 100644
@@ -334,7 +334,7 @@ pkglib_MODULES += hello.mod boot.mod handler.mod ls.mod	\
 	cmp.mod cat.mod help.mod search.mod					\
 	loopback.mod fs_uuid.mod configfile.mod echo.mod	\
 	terminfo.mod test.mod blocklist.mod hexdump.mod		\
-	read.mod sleep.mod loadenv.mod crc.mod
+	read.mod sleep.mod loadenv.mod crc.mod parttool.mod pcpart.mod
 
 # For hello.mod.
 hello_mod_SOURCES = hello/hello.c
@@ -346,6 +346,16 @@ boot_mod_SOURCES = commands/boot.c
 boot_mod_CFLAGS = $(COMMON_CFLAGS)
 boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For parttool.mod.
+parttool_mod_SOURCES = commands/parttool.c
+parttool_mod_CFLAGS = $(COMMON_CFLAGS)
+parttool_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For pcpart.mod.
+pcpart_mod_SOURCES = parttool/pcpart.c
+pcpart_mod_CFLAGS = $(COMMON_CFLAGS)
+pcpart_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # For handler.mod.
 handler_mod_SOURCES = commands/handler.c
 handler_mod_CFLAGS = $(COMMON_CFLAGS)
conf/i386-coreboot.rmk +1 -0
index 33b798c..ddcc308 100644
@@ -89,6 +89,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c	\
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
+	commands/parttool.c parttool/pcpart.c				\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
conf/i386-efi.rmk +1 -0
index f9380d1..a2454d9 100644
@@ -66,6 +66,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c 	\
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
+	commands/parttool.c parttool/pcpart.c				\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
conf/i386-pc.rmk +1 -0
index d5e1fab..3a00d17 100644
@@ -152,6 +152,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c	\
 	efiemu/modules/pnvram.c efiemu/i386/loadcore32.c 		\
 	efiemu/i386/loadcore64.c efiemu/symbols.c efiemu/prepare32.c	\
 	efiemu/prepare64.c efiemu/uppermem.c lib/crc.c 	\
+	commands/parttool.c parttool/pcpart.c				\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES) 
conf/i386.rmk +0 -10
index 9ae65ae..4e86ed8 100644
@@ -19,13 +19,3 @@ pkglib_MODULES += uppermem.mod
 uppermem_mod_SOURCES = lib/i386/uppermem.c
 uppermem_mod_CFLAGS = $(COMMON_CFLAGS)
 uppermem_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
-pkglib_MODULES += xnu.mod _xnu.mod
-_xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c loader/macho.c loader/xnu.c loader/xnu_rescue.c loader/i386/xnu_helper.S
-_xnu_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall
-_xnu_mod_LDFLAGS = $(COMMON_LDFLAGS)
-_xnu_mod_ASFLAGS = $(COMMON_ASFLAGS)
-
-xnu_mod_SOURCES = loader/xnu_normal.c
-xnu_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall
-xnu_mod_LDFLAGS = $(COMMON_LDFLAGS)
conf/powerpc-ieee1275.rmk +1 -0
index f33d19a..66d1d58 100644
@@ -70,6 +70,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c 	\
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
+	commands/parttool.c parttool/pcpart.c				\
 	grub_script.tab.c grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
conf/sparc64-ieee1275.rmk +1 -0
index 75cc1f4..0794dc0 100644
@@ -67,6 +67,7 @@ grub_mkimage_SOURCES = util/sparc64/ieee1275/grub-mkimage.c util/misc.c \
 #	partmap/acorn.c							\
 #	util/console.c util/grub-emu.c util/misc.c			\
 #	util/hostdisk.c util/getroot.c					\
+#	commands/parttool.c parttool/pcpart.c				\
 #	util/sparc64/ieee1275/misc.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
conf/x86_64-efi.rmk +1 -0
index ebbfb23..fb7bb32 100644
@@ -68,6 +68,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c 	\
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
+	commands/parttool.c parttool/pcpart.c				\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES)
include/grub/parttool.h new file +58 -0

58 lines not on this page · raw message

parttool/pcpart.c new file +152 -0

152 lines not on this page · raw message

author
#3 lore raw

Can someone review this patch?

Quoted 11 lines · phcoder

Update

Quoted 7 lines · phcoder

Sorry I forgot include/grub/parttool.h

Quoted 2 lines · phcoder

Hello here is the implementation of parttool with the syntax I proposed earlier and equivalent of parttype, makeactive and hide/unhide

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#4 lore raw
Quoted 1 line · On Saturday 04 April 2009 18:22:39 phcoder wrote:

Can someone review this patch?

Only some style should be corrected. For example:

+#ifndef GRUB_UTIL
+ if (!parts)
+ grub_dl_unref (mymod);
+#endif

Our convention is to put a space between "!" and "parts", so this should be:

+#ifndef GRUB_UTIL
+ if (! parts)
+ grub_dl_unref (mymod);
+#endif

Also, the ChangeLog should state what variables are affected explicitly. For example:

* conf/common.rmk: Added parttool.mod and pcpart.mod

Instead, you should say:

* conf/common.rmk (parttool_mod_SOURCES): New variable. (parttool_mod_CFLAGS): Likewise. (parttool_mod_LDFLAGS): Likewise.
...and so on...

The code itself looks good, so you can check it in, once you correct the styles.

Regards,
Okuji

author
#5 lore raw

Fixed & commited. My next patch will be to add automatic module loading in parttool

Quoted 38 lines · Yoshinori K. Okuji
Quoted 1 line · On Saturday 04 April 2009 18:22:39 phcoder wrote:

Can someone review this patch?

Only some style should be corrected. For example:

commands/parttool.c new file +4 -0
+#ifndef GRUB_UTIL
+  if (!parts)
+    grub_dl_unref (mymod);
+#endif

Our convention is to put a space between "!" and "parts", so this should be:

commands/parttool.c new file +4 -0
+#ifndef GRUB_UTIL
+  if (! parts)
+    grub_dl_unref (mymod);
+#endif

Also, the ChangeLog should state what variables are affected explicitly. For example:

* conf/common.rmk: Added parttool.mod and pcpart.mod

Instead, you should say:

* conf/common.rmk (parttool_mod_SOURCES): New variable. (parttool_mod_CFLAGS): Likewise. (parttool_mod_LDFLAGS): Likewise.
...and so on...

The code itself looks good, so you can check it in, once you correct the styles.

Regards,
Okuji

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#6 lore raw
Quoted 2 lines · phcoder

Fixed & commited. My next patch will be to add automatic module loading in parttool

It would be great to make parttool actually give some usage information. Right now, there is no information at all.

grub> parttool
error: too few arguments
grub> parttool --help
error: too few arguments
grub> help parttool
grub>

Signature · 2 lines
Regards,
Pavel Roskin
author
#7 lore raw
Quoted 6 lines · Pavel Roskin
Quoted 1 line · phcoder

Fixed & commited. My next patch will be to add automatic module loading in parttool

It would be great to make parttool actually give some usage information. Right now, there is no information at all.

Quoted 7 lines

grub> parttool
error: too few arguments
grub> parttool --help
error: too few arguments
grub> help parttool
grub>

Ok, I'll fix this

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#8 lore raw
Quoted 8 lines · phcoder
Quoted 7 lines · Pavel Roskin
Quoted 2 lines · phcoder

Fixed & commited. My next patch will be to add automatic module loading in parttool

It would be great to make parttool actually give some usage information. Right now, there is no information at all.

Quoted 8 lines
Quoted 7 lines

grub> parttool
error: too few arguments
grub> parttool --help
error: too few arguments
grub> help parttool
grub>

Ok, I'll fix this

I've just fixed "help parttool", it was a trivial bug in the "help" command. Still, a longer help message would be nice to have.

Signature · 2 lines
Regards,
Pavel Roskin
author
#9 lore raw
Quoted 14 lines · Pavel Roskin
Quoted 13 lines · phcoder
Quoted 12 lines · Pavel Roskin
Quoted 1 line · phcoder

Fixed & commited. My next patch will be to add automatic module loading in parttool

It would be great to make parttool actually give some usage information. Right now, there is no information at all.

grub> parttool
error: too few arguments
grub> parttool --help
error: too few arguments
grub> help parttool
grub>

Quoted 5 lines
Quoted 1 line

Ok, I'll fix this

I've just fixed "help parttool", it was a trivial bug in the "help" command. Still, a longer help message would be nice to have.

The problem is that the exact available options depend on partition type so you have to specify
parttool <partition> help
Unfortunately for now you have to load the module pcpart.mod manually. I'll fix this problem by making parttool load the corresponding module automatically

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#10 lore raw
Quoted 6 lines · phcoder

The problem is that the exact available options depend on partition type so you have to specify
parttool <partition> help
Unfortunately for now you have to load the module pcpart.mod manually. I'll fix this problem by making parttool load the corresponding module automatically

OK. And please put "parttool PARTITION help" in quotes and capitalize sentences. It took me some time to understand what the help says.

Signature · 2 lines
Regards,
Pavel Roskin
author
#11 lore raw

Is this what you mean?

Quoted 9 lines · Pavel Roskin
Quoted 3 lines · phcoder

The problem is that the exact available options depend on partition type so you have to specify
parttool <partition> help
Unfortunately for now you have to load the module pcpart.mod manually. I'll fix this problem by making parttool load the corresponding module automatically

OK. And please put "parttool PARTITION help" in quotes and capitalize sentences. It took me some time to understand what the help says.

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
ChangeLog +8 -0
index c679982..20c1804 100644
@@ -1,3 +1,11 @@
+2009-04-08  Vladimir Serbinenko  <[email protected]>
+	
+	Parttool help message improvement
+
+	* commands/parttool.c (helpmsg): new variable
+	(grub_cmd_parttool): output help if not enough arguments are supplied
+	(GRUB_MOD_INIT(parttool)): use helpmsg
+
 2009-04-07  David S. Miller  <[email protected]>
 
 	* kern/sparc64/dl.c (grub_arch_dl_relocate_symbols): Add
commands/parttool.c +9 -4
index 6eec13b..24bdcce 100644
@@ -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, 
@@ -102,7 +106,10 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
   grub_err_t err = GRUB_ERR_NONE;
 
   if (argc < 2)
-    return grub_error (GRUB_ERR_BAD_ARGUMENT, "too few arguments");
+    {
+      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] == ')')
     {
@@ -252,9 +259,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)
#12 lore raw
Quoted 1 line · phcoder

Is this what you mean?

Yes.

commands/parttool.c line 39

Quoted 4 lines
commands/parttool.c +4 -0
+static char helpmsg[] =
+  "perform COMMANDS on partition.\n"
+  "Use \"parttool PARTITION help\" for the list "
+  " of available commands";

Please remove one space after "list".

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.

It would be nice to have some feedback, e.g.
parttool (hd0,1) hidden+
Setting partition type to 0x92

"hidden" should work like "hidden+". I prefer plus and minus before the word, not after, but it's a matter of taste.

The "hidden" attribute doesn't apply to all partition types. There is no such thing as a hidden Linux swap partition.

"parttool PARTITION" should work like "parttool PARTITION help" or maybe it should give information about the partition.

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".

Signature · 2 lines
Regards,
Pavel Roskin
author
#13 lore raw

Thank you for the testing

Quoted 1 line

Please remove one space after "list".

done

Quoted 5 lines

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

Quoted 6 lines

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

Quoted 3 lines

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

Quoted 3 lines

"parttool PARTITION" should work like "parttool PARTITION help" or maybe it should give information about the partition.

Done

Quoted 4 lines

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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
ChangeLog +17 -0
index 0c50854..60aa9e9 100644
@@ -1,3 +1,20 @@
+2009-04-17  Vladimir Serbinenko  <[email protected]>
+	
+	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  <[email protected]>
 
 	* commands/efi/loadbios.c (grub_cmd_fakebios): Add missing return
Makefile.in +4 -1
index b24ee2e..f73192e 100644
@@ -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
 
commands/parttool.c +128 -51

235 lines not on this page · raw message

genmk.rb +8 -1
index b619421..3532cd8 100644
@@ -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 $< \
genparttoollist.sh new file +19 -0
new file mode 100644
index 0000000..2424b8a
@@ -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
parttool/pcpart.c +6 -1
index 59f24ba..a2b9452 100644
@@ -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, 
#14 lore raw

committed

Quoted 49 lines · phcoder

Thank you for the testing

Quoted 2 lines

Please remove one space after "list".

done

Quoted 6 lines

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

Quoted 7 lines

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

Quoted 4 lines

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

Quoted 10 lines

"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