nfsmount: style fix
[oweals/busybox.git] / util-linux / fdisk.c
index 4e23cdb85dec2eebb80b7eb6bc2a9c989bde3d8b..8c722581606d2ac2732f2b15e23e7bcb066f8bd6 100644 (file)
@@ -1,18 +1,18 @@
+/* vi: set sw=4 ts=4: */
 /* fdisk.c -- Partition table manipulator for Linux.
  *
  * Copyright (C) 1992  A. V. Le Blanc (LeBlanc@mcc.ac.uk)
+ * Copyright (C) 2001,2002 Vladimir Oleynik <dzo@simtreas.ru> (initial bb port)
  *
  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
- * Copyright (C) 2001,2002 Vladimir Oleynik <dzo@simtreas.ru>
- *    initial busybox port, BSD license 
- * 
- * This applet have not the support person from busybox.
  */
 
 /* Current changes have not compatibility with this version */
 #define UTIL_LINUX_VERSION "2.12"
 
 
+#define _(x) x
+
 #define PROC_PARTITIONS "/proc/partitions"
 
 #include <features.h>
 
 #define DKTYPENAMES
 
-#define BLKRRPART  _IO(0x12,95)    /* re-read partition table */
-#define BLKGETSIZE _IO(0x12,96)    /* return device size */
-#define BLKFLSBUF  _IO(0x12,97)    /* flush buffer cache */
-#define BLKSSZGET  _IO(0x12,104)   /* get block device sector size */
-
-/* Avoid conflicts with the 2.6 kernel headers, which define
- * _IOR rather differently */
-#undef _IOR
-#define _IOR(type,nr,size)      _IOC(_IOC_READ,(type),(nr),sizeof(size))
-#define BLKGETSIZE64 _IOR(0x12,114,uint64_t)
-
 /*
    fdisk.h
 */
@@ -489,7 +478,7 @@ check_aix_label(void)
 
 #define BSD_LINUX_BOOTDIR "/usr/ucb/mdec"
 
-#if defined (i386) || defined (__sparc__) || defined (__arm__) || defined (__mips__) || defined (__s390__) || defined (__sh__) || defined(__x86_64__)
+#if defined (i386) || defined (__sparc__) || defined (__arm__) || defined (__m68k__) || defined (__mips__) || defined (__s390__) || defined (__sh__) || defined(__x86_64__)
 #define BSD_LABELSECTOR   1
 #define BSD_LABELOFFSET   0
 #elif defined (__alpha__) || defined (__powerpc__) || defined (__ia64__) || defined (__hppa__)
@@ -1325,7 +1314,7 @@ xbsd_write_bootstrap(void)
 
 /* We need a backup of the disklabel (xbsd_dlabel might have changed). */
        d = &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE];
-       bcopy(d, &dl, sizeof(struct xbsd_disklabel));
+       memmove(&dl, d, sizeof(struct xbsd_disklabel));
 
 /* The disklabel will be overwritten by 0's from bootxx anyway */
        memset(d, 0, sizeof(struct xbsd_disklabel));
@@ -1342,7 +1331,7 @@ xbsd_write_bootstrap(void)
                        exit(EXIT_FAILURE);
                }
 
-       bcopy(&dl, d, sizeof(struct xbsd_disklabel));
+       memmove(d, &dl, sizeof(struct xbsd_disklabel));
 
 #if defined (__powerpc__) || defined (__hppa__)
        sector = 0;
@@ -1455,10 +1444,6 @@ xbsd_initlabel(struct partition *p, struct xbsd_disklabel *d)
        else
                d->d_type = BSD_DTYPE_ST506;
 
-#if 0 /* not used (at least not written to disk) by NetBSD/i386 1.0 */
-       d->d_subtype = BSD_DSTYPE_INDOSPART & pindex;
-#endif
-
 #if !defined (__alpha__)
        d->d_flags = BSD_D_DOSPART;
 #else
@@ -1529,8 +1514,8 @@ xbsd_readlabel (struct partition *p, struct xbsd_disklabel *d)
        if (BSD_BBSIZE != read(fd, disklabelbuffer, BSD_BBSIZE))
                fdisk_fatal(unable_to_read);
 
-       bcopy(&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
-                  d, sizeof(struct xbsd_disklabel));
+       memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
+                  sizeof(struct xbsd_disklabel));
 
        if (d->d_magic != BSD_DISKMAGIC || d->d_magic2 != BSD_DISKMAGIC)
                return 0;
@@ -1565,8 +1550,8 @@ xbsd_writelabel (struct partition *p, struct xbsd_disklabel *d)
        /* This is necessary if we want to write the bootstrap later,
           otherwise we'd write the old disklabel with the bootstrap.
        */
-       bcopy(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
-               sizeof(struct xbsd_disklabel));
+       memmove(&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
+               d, sizeof(struct xbsd_disklabel));
 
 #if defined (__alpha__) && BSD_LABELSECTOR == 0
        alpha_bootblock_checksum (disklabelbuffer);
@@ -1646,13 +1631,13 @@ alpha_bootblock_checksum(char *boot)
 #endif /* OSF_LABEL */
 
 #if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL)
-static inline unsigned short
+static unsigned short
 __swap16(unsigned short x)
 {
        return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8);
 }
 
-static inline uint32_t
+static uint32_t
 __swap32(uint32_t x)
 {
        return (((x & 0xFF) << 24) |
@@ -1986,7 +1971,7 @@ create_sgiinfo(void)
        /* I keep SGI's habit to write the sgilabel to the second block */
        sgilabel->directory[0].vol_file_start = SGI_SSWAP32(2);
        sgilabel->directory[0].vol_file_size = SGI_SSWAP32(sizeof(sgiinfo));
-       strncpy((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8);
+       strcpy((char*)sgilabel->directory[0].vol_file_name, "sgilabel");
 }
 
 static sgiinfo *fill_sgiinfo(void);
@@ -2346,7 +2331,7 @@ create_sgilabel(void)
                "until you decide to write them. After that, of course, the previous\n"
                "content will be unrecoverably lost.\n\n"));
 
-       sgi_other_endian = (BYTE_ORDER == LITTLE_ENDIAN);
+       sgi_other_endian = (BB_LITTLE_ENDIAN);
        res = ioctl(fd, BLKGETSIZE, &longsectors);
        if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
                heads = geometry.heads;
@@ -2617,14 +2602,10 @@ sun_autoconfigure_scsi(void)
        if (!ioctl(fd, SCSI_IOCTL_GET_IDLUN, &id)) {
                sprintf(buffer,
                        "Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n",
-#if 0
-                       ((id[0]>>24)&0xff)-/*PROC_SCSI_SCSI+PROC_SCSI_FILE*/33,
-#else
                        /* This is very wrong (works only if you have one HBA),
                           but I haven't found a way how to get hostno
                           from the current kernel */
                        0,
-#endif
                        (id[0]>>16) & 0xff,
                        id[0] & 0xff,
                        (id[0]>>8) & 0xff
@@ -2684,11 +2665,7 @@ create_sunlabel(void)
                _("Building a new sun disklabel. Changes will remain in memory only,\n"
                "until you decide to write them. After that, of course, the previous\n"
                "content won't be recoverable.\n\n"));
-#if BYTE_ORDER == LITTLE_ENDIAN
-       sun_other_endian = 1;
-#else
-       sun_other_endian = 0;
-#endif
+       sun_other_endian = BB_LITTLE_ENDIAN;
        memset(MBRbuffer, 0, sizeof(MBRbuffer));
        sunlabel->magic = SUN_SSWAP16(SUN_LABEL_MAGIC);
        if (!floppy) {
@@ -3942,7 +3919,7 @@ get_sectorsize(void)
        }
 }
 
-static inline void
+static void
 get_kernel_geometry(void)
 {
        struct hd_geometry geometry;
@@ -4661,25 +4638,10 @@ check_consistency(const struct partition *p, int partition)
                printf(_("logical=(%d, %d, %d)\n"),lec, leh, les);
        }
 
-#if 0
-/* Beginning on cylinder boundary? */
-       if (pbh != !pbc || pbs != 1) {
-               printf(_("Partition %i does not start on cylinder "
-                       "boundary:\n"), partition + 1);
-               printf(_("     phys=(%d, %d, %d) "), pbc, pbh, pbs);
-               printf(_("should be (%d, %d, 1)\n"), pbc, !pbc);
-       }
-#endif
-
 /* Ending on cylinder boundary? */
        if (peh != (heads - 1) || pes != sectors) {
                printf(_("Partition %i does not end on cylinder boundary.\n"),
                        partition + 1);
-#if 0
-               printf(_("     phys=(%d, %d, %d) "), pec, peh, pes);
-               printf(_("should be (%d, %d, %d)\n"),
-               pec, heads - 1, sectors);
-#endif
        }
 }
 
@@ -5082,7 +5044,7 @@ static void
 add_partition(int n, int sys)
 {
        char mesg[256];         /* 48 does not suffice in Japanese */
-       int i, readed = 0;
+       int i, num_read = 0;
        struct partition *p = ptes[n].part_table;
        struct partition *q = ptes[ext_index].part_table;
        long long llimit;
@@ -5131,12 +5093,12 @@ add_partition(int n, int sys)
                }
                if (start > limit)
                        break;
-               if (start >= temp+units_per_sector && readed) {
+               if (start >= temp+units_per_sector && num_read) {
                        printf(_("Sector %llu is already allocated\n"), (unsigned long long)temp);
                        temp = start;
-                       readed = 0;
+                       num_read = 0;
                }
-               if (!readed && start == temp) {
+               if (!num_read && start == temp) {
                        off_t saved_start;
 
                        saved_start = start;
@@ -5146,9 +5108,9 @@ add_partition(int n, int sys)
                                start = (start - 1) * units_per_sector;
                                if (start < saved_start) start = saved_start;
                        }
-                       readed = 1;
+                       num_read = 1;
                }
-       } while (start != temp || !readed);
+       } while (start != temp || !num_read);
        if (n > 4) {                    /* NOT for fifth partition */
                struct pte *pe = &ptes[n];
 
@@ -5200,7 +5162,7 @@ add_partition(int n, int sys)
                ext_index = n;
                pen->ext_pointer = p;
                pe4->offset = extended_offset = start;
-               pe4->sectorbuffer = xcalloc(1, sector_size);
+               pe4->sectorbuffer = xzalloc(sector_size);
                pe4->part_table = pt_offset(pe4->sectorbuffer, 0);
                pe4->ext_pointer = pe4->part_table + 1;
                pe4->changed = 1;
@@ -5214,7 +5176,7 @@ add_logical(void)
        if (partitions > 5 || ptes[4].part_table->sys_ind) {
                struct pte *pe = &ptes[partitions];
 
-               pe->sectorbuffer = xcalloc(1, sector_size);
+               pe->sectorbuffer = xzalloc(sector_size);
                pe->part_table = pt_offset(pe->sectorbuffer, 0);
                pe->ext_pointer = pe->part_table + 1;
                pe->offset = 0;
@@ -5753,14 +5715,9 @@ int fdisk_main(int argc, char **argv)
                }
        }
 
-#if 0
-       printf(_("This kernel finds the sector size itself - "
-                "-b option ignored\n"));
-#else
        if (user_set_sector_size && argc-optind != 1)
                printf(_("Warning: the -b (set sector size) option should"
                         " be used with one specified device\n"));
-#endif
 
 #ifdef CONFIG_FEATURE_FDISK_WRITABLE
        if (optl) {