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

« back to all changes in this revision

Viewing changes to shlibs/blkid/src/partitions/solaris_x86.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
 
 * Solaris x86 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
 
 
16
 
/*
17
 
 * Solaris-x86 is always within primary dos partition (nested PT table).  The
18
 
 * solaris-x86 vtoc allows to split the entire partition to "slices". The
19
 
 * offset (start) of the slice is always relatively to the primary dos
20
 
 * partition.
21
 
 *
22
 
 * Note that Solaris-SPARC uses entire disk with a different partitionning
23
 
 * scheme.
24
 
 */
25
 
 
26
 
/* some other implementation than Linux kernel assume 8 partitions only */
27
 
#define SOLARIS_MAXPARTITIONS   16
28
 
 
29
 
/* disklabel (vtoc) location  */
30
 
#define SOLARIS_SECTOR          1                       /* in 512-sectors */
31
 
#define SOLARIS_OFFSET          (SOLARIS_SECTOR << 9)   /* in bytes */
32
 
#define SOLARIS_MAGICOFFSET     (SOLARIS_OFFSET + 12)   /* v_sanity offset in bytes */
33
 
 
34
 
/* slice tags */
35
 
#define SOLARIS_TAG_WHOLEDISK   5
36
 
 
37
 
struct solaris_slice {
38
 
        uint16_t s_tag;      /* ID tag of partition */
39
 
        uint16_t s_flag;     /* permission flags */
40
 
        uint32_t s_start;    /* start sector no of partition */
41
 
        uint32_t s_size;     /* # of blocks in partition */
42
 
} __attribute__((packed));
43
 
 
44
 
struct solaris_vtoc {
45
 
        unsigned int v_bootinfo[3];     /* info needed by mboot (unsupported) */
46
 
 
47
 
        uint32_t     v_sanity;          /* to verify vtoc sanity */
48
 
        uint32_t     v_version;         /* layout version */
49
 
        char         v_volume[8];       /* volume name */
50
 
        uint16_t     v_sectorsz;        /* sector size in bytes */
51
 
        uint16_t     v_nparts;          /* number of partitions */
52
 
        unsigned int v_reserved[10];    /* free space */
53
 
 
54
 
        struct solaris_slice v_slice[SOLARIS_MAXPARTITIONS]; /* slices */
55
 
 
56
 
        unsigned int timestamp[SOLARIS_MAXPARTITIONS]; /* timestamp (unsupported) */
57
 
        char         v_asciilabel[128]; /* for compatibility */
58
 
} __attribute__((packed));
59
 
 
60
 
static int probe_solaris_pt(blkid_probe pr, const struct blkid_idmag *mag)
61
 
{
62
 
        struct solaris_vtoc *l; /* disk label */
63
 
        struct solaris_slice *p;        /* partitsion */
64
 
        blkid_parttable tab = NULL;
65
 
        blkid_partition parent;
66
 
        blkid_partlist ls;
67
 
        int i;
68
 
        uint16_t nparts;
69
 
 
70
 
        l = (struct solaris_vtoc *) blkid_probe_get_sector(pr, SOLARIS_SECTOR);
71
 
        if (!l)
72
 
                goto nothing;
73
 
 
74
 
        if (le32_to_cpu(l->v_version) != 1) {
75
 
                DBG(DEBUG_LOWPROBE, printf(
76
 
                        "WARNING: unsupported solaris x86 version %d, ignore\n",
77
 
                        le32_to_cpu(l->v_version)));
78
 
                goto nothing;
79
 
        }
80
 
 
81
 
        if (blkid_partitions_need_typeonly(pr))
82
 
                /* caller does not ask for details about partitions */
83
 
                return 0;
84
 
 
85
 
        ls = blkid_probe_get_partlist(pr);
86
 
        if (!ls)
87
 
                goto err;
88
 
 
89
 
        parent = blkid_partlist_get_parent(ls);
90
 
 
91
 
        tab = blkid_partlist_new_parttable(ls, "solaris", SOLARIS_OFFSET);
92
 
        if (!tab)
93
 
                goto err;
94
 
 
95
 
        nparts = le16_to_cpu(l->v_nparts);
96
 
        if (nparts > SOLARIS_MAXPARTITIONS)
97
 
                nparts = SOLARIS_MAXPARTITIONS;
98
 
 
99
 
        for (i = 1, p = &l->v_slice[0]; i < nparts; i++, p++) {
100
 
 
101
 
                uint32_t start = le32_to_cpu(p->s_start);
102
 
                uint32_t size = le32_to_cpu(p->s_size);
103
 
                blkid_partition par;
104
 
 
105
 
                if (size == 0 || le16_to_cpu(p->s_tag) == SOLARIS_TAG_WHOLEDISK)
106
 
                        continue;
107
 
 
108
 
                if (parent)
109
 
                        /* Solaris slices are relative to the parent (primary
110
 
                         * DOS partition) */
111
 
                        start += blkid_partition_get_start(parent);
112
 
 
113
 
                if (parent && !blkid_is_nested_dimension(parent, start, size)) {
114
 
                        DBG(DEBUG_LOWPROBE, printf(
115
 
                                "WARNING: solaris partition (%d) overflow "
116
 
                                "detected, ignore\n", i));
117
 
                        continue;
118
 
                }
119
 
 
120
 
                par = blkid_partlist_add_partition(ls, tab, start, size);
121
 
                if (!par)
122
 
                        goto err;
123
 
 
124
 
                blkid_partition_set_type(par, le16_to_cpu(p->s_tag));
125
 
                blkid_partition_set_flags(par, le16_to_cpu(p->s_flag));
126
 
        }
127
 
 
128
 
        return 0;
129
 
 
130
 
nothing:
131
 
        return 1;
132
 
err:
133
 
        return -1;
134
 
}
135
 
 
136
 
const struct blkid_idinfo solaris_x86_pt_idinfo =
137
 
{
138
 
        .name           = "solaris",
139
 
        .probefunc      = probe_solaris_pt,
140
 
        .magics         =
141
 
        {
142
 
                {
143
 
                  .magic = "\xEE\xDE\x0D\x60",  /* little-endian magic string */
144
 
                  .len = 4,                     /* v_sanity size in bytes */
145
 
                  .sboff = SOLARIS_MAGICOFFSET  /* offset of v_sanity */
146
 
                },
147
 
                { NULL }
148
 
        }
149
 
};
150