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

index 3901173a330c9bda0c1c9544c8d4064a1729641f..b2e7af5d74bffaad9601e746dcd410b4f631a883 100644 (file)
@@ -12,4 +12,5 @@ libblkid_partitions_la_SOURCES = partitions.c \
                                bsd.c \
                                unixware.c \
                                solaris_x86.c \
-                               sun.c
+                               sun.c \
+                               sgi.c
index 130f21a43f9356c94c7f72f27cba3c0757add0a5..88cfae6efa6c20fc22c9f39e13f606965ee2eb20 100644 (file)
@@ -103,6 +103,7 @@ static void partitions_free_data(blkid_probe pr, void *data);
 static const struct blkid_idinfo *idinfos[] =
 {
        &aix_pt_idinfo,
+       &sgi_pt_idinfo,
        &sun_pt_idinfo,
        &bsd_pt_idinfo,
        &unixware_pt_idinfo,
index ba8356e9543df88a87fefa682f862b3e57a74de1..685e228feb4b9202e8a833f1c56974aced899c45 100644 (file)
@@ -40,5 +40,6 @@ extern const struct blkid_idinfo bsd_pt_idinfo;
 extern const struct blkid_idinfo unixware_pt_idinfo;
 extern const struct blkid_idinfo solaris_x86_pt_idinfo;
 extern const struct blkid_idinfo sun_pt_idinfo;
+extern const struct blkid_idinfo sgi_pt_idinfo;
 
 #endif /* BLKID_PARTITIONS_H */
diff --git a/shlibs/blkid/src/partitions/sgi.c b/shlibs/blkid/src/partitions/sgi.c
new file mode 100644 (file)
index 0000000..5ebf9de
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * sgi 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"
+
+#define SGI_MAXPARTITIONS      16
+
+/* partition type */
+#define SGI_TYPE_VOLHDR                0x00
+#define SGI_TYPE_VOLULME       0x06    /* entire disk */
+
+struct sgi_device_parameter {
+       unsigned char skew;
+       unsigned char gap1;
+       unsigned char gap2;
+       unsigned char sparecyl;
+
+       uint16_t pcylcount;
+       uint16_t head_vol0;
+       uint16_t ntrks;         /* tracks in cyl 0 or vol 0 */
+
+       unsigned char cmd_tag_queue_depth;
+       unsigned char unused0;
+
+       uint16_t unused1;
+       uint16_t nsect;         /* sectors/tracks in cyl 0 or vol 0 */
+       uint16_t bytes;
+       uint16_t ilfact;
+       uint32_t flags;         /* controller flags */
+       uint32_t datarate;
+       uint32_t retries_on_error;
+       uint32_t ms_per_word;
+       uint16_t xylogics_gap1;
+       uint16_t xylogics_syncdelay;
+       uint16_t xylogics_readdelay;
+       uint16_t xylogics_gap2;
+       uint16_t xylogics_readgate;
+       uint16_t xylogics_writecont;
+};
+
+struct sgi_disklabel {
+       uint32_t magic;                 /* magic number */
+       uint16_t root_part_num;         /* # root partition */
+       uint16_t swap_part_num;         /* # swap partition */
+       unsigned char boot_file[16];    /* name of boot file */
+
+       struct sgi_device_parameter     devparam;       /* not used now */
+
+       struct sgi_volume {
+               unsigned char name[8];  /* name of volume */
+               uint32_t block_num;     /* logical block number */
+               uint32_t num_bytes;     /* how big, in bytes */
+       } volume[15];
+
+       struct sgi_partition {
+               uint32_t num_blocks;    /* size in logical blocks */
+               uint32_t first_block;   /* first logical block */
+               uint32_t type;          /* type of this partition */
+       } partitions[SGI_MAXPARTITIONS];
+
+       /* checksum is the 32bit 2's complement sum of the disklabel */
+       uint32_t csum;                  /* disk label checksum */
+       uint32_t padding;               /* padding */
+};
+
+static uint32_t count_checksum(struct sgi_disklabel *label)
+{
+       int i;
+       uint32_t *ptr = (uint32_t *) label;
+       uint32_t sum = 0;
+
+       i = sizeof(*label) / sizeof(*ptr);
+
+       while (i--)
+               sum += be32_to_cpu(ptr[i]);
+
+       return sum;
+}
+
+
+static int probe_sgi_pt(blkid_probe pr, const struct blkid_idmag *mag)
+{
+       struct sgi_disklabel *l;
+       struct sgi_partition *p;
+       blkid_parttable tab = NULL;
+       blkid_partlist ls;
+       int i;
+
+       l = (struct sgi_disklabel *) blkid_probe_get_sector(pr, 0);
+       if (!l)
+               goto nothing;
+
+       if (count_checksum(l)) {
+               DBG(DEBUG_LOWPROBE, printf(
+                       "detected corrupted sgi disk label -- ignore\n"));
+               goto nothing;
+       }
+
+       if (blkid_partitions_need_typeonly(pr))
+               /* caller does not ask for details about partitions */
+               return 0;
+
+       ls = blkid_probe_get_partlist(pr);
+       if (!ls)
+               goto err;
+
+       tab = blkid_partlist_new_parttable(ls, "sgi", 0);
+       if (!tab)
+               goto err;
+
+       for(i = 0, p = &l->partitions[0]; i < SGI_MAXPARTITIONS; i++, p++) {
+               uint32_t size = be32_to_cpu(p->num_blocks);
+               uint32_t start = be32_to_cpu(p->first_block);
+               uint32_t type = be32_to_cpu(p->type);
+
+               if (size == 0 || type == SGI_TYPE_VOLULME ||
+                                type == SGI_TYPE_VOLHDR)
+                       continue;
+
+               if (!blkid_partlist_add_partition(ls, tab, type, start, size))
+                       goto err;
+       }
+
+       return 0;
+
+nothing:
+       return 1;
+err:
+       return -1;
+}
+
+const struct blkid_idinfo sgi_pt_idinfo =
+{
+       .name           = "sgi",
+       .probefunc      = probe_sgi_pt,
+       .magics         =
+       {
+               { .magic = "\x0B\xE5\xA9\x41", .len = 4 },
+               { NULL }
+       }
+};
+