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

« back to all changes in this revision

Viewing changes to libblkid/src/partitions/ultrix.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
 * uktrix partition parsing code
 
3
 *
 
4
 * Copyright (C) 2010 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
 
 
17
#define ULTRIX_MAXPARTITIONS    8
 
18
#define ULTRIX_MAGIC            0x032957
 
19
 
 
20
/* sector with partition table */
 
21
#define ULTRIX_SECTOR           ((16384 - sizeof(struct ultrix_disklabel)) >> 9)
 
22
/* position of partition table within ULTRIX_SECTOR */
 
23
#define ULTRIX_OFFSET           (512 - sizeof(struct ultrix_disklabel))
 
24
 
 
25
struct ultrix_disklabel {
 
26
        int32_t pt_magic;       /* magic no. indicating part. info exits */
 
27
        int32_t pt_valid;       /* set by driver if pt is current */
 
28
        struct  pt_info {
 
29
                int32_t         pi_nblocks; /* no. of sectors */
 
30
                uint32_t        pi_blkoff;  /* block offset for start */
 
31
        } pt_part[ULTRIX_MAXPARTITIONS];
 
32
} __attribute__((packed));
 
33
 
 
34
 
 
35
static int probe_ultrix_pt(blkid_probe pr,
 
36
                const struct blkid_idmag *mag __attribute__((__unused__)))
 
37
{
 
38
        unsigned char *data;
 
39
        struct ultrix_disklabel *l;
 
40
        blkid_parttable tab = NULL;
 
41
        blkid_partlist ls;
 
42
        int i;
 
43
 
 
44
        data = blkid_probe_get_sector(pr, ULTRIX_SECTOR);
 
45
        if (!data)
 
46
                goto nothing;
 
47
 
 
48
        l = (struct ultrix_disklabel *) (data + ULTRIX_OFFSET);
 
49
 
 
50
        if (l->pt_magic != ULTRIX_MAGIC || l->pt_valid != 1)
 
51
                goto nothing;
 
52
 
 
53
        if (blkid_partitions_need_typeonly(pr))
 
54
                /* caller does not ask for details about partitions */
 
55
                return 0;
 
56
 
 
57
        ls = blkid_probe_get_partlist(pr);
 
58
        if (!ls)
 
59
                goto err;
 
60
 
 
61
        tab = blkid_partlist_new_parttable(ls, "ultrix", 0);
 
62
        if (!tab)
 
63
                goto err;
 
64
 
 
65
        for (i = 0; i < ULTRIX_MAXPARTITIONS; i++) {
 
66
                if (!l->pt_part[i].pi_nblocks)
 
67
                         blkid_partlist_increment_partno(ls);
 
68
                else {
 
69
                        if (!blkid_partlist_add_partition(ls, tab,
 
70
                                                l->pt_part[i].pi_blkoff,
 
71
                                                l->pt_part[i].pi_nblocks))
 
72
                                goto err;
 
73
                }
 
74
        }
 
75
 
 
76
        return 0;
 
77
nothing:
 
78
        return 1;
 
79
err:
 
80
        return -1;
 
81
}
 
82
 
 
83
const struct blkid_idinfo ultrix_pt_idinfo =
 
84
{
 
85
        .name           = "ultrix",
 
86
        .probefunc      = probe_ultrix_pt,
 
87
        .magics         = BLKID_NONE_MAGIC
 
88
};
 
89