~ubuntu-branches/ubuntu/lucid/loop-aes-utils/lucid-security

« back to all changes in this revision

Viewing changes to fdisk/fdisksunlabel.c

  • Committer: Bazaar Package Importer
  • Author(s): Max Vozeler
  • Date: 2009-07-06 02:08:18 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090706020818-11pxao7bhgjenfv9
Tags: 2.15.1~rc1-2
Disable ncurses (--without-ncurses), not used in
mount/. Fixes FTBFS (closes: #535676).

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include <sys/sysmacros.h>      /* major */
20
20
 
21
21
#include "nls.h"
 
22
#include "blkdev.h"
22
23
 
23
24
#include <endian.h>
24
25
#ifdef HAVE_SCSI_SCSI_H
26
27
#include <scsi/scsi.h>          /* SCSI_IOCTL_GET_IDLUN */
27
28
#undef u_char
28
29
#endif
 
30
#ifdef HAVE_LINUX_MAJOR_H
29
31
#include <linux/major.h>        /* FLOPPY_MAJOR */
 
32
#endif
30
33
 
31
34
#include "common.h"
32
35
#include "fdisk.h"
57
60
};
58
61
 
59
62
static inline unsigned short __swap16(unsigned short x) {
60
 
        return (((__u16)(x) & 0xFF) << 8) | (((__u16)(x) & 0xFF00) >> 8);
 
63
        return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8);
61
64
}
62
 
static inline __u32 __swap32(__u32 x) {
63
 
        return (((__u32)(x) & 0xFF) << 24) | (((__u32)(x) & 0xFF00) << 8) | (((__u32)(x) & 0xFF0000) >> 8) | (((__u32)(x) & 0xFF000000) >> 24);
 
65
static inline uint32_t __swap32(uint32_t x) {
 
66
        return (((uint32_t)(x) & 0xFF) << 24) | (((uint32_t)(x) & 0xFF00) << 8) | (((uint32_t)(x) & 0xFF0000) >> 8) | (((uint32_t)(x) & 0xFF000000) >> 24);
64
67
}
65
68
 
66
69
#define SSWAP16(x) (other_endian ? __swap16(x) \
67
 
                                 : (__u16)(x))
 
70
                                 : (uint16_t)(x))
68
71
#define SSWAP32(x) (other_endian ? __swap32(x) \
69
 
                                 : (__u32)(x))
 
72
                                 : (uint32_t)(x))
70
73
 
 
74
#ifndef FLOPPY_MAJOR
 
75
#define FLOPPY_MAJOR 2
 
76
#endif
71
77
#ifndef IDE0_MAJOR
72
78
#define IDE0_MAJOR 3
73
79
#endif
96
102
        }
97
103
}
98
104
 
99
 
static void set_sun_partition(int i, __u32 start, __u32 stop, __u16 sysid)
 
105
static void set_sun_partition(int i, uint32_t start, uint32_t stop, uint16_t sysid)
100
106
{
101
107
        sunlabel->part_tags[i].tag = SSWAP16(sysid);
102
108
        sunlabel->part_tags[i].flag = SSWAP16(0);
203
209
        sunlabel->version = SSWAP32(SUN_LABEL_VERSION);
204
210
        sunlabel->num_partitions = SSWAP16(SUN_NUM_PARTITIONS);
205
211
 
206
 
        res = disksize(fd, &llsectors);
 
212
        res = blkdev_get_sectors(fd, &llsectors);
207
213
        sec_fac = sector_size / 512;
208
214
 
 
215
#ifdef HDIO_GETGEO
209
216
        if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
210
217
                heads = geometry.heads;
211
218
                sectors = geometry.sectors;
222
229
                                  "This value may be truncated for devices"
223
230
                                  " > 33.8 GB.\n"), disk_device, cylinders);
224
231
                }
225
 
        } else {
 
232
        } else
 
233
#endif
 
234
        {
226
235
                heads = read_int(1,1,1024,0,_("Heads"));
227
236
                sectors = read_int(1,1,1024,0,_("Sectors/track"));
228
237
                cylinders = read_int(1,1,65535,0,_("Cylinders"));
270
279
        set_changed(0);
271
280
}
272
281
 
273
 
void toggle_sunflags(int i, __u16 mask)
 
282
void toggle_sunflags(int i, uint16_t mask)
274
283
{
275
284
        struct sun_tag_flag *p = &sunlabel->part_tags[i];
276
285
 
279
288
        set_changed(i);
280
289
}
281
290
 
282
 
static void fetch_sun(__u32 *starts, __u32 *lens, __u32 *start, __u32 *stop)
 
291
static void fetch_sun(uint32_t *starts, uint32_t *lens, uint32_t *start, uint32_t *stop)
283
292
{
284
293
        int i, continuous = 1;
285
294
 
328
337
 
329
338
void verify_sun(void)
330
339
{
331
 
    __u32 starts[SUN_NUM_PARTITIONS], lens[SUN_NUM_PARTITIONS], start, stop;
 
340
    uint32_t starts[SUN_NUM_PARTITIONS], lens[SUN_NUM_PARTITIONS], start, stop;
332
341
    int i,j,k,starto,endo;
333
342
    int array[SUN_NUM_PARTITIONS];
334
343
 
394
403
 
395
404
void add_sun_partition(int n, int sys)
396
405
{
397
 
        __u32 starts[SUN_NUM_PARTITIONS], lens[SUN_NUM_PARTITIONS];
 
406
        uint32_t starts[SUN_NUM_PARTITIONS], lens[SUN_NUM_PARTITIONS];
398
407
        struct sun_partition *part = &sunlabel->partitions[n];
399
408
        struct sun_tag_flag *tag = &sunlabel->part_tags[n];
400
 
        __u32 start, stop, stop2;
 
409
        uint32_t start, stop, stop2;
401
410
        int whole_disk = 0;
402
411
                
403
412
        char mesg[256];
437
446
                                first += cs - x;
438
447
                }
439
448
                if (n == 2 && first != 0)
440
 
                        printf ("\
 
449
                        printf (_("\
441
450
It is highly recommended that the third partition covers the whole disk\n\
442
 
and is of type `Whole disk'\n");
 
451
and is of type `Whole disk'\n"));
443
452
                /* ewt asks to add: "don't start a partition at cyl 0"
444
453
                   However, edmundo@rano.demon.co.uk writes:
445
454
                   "In addition to having a Sun partition table, to be able to
530
539
        part->num_sectors = 0;
531
540
}
532
541
 
533
 
int sun_change_sysid(int i, __u16 sys)
 
542
int sun_change_sysid(int i, uint16_t sys)
534
543
{
535
544
        struct sun_partition *part = &sunlabel->partitions[i];
536
545
        struct sun_tag_flag *tag = &sunlabel->part_tags[i];
597
606
                struct sun_tag_flag *tag = &sunlabel->part_tags[i];
598
607
 
599
608
                if (part->num_sectors) {
600
 
                        __u32 start = SSWAP32(part->start_cylinder) * heads * sectors;
601
 
                        __u32 len = SSWAP32(part->num_sectors);
 
609
                        uint32_t start = SSWAP32(part->start_cylinder) * heads * sectors;
 
610
                        uint32_t len = SSWAP32(part->num_sectors);
602
611
                        printf(
603
612
                            "%s %c%c %9ld %9ld %9ld%c  %2x  %s\n",
604
613
/* device */              partname(disk_device, i+1, w),