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

« back to all changes in this revision

Viewing changes to libblkid/src/partitions/sgi.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-08-18 15:43:56 UTC
  • mfrom: (1.6.5) (4.1.16 experimental)
  • Revision ID: package-import@ubuntu.com-20140818154356-sqn436j3vndc62qb
Tags: 2.25-8ubuntu1
* Merge with Debian experimental.
  - This is now a non-ancient version. (LP: #1012081)
  - No longer uses /etc/blkid.tab by default, but a file in /run/.
    (LP: #1244595)
  - mkswap wipes fs signatures (LP: #1047666)
  - Fix "reatime" manpage typo (LP: #1047666)
  - wipefs properly cleans up fs signatures (LP: #1059872)
  Remaining Ubuntu changes:
  - Regularly trim SSDs automatically (core-1311-ssd-trimming):
    + Add debian/fstrim-all: Script to detect which mounted partitions
      need/support trimming, and call fstrim(8) on all of them.
      Install into /usr/sbin/.
    + Add debian/fstrim-all.8: Manpage for the above.
    + Add debian/fstrim-all.cron: Trivial shell script to call fstrim-all,
      so that admins can easily adjust/disable it. Installed as
      /etc/cron.weekly/fstrim.
  - Upstart support:
    + Add hwclock{-save}.upstart, and install them in debian/rules.
    + Drop initscripts dependency.
    + Drop debian/hwclock.rules and hwclock.default.
  - Add mountall-options.patch, see patch header.
  - uuid-runtime.postinst: Due to the way the uuidd account is created, it
    will get a uid/gid allocation for userns use. This isn't needed and is a
    waste of uid/gid so always clear uuidd from subuid/subgid.
* Drop /lib/init/fstab parsing fallback in mount. Patch does not apply at
  all any more, is specific to mountall (and thus should not be relied
  upon), and not very useful; all init systems, schroot, debootstrap etc.
  mount /sys, /proc/ and friends by themselves already.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#include <stdint.h>
14
14
 
15
15
#include "partitions.h"
16
 
 
17
 
#define SGI_MAXPARTITIONS       16
18
 
 
19
 
/* partition type */
20
 
#define SGI_TYPE_VOLHDR         0x00
21
 
#define SGI_TYPE_VOLULME        0x06    /* entire disk */
22
 
 
23
 
struct sgi_device_parameter {
24
 
        unsigned char skew;
25
 
        unsigned char gap1;
26
 
        unsigned char gap2;
27
 
        unsigned char sparecyl;
28
 
 
29
 
        uint16_t pcylcount;
30
 
        uint16_t head_vol0;
31
 
        uint16_t ntrks;         /* tracks in cyl 0 or vol 0 */
32
 
 
33
 
        unsigned char cmd_tag_queue_depth;
34
 
        unsigned char unused0;
35
 
 
36
 
        uint16_t unused1;
37
 
        uint16_t nsect;         /* sectors/tracks in cyl 0 or vol 0 */
38
 
        uint16_t bytes;
39
 
        uint16_t ilfact;
40
 
        uint32_t flags;         /* controller flags */
41
 
        uint32_t datarate;
42
 
        uint32_t retries_on_error;
43
 
        uint32_t ms_per_word;
44
 
        uint16_t xylogics_gap1;
45
 
        uint16_t xylogics_syncdelay;
46
 
        uint16_t xylogics_readdelay;
47
 
        uint16_t xylogics_gap2;
48
 
        uint16_t xylogics_readgate;
49
 
        uint16_t xylogics_writecont;
50
 
} __attribute__((packed));
51
 
 
52
 
struct sgi_disklabel {
53
 
        uint32_t magic;                 /* magic number */
54
 
        uint16_t root_part_num;         /* # root partition */
55
 
        uint16_t swap_part_num;         /* # swap partition */
56
 
        unsigned char boot_file[16];    /* name of boot file */
57
 
 
58
 
        struct sgi_device_parameter     devparam;       /* not used now */
59
 
 
60
 
        struct sgi_volume {
61
 
                unsigned char name[8];  /* name of volume */
62
 
                uint32_t block_num;     /* logical block number */
63
 
                uint32_t num_bytes;     /* how big, in bytes */
64
 
        } __attribute__((packed)) volume[15];
65
 
 
66
 
        struct sgi_partition {
67
 
                uint32_t num_blocks;    /* size in logical blocks */
68
 
                uint32_t first_block;   /* first logical block */
69
 
                uint32_t type;          /* type of this partition */
70
 
        } __attribute__((packed)) partitions[SGI_MAXPARTITIONS];
71
 
 
72
 
        /* checksum is the 32bit 2's complement sum of the disklabel */
73
 
        uint32_t csum;                  /* disk label checksum */
74
 
        uint32_t padding;               /* padding */
75
 
} __attribute__((packed));
76
 
 
77
 
static uint32_t count_checksum(struct sgi_disklabel *label)
78
 
{
79
 
        int i;
80
 
        uint32_t *ptr = (uint32_t *) label;
81
 
        uint32_t sum = 0;
82
 
 
83
 
        i = sizeof(*label) / sizeof(*ptr);
84
 
 
85
 
        while (i--)
86
 
                sum += be32_to_cpu(ptr[i]);
87
 
 
88
 
        return sum;
89
 
}
90
 
 
 
16
#include "pt-sgi.h"
91
17
 
92
18
static int probe_sgi_pt(blkid_probe pr,
93
19
                const struct blkid_idmag *mag __attribute__((__unused__)))
99
25
        int i;
100
26
 
101
27
        l = (struct sgi_disklabel *) blkid_probe_get_sector(pr, 0);
102
 
        if (!l)
 
28
        if (!l) {
 
29
                if (errno)
 
30
                        return -errno;
103
31
                goto nothing;
 
32
        }
104
33
 
105
 
        if (count_checksum(l)) {
106
 
                DBG(DEBUG_LOWPROBE, printf(
107
 
                        "detected corrupted sgi disk label -- ignore\n"));
 
34
        if (sgi_pt_checksum(l)) {
 
35
                DBG(LOWPROBE, ul_debug(
 
36
                        "detected corrupted sgi disk label -- ignore"));
108
37
                goto nothing;
109
38
        }
110
39
 
111
40
        if (blkid_partitions_need_typeonly(pr))
112
41
                /* caller does not ask for details about partitions */
113
 
                return 0;
 
42
                return BLKID_PROBE_OK;
114
43
 
115
44
        ls = blkid_probe_get_partlist(pr);
116
45
        if (!ls)
117
 
                goto err;
 
46
                goto nothing;
118
47
 
119
48
        tab = blkid_partlist_new_parttable(ls, "sgi", 0);
120
49
        if (!tab)
126
55
                uint32_t type = be32_to_cpu(p->type);
127
56
                blkid_partition par;
128
57
 
129
 
                if (size == 0 || type == SGI_TYPE_VOLULME ||
130
 
                                 type == SGI_TYPE_VOLHDR) {
 
58
                if (!size) {
131
59
                        blkid_partlist_increment_partno(ls);
132
60
                        continue;
133
61
                }
138
66
                blkid_partition_set_type(par, type);
139
67
        }
140
68
 
141
 
        return 0;
 
69
        return BLKID_PROBE_OK;
142
70
 
143
71
nothing:
144
 
        return 1;
 
72
        return BLKID_PROBE_NONE;
145
73
err:
146
 
        return -1;
 
74
        return -ENOMEM;
147
75
}
148
76
 
149
77
const struct blkid_idinfo sgi_pt_idinfo =