From c2fbbb7907b589374f186ad57a9b3beba8578632 Mon Sep 17 00:00:00 2001 From: Bastian Blank Date: Thu, 9 Feb 2006 17:22:18 +0000 Subject: [kpartx] Add support for mac partition table Signed-off-by: Bastian Blank --- kpartx/Makefile | 4 ++-- kpartx/byteorder.h | 6 ++++++ kpartx/kpartx.c | 1 + kpartx/kpartx.h | 1 + kpartx/mac.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ kpartx/mac.h | 30 ++++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 kpartx/mac.c create mode 100644 kpartx/mac.h (limited to 'kpartx') diff --git a/kpartx/Makefile b/kpartx/Makefile index 1b68ca6..bf6e6c1 100644 --- a/kpartx/Makefile +++ b/kpartx/Makefile @@ -10,12 +10,12 @@ CFLAGS += -I. -D_LARGEFILE64_SOURCE ifeq ($(strip $(BUILD)),klibc) OBJS = bsd.o dos.o kpartx.o solaris.o unixware.o gpt.o crc32.o \ - lopart.o xstrncpy.o devmapper.o dasd.o \ + lopart.o xstrncpy.o devmapper.o dasd.o mac.o \ $(MULTIPATHLIB)-$(BUILD).a $(libdm) else LDFLAGS = -ldevmapper OBJS = bsd.o dos.o kpartx.o solaris.o unixware.o dasd.o \ - gpt.o crc32.o lopart.o xstrncpy.o devmapper.o + gpt.o mac.o crc32.o lopart.o xstrncpy.o devmapper.o endif EXEC = kpartx diff --git a/kpartx/byteorder.h b/kpartx/byteorder.h index 6d2588b..21962d6 100644 --- a/kpartx/byteorder.h +++ b/kpartx/byteorder.h @@ -9,9 +9,15 @@ #endif #if BYTE_ORDER == LITTLE_ENDIAN +# define le16_to_cpu(x) (x) +# define be16_to_cpu(x) bswap_16(x) # define le32_to_cpu(x) (x) +# define be32_to_cpu(x) bswap_32(x) #elif BYTE_ORDER == BIG_ENDIAN +# define le16_to_cpu(x) bswap_16(x) +# define be16_to_cpu(x) (x) # define le32_to_cpu(x) bswap_32(x) +# define be32_to_cpu(x) (x) #else # error unsupported #endif diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c index c1c2fae..2198302 100644 --- a/kpartx/kpartx.c +++ b/kpartx/kpartx.c @@ -78,6 +78,7 @@ initpts(void) addpts("solaris", read_solaris_pt); addpts("unixware", read_unixware_pt); addpts("dasd", read_dasd_pt); + addpts("mac", read_mac_pt); } static char short_opts[] = "ladgvnp:t:"; diff --git a/kpartx/kpartx.h b/kpartx/kpartx.h index 9819268..6a715de 100644 --- a/kpartx/kpartx.h +++ b/kpartx/kpartx.h @@ -32,6 +32,7 @@ extern ptreader read_solaris_pt; extern ptreader read_unixware_pt; extern ptreader read_gpt_pt; extern ptreader read_dasd_pt; +extern ptreader read_mac_pt; char *getblock(int fd, unsigned int secnr); diff --git a/kpartx/mac.c b/kpartx/mac.c new file mode 100644 index 0000000..5432e67 --- /dev/null +++ b/kpartx/mac.c @@ -0,0 +1,47 @@ +#include "kpartx.h" +#include "byteorder.h" +#include +#include +#include "mac.h" + +int +read_mac_pt(int fd, struct slice all, struct slice *sp, int ns) { + struct mac_driver_desc *md; + struct mac_partition *part; + unsigned secsize; + char *data; + int blk, blocks_in_map; + int n = 0; + + md = (struct mac_driver_desc *) getblock(fd, 0); + if (md == NULL) + return -1; + + if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) + return -1; + + secsize = be16_to_cpu(md->block_size); + data = getblock(fd, secsize/512); + if (!data) + return -1; + part = (struct mac_partition *) (data + secsize%512); + + if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) + return -1; + + blocks_in_map = be32_to_cpu(part->map_count); + for (blk = 1; blk <= blocks_in_map && blk <= ns; ++blk, ++n) { + int pos = blk * secsize; + data = getblock(fd, pos/512); + if (!data) + return -1; + + part = (struct mac_partition *) (data + pos%512); + if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) + break; + + sp[n].start = be32_to_cpu(part->start_block) * (secsize/512); + sp[n].size = be32_to_cpu(part->block_count) * (secsize/512); + } + return n; +} diff --git a/kpartx/mac.h b/kpartx/mac.h new file mode 100644 index 0000000..3c712ba --- /dev/null +++ b/kpartx/mac.h @@ -0,0 +1,30 @@ +#ifndef MAC_H +#define MAC_H + +#include + +#define MAC_PARTITION_MAGIC 0x504d + +/* type field value for A/UX or other Unix partitions */ +#define APPLE_AUX_TYPE "Apple_UNIX_SVR2" + +struct mac_partition { + uint16_t signature; /* expected to be MAC_PARTITION_MAGIC */ + uint16_t res1; + uint32_t map_count; /* # blocks in partition map */ + uint32_t start_block; /* absolute starting block # of partition */ + uint32_t block_count; /* number of blocks in partition */ + /* there is more stuff after this that we don't need */ +}; + +#define MAC_DRIVER_MAGIC 0x4552 + +/* Driver descriptor structure, in block 0 */ +struct mac_driver_desc { + uint16_t signature; /* expected to be MAC_DRIVER_MAGIC */ + uint16_t block_size; + uint32_t block_count; + /* ... more stuff */ +}; + +#endif -- cgit v1.2.3