~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to shlibs/blkid/src/partitions/minix.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

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