ip: use rtnl_send_check() on flush commands, closes 6962
[oweals/busybox.git] / util-linux / fdisk_osf.c
index aeccc6913799a5989c8bd7878e937fa491feec7a..1328c1fcdcf374b9ec64eb15d263b433fc8c51dc 100644 (file)
@@ -18,7 +18,7 @@
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
 #define BSD_LINUX_BOOTDIR "/usr/ucb/mdec"
 
-#if defined(i386) || defined(__sparc__) || defined(__arm__) \
- || defined(__m68k__) || defined(__mips__) || defined(__s390__) \
- || defined(__s390__) || defined(__s390x__) \
- || defined(__sh__) || defined(__x86_64__) || defined(__avr32__)
-# define BSD_LABELSECTOR   1
-# define BSD_LABELOFFSET   0
-#elif defined(__alpha__) || defined(__powerpc__) || defined(__ia64__) \
+#if defined(__alpha__) \
+ || defined(__powerpc__) \
+ || defined(__ia64__) \
  || defined(__hppa__)
 # define BSD_LABELSECTOR   0
 # define BSD_LABELOFFSET   64
 #else
-# error unknown architecture
+# define BSD_LABELSECTOR   1
+# define BSD_LABELOFFSET   0
 #endif
 
 #define BSD_BBSIZE        8192          /* size of boot area, with label */
@@ -65,8 +62,8 @@ struct xbsd_disklabel {
        int16_t    d_type;                 /* drive type */
        int16_t    d_subtype;              /* controller/d_type specific */
        char       d_typename[16];         /* type name, e.g. "eagle" */
-       char       d_packname[16];                 /* pack identifier */
-                       /* disk geometry: */
+       char       d_packname[16];         /* pack identifier */
+       /* disk geometry: */
        uint32_t   d_secsize;              /* # of bytes per sector */
        uint32_t   d_nsectors;             /* # of data sectors per track */
        uint32_t   d_ntracks;              /* # of tracks per cylinder */
@@ -87,7 +84,7 @@ struct xbsd_disklabel {
         */
        uint32_t   d_acylinders;           /* # of alt. cylinders per unit */
 
-                       /* hardware characteristics: */
+       /* hardware characteristics: */
        /*
         * d_interleave, d_trackskew and d_cylskew describe perturbations
         * in the media format used to compensate for a slow controller.
@@ -117,11 +114,11 @@ struct xbsd_disklabel {
        uint32_t   d_spare[NSPARE];        /* reserved for future use */
        uint32_t   d_magic2;               /* the magic number (again) */
        uint16_t   d_checksum;             /* xor of data incl. partitions */
-                       /* filesystem and partition information: */
+       /* filesystem and partition information: */
        uint16_t   d_npartitions;          /* number of partitions in following */
        uint32_t   d_bbsize;               /* size of boot area at sn0, bytes */
        uint32_t   d_sbsize;               /* max size of fs superblock, bytes */
-       struct xbsd_partition    {      /* the partition table */
+       struct xbsd_partition { /* the partition table */
                uint32_t   p_size;         /* number of sectors in partition */
                uint32_t   p_offset;       /* starting sector */
                uint32_t   p_fsize;        /* filesystem basic fragment size */
@@ -367,12 +364,13 @@ bsd_select(void)
                                        partname(disk_device, t+1, 0));
                                return;
                        }
-                               printf("Reading disklabel of %s at sector %d\n",
+                               printf("Reading disklabel of %s at sector %u\n",
                                        partname(disk_device, t+1, 0), ss + BSD_LABELSECTOR);
-                       if (xbsd_readlabel(xbsd_part) == 0)
+                       if (xbsd_readlabel(xbsd_part) == 0) {
                                if (xbsd_create_disklabel() == 0)
                                        return;
                                break;
+                       }
                }
        }
 
@@ -510,7 +508,7 @@ xbsd_print_disklabel(int show_all)
                if ((unsigned) lp->d_type < ARRAY_SIZE(xbsd_dktypenames)-1)
                        printf("type: %s\n", xbsd_dktypenames[lp->d_type]);
                else
-                       printf("type: %d\n", lp->d_type);
+                       printf("type: %u\n", lp->d_type);
                printf("disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename);
                printf("label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname);
                printf("flags: ");
@@ -518,18 +516,18 @@ xbsd_print_disklabel(int show_all)
                bb_putchar('\n');
                /* On various machines the fields of *lp are short/int/long */
                /* In order to avoid problems, we cast them all to long. */
-               printf("bytes/sector: %ld\n", (long) lp->d_secsize);
-               printf("sectors/track: %ld\n", (long) lp->d_nsectors);
-               printf("tracks/cylinder: %ld\n", (long) lp->d_ntracks);
-               printf("sectors/cylinder: %ld\n", (long) lp->d_secpercyl);
-               printf("cylinders: %ld\n", (long) lp->d_ncylinders);
-               printf("rpm: %d\n", lp->d_rpm);
-               printf("interleave: %d\n", lp->d_interleave);
-               printf("trackskew: %d\n", lp->d_trackskew);
-               printf("cylinderskew: %d\n", lp->d_cylskew);
-               printf("headswitch: %ld\t\t# milliseconds\n",
+               printf("bytes/sector: %lu\n", (long) lp->d_secsize);
+               printf("sectors/track: %lu\n", (long) lp->d_nsectors);
+               printf("tracks/cylinder: %lu\n", (long) lp->d_ntracks);
+               printf("sectors/cylinder: %lu\n", (long) lp->d_secpercyl);
+               printf("cylinders: %lu\n", (long) lp->d_ncylinders);
+               printf("rpm: %u\n", lp->d_rpm);
+               printf("interleave: %u\n", lp->d_interleave);
+               printf("trackskew: %u\n", lp->d_trackskew);
+               printf("cylinderskew: %u\n", lp->d_cylskew);
+               printf("headswitch: %lu\t\t# milliseconds\n",
                        (long) lp->d_headswitch);
-               printf("track-to-track seek: %ld\t# milliseconds\n",
+               printf("track-to-track seek: %lu\t# milliseconds\n",
                        (long) lp->d_trkseek);
                printf("drivedata: ");
                for (i = NDDATA - 1; i >= 0; i--)
@@ -538,25 +536,25 @@ xbsd_print_disklabel(int show_all)
                if (i < 0)
                        i = 0;
                for (j = 0; j <= i; j++)
-                       printf("%ld ", (long) lp->d_drivedata[j]);
+                       printf("%lu ", (long) lp->d_drivedata[j]);
        }
-       printf("\n%d partitions:\n", lp->d_npartitions);
+       printf("\n%u partitions:\n", lp->d_npartitions);
        printf("#       start       end      size     fstype   [fsize bsize   cpg]\n");
        pp = lp->d_partitions;
        for (i = 0; i < lp->d_npartitions; i++, pp++) {
                if (pp->p_size) {
                        if (display_in_cyl_units && lp->d_secpercyl) {
-                               printf("  %c: %8ld%c %8ld%c %8ld%c  ",
+                               printf("  %c: %8lu%c %8lu%c %8lu%c  ",
                                        'a' + i,
-                                       (long) pp->p_offset / lp->d_secpercyl + 1,
+                                       (unsigned long) pp->p_offset / lp->d_secpercyl + 1,
                                        (pp->p_offset % lp->d_secpercyl) ? '*' : ' ',
-                                       (long) (pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl,
+                                       (unsigned long) (pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl,
                                        ((pp->p_offset + pp->p_size) % lp->d_secpercyl) ? '*' : ' ',
                                        (long) pp->p_size / lp->d_secpercyl,
                                        (pp->p_size % lp->d_secpercyl) ? '*' : ' '
                                );
                        } else {
-                               printf("  %c: %8ld  %8ld  %8ld   ",
+                               printf("  %c: %8lu  %8lu  %8lu   ",
                                        'a' + i,
                                        (long) pp->p_offset,
                                        (long) pp->p_offset + pp->p_size - 1,
@@ -571,11 +569,11 @@ xbsd_print_disklabel(int show_all)
 
                        switch (pp->p_fstype) {
                        case BSD_FS_UNUSED:
-                               printf("    %5ld %5ld %5.5s ",
+                               printf("    %5lu %5lu %5.5s ",
                                        (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, "");
                                break;
                        case BSD_FS_BSDFFS:
-                               printf("    %5ld %5ld %5d ",
+                               printf("    %5lu %5lu %5u ",
                                        (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, pp->p_cpg);
                                break;
                        default:
@@ -615,7 +613,7 @@ xbsd_create_disklabel(void)
 
        while (1) {
                c = read_nonempty("Do you want to create a disklabel? (y/n) ");
-               if (c == 'y' || c == 'Y') {
+               if ((c|0x20) == 'y') {
                        if (xbsd_initlabel(
 #if defined(__alpha__) || defined(__powerpc__) || defined(__hppa__) || \
        defined(__s390__) || defined(__s390x__)
@@ -629,7 +627,7 @@ xbsd_create_disklabel(void)
                        }
                        return 0;
                }
-               if (c == 'n')
+               if ((c|0x20) == 'n')
                        return 0;
        }
 }
@@ -637,7 +635,7 @@ xbsd_create_disklabel(void)
 static int
 edit_int(int def, const char *mesg)
 {
-       mesg = xasprintf("%s (%d): ", mesg, def);
+       mesg = xasprintf("%s (%u): ", mesg, def);
        do {
                if (!read_line(mesg))
                        goto ret;
@@ -711,6 +709,9 @@ sync_disks(void)
 static void
 xbsd_write_bootstrap(void)
 {
+#ifndef MAXPATHLEN
+# define MAXPATHLEN 1024
+#endif
        char path[MAXPATHLEN];
        const char *bootdir = BSD_LINUX_BOOTDIR;
        const char *dkbasename;
@@ -857,7 +858,7 @@ xbsd_initlabel(struct partition *p)
 
        d->d_magic = BSD_DISKMAGIC;
 
-       if (strncmp(disk_device, "/dev/sd", 7) == 0)
+       if (is_prefixed_with(disk_device, "/dev/sd"))
                d->d_type = BSD_DTYPE_SCSI;
        else
                d->d_type = BSD_DTYPE_ST506;
@@ -901,8 +902,7 @@ xbsd_initlabel(struct partition *p)
        pp->p_fstype = BSD_FS_UNUSED;
 #else
        d->d_npartitions = 3;
-       pp = &d->d_partitions[2];             /* Partition C should be
-                                                  the whole disk */
+       pp = &d->d_partitions[2]; /* Partition C should be the whole disk */
        pp->p_offset = 0;
        pp->p_size   = d->d_secperunit;
        pp->p_fstype = BSD_FS_UNUSED;
@@ -938,7 +938,7 @@ xbsd_readlabel(struct partition *p)
                fdisk_fatal(unable_to_read);
 
        memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
-                  sizeof(struct xbsd_disklabel));
+                       sizeof(struct xbsd_disklabel));
 
        if (d->d_magic != BSD_DISKMAGIC || d->d_magic2 != BSD_DISKMAGIC)
                return 0;
@@ -950,7 +950,7 @@ xbsd_readlabel(struct partition *p)
        }
 
        if (d->d_npartitions > BSD_MAXPARTITIONS)
-               printf("Warning: too many partitions (%d, maximum is %d)\n",
+               printf("Warning: too many partitions (%u, maximum is %u)\n",
                        d->d_npartitions, BSD_MAXPARTITIONS);
        return 1;
 }
@@ -964,6 +964,7 @@ xbsd_writelabel(struct partition *p)
 #if !defined(__alpha__) && !defined(__powerpc__) && !defined(__hppa__)
        sector = get_start_sect(p) + BSD_LABELSECTOR;
 #else
+       (void)p; /* silence warning */
        sector = BSD_LABELSECTOR;
 #endif