/src/util-linux/libblkid/src/partitions/sgi.c
Line | Count | Source |
1 | | /* |
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 | | |
18 | | static int probe_sgi_pt(blkid_probe pr, |
19 | | const struct blkid_idmag *mag __attribute__((__unused__))) |
20 | 91 | { |
21 | 91 | struct sgi_disklabel *l; |
22 | 91 | struct sgi_partition *p; |
23 | 91 | blkid_parttable tab = NULL; |
24 | 91 | blkid_partlist ls; |
25 | 91 | int i; |
26 | | |
27 | 91 | l = (struct sgi_disklabel *) blkid_probe_get_sector(pr, 0); |
28 | 91 | if (!l) { |
29 | 0 | if (errno) |
30 | 0 | return -errno; |
31 | 0 | goto nothing; |
32 | 0 | } |
33 | | |
34 | 91 | if (!blkid_probe_verify_csum(pr, sgi_pt_checksum(l), 0)) { |
35 | 90 | DBG(LOWPROBE, ul_debug( |
36 | 90 | "detected corrupted sgi disk label -- ignore")); |
37 | 90 | goto nothing; |
38 | 90 | } |
39 | | |
40 | 1 | if (blkid_partitions_need_typeonly(pr)) |
41 | | /* caller does not ask for details about partitions */ |
42 | 1 | return BLKID_PROBE_OK; |
43 | | |
44 | 0 | ls = blkid_probe_get_partlist(pr); |
45 | 0 | if (!ls) |
46 | 0 | goto nothing; |
47 | | |
48 | 0 | tab = blkid_partlist_new_parttable(ls, "sgi", 0); |
49 | 0 | if (!tab) |
50 | 0 | goto err; |
51 | | |
52 | 0 | for(i = 0, p = &l->partitions[0]; i < SGI_MAXPARTITIONS; i++, p++) { |
53 | 0 | uint32_t size = be32_to_cpu(p->num_blocks); |
54 | 0 | uint32_t start = be32_to_cpu(p->first_block); |
55 | 0 | uint32_t type = be32_to_cpu(p->type); |
56 | 0 | blkid_partition par; |
57 | |
|
58 | 0 | if (!size) { |
59 | 0 | blkid_partlist_increment_partno(ls); |
60 | 0 | continue; |
61 | 0 | } |
62 | 0 | par = blkid_partlist_add_partition(ls, tab, start, size); |
63 | 0 | if (!par) |
64 | 0 | goto err; |
65 | | |
66 | 0 | blkid_partition_set_type(par, type); |
67 | 0 | } |
68 | | |
69 | 0 | return BLKID_PROBE_OK; |
70 | | |
71 | 90 | nothing: |
72 | 90 | return BLKID_PROBE_NONE; |
73 | 0 | err: |
74 | | return -ENOMEM; |
75 | 0 | } |
76 | | |
77 | | const 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 | | |