blob: 43c9d9af10e5f3c95b2a2053640466b7d5661e18 [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"
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050015#include "minix.h"
16
17static int probe_minix_pt(blkid_probe pr,
18 const struct blkid_idmag *mag __attribute__((__unused__)))
19{
20 struct dos_partition *p;
21 blkid_parttable tab = NULL;
22 blkid_partition parent;
23 blkid_partlist ls;
24 unsigned char *data;
25 int i;
26
27 data = blkid_probe_get_sector(pr, 0);
bigbiff7b4c7a62015-01-01 19:44:14 -050028 if (!data) {
29 if (errno)
30 return -errno;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050031 goto nothing;
bigbiff7b4c7a62015-01-01 19:44:14 -050032 }
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050033
34 ls = blkid_probe_get_partlist(pr);
35 if (!ls)
bigbiff7b4c7a62015-01-01 19:44:14 -050036 goto nothing;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050037
38 /* Parent is required, because Minix uses the same PT as DOS and
39 * difference is only in primary partition (parent) type.
40 */
41 parent = blkid_partlist_get_parent(ls);
42 if (!parent)
43 goto nothing;
44
bigbiff7b4c7a62015-01-01 19:44:14 -050045 if (blkid_partition_get_type(parent) != MBR_MINIX_PARTITION)
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050046 goto nothing;
47
48 if (blkid_partitions_need_typeonly(pr))
49 /* caller does not ask for details about partitions */
bigbiff7b4c7a62015-01-01 19:44:14 -050050 return BLKID_PROBE_OK;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050051
bigbiff7b4c7a62015-01-01 19:44:14 -050052 tab = blkid_partlist_new_parttable(ls, "minix", MBR_PT_OFFSET);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050053 if (!tab)
54 goto err;
55
bigbiff7b4c7a62015-01-01 19:44:14 -050056 for (i = 0, p = mbr_get_partition(data, 0);
57 i < MINIX_MAXPARTITIONS; i++, p++) {
58
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050059 uint32_t start, size;
60 blkid_partition par;
61
bigbiff7b4c7a62015-01-01 19:44:14 -050062 if (p->sys_ind != MBR_MINIX_PARTITION)
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050063 continue;
64
bigbiff7b4c7a62015-01-01 19:44:14 -050065 start = dos_partition_get_start(p);
66 size = dos_partition_get_size(p);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050067
68 if (parent && !blkid_is_nested_dimension(parent, start, size)) {
bigbiff7b4c7a62015-01-01 19:44:14 -050069 DBG(LOWPROBE, ul_debug(
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050070 "WARNING: minix partition (%d) overflow "
bigbiff7b4c7a62015-01-01 19:44:14 -050071 "detected, ignore", i));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050072 continue;
73 }
74
75 par = blkid_partlist_add_partition(ls, tab, start, size);
76 if (!par)
77 goto err;
78
bigbiff7b4c7a62015-01-01 19:44:14 -050079 blkid_partition_set_type(par, p->sys_ind);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050080 blkid_partition_set_flags(par, p->boot_ind);
81 }
82
bigbiff7b4c7a62015-01-01 19:44:14 -050083 return BLKID_PROBE_OK;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050084
85nothing:
bigbiff7b4c7a62015-01-01 19:44:14 -050086 return BLKID_PROBE_NONE;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050087err:
bigbiff7b4c7a62015-01-01 19:44:14 -050088 return -ENOMEM;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050089}
90
91/* same as DOS */
92const struct blkid_idinfo minix_pt_idinfo =
93{
94 .name = "minix",
95 .probefunc = probe_minix_pt,
96 .magics =
97 {
98 { .magic = "\x55\xAA", .len = 2, .sboff = 510 },
99 { NULL }
100 }
101};
102