From 0e72876572ecb01267857d30d52868a1112bbdc7 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 16 Sep 2009 16:07:16 +0200 Subject: [PATCH] libblkid: add SGI partitions support Signed-off-by: Karel Zak --- shlibs/blkid/src/partitions/Makefile.am | 3 +- shlibs/blkid/src/partitions/partitions.c | 1 + shlibs/blkid/src/partitions/partitions.h | 1 + shlibs/blkid/src/partitions/sgi.c | 153 +++++++++++++++++++++++ 4 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 shlibs/blkid/src/partitions/sgi.c diff --git a/shlibs/blkid/src/partitions/Makefile.am b/shlibs/blkid/src/partitions/Makefile.am index 3901173a..b2e7af5d 100644 --- a/shlibs/blkid/src/partitions/Makefile.am +++ b/shlibs/blkid/src/partitions/Makefile.am @@ -12,4 +12,5 @@ libblkid_partitions_la_SOURCES = partitions.c \ bsd.c \ unixware.c \ solaris_x86.c \ - sun.c + sun.c \ + sgi.c diff --git a/shlibs/blkid/src/partitions/partitions.c b/shlibs/blkid/src/partitions/partitions.c index 130f21a4..88cfae6e 100644 --- a/shlibs/blkid/src/partitions/partitions.c +++ b/shlibs/blkid/src/partitions/partitions.c @@ -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, diff --git a/shlibs/blkid/src/partitions/partitions.h b/shlibs/blkid/src/partitions/partitions.h index ba8356e9..685e228f 100644 --- a/shlibs/blkid/src/partitions/partitions.h +++ b/shlibs/blkid/src/partitions/partitions.h @@ -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 index 00000000..5ebf9ded --- /dev/null +++ b/shlibs/blkid/src/partitions/sgi.c @@ -0,0 +1,153 @@ +/* + * sgi partition parsing code + * + * Copyright (C) 2009 Karel Zak + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + * + */ +#include +#include +#include +#include + +#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 } + } +}; + -- 2.39.5