All of lore.kernel.org
 help / color / mirror / Atom feed
From: phcoder <phcoder@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] parttool
Date: Fri, 17 Apr 2009 13:12:11 +0200	[thread overview]
Message-ID: <49E8640B.50407@gmail.com> (raw)
In-Reply-To: <1239222271.2948.22.camel@mj>

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

  reply	other threads:[~2009-04-17 11:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2009-04-25 12:21                           ` Vladimir Serbinenko

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=49E8640B.50407@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

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

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