All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] parttool
@ 2009-03-04 21:15 phcoder
  2009-03-10 17:45 ` phcoder
  0 siblings, 1 reply; 15+ messages in thread
From: phcoder @ 2009-03-04 21:15 UTC (permalink / raw)
  To: The development of GRUB 2

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

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

Regards
Vladimir 'phcoder' Serbinenko

[-- Attachment #2: parttool.diff --]
[-- Type: text/x-patch, Size: 15318 bytes --]

Index: conf/common.rmk
===================================================================
--- conf/common.rmk	(revision 2017)
+++ conf/common.rmk	(working copy)
@@ -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)
Index: conf/i386-coreboot.rmk
===================================================================
--- conf/i386-coreboot.rmk	(revision 2017)
+++ conf/i386-coreboot.rmk	(working copy)
@@ -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)
Index: conf/i386-efi.rmk
===================================================================
--- conf/i386-efi.rmk	(revision 2017)
+++ conf/i386-efi.rmk	(working copy)
@@ -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)
Index: conf/i386-ieee1275.rmk
===================================================================
--- conf/i386-ieee1275.rmk	(revision 2017)
+++ conf/i386-ieee1275.rmk	(working copy)
@@ -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)
Index: conf/i386-pc.rmk
===================================================================
--- conf/i386-pc.rmk	(revision 2017)
+++ conf/i386-pc.rmk	(working copy)
@@ -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) 
 
Index: conf/powerpc-ieee1275.rmk
===================================================================
--- conf/powerpc-ieee1275.rmk	(revision 2017)
+++ conf/powerpc-ieee1275.rmk	(working copy)
@@ -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)
Index: conf/sparc64-ieee1275.rmk
===================================================================
--- conf/sparc64-ieee1275.rmk	(revision 2017)
+++ conf/sparc64-ieee1275.rmk	(working copy)
@@ -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)
Index: conf/x86_64-efi.rmk
===================================================================
--- conf/x86_64-efi.rmk	(revision 2017)
+++ conf/x86_64-efi.rmk	(working copy)
@@ -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)
Index: commands/parttool.c
===================================================================
--- commands/parttool.c	(revision 0)
+++ commands/parttool.c	(revision 0)
@@ -0,0 +1,248 @@
+/* parttool.c - common dispatcher and parser for partition operations */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/types.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+#include <grub/dl.h>
+#include <grub/normal.h>
+#include <grub/device.h>
+#include <grub/disk.h>
+#include <grub/partition.h>
+#include <grub/parttool.h>
+
+struct grub_parttool *parts = 0;
+static int curhandle = 0;
+static grub_dl_t mymod;
+
+int 
+grub_parttool_register(const char *part_name, 
+		       const grub_parttool_function_t func,
+		       const struct grub_parttool_argdesc *args)
+{
+  struct grub_parttool *cur;
+  int nargs = 0;
+  struct grub_parttool_argdesc *curarg;
+
+#ifndef GRUB_UTIL
+  if (!parts)
+    grub_dl_ref (mymod);
+#endif
+
+  cur = (struct grub_parttool *) grub_malloc (sizeof (struct grub_parttool));
+  cur->next = parts;
+  cur->name = grub_strdup (part_name);
+  cur->handle = curhandle++;
+  for (curarg = args; curarg->name != 0; curarg++)
+    nargs++;
+  cur->nargs = nargs;
+  cur->args = (struct grub_parttool_argdesc *) 
+    grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc));
+  grub_memcpy (cur->args, args, 
+	       (nargs + 1) * sizeof (struct grub_parttool_argdesc));
+  
+  cur->func = func;
+  parts = cur;
+  return cur->handle;
+}
+
+void
+grub_parttool_unregister (int handle)
+{
+  struct grub_parttool *prev = 0, *cur;
+  for (cur = parts; cur; prev=cur, cur = cur->next)
+    if (cur->handle == handle)
+      {
+	grub_free (cur->args);
+	grub_free (cur->name);
+	if (prev)
+	  prev->next = cur->next;
+	else
+	  parts = cur->next;
+	grub_free (cur);
+      }
+#ifndef GRUB_UTIL
+  if (!parts)
+    grub_dl_unref (mymod);
+#endif
+}
+
+static grub_err_t
+grub_cmd_parttool (struct grub_arg_list *state __attribute__ ((unused)),
+		   int argc, char **args)
+{
+  grub_device_t dev;
+  struct grub_parttool *cur, *ptool;
+  int *parsed;
+  int i, j;
+  grub_err_t err = GRUB_ERR_NONE;
+
+  if (argc < 2)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "too few arguments");
+
+  dev = grub_device_open (args[0]); 
+
+  if (!dev)
+    return grub_errno;
+
+  if (!dev->disk)
+    {
+      grub_device_close (dev);
+      return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a disk");
+    }
+
+  if (!dev->disk->partition)
+    {
+      grub_device_close (dev);
+      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"))
+      {
+	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);
+
+		  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;
+      }
+
+  for (i = 1; i < argc; i++)
+    if (!parsed[i])
+      {
+	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))
+	    {
+	      for (curarg = cur->args; curarg->name; curarg++)
+		if (!grub_strncmp (curarg->name, args[i], 
+				   grub_strlen (curarg->name))
+		    && ((curarg->type == GRUB_PARTTOOL_ARG_BOOL 
+			 && (args[i][grub_strlen (curarg->name)] == '+' 
+			     || args[i][grub_strlen (curarg->name)] == '-'))
+			|| (curarg->type==GRUB_PARTTOOL_ARG_VAL
+			    && args[i][grub_strlen (curarg->name)] == '=')))
+		    
+		  break;
+	      if (curarg)
+		break;
+	    }
+	if (!cur)
+	  return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised argument %s",
+			     args[i]);
+	ptool = cur;
+	pargs = (struct grub_parttool_args *) 
+	  grub_malloc (ptool->nargs * sizeof (struct grub_parttool_args));
+	grub_memset (pargs, 0, 
+		     ptool->nargs * sizeof (struct grub_parttool_args));
+	for (j = i; j < argc; j++)
+	  if (!parsed[j])
+	    {
+	      for (curarg = ptool->args; curarg->name; curarg++)
+		if (!grub_strncmp (curarg->name, args[i], 
+				   grub_strlen (curarg->name))
+		    && ((curarg->type == GRUB_PARTTOOL_ARG_BOOL 
+			 && (args[j][grub_strlen (curarg->name)] == '+' 
+			     || args[j][grub_strlen (curarg->name)] == '-'))
+			|| (curarg->type == GRUB_PARTTOOL_ARG_VAL
+			    && args[j][grub_strlen (curarg->name)] == '=')))
+		  {
+		    parsed[j] = 1;
+		    pargs[curarg - ptool->args].set = 1;
+		    switch (curarg->type)
+		      {
+		      case GRUB_PARTTOOL_ARG_BOOL:
+			pargs[curarg - ptool->args].bool 
+			  = (args[j][grub_strlen (curarg->name)] != '-');
+			break;
+
+		      case GRUB_PARTTOOL_ARG_VAL:
+			pargs[curarg - ptool->args].str 
+			  = (args[j]+grub_strlen (curarg->name)+ 1);
+			break;
+			
+		      case GRUB_PARTTOOL_ARG_END:
+			break;
+		      }
+		  }
+	    }
+
+	err = ptool->func (dev, pargs);
+	grub_free (pargs);
+	if (err)
+	  break;
+      }
+
+  grub_device_close (dev);
+  return err;
+}
+
+GRUB_MOD_INIT(parttool)
+{
+  (void)mod;			/* To stop warning. */
+  mymod = mod;
+  grub_register_command ("parttool", grub_cmd_parttool, GRUB_COMMAND_FLAG_BOTH,
+			 "parttool PARTITION COMMANDS", 
+			 "perform COMMANDS on partition."
+			 " use parttool PARTITION help for the list "
+			 " of available commands", 0);
+}
+
+GRUB_MOD_FINI(parttool)
+{
+  grub_unregister_command ("parttool");
+}
Index: parttool/pcpart.c
===================================================================
--- parttool/pcpart.c	(revision 0)
+++ parttool/pcpart.c	(revision 0)
@@ -0,0 +1,152 @@
+/* pcpart.c - manipulate fdisk partitions */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/types.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+#include <grub/pc_partition.h>
+#include <grub/device.h>
+#include <grub/disk.h>
+#include <grub/partition.h>
+#include <grub/parttool.h>
+
+static int activate_table_handle = -1;
+static int type_table_handle = -1;
+
+static struct grub_parttool_argdesc grub_pcpart_bootargs[] =
+{
+  {"boot", "Make partition active", GRUB_PARTTOOL_ARG_BOOL},
+  {0, 0, 0}
+};
+
+static grub_err_t grub_pcpart_boot (const grub_device_t dev, 
+				    const struct grub_parttool_args *args)
+{
+  int i, index;
+  grub_partition_t part;
+  struct grub_pc_partition_mbr mbr;
+
+  if (dev->disk->partition->offset)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a primary partition");
+
+  index = dev->disk->partition->index;
+  part = dev->disk->partition;
+  dev->disk->partition = 0;
+
+  /* Read the MBR.  */
+  if (grub_disk_read (dev->disk, 0, 0, sizeof (mbr), (char *) &mbr))
+    {
+      dev->disk->partition = part;
+      return grub_errno;
+    }
+
+  if (args[0].set && args[0].bool)
+    {
+      for (i = 0; i < 4; i++)
+	mbr.entries[i].flag = 0x0;
+      mbr.entries[index].flag = 0x80;
+    }
+  else
+    mbr.entries[index].flag = 0x0;
+
+   /* Write the MBR.  */
+  grub_disk_write (dev->disk, 0, 0, sizeof (mbr), (char *) &mbr);
+
+  dev->disk->partition = part;
+
+  return GRUB_ERR_NONE;
+}
+
+static struct grub_parttool_argdesc grub_pcpart_typeargs[] =
+{
+  {"type", "Change partition type", GRUB_PARTTOOL_ARG_VAL},
+  {"hidden", "Make partition hidden", GRUB_PARTTOOL_ARG_BOOL},
+  {0, 0, 0}
+};
+
+static grub_err_t grub_pcpart_type (const grub_device_t dev, 
+				    const struct grub_parttool_args *args)
+{
+  int index;
+  grub_uint8_t type;
+  grub_partition_t part;
+  struct grub_pc_partition_mbr mbr;
+
+  index = dev->disk->partition->index;
+  part = dev->disk->partition;
+  dev->disk->partition = 0;
+
+  /* Read the parttable.  */
+  if (grub_disk_read (dev->disk, part->offset, 0, 
+		      sizeof (mbr), (char *) &mbr))
+    {
+      dev->disk->partition = part;
+      return grub_errno;
+    }
+
+  if (args[0].set)
+    type = grub_strtoul (args[0].str, 0, 0);
+  else
+    type = mbr.entries[index].type;
+
+  if (args[1].set)
+    {
+      if (args[1].bool)
+	type |= GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG;
+      else
+	type &= ~GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG;
+    }
+
+  if (grub_pc_partition_is_empty (type) 
+      || grub_pc_partition_is_extended (type))
+    {
+      dev->disk->partition = part;
+      return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid type");
+    }
+
+  mbr.entries[index].type = type;
+
+   /* Write the parttable.  */
+  grub_disk_write (dev->disk, part->offset, 0, 
+		   sizeof (mbr), (char *) &mbr);
+
+  dev->disk->partition = part;
+
+  return GRUB_ERR_NONE;
+}
+
+GRUB_MOD_INIT (pcpart)
+{
+  (void)mod;			/* To stop warning. */
+
+  activate_table_handle = grub_parttool_register("pc_partition_map", 
+						 grub_pcpart_boot,
+						 grub_pcpart_bootargs);
+  type_table_handle = grub_parttool_register("pc_partition_map", 
+					     grub_pcpart_type,
+					     grub_pcpart_typeargs);
+ 
+}
+GRUB_MOD_FINI(pcpart)
+{
+  grub_parttool_unregister (activate_table_handle);
+  grub_parttool_unregister (type_table_handle);
+}

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-03-04 21:15 [PATCH] parttool phcoder
@ 2009-03-10 17:45 ` phcoder
  2009-03-20 19:33   ` phcoder
  0 siblings, 1 reply; 15+ messages in thread
From: phcoder @ 2009-03-10 17:45 UTC (permalink / raw)
  To: The development of GRUB 2

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

Sorry I forgot include/grub/parttool.h

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


-- 

Regards
Vladimir 'phcoder' Serbinenko

[-- Attachment #2: parttool.h --]
[-- Type: text/x-chdr, Size: 1552 bytes --]

/*
 *  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*/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-03-10 17:45 ` phcoder
@ 2009-03-20 19:33   ` phcoder
  2009-04-04  9:22     ` phcoder
  0 siblings, 1 reply; 15+ messages in thread
From: phcoder @ 2009-03-20 19:33 UTC (permalink / raw)
  To: The development of GRUB 2

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

Update
phcoder wrote:
> Sorry I forgot include/grub/parttool.h
> 
> phcoder wrote:
>> Hello here is the implementation of parttool with the syntax I 
>> proposed earlier and equivalent of parttype, makeactive and hide/unhide
>>
> 
> 


-- 

Regards
Vladimir 'phcoder' Serbinenko

[-- Attachment #2: parttool.diff --]
[-- Type: text/x-diff, Size: 18540 bytes --]

diff --git a/ChangeLog b/ChangeLog
index e3ac3ac..5fc3e37 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,20 @@
 2009-03-15  Vladimir Serbinenko  <phcoder@gmail.com>
+
+	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  <phcoder@gmail.com>
  
 	Efiemu
  
diff --git a/commands/parttool.c b/commands/parttool.c
new file mode 100644
index 0000000..fb6bdaa
--- /dev/null
+++ b/commands/parttool.c
@@ -0,0 +1,261 @@
+/* parttool.c - common dispatcher and parser for partition operations */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/types.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+#include <grub/dl.h>
+#include <grub/normal.h>
+#include <grub/device.h>
+#include <grub/disk.h>
+#include <grub/partition.h>
+#include <grub/parttool.h>
+
+struct grub_parttool *parts = 0;
+static int curhandle = 0;
+static grub_dl_t mymod;
+
+int 
+grub_parttool_register(const char *part_name, 
+		       const grub_parttool_function_t func,
+		       const struct grub_parttool_argdesc *args)
+{
+  struct grub_parttool *cur;
+  int nargs = 0;
+  struct grub_parttool_argdesc *curarg;
+
+#ifndef GRUB_UTIL
+  if (!parts)
+    grub_dl_ref (mymod);
+#endif
+
+  cur = (struct grub_parttool *) grub_malloc (sizeof (struct grub_parttool));
+  cur->next = parts;
+  cur->name = grub_strdup (part_name);
+  cur->handle = curhandle++;
+  for (curarg = args; curarg->name != 0; curarg++)
+    nargs++;
+  cur->nargs = nargs;
+  cur->args = (struct grub_parttool_argdesc *) 
+    grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc));
+  grub_memcpy (cur->args, args, 
+	       (nargs + 1) * sizeof (struct grub_parttool_argdesc));
+  
+  cur->func = func;
+  parts = cur;
+  return cur->handle;
+}
+
+void
+grub_parttool_unregister (int handle)
+{
+  struct grub_parttool *prev = 0, *cur, *t;
+  for (cur = parts; cur; )
+    if (cur->handle == handle)
+      {
+	grub_free (cur->args);
+	grub_free (cur->name);
+	if (prev)
+	  prev->next = cur->next;
+	else
+	  parts = cur->next;
+	t = cur;
+	cur = cur->next;
+	grub_free (t);
+      }
+    else
+      {
+	prev = cur;
+	cur = cur->next;
+      }
+#ifndef GRUB_UTIL
+  if (!parts)
+    grub_dl_unref (mymod);
+#endif
+}
+
+static grub_err_t
+grub_cmd_parttool (struct grub_arg_list *state __attribute__ ((unused)),
+		   int argc, char **args)
+{
+  grub_device_t dev;
+  struct grub_parttool *cur, *ptool;
+  int *parsed;
+  int i, j;
+  grub_err_t err = GRUB_ERR_NONE;
+
+  if (argc < 2)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "too few arguments");
+
+  if (args[0][0] == '(' && args[0][grub_strlen (args[0]) - 1] == ')')
+    {
+      args[0][grub_strlen (args[0])-1] = 0;
+      args[0]++;
+    }
+
+  dev = grub_device_open (args[0]); 
+
+  if (!dev)
+    return grub_errno;
+
+  if (!dev->disk)
+    {
+      grub_device_close (dev);
+      return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a disk");
+    }
+
+  if (!dev->disk->partition)
+    {
+      grub_device_close (dev);
+      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"))
+      {
+	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);
+
+		  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;
+      }
+
+  for (i = 1; i < argc; i++)
+    if (!parsed[i])
+      {
+	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))
+	    {
+	      for (curarg = cur->args; curarg->name; curarg++)
+		if (!grub_strncmp (curarg->name, args[i], 
+				   grub_strlen (curarg->name))
+		    && ((curarg->type == GRUB_PARTTOOL_ARG_BOOL 
+			 && (args[i][grub_strlen (curarg->name)] == '+' 
+			     || args[i][grub_strlen (curarg->name)] == '-'))
+			|| (curarg->type==GRUB_PARTTOOL_ARG_VAL
+			    && args[i][grub_strlen (curarg->name)] == '=')))
+		    
+		  break;
+	      if (curarg->name)
+		break;
+	    }
+	if (!cur)
+	  return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised argument %s",
+			     args[i]);
+	ptool = cur;
+	pargs = (struct grub_parttool_args *) 
+	  grub_malloc (ptool->nargs * sizeof (struct grub_parttool_args));
+	grub_memset (pargs, 0, 
+		     ptool->nargs * sizeof (struct grub_parttool_args));
+	for (j = i; j < argc; j++)
+	  if (!parsed[j])
+	    {
+	      for (curarg = ptool->args; curarg->name; curarg++)
+		if (!grub_strncmp (curarg->name, args[i], 
+				   grub_strlen (curarg->name))
+		    && ((curarg->type == GRUB_PARTTOOL_ARG_BOOL 
+			 && (args[j][grub_strlen (curarg->name)] == '+' 
+			     || args[j][grub_strlen (curarg->name)] == '-'))
+			|| (curarg->type == GRUB_PARTTOOL_ARG_VAL
+			    && args[j][grub_strlen (curarg->name)] == '=')))
+		  {
+		    parsed[j] = 1;
+		    pargs[curarg - ptool->args].set = 1;
+		    switch (curarg->type)
+		      {
+		      case GRUB_PARTTOOL_ARG_BOOL:
+			pargs[curarg - ptool->args].bool 
+			  = (args[j][grub_strlen (curarg->name)] != '-');
+			break;
+
+		      case GRUB_PARTTOOL_ARG_VAL:
+			pargs[curarg - ptool->args].str 
+			  = (args[j]+grub_strlen (curarg->name)+ 1);
+			break;
+			
+		      case GRUB_PARTTOOL_ARG_END:
+			break;
+		      }
+		  }
+	    }
+
+	err = ptool->func (dev, pargs);
+	grub_free (pargs);
+	if (err)
+	  break;
+      }
+
+  grub_device_close (dev);
+  return err;
+}
+
+GRUB_MOD_INIT(parttool)
+{
+  (void)mod;			/* To stop warning. */
+  mymod = mod;
+  grub_register_command ("parttool", grub_cmd_parttool, GRUB_COMMAND_FLAG_BOTH,
+			 "parttool PARTITION COMMANDS", 
+			 "perform COMMANDS on partition."
+			 " use parttool PARTITION help for the list "
+			 " of available commands", 0);
+}
+
+GRUB_MOD_FINI(parttool)
+{
+  grub_unregister_command ("parttool");
+}
diff --git a/conf/common.rmk b/conf/common.rmk
index 857d8b8..100fae7 100644
--- a/conf/common.rmk
+++ b/conf/common.rmk
@@ -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)
diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk
index 33b798c..ddcc308 100644
--- a/conf/i386-coreboot.rmk
+++ b/conf/i386-coreboot.rmk
@@ -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)
diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk
index f9380d1..a2454d9 100644
--- a/conf/i386-efi.rmk
+++ b/conf/i386-efi.rmk
@@ -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)
diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk
index d5e1fab..3a00d17 100644
--- a/conf/i386-pc.rmk
+++ b/conf/i386-pc.rmk
@@ -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) 
diff --git a/conf/i386.rmk b/conf/i386.rmk
index 9ae65ae..4e86ed8 100644
--- a/conf/i386.rmk
+++ b/conf/i386.rmk
@@ -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)
diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk
index f33d19a..66d1d58 100644
--- a/conf/powerpc-ieee1275.rmk
+++ b/conf/powerpc-ieee1275.rmk
@@ -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)
diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk
index 75cc1f4..0794dc0 100644
--- a/conf/sparc64-ieee1275.rmk
+++ b/conf/sparc64-ieee1275.rmk
@@ -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)
diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk
index ebbfb23..fb7bb32 100644
--- a/conf/x86_64-efi.rmk
+++ b/conf/x86_64-efi.rmk
@@ -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)
diff --git a/include/grub/parttool.h b/include/grub/parttool.h
new file mode 100644
index 0000000..0e05f4c
--- /dev/null
+++ b/include/grub/parttool.h
@@ -0,0 +1,58 @@
+/*
+ *  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*/
diff --git a/parttool/pcpart.c b/parttool/pcpart.c
new file mode 100644
index 0000000..53e6403
--- /dev/null
+++ b/parttool/pcpart.c
@@ -0,0 +1,152 @@
+/* pcpart.c - manipulate fdisk partitions */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  This program 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 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/types.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+#include <grub/pc_partition.h>
+#include <grub/device.h>
+#include <grub/disk.h>
+#include <grub/partition.h>
+#include <grub/parttool.h>
+
+static int activate_table_handle = -1;
+static int type_table_handle = -1;
+
+static struct grub_parttool_argdesc grub_pcpart_bootargs[] =
+{
+  {"boot", "Make partition active", GRUB_PARTTOOL_ARG_BOOL},
+  {0, 0, 0}
+};
+
+static grub_err_t grub_pcpart_boot (const grub_device_t dev, 
+				    const struct grub_parttool_args *args)
+{
+  int i, index;
+  grub_partition_t part;
+  struct grub_pc_partition_mbr mbr;
+
+  if (dev->disk->partition->offset)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a primary partition");
+
+  index = dev->disk->partition->index;
+  part = dev->disk->partition;
+  dev->disk->partition = 0;
+
+  /* Read the MBR.  */
+  if (grub_disk_read (dev->disk, 0, 0, sizeof (mbr), (char *) &mbr))
+    {
+      dev->disk->partition = part;
+      return grub_errno;
+    }
+
+  if (args[0].set && args[0].bool)
+    {
+      for (i = 0; i < 4; i++)
+	mbr.entries[i].flag = 0x0;
+      mbr.entries[index].flag = 0x80;
+    }
+  else
+    mbr.entries[index].flag = 0x0;
+
+   /* Write the MBR.  */
+  grub_disk_write (dev->disk, 0, 0, sizeof (mbr), (char *) &mbr);
+
+  dev->disk->partition = part;
+
+  return GRUB_ERR_NONE;
+}
+
+static struct grub_parttool_argdesc grub_pcpart_typeargs[] =
+{
+  {"type", "Change partition type", GRUB_PARTTOOL_ARG_VAL},
+  {"hidden", "Make partition hidden", GRUB_PARTTOOL_ARG_BOOL},
+  {0, 0, 0}
+};
+
+static grub_err_t grub_pcpart_type (const grub_device_t dev, 
+				    const struct grub_parttool_args *args)
+{
+  int index;
+  grub_uint8_t type;
+  grub_partition_t part;
+  struct grub_pc_partition_mbr mbr;
+
+  index = dev->disk->partition->index;
+  part = dev->disk->partition;
+  dev->disk->partition = 0;
+
+  /* Read the parttable.  */
+  if (grub_disk_read (dev->disk, part->offset, 0, 
+		      sizeof (mbr), (char *) &mbr))
+    {
+      dev->disk->partition = part;
+      return grub_errno;
+    }
+
+  if (args[0].set)
+    type = grub_strtoul (args[0].str, 0, 0);
+  else
+    type = mbr.entries[index].type;
+
+  if (args[1].set)
+    {
+      if (args[1].bool)
+	type |= GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG;
+      else
+	type &= ~GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG;
+    }
+
+  if (grub_pc_partition_is_empty (type) 
+      || grub_pc_partition_is_extended (type))
+    {
+      dev->disk->partition = part;
+      return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid type");
+    }
+
+  mbr.entries[index].type = type;
+
+   /* Write the parttable.  */
+  grub_disk_write (dev->disk, part->offset, 0, 
+		   sizeof (mbr), (char *) &mbr);
+
+  dev->disk->partition = part;
+
+  return GRUB_ERR_NONE;
+}
+
+GRUB_MOD_INIT (pcpart)
+{
+  (void)mod;			/* To stop warning. */
+
+  activate_table_handle = grub_parttool_register("pc_partition_map", 
+						 grub_pcpart_boot,
+						 grub_pcpart_bootargs);
+  type_table_handle = grub_parttool_register("pc_partition_map", 
+					     grub_pcpart_type,
+					     grub_pcpart_typeargs);
+ 
+}
+GRUB_MOD_FINI(pcpart)
+{
+  grub_parttool_unregister (activate_table_handle);
+  grub_parttool_unregister (type_table_handle);
+}

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-03-20 19:33   ` phcoder
@ 2009-04-04  9:22     ` phcoder
  2009-04-05 14:48       ` Yoshinori K. Okuji
  0 siblings, 1 reply; 15+ messages in thread
From: phcoder @ 2009-04-04  9:22 UTC (permalink / raw)
  To: The development of GRUB 2

Can someone review this patch?
phcoder wrote:
> Update
> phcoder wrote:
>> Sorry I forgot include/grub/parttool.h
>>
>> phcoder wrote:
>>> Hello here is the implementation of parttool with the syntax I 
>>> proposed earlier and equivalent of parttype, makeactive and hide/unhide
>>>
>>
>>
> 
> 


-- 

Regards
Vladimir 'phcoder' Serbinenko



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-04-04  9:22     ` phcoder
@ 2009-04-05 14:48       ` Yoshinori K. Okuji
  2009-04-06  9:52         ` phcoder
  0 siblings, 1 reply; 15+ messages in thread
From: Yoshinori K. Okuji @ 2009-04-05 14:48 UTC (permalink / raw)
  To: The development of GRUB 2

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



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-04-05 14:48       ` Yoshinori K. Okuji
@ 2009-04-06  9:52         ` phcoder
  2009-04-06 15:53           ` Pavel Roskin
  0 siblings, 1 reply; 15+ messages in thread
From: phcoder @ 2009-04-06  9:52 UTC (permalink / raw)
  To: The development of GRUB 2

Fixed & commited. My next patch will be to add automatic module loading 
in parttool
Yoshinori K. Okuji wrote:
> 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
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel


-- 

Regards
Vladimir 'phcoder' Serbinenko



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-04-06  9:52         ` phcoder
@ 2009-04-06 15:53           ` Pavel Roskin
  2009-04-06 15:56             ` phcoder
  0 siblings, 1 reply; 15+ messages in thread
From: Pavel Roskin @ 2009-04-06 15:53 UTC (permalink / raw)
  To: The development of GRUB 2

On Mon, 2009-04-06 at 11:52 +0200, phcoder wrote:
> 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>

-- 
Regards,
Pavel Roskin



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-04-06 15:53           ` Pavel Roskin
@ 2009-04-06 15:56             ` phcoder
  2009-04-06 16:20               ` Pavel Roskin
  0 siblings, 1 reply; 15+ messages in thread
From: phcoder @ 2009-04-06 15:56 UTC (permalink / raw)
  To: The development of GRUB 2

Pavel Roskin wrote:
> On Mon, 2009-04-06 at 11:52 +0200, phcoder wrote:
>> 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>
> 
Ok, I'll fix this

-- 

Regards
Vladimir 'phcoder' Serbinenko



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-04-06 15:56             ` phcoder
@ 2009-04-06 16:20               ` Pavel Roskin
  2009-04-06 16:25                 ` phcoder
  0 siblings, 1 reply; 15+ messages in thread
From: Pavel Roskin @ 2009-04-06 16:20 UTC (permalink / raw)
  To: The development of GRUB 2

On Mon, 2009-04-06 at 17:56 +0200, phcoder wrote:
> Pavel Roskin wrote:
> > On Mon, 2009-04-06 at 11:52 +0200, phcoder wrote:
> >> 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>
> > 
> 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.

-- 
Regards,
Pavel Roskin



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-04-06 16:20               ` Pavel Roskin
@ 2009-04-06 16:25                 ` phcoder
  2009-04-06 16:33                   ` Pavel Roskin
  0 siblings, 1 reply; 15+ messages in thread
From: phcoder @ 2009-04-06 16:25 UTC (permalink / raw)
  To: The development of GRUB 2

Pavel Roskin wrote:
> On Mon, 2009-04-06 at 17:56 +0200, phcoder wrote:
>> Pavel Roskin wrote:
>>> On Mon, 2009-04-06 at 11:52 +0200, phcoder wrote:
>>>> 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>
>>>
>> 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

-- 

Regards
Vladimir 'phcoder' Serbinenko



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-04-06 16:25                 ` phcoder
@ 2009-04-06 16:33                   ` Pavel Roskin
  2009-04-08  9:35                     ` phcoder
  0 siblings, 1 reply; 15+ messages in thread
From: Pavel Roskin @ 2009-04-06 16:33 UTC (permalink / raw)
  To: The development of GRUB 2

On Mon, 2009-04-06 at 18:25 +0200, phcoder wrote:

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

-- 
Regards,
Pavel Roskin



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-04-06 16:33                   ` Pavel Roskin
@ 2009-04-08  9:35                     ` phcoder
  2009-04-08 20:24                       ` Pavel Roskin
  0 siblings, 1 reply; 15+ messages in thread
From: phcoder @ 2009-04-08  9:35 UTC (permalink / raw)
  To: The development of GRUB 2

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

Is this what you mean?
Pavel Roskin wrote:
> On Mon, 2009-04-06 at 18:25 +0200, phcoder wrote:
> 
>> 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.
> 


-- 

Regards
Vladimir 'phcoder' Serbinenko

[-- Attachment #2: parttoolhelp.diff --]
[-- Type: text/x-diff, Size: 1700 bytes --]

diff --git a/ChangeLog b/ChangeLog
index c679982..20c1804 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-04-08  Vladimir Serbinenko  <phcoder@gmail.com>
+	
+	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  <davem@davemloft.net>
 
 	* kern/sparc64/dl.c (grub_arch_dl_relocate_symbols): Add
diff --git a/commands/parttool.c b/commands/parttool.c
index 6eec13b..24bdcce 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, 
@@ -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)

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-04-08  9:35                     ` phcoder
@ 2009-04-08 20:24                       ` Pavel Roskin
  2009-04-17 11:12                         ` phcoder
  0 siblings, 1 reply; 15+ messages in thread
From: Pavel Roskin @ 2009-04-08 20:24 UTC (permalink / raw)
  To: The development of GRUB 2

On Wed, 2009-04-08 at 11:35 +0200, phcoder wrote:
> Is this what you mean?

Yes.

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

-- 
Regards,
Pavel Roskin



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-04-08 20:24                       ` Pavel Roskin
@ 2009-04-17 11:12                         ` phcoder
  2009-04-25 12:21                           ` Vladimir Serbinenko
  0 siblings, 1 reply; 15+ messages in thread
From: phcoder @ 2009-04-17 11:12 UTC (permalink / raw)
  To: The development of GRUB 2

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

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

[-- Attachment #2: parttoolimp.diff --]
[-- Type: text/x-diff, Size: 11943 bytes --]

diff --git a/ChangeLog b/ChangeLog
index 0c50854..60aa9e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2009-04-17  Vladimir Serbinenko  <phcoder@gmail.com>
+	
+	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  <bean123ch@gmail.com>
 
 	* 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, 

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] parttool
  2009-04-17 11:12                         ` phcoder
@ 2009-04-25 12:21                           ` Vladimir Serbinenko
  0 siblings, 0 replies; 15+ messages in thread
From: Vladimir Serbinenko @ 2009-04-25 12:21 UTC (permalink / raw)
  To: The development of GRUB 2

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

committed

On Fri, Apr 17, 2009 at 1:12 PM, phcoder <phcoder@gmail.com> wrote:

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

[-- Attachment #2: Type: text/html, Size: 2920 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2009-04-25 12:21 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-04 21:15 [PATCH] parttool phcoder
2009-03-10 17:45 ` phcoder
2009-03-20 19:33   ` phcoder
2009-04-04  9:22     ` phcoder
2009-04-05 14:48       ` Yoshinori K. Okuji
2009-04-06  9:52         ` phcoder
2009-04-06 15:53           ` Pavel Roskin
2009-04-06 15:56             ` phcoder
2009-04-06 16:20               ` Pavel Roskin
2009-04-06 16:25                 ` phcoder
2009-04-06 16:33                   ` Pavel Roskin
2009-04-08  9:35                     ` phcoder
2009-04-08 20:24                       ` Pavel Roskin
2009-04-17 11:12                         ` phcoder
2009-04-25 12:21                           ` Vladimir Serbinenko

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.