]> err.no Git - util-linux/commitdiff
libblkid: add MINIX partitions support
authorKarel Zak <kzak@redhat.com>
Wed, 16 Sep 2009 14:12:29 +0000 (16:12 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 16 Sep 2009 14:12:29 +0000 (16:12 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/partitions/Makefile.am
shlibs/blkid/src/partitions/dos.c
shlibs/blkid/src/partitions/minix.c [new file with mode: 0644]
shlibs/blkid/src/partitions/partitions.c
shlibs/blkid/src/partitions/partitions.h

index 906ba68c7c66dec22e4e6683352c40874d9da979..30ce0ee353926229749f8e888855ed09e78b49b9 100644 (file)
@@ -16,4 +16,5 @@ libblkid_partitions_la_SOURCES = partitions.c \
                                sgi.c \
                                mac.c \
                                dos.c \
-                               dos.h
+                               dos.h \
+                               minix.c
index d03e18e6530cee10d723217d4c23578c9346dc0e..21728a5ae6622b301b8d688d5e300e25fbc25969 100644 (file)
@@ -26,6 +26,7 @@ static const struct dos_subtypes {
        { BLKID_OPENBSD_PARTITION, &bsd_pt_idinfo },
        { BLKID_UNIXWARE_PARTITION, &unixware_pt_idinfo },
        { BLKID_SOLARIS_X86_PARTITION, &solaris_x86_pt_idinfo },
+       { BLKID_MINIX_PARTITION, &minix_pt_idinfo }
 };
 
 static inline int is_extended(struct dos_partition *p)
diff --git a/shlibs/blkid/src/partitions/minix.c b/shlibs/blkid/src/partitions/minix.c
new file mode 100644 (file)
index 0000000..e2f9140
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Minix partition parsing code
+ *
+ * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "partitions.h"
+#include "dos.h"
+
+/*
+ * Minix subpartitions are always within primary dos partition.
+ */
+#define MINIX_MAXPARTITIONS 4
+
+static int probe_minix_pt(blkid_probe pr, const struct blkid_idmag *mag)
+{
+       struct dos_partition *p;
+       blkid_parttable tab = NULL;
+       blkid_partition parent;
+       blkid_partlist ls;
+       unsigned char *data;
+       int i;
+
+       data = blkid_probe_get_sector(pr, 0);
+       if (!data)
+               goto nothing;
+
+       ls = blkid_probe_get_partlist(pr);
+       if (!ls)
+               goto err;
+
+       /* Parent is required, because Minix uses the same PT as DOS and
+        * difference is only in primary partition (parent) type.
+        */
+       parent = blkid_partlist_get_parent(ls);
+       if (!parent)
+               goto nothing;
+
+       if (blkid_partition_get_type(parent) != BLKID_MINIX_PARTITION)
+               goto nothing;
+
+       if (blkid_partitions_need_typeonly(pr))
+               /* caller does not ask for details about partitions */
+               return 0;
+
+       p = (struct dos_partition *) (data + BLKID_MSDOS_PT_OFFSET);
+
+       tab = blkid_partlist_new_parttable(ls, "minix", BLKID_MSDOS_PT_OFFSET);
+       if (!tab)
+               goto err;
+
+       for (i = 0; i < MINIX_MAXPARTITIONS; i++, p++) {
+               uint32_t start, size;
+
+               if (p->sys_type != BLKID_MINIX_PARTITION)
+                       continue;
+
+               start = dos_partition_start(p);
+               size = dos_partition_size(p);
+
+               if (parent && !blkid_is_nested_dimension(parent, start, size)) {
+                       DBG(DEBUG_LOWPROBE, printf(
+                               "WARNING: minix partition (%d) overflow "
+                               "detected, ignore\n", i));
+                       continue;
+               }
+
+               if (!blkid_partlist_add_partition(ls, tab,
+                                       p->sys_type, start, size))
+                       goto err;
+       }
+
+       return 0;
+
+nothing:
+       return 1;
+err:
+       return -1;
+}
+
+/* same as DOS */
+const struct blkid_idinfo minix_pt_idinfo =
+{
+       .name           = "minix",
+       .probefunc      = probe_minix_pt,
+       .magics         =
+       {
+               { .magic = "\x55\xAA", .len = 2, .sboff = 510 },
+               { NULL }
+       }
+};
+
index 064ec69a88c70d5b2615fd8203a689dba0d46fe3..0f74d5a0c4752940d8ea0be008da6e6922192a65 100644 (file)
@@ -109,7 +109,8 @@ static const struct blkid_idinfo *idinfos[] =
        &mac_pt_idinfo,
        &bsd_pt_idinfo,
        &unixware_pt_idinfo,
-       &solaris_x86_pt_idinfo
+       &solaris_x86_pt_idinfo,
+       &minix_pt_idinfo
 };
 
 /*
index 205311a5f874acec25ac5058608995a975e0866b..668f8e931ce8964d10a248412b98c3a97eb240cf 100644 (file)
@@ -43,5 +43,6 @@ extern const struct blkid_idinfo sun_pt_idinfo;
 extern const struct blkid_idinfo sgi_pt_idinfo;
 extern const struct blkid_idinfo mac_pt_idinfo;
 extern const struct blkid_idinfo dos_pt_idinfo;
+extern const struct blkid_idinfo minix_pt_idinfo;
 
 #endif /* BLKID_PARTITIONS_H */