File: mac.c

package info (click to toggle)
multipath-tools 0.14.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,088 kB
  • sloc: ansic: 64,885; perl: 1,622; makefile: 742; sh: 732; pascal: 155
file content (48 lines) | stat: -rw-r--r-- 1,184 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "kpartx.h"
#include "byteorder.h"
#include <stdio.h>
#include <string.h>
#include "mac.h"

int
read_mac_pt(int fd, __attribute__((unused)) struct slice all,
	    struct slice *sp, unsigned int ns) {
	struct mac_driver_desc *md;
	struct mac_partition *part;
	unsigned secsize;
	char *data;
	unsigned 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;
}