~ubuntu-branches/ubuntu/quantal/util-linux/quantal

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-06-20 22:31:50 UTC
  • mfrom: (1.6.3 upstream) (4.5.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110620223150-lz8wrv0946ihcz3z
Tags: 2.19.1-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build for multiarch.
  - Add pre-depends on multiarch-support.
  - configure.ac: don't try to be clever about extracting a path name from
    $libdir to append to /usr in a way that's not overridable; instead,
    reuse the built-in configurable libexecdir.
  - Fix up the .pc.in files to know about libexecdir, so our substitutions
    don't leave us with unusable pkg-config files.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - Mention mountall(8) in fstab(5) manpages, along with its special
    options.
  - Since upstart is required in Ubuntu, the hwclock.sh init script is not
    called on startup and the hwclockfirst.sh init script is removed.
  - Drop depends on initscripts for the above.
  - Replace hwclock udev rule with an Upstart job.
  - For the case where mount is called with a directory to mount, look
    that directory up in mountall's /lib/init/fstab if we couldn't find
    it mentioned anywhere else.  This means "mount /proc", "mount /sys",
    etc. work.
  - mount.8 points to the cifs-utils package, not the obsolete smbfs one. 
* Dropped changes:
  - mount.preinst: lsb_release has been fixed in lucid and above to be
    usable without configuration, so we don't have to diverge from Debian
    here anymore.
* Changes merged upstream:
  - sfdisk support for '+' with '-N'
  - mount/umount.c: fix a segfault on umount with empty mtab entry
  - Fix arbitrary unmount with fuse security issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
                uint16_t nparts;      /* num of partitions */
33
33
 
34
34
                struct sun_info {     /* partition information */
35
 
                        uint16_t id;
 
35
                        uint16_t id;  /* tag */
36
36
                        uint16_t flags;
37
37
                } __attribute__ ((packed)) infos[8];
38
38
 
84
84
{
85
85
        struct sun_disklabel *l;
86
86
        struct sun_partition *p;
87
 
        struct sun_info *infos = NULL;
88
87
        blkid_parttable tab = NULL;
89
88
        blkid_partlist ls;
90
89
        uint16_t nparts;
91
90
        blkid_loff_t spc;
92
 
        int i;
 
91
        int i, use_vtoc;
93
92
 
94
93
        l = (struct sun_disklabel *) blkid_probe_get_sector(pr, 0);
95
94
        if (!l)
113
112
        if (!tab)
114
113
                goto err;
115
114
 
116
 
        /* default number of partitions */
117
 
        nparts = SUN_MAXPARTITIONS;
118
 
 
119
115
        /* sectors per cylinder (partition offset is in cylinders...) */
120
116
        spc = be16_to_cpu(l->ntrks) * be16_to_cpu(l->nsect);
121
117
 
122
 
        if ((be32_to_cpu(l->vtoc.sanity) == SUN_VTOC_SANITY) &&
123
 
            (be32_to_cpu(l->vtoc.version) == SUN_VTOC_VERSION) &&
124
 
            (be16_to_cpu(l->vtoc.nparts) <= SUN_MAXPARTITIONS)) {
125
 
 
126
 
                nparts = be16_to_cpu(l->vtoc.nparts);
127
 
                infos = l->vtoc.infos;                  /* for partition type */
128
 
        }
 
118
        DBG(DEBUG_LOWPROBE,
 
119
                printf("Sun VTOC sanity=%u version=%u nparts=%u\n",
 
120
                        be32_to_cpu(l->vtoc.sanity),
 
121
                        be32_to_cpu(l->vtoc.version),
 
122
                        be16_to_cpu(l->vtoc.nparts)));
 
123
 
 
124
        /* Check to see if we can use the VTOC table */
 
125
        use_vtoc = ((be32_to_cpu(l->vtoc.sanity) == SUN_VTOC_SANITY) &&
 
126
                    (be32_to_cpu(l->vtoc.version) == SUN_VTOC_VERSION) &&
 
127
                    (be16_to_cpu(l->vtoc.nparts) <= SUN_MAXPARTITIONS));
 
128
 
 
129
        /* Use 8 partition entries if not specified in validated VTOC */
 
130
        nparts = use_vtoc ? be16_to_cpu(l->vtoc.nparts) : SUN_MAXPARTITIONS;
 
131
 
 
132
        /*
 
133
         * So that old Linux-Sun partitions continue to work,
 
134
         * alow the VTOC to be used under the additional condition ...
 
135
         */
 
136
        use_vtoc = use_vtoc || !(l->vtoc.sanity || l->vtoc.version || l->vtoc.nparts);
129
137
 
130
138
        for (i = 0, p = l->partitions; i < nparts; i++, p++) {
131
139
 
132
 
                blkid_loff_t start;
133
 
                blkid_loff_t size;
134
 
                uint16_t type = infos ? be16_to_cpu(infos[i].id) : 0;
 
140
                blkid_loff_t start, size;
 
141
                uint16_t type = 0, flags = 0;
 
142
                blkid_partition par;
135
143
 
136
144
                start = be32_to_cpu(p->start_cylinder) * spc;
137
145
                size = be32_to_cpu(p->num_sectors);
 
146
                if (use_vtoc) {
 
147
                        type = be16_to_cpu(l->vtoc.infos[i].id);
 
148
                        flags = be16_to_cpu(l->vtoc.infos[i].flags);
 
149
                }
138
150
 
139
 
                if (type == SUN_TAG_WHOLEDISK || !size)
 
151
                if (type == SUN_TAG_WHOLEDISK || !size) {
 
152
                        blkid_partlist_increment_partno(ls);
140
153
                        continue;
141
 
 
142
 
                if (!blkid_partlist_add_partition(ls, tab, type, start, size))
 
154
                }
 
155
                par = blkid_partlist_add_partition(ls, tab, start, size);
 
156
                if (!par)
143
157
                        goto err;
 
158
 
 
159
                if (type)
 
160
                        blkid_partition_set_type(par, type);
 
161
                if (flags)
 
162
                        blkid_partition_set_flags(par, flags);
144
163
        }
145
164
        return 0;
146
165