/src/util-linux/libblkid/src/partitions/ultrix.c
Line | Count | Source |
1 | | /* |
2 | | * uktrix partition parsing code |
3 | | * |
4 | | * Copyright (C) 2010 Karel Zak <kzak@redhat.com> |
5 | | * |
6 | | * This file may be redistributed under the terms of the |
7 | | * GNU Lesser General Public License. |
8 | | * |
9 | | */ |
10 | | #include <stdio.h> |
11 | | #include <string.h> |
12 | | #include <stdlib.h> |
13 | | #include <stdint.h> |
14 | | |
15 | | #include "partitions.h" |
16 | | |
17 | 0 | #define ULTRIX_MAXPARTITIONS 8 |
18 | | |
19 | 10.5k | #define ULTRIX_MAGIC 0x032957 |
20 | 6 | #define ULTRIX_MAGIC_STR "\x02\x29\x57" |
21 | | |
22 | | /* sector with partition table */ |
23 | 5.27k | #define ULTRIX_SECTOR ((16384 - sizeof(struct ultrix_disklabel)) >> 9) |
24 | | /* position of partition table within ULTRIX_SECTOR */ |
25 | 5.27k | #define ULTRIX_OFFSET (512 - sizeof(struct ultrix_disklabel)) |
26 | | |
27 | | struct ultrix_disklabel { |
28 | | int32_t pt_magic; /* magic no. indicating part. info exits */ |
29 | | int32_t pt_valid; /* set by driver if pt is current */ |
30 | | struct pt_info { |
31 | | int32_t pi_nblocks; /* no. of sectors */ |
32 | | uint32_t pi_blkoff; /* block offset for start */ |
33 | | } pt_part[ULTRIX_MAXPARTITIONS]; |
34 | | } __attribute__((packed)); |
35 | | |
36 | | |
37 | | static int probe_ultrix_pt(blkid_probe pr, |
38 | | const struct blkid_idmag *mag __attribute__((__unused__))) |
39 | 5.26k | { |
40 | 5.26k | const unsigned char *data; |
41 | 5.26k | const struct ultrix_disklabel *l; |
42 | 5.26k | blkid_parttable tab = NULL; |
43 | 5.26k | blkid_partlist ls; |
44 | 5.26k | int i; |
45 | | |
46 | 5.26k | data = blkid_probe_get_sector(pr, ULTRIX_SECTOR); |
47 | 5.26k | if (!data) { |
48 | 0 | if (errno) |
49 | 0 | return -errno; |
50 | 0 | goto nothing; |
51 | 0 | } |
52 | | |
53 | 5.26k | l = (const struct ultrix_disklabel *) (data + ULTRIX_OFFSET); |
54 | | |
55 | 5.26k | if (l->pt_magic != ULTRIX_MAGIC || l->pt_valid != 1) |
56 | 5.26k | goto nothing; |
57 | | |
58 | 3 | if (blkid_probe_set_magic(pr, (ULTRIX_SECTOR << 9) + ULTRIX_OFFSET, |
59 | 3 | sizeof(ULTRIX_MAGIC_STR) - 1, |
60 | 3 | (unsigned char *) ULTRIX_MAGIC_STR)) |
61 | 0 | goto err; |
62 | | |
63 | 3 | if (blkid_partitions_need_typeonly(pr)) |
64 | | /* caller does not ask for details about partitions */ |
65 | 3 | return BLKID_PROBE_OK; |
66 | | |
67 | 0 | ls = blkid_probe_get_partlist(pr); |
68 | 0 | if (!ls) |
69 | 0 | goto nothing; |
70 | | |
71 | 0 | tab = blkid_partlist_new_parttable(ls, "ultrix", 0); |
72 | 0 | if (!tab) |
73 | 0 | goto err; |
74 | | |
75 | 0 | for (i = 0; i < ULTRIX_MAXPARTITIONS; i++) { |
76 | 0 | if (!l->pt_part[i].pi_nblocks) |
77 | 0 | blkid_partlist_increment_partno(ls); |
78 | 0 | else { |
79 | 0 | if (!blkid_partlist_add_partition(ls, tab, |
80 | 0 | l->pt_part[i].pi_blkoff, |
81 | 0 | l->pt_part[i].pi_nblocks)) |
82 | 0 | goto err; |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | 0 | return BLKID_PROBE_OK; |
87 | 5.26k | nothing: |
88 | 5.26k | return BLKID_PROBE_NONE; |
89 | 0 | err: |
90 | | return -ENOMEM; |
91 | 0 | } |
92 | | |
93 | | const struct blkid_idinfo ultrix_pt_idinfo = |
94 | | { |
95 | | .name = "ultrix", |
96 | | .probefunc = probe_ultrix_pt, |
97 | | .magics = BLKID_NONE_MAGIC |
98 | | }; |
99 | | |