Am Freitag, den 01.08.2008, 15:12 +0200 schrieb Robert Millan:

> This looks fine, but I'd suggest to avoid hardcoding numbers when possible.  
> So
> if you're adding 5 because that's the size of "/dev/", I think it's a good 
> idea
> to use sizeof("/dev/")-1, and so on.  This way the code is much easier to
> understand IMHO.
> 
> (yes, I know the existing code above yours doesn't do this, but i think it's
> a good idea to push for higher quality standards anyway ;-))
> 

Attached are now 2 patches for my added code and the one above.
I personally prefer the strcpy one, there's no need to use memcpy, it
should never happen that the /dev/md* devices contain a ASCII NUL
Maybe there's a way to make it even better so please comment all of you
grub-devels :)
Index: util/getroot.c
===================================================================
--- util/getroot.c	(Revision 1757)
+++ util/getroot.c	(Arbeitskopie)
@@ -457,9 +457,15 @@
 	}
       else if (os_dev[7] >= '0' && os_dev[7] <= '9')
 	{
-	  memcpy (grub_dev, os_dev + 5, 7);
+	  memcpy (grub_dev, os_dev + sizeof("/dev/") -1, 7);
 	  grub_dev[7] = '\0';
 	}
+      else if (os_dev[7] == '/' && os_dev[8] >= '0' && os_dev[8] <= '9')
+	{
+	  memcpy (grub_dev, "md", sizeof("md") -1);
+	  memcpy (grub_dev + sizeof ("md") -1, os_dev + sizeof("/dev/md/") -1, 5);
+	  grub_dev[7] = '\0';
+	}
       else
 	grub_util_error ("Unknown kind of RAID device `%s'", os_dev);
 
Index: util/getroot.c
===================================================================
--- util/getroot.c	(Revision 1757)
+++ util/getroot.c	(Arbeitskopie)
@@ -457,9 +457,16 @@
 	}
       else if (os_dev[7] >= '0' && os_dev[7] <= '9')
 	{
-	  memcpy (grub_dev, os_dev + 5, 7);
+	  strcpy (grub_dev,"md");
+	  strncpy (grub_dev, os_dev + sizeof("/dev/md") -1,5);
 	  grub_dev[7] = '\0';
 	}
+      else if (os_dev[7] == '/' && os_dev[8] >= '0' && os_dev[8] <= '9')
+	{
+	  strcpy (grub_dev,"md");
+	  strncpy (grub_dev + sizeof ("md") -1, os_dev + sizeof("/dev/md/") -1, 5);
+	  grub_dev[7] = '\0';
+	}
       else
 	grub_util_error ("Unknown kind of RAID device `%s'", os_dev);
 
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to