Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/util-linux/fdisk_sun.c

    r1765 r2725  
    1 #if ENABLE_FEATURE_SUN_LABEL
    2 
    3 #define SUNOS_SWAP 3
    4 #define SUN_WHOLE_DISK 5
    5 
    6 #define SUN_LABEL_MAGIC          0xDABE
    7 #define SUN_LABEL_MAGIC_SWAPPED  0xBEDA
    8 #define SUN_SSWAP16(x) (sun_other_endian ? fdisk_swap16(x) : (uint16_t)(x))
    9 #define SUN_SSWAP32(x) (sun_other_endian ? fdisk_swap32(x) : (uint32_t)(x))
    10 
    11 /* Copied from linux/major.h */
    12 #define FLOPPY_MAJOR    2
    13 
    14 #define SCSI_IOCTL_GET_IDLUN 0x5382
    15 
    161/*
    17  * fdisksunlabel.c
     2 * fdisk_sun.c
    183 *
    194 * I think this is mostly, or entirely, due to
     
    249 * Sat Mar 20 EST 1999 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
    2510 *      Internationalization
     11 *
     12 * Licensed under GPLv2, see file LICENSE in this source tree.
    2613 */
    2714
    28 
    29 static int sun_other_endian;
    30 static int scsi_disk;
    31 static int floppy;
     15#if ENABLE_FEATURE_SUN_LABEL
     16
     17#define SUNOS_SWAP 3
     18#define SUN_WHOLE_DISK 5
     19
     20#define SUN_LABEL_MAGIC          0xDABE
     21#define SUN_LABEL_MAGIC_SWAPPED  0xBEDA
     22#define SUN_SSWAP16(x) (sun_other_endian ? fdisk_swap16(x) : (uint16_t)(x))
     23#define SUN_SSWAP32(x) (sun_other_endian ? fdisk_swap32(x) : (uint32_t)(x))
     24
     25/* Copied from linux/major.h */
     26#define FLOPPY_MAJOR    2
     27
     28#define SCSI_IOCTL_GET_IDLUN 0x5382
     29
     30static smallint sun_other_endian;
     31static smallint scsi_disk;
     32static smallint floppy;
    3233
    3334#ifndef IDE0_MAJOR
     
    4344    struct stat bootstat;
    4445
    45     if (fstat(fd, &bootstat) < 0) {
     46    if (fstat(dev_fd, &bootstat) < 0) {
    4647        scsi_disk = 0;
    4748        floppy = 0;
     
    8182
    8283static void
    83 set_sun_partition(int i, uint start, uint stop, int sysid)
     84set_sun_partition(int i, unsigned start, unsigned stop, int sysid)
    8485{
    8586    sunlabel->infos[i].id = sysid;
    8687    sunlabel->partitions[i].start_cylinder =
    87         SUN_SSWAP32(start / (heads * sectors));
     88        SUN_SSWAP32(start / (g_heads * g_sectors));
    8889    sunlabel->partitions[i].num_sectors =
    8990        SUN_SSWAP32(stop - start);
     
    9899
    99100    if (sunlabel->magic != SUN_LABEL_MAGIC
    100      && sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED) {
    101         current_label_type = label_dos;
     101     && sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED
     102    ) {
     103        current_label_type = LABEL_DOS;
    102104        sun_other_endian = 0;
    103105        return 0;
     
    112114"or force a fresh label (s command in main menu)\n");
    113115    } else {
    114         heads = SUN_SSWAP16(sunlabel->ntrks);
    115         cylinders = SUN_SSWAP16(sunlabel->ncyl);
    116         sectors = SUN_SSWAP16(sunlabel->nsect);
     116        g_heads = SUN_SSWAP16(sunlabel->ntrks);
     117        g_cylinders = SUN_SSWAP16(sunlabel->ncyl);
     118        g_sectors = SUN_SSWAP16(sunlabel->nsect);
    117119    }
    118120    update_units();
    119     current_label_type = label_sun;
    120     partitions = 8;
     121    current_label_type = LABEL_SUN;
     122    g_partitions = 8;
    121123    return 1;
    122124}
     
    169171    int i;
    170172
    171     if (ioctl(fd, SCSI_IOCTL_GET_IDLUN, &id))
     173    if (ioctl(dev_fd, SCSI_IOCTL_GET_IDLUN, &id))
    172174        return NULL;
    173175
    174176    sprintf(buffer,
    175         "Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n",
     177        "Host: scsi%u Channel: %02u Id: %02u Lun: %02u\n",
    176178        /* This is very wrong (works only if you have one HBA),
    177179           but I haven't found a way how to get hostno
     
    182184        (id[0]>>8) & 0xff
    183185    );
    184     pfd = fopen("/proc/scsi/scsi", "r");
     186    pfd = fopen_for_read("/proc/scsi/scsi");
    185187    if (!pfd) {
    186188        return NULL;
     
    231233{
    232234    struct hd_geometry geometry;
    233     unsigned int ndiv;
    234     int i;
     235    unsigned ndiv;
    235236    unsigned char c;
    236237    const struct sun_predefined_drives *p = NULL;
     
    242243    sunlabel->magic = SUN_SSWAP16(SUN_LABEL_MAGIC);
    243244    if (!floppy) {
     245        unsigned i;
    244246        puts("Drive type\n"
    245247         "   ?   auto configure\n"
     
    273275    }
    274276    if (!p || floppy) {
    275         if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
    276             heads = geometry.heads;
    277             sectors = geometry.sectors;
    278             cylinders = geometry.cylinders;
     277        if (!ioctl(dev_fd, HDIO_GETGEO, &geometry)) {
     278            g_heads = geometry.heads;
     279            g_sectors = geometry.sectors;
     280            g_cylinders = geometry.cylinders;
    279281        } else {
    280             heads = 0;
    281             sectors = 0;
    282             cylinders = 0;
     282            g_heads = 0;
     283            g_sectors = 0;
     284            g_cylinders = 0;
    283285        }
    284286        if (floppy) {
    285287            sunlabel->nacyl = 0;
    286             sunlabel->pcylcount = SUN_SSWAP16(cylinders);
     288            sunlabel->pcylcount = SUN_SSWAP16(g_cylinders);
    287289            sunlabel->rspeed = SUN_SSWAP16(300);
    288290            sunlabel->ilfact = SUN_SSWAP16(1);
    289291            sunlabel->sparecyl = 0;
    290292        } else {
    291             heads = read_int(1, heads, 1024, 0, "Heads");
    292             sectors = read_int(1, sectors, 1024, 0, "Sectors/track");
    293         if (cylinders)
    294             cylinders = read_int(1, cylinders-2, 65535, 0, "Cylinders");
     293            g_heads = read_int(1, g_heads, 1024, 0, "Heads");
     294            g_sectors = read_int(1, g_sectors, 1024, 0, "Sectors/track");
     295        if (g_cylinders)
     296            g_cylinders = read_int(1, g_cylinders - 2, 65535, 0, "Cylinders");
    295297        else
    296             cylinders = read_int(1, 0, 65535, 0, "Cylinders");
     298            g_cylinders = read_int(1, 0, 65535, 0, "Cylinders");
    297299            sunlabel->nacyl = SUN_SSWAP16(read_int(0, 2, 65535, 0, "Alternate cylinders"));
    298             sunlabel->pcylcount = SUN_SSWAP16(read_int(0, cylinders+SUN_SSWAP16(sunlabel->nacyl), 65535, 0, "Physical cylinders"));
     300            sunlabel->pcylcount = SUN_SSWAP16(read_int(0, g_cylinders + SUN_SSWAP16(sunlabel->nacyl), 65535, 0, "Physical cylinders"));
    299301            sunlabel->rspeed = SUN_SSWAP16(read_int(1, 5400, 100000, 0, "Rotation speed (rpm)"));
    300302            sunlabel->ilfact = SUN_SSWAP16(read_int(1, 1, 32, 0, "Interleave factor"));
    301             sunlabel->sparecyl = SUN_SSWAP16(read_int(0, 0, sectors, 0, "Extra sectors per cylinder"));
     303            sunlabel->sparecyl = SUN_SSWAP16(read_int(0, 0, g_sectors, 0, "Extra sectors per cylinder"));
    302304        }
    303305    } else {
     
    310312        sunlabel->rspeed = SUN_SSWAP16(p->rspeed);
    311313        sunlabel->ilfact = SUN_SSWAP16(1);
    312         cylinders = p->ncyl;
    313         heads = p->ntrks;
    314         sectors = p->nsect;
     314        g_cylinders = p->ncyl;
     315        g_heads = p->ntrks;
     316        g_sectors = p->nsect;
    315317        puts("You may change all the disk params from the x menu");
    316318    }
    317319
    318320    snprintf((char *)(sunlabel->info), sizeof(sunlabel->info),
    319         "%s%s%s cyl %d alt %d hd %d sec %d",
     321        "%s%s%s cyl %u alt %u hd %u sec %u",
    320322        p ? p->vendor : "", (p && *p->vendor) ? " " : "",
    321323        p ? p->model : (floppy ? "3,5\" floppy" : "Linux custom"),
    322         cylinders, SUN_SSWAP16(sunlabel->nacyl), heads, sectors);
    323 
    324     sunlabel->ntrks = SUN_SSWAP16(heads);
    325     sunlabel->nsect = SUN_SSWAP16(sectors);
    326     sunlabel->ncyl = SUN_SSWAP16(cylinders);
     324        g_cylinders, SUN_SSWAP16(sunlabel->nacyl), g_heads, g_sectors);
     325
     326    sunlabel->ntrks = SUN_SSWAP16(g_heads);
     327    sunlabel->nsect = SUN_SSWAP16(g_sectors);
     328    sunlabel->ncyl = SUN_SSWAP16(g_cylinders);
    327329    if (floppy)
    328         set_sun_partition(0, 0, cylinders * heads * sectors, LINUX_NATIVE);
     330        set_sun_partition(0, 0, g_cylinders * g_heads * g_sectors, LINUX_NATIVE);
    329331    else {
    330         if (cylinders * heads * sectors >= 150 * 2048) {
    331             ndiv = cylinders - (50 * 2048 / (heads * sectors)); /* 50M swap */
     332        if (g_cylinders * g_heads * g_sectors >= 150 * 2048) {
     333            ndiv = g_cylinders - (50 * 2048 / (g_heads * g_sectors)); /* 50M swap */
    332334        } else
    333             ndiv = cylinders * 2 / 3;
    334         set_sun_partition(0, 0, ndiv * heads * sectors, LINUX_NATIVE);
    335         set_sun_partition(1, ndiv * heads * sectors, cylinders * heads * sectors, LINUX_SWAP);
     335            ndiv = g_cylinders * 2 / 3;
     336        set_sun_partition(0, 0, ndiv * g_heads * g_sectors, LINUX_NATIVE);
     337        set_sun_partition(1, ndiv * g_heads * g_sectors, g_cylinders * g_heads * g_sectors, LINUX_SWAP);
    336338        sunlabel->infos[1].flags |= 0x01; /* Not mountable */
    337339    }
    338     set_sun_partition(2, 0, cylinders * heads * sectors, SUN_WHOLE_DISK);
     340    set_sun_partition(2, 0, g_cylinders * g_heads * g_sectors, SUN_WHOLE_DISK);
    339341    {
    340342        unsigned short *ush = (unsigned short *)sunlabel;
     
    347349    set_all_unchanged();
    348350    set_changed(0);
    349     get_boot(create_empty_sun);
     351    get_boot(CREATE_EMPTY_SUN);
    350352}
    351353
     
    361363
    362364static void
    363 fetch_sun(uint *starts, uint *lens, uint *start, uint *stop)
     365fetch_sun(unsigned *starts, unsigned *lens, unsigned *start, unsigned *stop)
    364366{
    365367    int i, continuous = 1;
    366368
    367369    *start = 0;
    368     *stop = cylinders * heads * sectors;
    369     for (i = 0; i < partitions; i++) {
     370    *stop = g_cylinders * g_heads * g_sectors;
     371    for (i = 0; i < g_partitions; i++) {
    370372        if (sunlabel->partitions[i].num_sectors
    371373         && sunlabel->infos[i].id
    372374         && sunlabel->infos[i].id != SUN_WHOLE_DISK) {
    373             starts[i] = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors;
     375            starts[i] = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * g_heads * g_sectors;
    374376            lens[i] = SUN_SSWAP32(sunlabel->partitions[i].num_sectors);
    375377            if (continuous) {
     
    390392}
    391393
    392 static uint *verify_sun_starts;
     394static unsigned *verify_sun_starts;
    393395
    394396static int
     
    404406verify_sun(void)
    405407{
    406     uint starts[8], lens[8], start, stop;
     408    unsigned starts[8], lens[8], start, stop;
    407409    int i,j,k,starto,endo;
    408410    int array[8];
    409411
    410412    verify_sun_starts = starts;
    411     fetch_sun(starts,lens,&start,&stop);
     413    fetch_sun(starts, lens, &start, &stop);
    412414    for (k = 0; k < 7; k++) {
    413415        for (i = 0; i < 8; i++) {
    414             if (k && (lens[i] % (heads * sectors))) {
    415                 printf("Partition %d doesn't end on cylinder boundary\n", i+1);
     416            if (k && (lens[i] % (g_heads * g_sectors))) {
     417                printf("Partition %u doesn't end on cylinder boundary\n", i+1);
    416418            }
    417419            if (lens[i]) {
     
    433435                                if (starts[j]+lens[j] < endo)
    434436                                    endo = starts[j]+lens[j];
    435                                 printf("Partition %d overlaps with others in "
    436                                     "sectors %d-%d\n", i+1, starto, endo);
     437                                printf("Partition %u overlaps with others in "
     438                                    "sectors %u-%u\n", i+1, starto, endo);
    437439                            }
    438440                        }
     
    453455        return;
    454456    }
    455     stop = cylinders * heads * sectors;
     457    stop = g_cylinders * g_heads * g_sectors;
    456458    if (starts[array[0]])
    457         printf("Unused gap - sectors 0-%d\n", starts[array[0]]);
     459        printf("Unused gap - sectors %u-%u\n", 0, starts[array[0]]);
    458460    for (i = 0; i < 7 && array[i+1] != -1; i++) {
    459         printf("Unused gap - sectors %d-%d\n", starts[array[i]]+lens[array[i]], starts[array[i+1]]);
     461        printf("Unused gap - sectors %u-%u\n", starts[array[i]]+lens[array[i]], starts[array[i+1]]);
    460462    }
    461463    start = starts[array[i]] + lens[array[i]];
    462464    if (start < stop)
    463         printf("Unused gap - sectors %d-%d\n", start, stop);
     465        printf("Unused gap - sectors %u-%u\n", start, stop);
    464466}
    465467
     
    467469add_sun_partition(int n, int sys)
    468470{
    469     uint start, stop, stop2;
    470     uint starts[8], lens[8];
     471    unsigned start, stop, stop2;
     472    unsigned starts[8], lens[8];
    471473    int whole_disk = 0;
    472474
     
    479481    }
    480482
    481     fetch_sun(starts,lens,&start,&stop);
     483    fetch_sun(starts, lens, &start, &stop);
    482484    if (stop <= start) {
    483485        if (n == 2)
     
    500502        else
    501503            /* Starting sector has to be properly aligned */
    502             first = (first + heads * sectors - 1) / (heads * sectors);
     504            first = (first + g_heads * g_sectors - 1) / (g_heads * g_sectors);
    503505        if (n == 2 && first != 0)
    504506            printf("\
     
    521523           starting at block 0 in an md, or the label will
    522524           be trashed. */
    523         for (i = 0; i < partitions; i++)
     525        for (i = 0; i < g_partitions; i++)
    524526            if (lens[i] && starts[i] <= first && starts[i] + lens[i] > first)
    525527                break;
    526         if (i < partitions && !whole_disk) {
     528        if (i < g_partitions && !whole_disk) {
    527529            if (n == 2 && !first) {
    528530                whole_disk = 1;
    529531                break;
    530532            }
    531             printf("Sector %d is already allocated\n", first);
     533            printf("Sector %u is already allocated\n", first);
    532534        } else
    533535            break;
    534536    }
    535     stop = cylinders * heads * sectors;
     537    stop = g_cylinders * g_heads * g_sectors;
    536538    stop2 = stop;
    537     for (i = 0; i < partitions; i++) {
     539    for (i = 0; i < g_partitions; i++) {
    538540        if (starts[i] > first && starts[i] < stop)
    539541            stop = starts[i];
     
    560562            printf(
    561563"You haven't covered the whole disk with the 3rd partition,\n"
    562 "but your value %d %s covers some other partition.\n"
    563 "Your entry has been changed to %d %s\n",
     564"but your value %u %s covers some other partition.\n"
     565"Your entry has been changed to %u %s\n",
    564566                scround(last), str_units(SINGULAR),
    565567                scround(stop), str_units(SINGULAR));
     
    582584     && sunlabel->infos[i].id == SUN_WHOLE_DISK
    583585     && !sunlabel->partitions[i].start_cylinder
    584      && (nsec = SUN_SSWAP32(sunlabel->partitions[i].num_sectors)) == heads * sectors * cylinders)
     586     && (nsec = SUN_SSWAP32(sunlabel->partitions[i].num_sectors)) == g_heads * g_sectors * g_cylinders)
    585587        printf("If you want to maintain SunOS/Solaris compatibility, "
    586588            "consider leaving this\n"
     
    627629    if (xtra)
    628630        printf(
    629         "\nDisk %s (Sun disk label): %d heads, %d sectors, %d rpm\n"
    630         "%d cylinders, %d alternate cylinders, %d physical cylinders\n"
    631         "%d extra sects/cyl, interleave %d:1\n"
     631        "\nDisk %s (Sun disk label): %u heads, %u sectors, %u rpm\n"
     632        "%u cylinders, %u alternate cylinders, %u physical cylinders\n"
     633        "%u extra sects/cyl, interleave %u:1\n"
    632634        "%s\n"
    633         "Units = %s of %d * 512 bytes\n\n",
    634             disk_device, heads, sectors, SUN_SSWAP16(sunlabel->rspeed),
    635             cylinders, SUN_SSWAP16(sunlabel->nacyl),
     635        "Units = %s of %u * 512 bytes\n\n",
     636            disk_device, g_heads, g_sectors, SUN_SSWAP16(sunlabel->rspeed),
     637            g_cylinders, SUN_SSWAP16(sunlabel->nacyl),
    636638            SUN_SSWAP16(sunlabel->pcylcount),
    637639            SUN_SSWAP16(sunlabel->sparecyl),
     
    641643    else
    642644        printf(
    643     "\nDisk %s (Sun disk label): %d heads, %d sectors, %d cylinders\n"
    644     "Units = %s of %d * 512 bytes\n\n",
    645             disk_device, heads, sectors, cylinders,
     645    "\nDisk %s (Sun disk label): %u heads, %u sectors, %u cylinders\n"
     646    "Units = %s of %u * 512 bytes\n\n",
     647            disk_device, g_heads, g_sectors, g_cylinders,
    646648            str_units(PLURAL), units_per_sector);
    647649
    648650    printf("%*s Flag    Start       End    Blocks   Id  System\n",
    649651        w + 1, "Device");
    650     for (i = 0; i < partitions; i++) {
     652    for (i = 0; i < g_partitions; i++) {
    651653        if (sunlabel->partitions[i].num_sectors) {
    652             uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors;
     654            uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * g_heads * g_sectors;
    653655            uint32_t len = SUN_SSWAP32(sunlabel->partitions[i].num_sectors);
    654             printf("%s %c%c %9ld %9ld %9ld%c  %2x  %s\n",
    655                 partname(disk_device, i+1, w),          /* device */
     656            printf("%s %c%c %9lu %9lu %9lu%c  %2x  %s\n",
     657                partname(disk_device, i+1, w),                  /* device */
    656658                (sunlabel->infos[i].flags & 0x01) ? 'u' : ' ',  /* flags */
    657659                (sunlabel->infos[i].flags & 0x10) ? 'r' : ' ',
     
    685687{
    686688    sunlabel->sparecyl =
    687         SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->sparecyl), sectors, 0,
     689        SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->sparecyl), g_sectors, 0,
    688690                "Extra sectors per cylinder"));
    689691}
     
    723725        csum ^= *ush++;
    724726    sunlabel->csum = csum;
    725     if (lseek(fd, 0, SEEK_SET) < 0)
    726         fdisk_fatal(unable_to_seek);
    727     if (write(fd, sunlabel, SECTOR_SIZE) != SECTOR_SIZE)
    728         fdisk_fatal(unable_to_write);
     727    write_sector(0, sunlabel);
    729728}
    730729#endif /* SUN_LABEL */
Note: See TracChangeset for help on using the changeset viewer.