blob: 9c060be1df4a8c39038fece88f0b609c8482d519 [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
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#define ULTRIX_MAXPARTITIONS 8
18
19#define ULTRIX_MAGIC 0x032957
20#define ULTRIX_MAGIC_STR "\x02\x29\x57"
21
22/* sector with partition table */
23#define ULTRIX_SECTOR ((16384 - sizeof(struct ultrix_disklabel)) >> 9)
24/* position of partition table within ULTRIX_SECTOR */
25#define ULTRIX_OFFSET (512 - sizeof(struct ultrix_disklabel))
26
27struct 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
37static int probe_ultrix_pt(blkid_probe pr,
38 const struct blkid_idmag *mag __attribute__((__unused__)))
39{
40 unsigned char *data;
41 struct ultrix_disklabel *l;
42 blkid_parttable tab = NULL;
43 blkid_partlist ls;
44 int i;
45
46 data = blkid_probe_get_sector(pr, ULTRIX_SECTOR);
bigbiff7b4c7a62015-01-01 19:44:14 -050047 if (!data) {
48 if (errno)
49 return -errno;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050050 goto nothing;
bigbiff7b4c7a62015-01-01 19:44:14 -050051 }
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050052
53 l = (struct ultrix_disklabel *) (data + ULTRIX_OFFSET);
54
55 if (l->pt_magic != ULTRIX_MAGIC || l->pt_valid != 1)
56 goto nothing;
57
58 if (blkid_probe_set_magic(pr, (ULTRIX_SECTOR << 9) + ULTRIX_OFFSET,
59 sizeof(ULTRIX_MAGIC_STR) - 1,
60 (unsigned char *) ULTRIX_MAGIC_STR))
61 goto err;
62
63 if (blkid_partitions_need_typeonly(pr))
64 /* caller does not ask for details about partitions */
bigbiff7b4c7a62015-01-01 19:44:14 -050065 return BLKID_PROBE_OK;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050066
67 ls = blkid_probe_get_partlist(pr);
68 if (!ls)
bigbiff7b4c7a62015-01-01 19:44:14 -050069 goto nothing;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050070
71 tab = blkid_partlist_new_parttable(ls, "ultrix", 0);
72 if (!tab)
73 goto err;
74
75 for (i = 0; i < ULTRIX_MAXPARTITIONS; i++) {
76 if (!l->pt_part[i].pi_nblocks)
77 blkid_partlist_increment_partno(ls);
78 else {
79 if (!blkid_partlist_add_partition(ls, tab,
80 l->pt_part[i].pi_blkoff,
81 l->pt_part[i].pi_nblocks))
82 goto err;
83 }
84 }
85
bigbiff7b4c7a62015-01-01 19:44:14 -050086 return BLKID_PROBE_OK;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050087nothing:
bigbiff7b4c7a62015-01-01 19:44:14 -050088 return BLKID_PROBE_NONE;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050089err:
bigbiff7b4c7a62015-01-01 19:44:14 -050090 return -ENOMEM;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050091}
92
93const struct blkid_idinfo ultrix_pt_idinfo =
94{
95 .name = "ultrix",
96 .probefunc = probe_ultrix_pt,
97 .magics = BLKID_NONE_MAGIC
98};
99