]> err.no Git - util-linux/commitdiff
libblkid: add blkid_partition_get_type_string()
authorKarel Zak <kzak@redhat.com>
Thu, 17 Sep 2009 15:01:19 +0000 (17:01 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 17 Sep 2009 15:01:19 +0000 (17:01 +0200)
.. because for example Mac and GPT don't use numbers, but strings or
UUIDs as partition type identifier.

Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/docs/libblkid-sections.txt
shlibs/blkid/samples/partitions.c
shlibs/blkid/src/blkid.h
shlibs/blkid/src/blkid.sym
shlibs/blkid/src/partitions/gpt.c
shlibs/blkid/src/partitions/mac.c
shlibs/blkid/src/partitions/partitions.c
shlibs/blkid/src/partitions/partitions.h
tests/expected/blkid/lowprobe-pt-gpt

index 4d98b160c15edb8bf0007930ec8ca35a9e5c2e39..af94607e22be112862bfd1f946216a5668a31563 100644 (file)
@@ -74,6 +74,7 @@ blkid_partition_get_size
 blkid_partition_get_start
 blkid_partition_get_table
 blkid_partition_get_type
+blkid_partition_get_type_string
 blkid_partition_get_uuid
 blkid_partition_is_extended
 blkid_partition_is_logical
index 78bcc0be55bf65bff3b4685e4ceee300d359e055..7e2648ab0e7c59d243c876b51a29322217f16f16 100644 (file)
@@ -83,6 +83,9 @@ int main(int argc, char *argv[])
                p = blkid_partition_get_uuid(par);
                if (p)
                        printf(" uuid='%s'", p);
+               p = blkid_partition_get_type_string(par);
+               if (p)
+                       printf(" type='%s'", p);
 
                putc('\n', stdout);
        }
index d0eb4b6a38b4a16edb8718fdea9eae458614ce21..057e31303d1d816b69820082fc6a395b8387ed57 100644 (file)
@@ -268,6 +268,7 @@ extern int blkid_partition_get_partno(blkid_partition par);
 extern blkid_loff_t blkid_partition_get_start(blkid_partition par);
 extern blkid_loff_t blkid_partition_get_size(blkid_partition par);
 extern int blkid_partition_get_type(blkid_partition par);
+extern const char *blkid_partition_get_type_string(blkid_partition par);
 extern int blkid_partition_is_logical(blkid_partition par);
 extern int blkid_partition_is_extended(blkid_partition par);
 extern int blkid_partition_is_primary(blkid_partition par);
index 89baf4832e49027bfb5327390c920286f18f7b17..8ac2081aa13fea20cb247fd593b0d8d717f537da 100644 (file)
@@ -80,6 +80,7 @@ global:
        blkid_partition_get_start;
        blkid_partition_get_table;
        blkid_partition_get_type;
+       blkid_partition_get_type_string;
        blkid_partition_get_uuid;
        blkid_partition_is_extended;
        blkid_partition_is_logical;
index b26dd6cd48bd0eedd9339422e9f1accc99a245f7..f2d54d741ceafaab08eee34d6d4c72ed6cc50885 100644 (file)
@@ -324,6 +324,9 @@ static int probe_gpt_pt(blkid_probe pr, const struct blkid_idmag *mag)
 
                blkid_partition_set_uuid(par,
                        (const unsigned char *) &e->unique_partition_guid);
+
+               blkid_partition_set_type_uuid(par,
+                       (const unsigned char *) &e->partition_type_guid);
        }
 
        return 0;
index 2d43d38b30c7eb13fe39aa11594f8b1be300033c..c51b11abab85f85468546644db906ee164137f24 100644 (file)
@@ -150,6 +150,9 @@ static int probe_mac_pt(blkid_probe pr, const struct blkid_idmag *mag)
 
                blkid_partition_set_name(par, (unsigned char *) p->name,
                                                sizeof(p->name));
+
+               blkid_partition_set_type_string(par, (unsigned char *) p->type,
+                                               sizeof(p->type));
        }
 
        return 0;
index b91e893cdad4acdae57212d143462d0bef9d8682..94d1556e9dcf57f63b08326ee2015ebcb24eeffb 100644 (file)
@@ -152,7 +152,9 @@ struct blkid_struct_parttable {
 struct blkid_struct_partition {
        blkid_loff_t    start;          /* begin of the partition */
        blkid_loff_t    size;           /* size of the partitions */
+
        int             type;           /* partition type */
+       char            typestr[37];    /* partition type string (GPT and Mac) */
 
        int             partno;         /* partition number */
        char            uuid[37];       /* UUID (when supported by PT), e.g GPT */
@@ -850,26 +852,33 @@ int blkid_partition_is_logical(blkid_partition par)
        return partition_get_logical_type(par) == 'L' ? TRUE : FALSE;
 }
 
-int blkid_partition_set_name(blkid_partition par,
-               const unsigned char *name, size_t len)
+static void set_string(unsigned char *item, size_t max,
+                               const unsigned char *data, size_t len)
 {
        int i;
 
-       if (!par)
-               return -1;
-       if (len >= sizeof(par->name))
-               len = sizeof(par->name) - 1;
+       if (len >= max)
+               len = max - 1;
 
-       memcpy(par->name, name, len);
-       par->name[len] = '\0';
+       memcpy(item, data, len);
+       item[len] = '\0';
 
        /* remove trailing whitespace */
-       i = strlen((char *) par->name);
+       i = strlen((char *) item);
        while (i--) {
-               if (!isspace(par->name[i]))
+               if (!isspace(item[i]))
                        break;
        }
-       par->name[++i] = '\0';
+       item[++i] = '\0';
+}
+
+int blkid_partition_set_name(blkid_partition par,
+               const unsigned char *name, size_t len)
+{
+       if (!par)
+               return -1;
+
+       set_string(par->name, sizeof(par->name), name, len);
        return 0;
 }
 
@@ -973,9 +982,51 @@ blkid_loff_t blkid_partition_get_size(blkid_partition par)
  * blkid_partition_get_type:
  * @par: partition
  *
- * Returns: partition type (see BLKID_*_PARTITION in blkid_parttypes.h).
+ * Returns: partition type.
  */
 int blkid_partition_get_type(blkid_partition par)
 {
        return par ? par->type : 0;
 }
+
+/* Sets partition 'type' for PT where the type is defined by string rather
+ * than by number
+ */
+int blkid_partition_set_type_string(blkid_partition par,
+               const unsigned char *type, size_t len)
+{
+       if (!par)
+               return -1;
+
+       set_string((unsigned char *) par->typestr,
+                       sizeof(par->typestr), type, len);
+       return 0;
+}
+
+/* Sets partition 'type' for PT where the type is defined by UUIDrather
+ * than by number
+ */
+int blkid_partition_set_type_uuid(blkid_partition par, const unsigned char *uuid)
+{
+       if (!par)
+               return -1;
+
+       blkid_unparse_uuid(uuid, par->typestr, sizeof(par->typestr));
+       return 0;
+}
+
+/**
+ * blkid_partition_get_type_string:
+ * @par: partition
+ *
+ * The type string is supported by a small subset of partition tables (e.g Mac
+ * and EFI GPT).  Note that GPT uses type UUID and this function returns this
+ * UUID as string.
+ *
+ * Returns: partition type string or NULL.
+ */
+const char *blkid_partition_get_type_string(blkid_partition par)
+{
+       return par && *par->typestr ? par->typestr : NULL;
+}
+
index e1678b350411b524beb2705848a6e325bc2557ee..e017768a14504d9b30c3efd97ac44c364a4ef9e8 100644 (file)
@@ -32,6 +32,12 @@ 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_set_type_string(blkid_partition par,
+                const unsigned char *type, size_t len);
+
+extern int blkid_partition_set_type_uuid(blkid_partition par,
+               const unsigned char *uuid);
+
 /*
  * partition probers
  */
index e9be134e5d1a09a5ee76bba62300ede2d4625c7a..8588f83ed4d2ff5ce84ec3671fa17a9bed25df9f 100644 (file)
@@ -1,7 +1,7 @@
 size: 10485760, sector size: 512, PT: gpt, offset: 512
 ---
-#1:         34       2013  0x0 name='ThisIsName' uuid='bc10cf1d-7e63-524c-8203-087ae10a820b'
-#2:       2048       2047  0x0 name='ThisIsOtherName' uuid='963ad0a1-3872-c646-bbb3-789cbe173ec7'
-#3:       4096       2047  0x0 name='primary' uuid='6c1b10a7-8c46-df47-aff6-cd444d12af61'
-#4:       6144       2047  0x0 name='primary' uuid='0a95c4af-f1f0-dd4a-802c-5957133486d1'
-#5:       8192       2047  0x0 name='primary' uuid='87a7b00d-6bc1-8648-af3a-fbb97299677c'
+#1:         34       2013  0x0 name='ThisIsName' uuid='bc10cf1d-7e63-524c-8203-087ae10a820b' type='a2a0d0eb-e5b9-3344-87c0-68b6b72699c7'
+#2:       2048       2047  0x0 name='ThisIsOtherName' uuid='963ad0a1-3872-c646-bbb3-789cbe173ec7' type='a2a0d0eb-e5b9-3344-87c0-68b6b72699c7'
+#3:       4096       2047  0x0 name='primary' uuid='6c1b10a7-8c46-df47-aff6-cd444d12af61' type='a2a0d0eb-e5b9-3344-87c0-68b6b72699c7'
+#4:       6144       2047  0x0 name='primary' uuid='0a95c4af-f1f0-dd4a-802c-5957133486d1' type='a2a0d0eb-e5b9-3344-87c0-68b6b72699c7'
+#5:       8192       2047  0x0 name='primary' uuid='87a7b00d-6bc1-8648-af3a-fbb97299677c' type='a2a0d0eb-e5b9-3344-87c0-68b6b72699c7'