]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: support pseudo PARTUUID= for MBR
authorKarel Zak <kzak@redhat.com>
Thu, 13 Jun 2013 13:11:04 +0000 (15:11 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 13 Jun 2013 13:16:56 +0000 (15:16 +0200)
  # blkid /dev/sdb1
  dev/sdb1: TYPE="ext2" PARTUUID="54e743a7-01"

the PARTUUID is generated from MBR Id and partition number. The same
method uses Linux kernel for root=PARTUUID= on systems with MBR.

Note that the patch also removes 0x prefix from PTUUID.

Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/partitions/dos.c
libblkid/src/partitions/partitions.c
libblkid/src/partitions/partitions.h

index a9c79c34ad4461d341167da136dfafa3d73b664e..a8c6276a7f89f8fa20d67ac97db3901fa925a482 100644 (file)
@@ -103,6 +103,7 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab,
 
                        blkid_partition_set_type(par, p->sys_type);
                        blkid_partition_set_flags(par, p->boot_ind);
+                       blkid_partition_gen_uuid(par);
                        ct_nodata = 0;
                }
                /* The first nested ext.partition should be a link to the next
@@ -185,7 +186,7 @@ static int probe_dos_pt(blkid_probe pr,
 
        id = dos_parttable_id(data);
        if (id)
-               snprintf(idstr, sizeof(idstr), "0x%08x", id);
+               snprintf(idstr, sizeof(idstr), "%08x", id);
 
        /*
         * Well, all checks pass, it's MS-DOS partiton table
@@ -232,6 +233,7 @@ static int probe_dos_pt(blkid_probe pr,
 
                blkid_partition_set_type(par, p->sys_type);
                blkid_partition_set_flags(par, p->boot_ind);
+               blkid_partition_gen_uuid(par);
        }
 
        /* Linux uses partition numbers greater than 4
index 46631032af526dd292d3cc6c858f53f29e582802..22373f8a91f32e5d2d4028fce73f0979a39aa929 100644 (file)
@@ -1281,6 +1281,16 @@ int blkid_partition_set_uuid(blkid_partition par, const unsigned char *uuid)
        return 0;
 }
 
+int blkid_partition_gen_uuid(blkid_partition par)
+{
+       if (!par || !par->tab || !*par->tab->id)
+               return -1;
+
+       snprintf(par->uuid, sizeof(par->uuid), "%s-%02x",
+                       par->tab->id, par->partno);
+       return 0;
+}
+
 /**
  * blkid_partition_get_name:
  * @par: partition
index 44423d9ccfe3e38890f738970140f36fb003011b..f7d1ba3d140d25bc0fc0739fa109885747539d07 100644 (file)
@@ -40,6 +40,7 @@ extern int blkid_partition_set_utf8name(blkid_partition par,
 
 extern int blkid_partition_set_uuid(blkid_partition par,
                const unsigned char *uuid);
+extern int blkid_partition_gen_uuid(blkid_partition par);
 
 extern int blkid_partition_set_type(blkid_partition par, int type);