Blame kpartx/mac.c

Packit Service 0af388
#include "kpartx.h"
Packit Service 0af388
#include "byteorder.h"
Packit Service 0af388
#include <stdio.h>
Packit Service 0af388
#include <string.h>
Packit Service 0af388
#include "mac.h"
Packit Service 0af388
Packit Service 0af388
int
Packit Service 0af388
read_mac_pt(int fd, __attribute__((unused)) struct slice all,
Packit Service 0af388
	    struct slice *sp, unsigned int ns) {
Packit Service 0af388
	struct mac_driver_desc *md;
Packit Service 0af388
	struct mac_partition *part;
Packit Service 0af388
	unsigned secsize;
Packit Service 0af388
	char *data;
Packit Service 0af388
	unsigned int blk, blocks_in_map;
Packit Service 0af388
	int n = 0;
Packit Service 0af388
Packit Service 0af388
	md = (struct mac_driver_desc *) getblock(fd, 0);
Packit Service 0af388
	if (md == NULL)
Packit Service 0af388
		return -1;
Packit Service 0af388
Packit Service 0af388
	if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC)
Packit Service 0af388
		return -1;
Packit Service 0af388
Packit Service 0af388
	secsize = be16_to_cpu(md->block_size);
Packit Service 0af388
	data = getblock(fd, secsize/512);
Packit Service 0af388
	if (!data)
Packit Service 0af388
		return -1;
Packit Service 0af388
	part = (struct mac_partition *) (data + secsize%512);
Packit Service 0af388
Packit Service 0af388
	if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
Packit Service 0af388
		return -1;
Packit Service 0af388
Packit Service 0af388
	blocks_in_map = be32_to_cpu(part->map_count);
Packit Service 0af388
	for (blk = 1; blk <= blocks_in_map && blk <= ns; ++blk, ++n) {
Packit Service 0af388
		int pos = blk * secsize;
Packit Service 0af388
		data = getblock(fd, pos/512);
Packit Service 0af388
		if (!data)
Packit Service 0af388
			return -1;
Packit Service 0af388
Packit Service 0af388
		part = (struct mac_partition *) (data + pos%512);
Packit Service 0af388
		if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
Packit Service 0af388
			break;
Packit Service 0af388
Packit Service 0af388
		sp[n].start = be32_to_cpu(part->start_block) * (secsize/512);
Packit Service 0af388
		sp[n].size = be32_to_cpu(part->block_count) * (secsize/512);
Packit Service 0af388
	}
Packit Service 0af388
	return n;
Packit Service 0af388
}