blob: bd57a6d4b06c095d33f7fb34ca88199b8841a2b1 [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
2 * Minix 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#include <stdio.h>
10#include <string.h>
11#include <stdlib.h>
12#include <stdint.h>
13
14#include "partitions.h"
15#include "dos.h"
16#include "minix.h"
17
18static int probe_minix_pt(blkid_probe pr,
19 const struct blkid_idmag *mag __attribute__((__unused__)))
20{
21 struct dos_partition *p;
22 blkid_parttable tab = NULL;
23 blkid_partition parent;
24 blkid_partlist ls;
25 unsigned char *data;
26 int i;
27
28 data = blkid_probe_get_sector(pr, 0);
29 if (!data)
30 goto nothing;
31
32 ls = blkid_probe_get_partlist(pr);
33 if (!ls)
34 goto err;
35
36 /* Parent is required, because Minix uses the same PT as DOS and
37 * difference is only in primary partition (parent) type.
38 */
39 parent = blkid_partlist_get_parent(ls);
40 if (!parent)
41 goto nothing;
42
43 if (blkid_partition_get_type(parent) != BLKID_MINIX_PARTITION)
44 goto nothing;
45
46 if (blkid_partitions_need_typeonly(pr))
47 /* caller does not ask for details about partitions */
48 return 0;
49
50 p = (struct dos_partition *) (data + BLKID_MSDOS_PT_OFFSET);
51
52 tab = blkid_partlist_new_parttable(ls, "minix", BLKID_MSDOS_PT_OFFSET);
53 if (!tab)
54 goto err;
55
56 for (i = 0; i < MINIX_MAXPARTITIONS; i++, p++) {
57 uint32_t start, size;
58 blkid_partition par;
59
60 if (p->sys_type != BLKID_MINIX_PARTITION)
61 continue;
62
63 start = dos_partition_start(p);
64 size = dos_partition_size(p);
65
66 if (parent && !blkid_is_nested_dimension(parent, start, size)) {
67 DBG(DEBUG_LOWPROBE, printf(
68 "WARNING: minix partition (%d) overflow "
69 "detected, ignore\n", i));
70 continue;
71 }
72
73 par = blkid_partlist_add_partition(ls, tab, start, size);
74 if (!par)
75 goto err;
76
77 blkid_partition_set_type(par, p->sys_type);
78 blkid_partition_set_flags(par, p->boot_ind);
79 }
80
81 return 0;
82
83nothing:
84 return 1;
85err:
86 return -1;
87}
88
89/* same as DOS */
90const struct blkid_idinfo minix_pt_idinfo =
91{
92 .name = "minix",
93 .probefunc = probe_minix_pt,
94 .magics =
95 {
96 { .magic = "\x55\xAA", .len = 2, .sboff = 510 },
97 { NULL }
98 }
99};
100