blob: 99c0bf1c73ea70035de5648eb259c7c51ecc7403 [file] [log] [blame]
bigbiff7b4c7a62015-01-01 19:44:14 -05001/*
2 * sgi partition parsing code
3 *
4 * Copyright (C) 2009 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#include "pt-sgi.h"
17
18static int probe_sgi_pt(blkid_probe pr,
19 const struct blkid_idmag *mag __attribute__((__unused__)))
20{
21 struct sgi_disklabel *l;
22 struct sgi_partition *p;
23 blkid_parttable tab = NULL;
24 blkid_partlist ls;
25 int i;
26
27 l = (struct sgi_disklabel *) blkid_probe_get_sector(pr, 0);
28 if (!l) {
29 if (errno)
30 return -errno;
31 goto nothing;
32 }
33
34 if (sgi_pt_checksum(l)) {
35 DBG(LOWPROBE, ul_debug(
36 "detected corrupted sgi disk label -- ignore"));
37 goto nothing;
38 }
39
40 if (blkid_partitions_need_typeonly(pr))
41 /* caller does not ask for details about partitions */
42 return BLKID_PROBE_OK;
43
44 ls = blkid_probe_get_partlist(pr);
45 if (!ls)
46 goto nothing;
47
48 tab = blkid_partlist_new_parttable(ls, "sgi", 0);
49 if (!tab)
50 goto err;
51
52 for(i = 0, p = &l->partitions[0]; i < SGI_MAXPARTITIONS; i++, p++) {
53 uint32_t size = be32_to_cpu(p->num_blocks);
54 uint32_t start = be32_to_cpu(p->first_block);
55 uint32_t type = be32_to_cpu(p->type);
56 blkid_partition par;
57
58 if (!size) {
59 blkid_partlist_increment_partno(ls);
60 continue;
61 }
62 par = blkid_partlist_add_partition(ls, tab, start, size);
63 if (!par)
64 goto err;
65
66 blkid_partition_set_type(par, type);
67 }
68
69 return BLKID_PROBE_OK;
70
71nothing:
72 return BLKID_PROBE_NONE;
73err:
74 return -ENOMEM;
75}
76
77const struct blkid_idinfo sgi_pt_idinfo =
78{
79 .name = "sgi",
80 .probefunc = probe_sgi_pt,
81 .magics =
82 {
83 { .magic = "\x0B\xE5\xA9\x41", .len = 4 },
84 { NULL }
85 }
86};
87