]> git.ozlabs.org Git - petitboot/commitdiff
discover/yaboot-parser: Handle 'partition=' directive override
authorNeelesh Gupta <neelegup@linux.vnet.ibm.com>
Thu, 29 Aug 2013 13:51:32 +0000 (19:21 +0530)
committerJeremy Kerr <jk@ozlabs.org>
Fri, 30 Aug 2013 01:29:09 +0000 (11:29 +1000)
In a yaboot conf file, we may see a device= directive that actually
specifies a partition (eg, sda1) rather than the underlying block device
(sda). If we then encounter a partition= directive, we don't handle the
resolution of the partition correctly, as we simply append the
partition number to the device= string.

This change implements a smarter handling of the partition= directive,
where we strip away any partition information from the device=
parameter first.

Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/yaboot-parser.c

index c0750fe1f227e08f4e17ccac674c7b4b2e8a89d9..22792d4a63b4007bcfc46c400ab88cf8b2adbbc4 100644 (file)
@@ -3,6 +3,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "log/log.h"
 #include "talloc/talloc.h"
 
 #include "log/log.h"
 #include "talloc/talloc.h"
@@ -53,9 +54,9 @@ static struct resource *create_yaboot_devpath_resource(
                const char *path)
 {
        struct discover_boot_option *opt = state->opt;
                const char *path)
 {
        struct discover_boot_option *opt = state->opt;
-       const char *dev, *part;
+       const char *dev, *part, *devpos;
        struct resource *res;
        struct resource *res;
-       char *devpath;
+       char *devpath, *devstr;
 
        dev = state->device;
        part = state->partition;
 
        dev = state->device;
        part = state->partition;
@@ -69,8 +70,19 @@ static struct resource *create_yaboot_devpath_resource(
                devpath = talloc_strdup(conf, path);
 
        } else if (dev && part) {
                devpath = talloc_strdup(conf, path);
 
        } else if (dev && part) {
-               devpath = talloc_asprintf(conf,
-                               "%s%s:%s", dev, part, path);
+               devpos = &dev[strlen(dev) - 1];
+               if (isdigit(*devpos)) {
+                       while (isdigit(*devpos))
+                               devpos--;
+
+                       devstr = talloc_strndup(conf, dev, devpos - dev + 1);
+                       devpath = talloc_asprintf(conf, "%s%s:%s", devstr,
+                                       part, path);
+                       talloc_free(devstr);
+               } else {
+                       devpath = talloc_asprintf(conf,
+                                       "%s%s:%s", dev, part, path);
+               }
        } else if (dev) {
                devpath = talloc_asprintf(conf, "%s:%s", dev, path);
        } else {
        } else if (dev) {
                devpath = talloc_asprintf(conf, "%s:%s", dev, path);
        } else {