File: ps3.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 (73 lines) | stat: -rw-r--r-- 1,572 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "kpartx.h"
#include "byteorder.h"
#include <sys/types.h>
#include <string.h>

#define SECTOR_SIZE		512
#define MAX_ACL_ENTRIES		8
#define MAX_PARTITIONS		8

#define MAGIC1			0x0FACE0FFULL
#define MAGIC2			0xDEADFACEULL

struct p_acl_entry {
	u_int64_t laid;
	u_int64_t rights;
};

struct d_partition {
	u_int64_t p_start;
	u_int64_t p_size;
	struct p_acl_entry p_acl[MAX_ACL_ENTRIES];
};

struct disklabel {
	u_int8_t d_res1[16];
	u_int64_t d_magic1;
	u_int64_t d_magic2;
	u_int64_t d_res2;
	u_int64_t d_res3;
	struct d_partition d_partitions[MAX_PARTITIONS];
	u_int8_t d_pad[0x600 - MAX_PARTITIONS * sizeof(struct d_partition) - 0x30];
};

static int
read_disklabel(int fd, struct disklabel *label) {
	unsigned char *data;
	unsigned int i;

	for (i = 0; i < sizeof(struct disklabel) / SECTOR_SIZE; i++) {
		data = (unsigned char *) getblock(fd, i);
		if (!data)
			return 0;

		memcpy((unsigned char *) label + i * SECTOR_SIZE, data, SECTOR_SIZE);
	}

	return 1;
}

int
read_ps3_pt(int fd, __attribute__((unused)) struct slice all,
	    struct slice *sp, __attribute__((unused)) unsigned int ns) {
	struct disklabel label;
	int n = 0;
	int i;

	if (!read_disklabel(fd, &label))
		return -1;

	if ((be64_to_cpu(label.d_magic1) != MAGIC1) ||
	    (be64_to_cpu(label.d_magic2) != MAGIC2))
		return -1;

	for (i = 0; i < MAX_PARTITIONS; i++) {
		if (label.d_partitions[i].p_start && label.d_partitions[i].p_size) {
			sp[n].start =  be64_to_cpu(label.d_partitions[i].p_start);
			sp[n].size =  be64_to_cpu(label.d_partitions[i].p_size);
			n++;
		}
	}

	return n;
}