Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/util-linux/fdisk.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 983 by niro, Fri Apr 24 18:33:46 2009 UTC revision 984 by niro, Sun May 30 11:32:42 2010 UTC
# Line 9  Line 9 
9    
10  #ifndef _LARGEFILE64_SOURCE  #ifndef _LARGEFILE64_SOURCE
11  /* For lseek64 */  /* For lseek64 */
12  #define _LARGEFILE64_SOURCE  # define _LARGEFILE64_SOURCE
13  #endif  #endif
14  #include <assert.h>             /* assert */  #include <assert.h>             /* assert */
15    #include <sys/mount.h>
16    #if !defined(BLKSSZGET)
17    # define BLKSSZGET _IO(0x12, 104)
18    #endif
19    #if !defined(BLKGETSIZE64)
20    # define BLKGETSIZE64 _IOR(0x12,114,size_t)
21    #endif
22  #include "libbb.h"  #include "libbb.h"
23    
24  /* Looks like someone forgot to add this to config system */  /* Looks like someone forgot to add this to config system */
25  #ifndef ENABLE_FEATURE_FDISK_BLKSIZE  #ifndef ENABLE_FEATURE_FDISK_BLKSIZE
26  # define ENABLE_FEATURE_FDISK_BLKSIZE 0  # define ENABLE_FEATURE_FDISK_BLKSIZE 0
27  # define USE_FEATURE_FDISK_BLKSIZE(a)  # define IF_FEATURE_FDISK_BLKSIZE(a)
28  #endif  #endif
29    
30  #define DEFAULT_SECTOR_SIZE      512  #define DEFAULT_SECTOR_SIZE      512
# Line 49  enum { Line 56  enum {
56  };  };
57    
58    
 /* Used for sector numbers. Today's disk sizes make it necessary */  
59  typedef unsigned long long ullong;  typedef unsigned long long ullong;
60    /* Used for sector numbers. Partition formats we know
61     * do not support more than 2^32 sectors
62     */
63    typedef uint32_t sector_t;
64    #if UINT_MAX == 4294967295
65    # define SECT_FMT ""
66    #elif ULONG_MAX == 4294967295
67    # define SECT_FMT "l"
68    #else
69    # error Cant detect sizeof(uint32_t)
70    #endif
71    
72  struct hd_geometry {  struct hd_geometry {
73   unsigned char heads;   unsigned char heads;
# Line 67  static const char msg_building_new_label Line 84  static const char msg_building_new_label
84  "won't be recoverable.\n\n";  "won't be recoverable.\n\n";
85    
86  static const char msg_part_already_defined[] ALIGN1 =  static const char msg_part_already_defined[] ALIGN1 =
87  "Partition %d is already defined, delete it before re-adding\n";  "Partition %u is already defined, delete it before re-adding\n";
88    
89    
90  struct partition {  struct partition {
# Line 83  struct partition { Line 100  struct partition {
100   unsigned char size4[4];         /* nr of sectors in partition */   unsigned char size4[4];         /* nr of sectors in partition */
101  } PACKED;  } PACKED;
102    
103  static const char unable_to_open[] ALIGN1 = "can't open %s";  static const char unable_to_open[] ALIGN1 = "can't open '%s'";
104  static const char unable_to_read[] ALIGN1 = "can't read from %s";  static const char unable_to_read[] ALIGN1 = "can't read from %s";
105  static const char unable_to_seek[] ALIGN1 = "can't seek on %s";  static const char unable_to_seek[] ALIGN1 = "can't seek on %s";
106    
# Line 132  static void update_units(void); Line 149  static void update_units(void);
149  static void change_units(void);  static void change_units(void);
150  static void reread_partition_table(int leave);  static void reread_partition_table(int leave);
151  static void delete_partition(int i);  static void delete_partition(int i);
152  static int get_partition(int warn, int max);  static unsigned get_partition(int warn, unsigned max);
153  static void list_types(const char *const *sys);  static void list_types(const char *const *sys);
154  static unsigned read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char *mesg);  static sector_t read_int(sector_t low, sector_t dflt, sector_t high, sector_t base, const char *mesg);
155  #endif  #endif
156  static const char *partition_type(unsigned char type);  static const char *partition_type(unsigned char type);
157  static void get_geometry(void);  static void get_geometry(void);
# Line 147  static int get_boot(void); Line 164  static int get_boot(void);
164  #define PLURAL   0  #define PLURAL   0
165  #define SINGULAR 1  #define SINGULAR 1
166    
167  static unsigned get_start_sect(const struct partition *p);  static sector_t get_start_sect(const struct partition *p);
168  static unsigned get_nr_sects(const struct partition *p);  static sector_t get_nr_sects(const struct partition *p);
169    
170  /*  /*
171   * per partition table entry data   * per partition table entry data
# Line 161  static unsigned get_nr_sects(const struc Line 178  static unsigned get_nr_sects(const struc
178  struct pte {  struct pte {
179   struct partition *part_table;   /* points into sectorbuffer */   struct partition *part_table;   /* points into sectorbuffer */
180   struct partition *ext_pointer;  /* points into sectorbuffer */   struct partition *ext_pointer;  /* points into sectorbuffer */
181   ullong offset;          /* disk sector number */   sector_t offset;                /* disk sector number */
182   char *sectorbuffer;     /* disk sector contents */   char *sectorbuffer;             /* disk sector contents */
183  #if ENABLE_FEATURE_FDISK_WRITABLE  #if ENABLE_FEATURE_FDISK_WRITABLE
184   char changed;           /* boolean */   char changed;           /* boolean */
185  #endif  #endif
# Line 304  struct globals { Line 321  struct globals {
321   unsigned user_cylinders, user_heads, user_sectors;   unsigned user_cylinders, user_heads, user_sectors;
322   unsigned pt_heads, pt_sectors;   unsigned pt_heads, pt_sectors;
323   unsigned kern_heads, kern_sectors;   unsigned kern_heads, kern_sectors;
324   ullong extended_offset;         /* offset of link pointers */   sector_t extended_offset;       /* offset of link pointers */
325   ullong total_number_of_sectors;   sector_t total_number_of_sectors;
326    
327   jmp_buf listingbuf;   jmp_buf listingbuf;
328   char line_buffer[80];   char line_buffer[80];
# Line 360  struct globals { Line 377  struct globals {
377    
378    
379  /* TODO: move to libbb? */  /* TODO: move to libbb? */
380  static ullong bb_BLKGETSIZE_sectors(int fd)  /* TODO: return unsigned long long, FEATURE_FDISK_BLKSIZE _can_ handle
381     * disks > 2^32 sectors
382     */
383    static sector_t bb_BLKGETSIZE_sectors(int fd)
384  {  {
385   uint64_t v64;   uint64_t v64;
386   unsigned long longsectors;   unsigned long longsectors;
387    
388   if (ioctl(fd, BLKGETSIZE64, &v64) == 0) {   if (ioctl(fd, BLKGETSIZE64, &v64) == 0) {
389   /* Got bytes, convert to 512 byte sectors */   /* Got bytes, convert to 512 byte sectors */
390   return (v64 >> 9);   v64 >>= 9;
391     if (v64 != (sector_t)v64) {
392     ret_trunc:
393     /* Not only DOS, but all other partition tables
394     * we support can't record more than 32 bit
395     * sector counts or offsets
396     */
397     bb_error_msg("device has more than 2^32 sectors, can't use all of them");
398     v64 = (uint32_t)-1L;
399     }
400     return v64;
401   }   }
402   /* Needs temp of type long */   /* Needs temp of type long */
403   if (ioctl(fd, BLKGETSIZE, &longsectors))   if (ioctl(fd, BLKGETSIZE, &longsectors))
404   longsectors = 0;   longsectors = 0;
405     if (sizeof(long) > sizeof(sector_t)
406     && longsectors != (sector_t)longsectors
407     ) {
408     goto ret_trunc;
409     }
410   return longsectors;   return longsectors;
411  }  }
412    
# Line 425  read_line(const char *prompt) Line 460  read_line(const char *prompt)
460   line_buffer[--sz] = '\0';   line_buffer[--sz] = '\0';
461    
462   line_ptr = line_buffer;   line_ptr = line_buffer;
463   while (*line_ptr && !isgraph(*line_ptr))   while (*line_ptr != '\0' && (unsigned char)*line_ptr <= ' ')
464   line_ptr++;   line_ptr++;
465   return *line_ptr;   return *line_ptr;
466  }  }
# Line 562  static void fdisk_fatal(const char *why) Line 597  static void fdisk_fatal(const char *why)
597  }  }
598    
599  static void  static void
600  seek_sector(ullong secno)  seek_sector(sector_t secno)
601  {  {
  secno *= sector_size;  
602  #if ENABLE_FDISK_SUPPORT_LARGE_DISKS  #if ENABLE_FDISK_SUPPORT_LARGE_DISKS
603   if (lseek64(dev_fd, (off64_t)secno, SEEK_SET) == (off64_t) -1)   off64_t off = (off64_t)secno * sector_size;
604     if (lseek64(dev_fd, off, SEEK_SET) == (off64_t) -1)
605   fdisk_fatal(unable_to_seek);   fdisk_fatal(unable_to_seek);
606  #else  #else
607   if (secno > MAXINT(off_t)   uint64_t off = (uint64_t)secno * sector_size;
608   || lseek(dev_fd, (off_t)secno, SEEK_SET) == (off_t) -1   if (off > MAXINT(off_t)
609     || lseek(dev_fd, (off_t)off, SEEK_SET) == (off_t) -1
610   ) {   ) {
611   fdisk_fatal(unable_to_seek);   fdisk_fatal(unable_to_seek);
612   }   }
# Line 579  seek_sector(ullong secno) Line 615  seek_sector(ullong secno)
615    
616  #if ENABLE_FEATURE_FDISK_WRITABLE  #if ENABLE_FEATURE_FDISK_WRITABLE
617  static void  static void
618  write_sector(ullong secno, const void *buf)  write_sector(sector_t secno, const void *buf)
619  {  {
620   seek_sector(secno);   seek_sector(secno);
621   xwrite(dev_fd, buf, sector_size);   xwrite(dev_fd, buf, sector_size);
# Line 703  set_start_sect(struct partition *p, unsi Line 739  set_start_sect(struct partition *p, unsi
739  }  }
740  #endif  #endif
741    
742  static unsigned  static sector_t
743  get_start_sect(const struct partition *p)  get_start_sect(const struct partition *p)
744  {  {
745   return read4_little_endian(p->start4);   return read4_little_endian(p->start4);
# Line 717  set_nr_sects(struct partition *p, unsign Line 753  set_nr_sects(struct partition *p, unsign
753  }  }
754  #endif  #endif
755    
756  static unsigned  static sector_t
757  get_nr_sects(const struct partition *p)  get_nr_sects(const struct partition *p)
758  {  {
759   return read4_little_endian(p->size4);   return read4_little_endian(p->size4);
# Line 725  get_nr_sects(const struct partition *p) Line 761  get_nr_sects(const struct partition *p)
761    
762  /* Allocate a buffer and read a partition table sector */  /* Allocate a buffer and read a partition table sector */
763  static void  static void
764  read_pte(struct pte *pe, ullong offset)  read_pte(struct pte *pe, sector_t offset)
765  {  {
766   pe->offset = offset;   pe->offset = offset;
767   pe->sectorbuffer = xzalloc(sector_size);   pe->sectorbuffer = xzalloc(sector_size);
# Line 739  read_pte(struct pte *pe, ullong offset) Line 775  read_pte(struct pte *pe, ullong offset)
775   pe->part_table = pe->ext_pointer = NULL;   pe->part_table = pe->ext_pointer = NULL;
776  }  }
777    
778  static unsigned  static sector_t
779  get_partition_start(const struct pte *pe)  get_partition_start(const struct pte *pe)
780  {  {
781   return pe->offset + get_start_sect(pe->part_table);   return pe->offset + get_start_sect(pe->part_table);
# Line 981  clear_partition(struct partition *p) Line 1017  clear_partition(struct partition *p)
1017    
1018  #if ENABLE_FEATURE_FDISK_WRITABLE  #if ENABLE_FEATURE_FDISK_WRITABLE
1019  static void  static void
1020  set_partition(int i, int doext, ullong start, ullong stop, int sysid)  set_partition(int i, int doext, sector_t start, sector_t stop, int sysid)
1021  {  {
1022   struct partition *p;   struct partition *p;
1023   ullong offset;   sector_t offset;
1024    
1025   if (doext) {   if (doext) {
1026   p = ptes[i].ext_pointer;   p = ptes[i].ext_pointer;
# Line 1045  warn_cylinders(void) Line 1081  warn_cylinders(void)
1081  {  {
1082   if (LABEL_IS_DOS && g_cylinders > 1024 && !nowarn)   if (LABEL_IS_DOS && g_cylinders > 1024 && !nowarn)
1083   printf("\n"   printf("\n"
1084  "The number of cylinders for this disk is set to %d.\n"  "The number of cylinders for this disk is set to %u.\n"
1085  "There is nothing wrong with that, but this is larger than 1024,\n"  "There is nothing wrong with that, but this is larger than 1024,\n"
1086  "and could in certain setups cause problems with:\n"  "and could in certain setups cause problems with:\n"
1087  "1) software that runs at boot time (e.g., old versions of LILO)\n"  "1) software that runs at boot time (e.g., old versions of LILO)\n"
# Line 1081  read_extended(int ext) Line 1117  read_extended(int ext)
1117     Do not try to 'improve' this test. */     Do not try to 'improve' this test. */
1118   struct pte *pre = &ptes[g_partitions - 1];   struct pte *pre = &ptes[g_partitions - 1];
1119  #if ENABLE_FEATURE_FDISK_WRITABLE  #if ENABLE_FEATURE_FDISK_WRITABLE
1120   printf("Warning: deleting partitions after %d\n",   printf("Warning: deleting partitions after %u\n",
1121   g_partitions);   g_partitions);
1122   pre->changed = 1;   pre->changed = 1;
1123  #endif  #endif
# Line 1100  read_extended(int ext) Line 1136  read_extended(int ext)
1136   if (pe->ext_pointer)   if (pe->ext_pointer)
1137   printf("Warning: extra link "   printf("Warning: extra link "
1138   "pointer in partition table"   "pointer in partition table"
1139   " %d\n", g_partitions + 1);   " %u\n", g_partitions + 1);
1140   else   else
1141   pe->ext_pointer = p;   pe->ext_pointer = p;
1142   } else if (p->sys_ind) {   } else if (p->sys_ind) {
1143   if (pe->part_table)   if (pe->part_table)
1144   printf("Warning: ignoring extra "   printf("Warning: ignoring extra "
1145    "data in partition table"    "data in partition table"
1146    " %d\n", g_partitions + 1);    " %u\n", g_partitions + 1);
1147   else   else
1148   pe->part_table = p;   pe->part_table = p;
1149   }   }
# Line 1140  read_extended(int ext) Line 1176  read_extended(int ext)
1176   if (!get_nr_sects(pe->part_table)   if (!get_nr_sects(pe->part_table)
1177   && (g_partitions > 5 || ptes[4].part_table->sys_ind)   && (g_partitions > 5 || ptes[4].part_table->sys_ind)
1178   ) {   ) {
1179   printf("Omitting empty partition (%d)\n", i+1);   printf("Omitting empty partition (%u)\n", i+1);
1180   delete_partition(i);   delete_partition(i);
1181   goto remove;    /* numbering changed */   goto remove;    /* numbering changed */
1182   }   }
# Line 1181  get_sectorsize(void) Line 1217  get_sectorsize(void)
1217   if (ioctl(dev_fd, BLKSSZGET, &arg) == 0)   if (ioctl(dev_fd, BLKSSZGET, &arg) == 0)
1218   sector_size = arg;   sector_size = arg;
1219   if (sector_size != DEFAULT_SECTOR_SIZE)   if (sector_size != DEFAULT_SECTOR_SIZE)
1220   printf("Note: sector size is %d "   printf("Note: sector size is %u "
1221   "(not " DEFAULT_SECTOR_SIZE_STR ")\n",   "(not " DEFAULT_SECTOR_SIZE_STR ")\n",
1222   sector_size);   sector_size);
1223   }   }
# Line 1302  static int get_boot(void) Line 1338  static int get_boot(void)
1338  // or get_boot() [table is bad] -> create_sunlabel() -> get_boot(CREATE_EMPTY_SUN).  // or get_boot() [table is bad] -> create_sunlabel() -> get_boot(CREATE_EMPTY_SUN).
1339  // (just factor out re-init of ptes[0,1,2,3] in a separate fn instead?)  // (just factor out re-init of ptes[0,1,2,3] in a separate fn instead?)
1340  // So skip opening device _again_...  // So skip opening device _again_...
1341   if (what == CREATE_EMPTY_DOS  USE_FEATURE_SUN_LABEL(|| what == CREATE_EMPTY_SUN))   if (what == CREATE_EMPTY_DOS  IF_FEATURE_SUN_LABEL(|| what == CREATE_EMPTY_SUN))
1342   goto created_table;   goto created_table;
1343    
1344   fd = open(disk_device, (option_mask32 & OPT_l) ? O_RDONLY : O_RDWR);   fd = open(disk_device, (option_mask32 & OPT_l) ? O_RDONLY : O_RDWR);
# Line 1372  static int get_boot(void) Line 1408  static int get_boot(void)
1408    "partition table, nor Sun, SGI or OSF "    "partition table, nor Sun, SGI or OSF "
1409    "disklabel\n");    "disklabel\n");
1410  #ifdef __sparc__  #ifdef __sparc__
1411   USE_FEATURE_SUN_LABEL(create_sunlabel();)   IF_FEATURE_SUN_LABEL(create_sunlabel();)
1412  #else  #else
1413   create_doslabel();   create_doslabel();
1414  #endif  #endif
# Line 1385  static int get_boot(void) Line 1421  static int get_boot(void)
1421  #endif /* FEATURE_FDISK_WRITABLE */  #endif /* FEATURE_FDISK_WRITABLE */
1422    
1423    
1424   USE_FEATURE_FDISK_WRITABLE(warn_cylinders();)   IF_FEATURE_FDISK_WRITABLE(warn_cylinders();)
1425   warn_geometry();   warn_geometry();
1426    
1427   for (i = 0; i < 4; i++) {   for (i = 0; i < 4; i++) {
1428   if (IS_EXTENDED(ptes[i].part_table->sys_ind)) {   if (IS_EXTENDED(ptes[i].part_table->sys_ind)) {
1429   if (g_partitions != 4)   if (g_partitions != 4)
1430   printf("Ignoring extra extended "   printf("Ignoring extra extended "
1431   "partition %d\n", i + 1);   "partition %u\n", i + 1);
1432   else   else
1433   read_extended(i);   read_extended(i);
1434   }   }
# Line 1402  static int get_boot(void) Line 1438  static int get_boot(void)
1438   struct pte *pe = &ptes[i];   struct pte *pe = &ptes[i];
1439   if (!valid_part_table_flag(pe->sectorbuffer)) {   if (!valid_part_table_flag(pe->sectorbuffer)) {
1440   printf("Warning: invalid flag 0x%02x,0x%02x of partition "   printf("Warning: invalid flag 0x%02x,0x%02x of partition "
1441   "table %d will be corrected by w(rite)\n",   "table %u will be corrected by w(rite)\n",
1442   pe->sectorbuffer[510],   pe->sectorbuffer[510],
1443   pe->sectorbuffer[511],   pe->sectorbuffer[511],
1444   i + 1);   i + 1);
1445   USE_FEATURE_FDISK_WRITABLE(pe->changed = 1;)   IF_FEATURE_FDISK_WRITABLE(pe->changed = 1;)
1446   }   }
1447   }   }
1448    
# Line 1421  static int get_boot(void) Line 1457  static int get_boot(void)
1457   *   *
1458   * There is no default if DFLT is not between LOW and HIGH.   * There is no default if DFLT is not between LOW and HIGH.
1459   */   */
1460  static unsigned  static sector_t
1461  read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char *mesg)  read_int(sector_t low, sector_t dflt, sector_t high, sector_t base, const char *mesg)
1462  {  {
1463   unsigned i;   sector_t value;
1464   int default_ok = 1;   int default_ok = 1;
1465   const char *fmt = "%s (%u-%u, default %u): ";   const char *fmt = "%s (%u-%u, default %u): ";
1466    
# Line 1447  read_int(unsigned low, unsigned dflt, un Line 1483  read_int(unsigned low, unsigned dflt, un
1483   int minus = (*line_ptr == '-');   int minus = (*line_ptr == '-');
1484   int absolute = 0;   int absolute = 0;
1485    
1486   i = atoi(line_ptr + 1);   value = atoi(line_ptr + 1);
1487    
1488     /* (1) if 2nd char is digit, use_default = 0.
1489     * (2) move line_ptr to first non-digit. */
1490   while (isdigit(*++line_ptr))   while (isdigit(*++line_ptr))
1491   use_default = 0;   use_default = 0;
1492    
# Line 1456  read_int(unsigned low, unsigned dflt, un Line 1494  read_int(unsigned low, unsigned dflt, un
1494   case 'c':   case 'c':
1495   case 'C':   case 'C':
1496   if (!display_in_cyl_units)   if (!display_in_cyl_units)
1497   i *= g_heads * g_sectors;   value *= g_heads * g_sectors;
1498   break;   break;
1499   case 'K':   case 'K':
1500   absolute = 1024;   absolute = 1024;
# Line 1479  read_int(unsigned low, unsigned dflt, un Line 1517  read_int(unsigned low, unsigned dflt, un
1517   ullong bytes;   ullong bytes;
1518   unsigned long unit;   unsigned long unit;
1519    
1520   bytes = (ullong) i * absolute;   bytes = (ullong) value * absolute;
1521   unit = sector_size * units_per_sector;   unit = sector_size * units_per_sector;
1522   bytes += unit/2; /* round */   bytes += unit/2; /* round */
1523   bytes /= unit;   bytes /= unit;
1524   i = bytes;   value = bytes;
1525   }   }
1526   if (minus)   if (minus)
1527   i = -i;   value = -value;
1528   i += base;   value += base;
1529   } else {   } else {
1530   i = atoi(line_ptr);   value = atoi(line_ptr);
1531   while (isdigit(*line_ptr)) {   while (isdigit(*line_ptr)) {
1532   line_ptr++;   line_ptr++;
1533   use_default = 0;   use_default = 0;
1534   }   }
1535   }   }
1536   if (use_default) {   if (use_default) {
1537   i = dflt;   value = dflt;
1538   printf("Using default value %u\n", i);   printf("Using default value %u\n", value);
1539   }   }
1540   if (i >= low && i <= high)   if (value >= low && value <= high)
1541   break;   break;
1542   printf("Value is out of range\n");   printf("Value is out of range\n");
1543   }   }
1544   return i;   return value;
1545  }  }
1546    
1547  static int  static unsigned
1548  get_partition(int warn, int max)  get_partition(int warn, unsigned max)
1549  {  {
1550   struct pte *pe;   struct pte *pe;
1551   int i;   unsigned i;
1552    
1553   i = read_int(1, 0, max, 0, "Partition number") - 1;   i = read_int(1, 0, max, 0, "Partition number") - 1;
1554   pe = &ptes[i];   pe = &ptes[i];
# Line 1520  get_partition(int warn, int max) Line 1558  get_partition(int warn, int max)
1558   || (LABEL_IS_SUN && (!sunlabel->partitions[i].num_sectors || !sunlabel->infos[i].id))   || (LABEL_IS_SUN && (!sunlabel->partitions[i].num_sectors || !sunlabel->infos[i].id))
1559   || (LABEL_IS_SGI && !sgi_get_num_sectors(i))   || (LABEL_IS_SGI && !sgi_get_num_sectors(i))
1560   ) {   ) {
1561   printf("Warning: partition %d has empty type\n", i+1);   printf("Warning: partition %u has empty type\n", i+1);
1562   }   }
1563   }   }
1564   return i;   return i;
1565  }  }
1566    
1567  static int  static int
1568  get_existing_partition(int warn, int max)  get_existing_partition(int warn, unsigned max)
1569  {  {
1570   int pno = -1;   int pno = -1;
1571   int i;   unsigned i;
1572    
1573   for (i = 0; i < max; i++) {   for (i = 0; i < max; i++) {
1574   struct pte *pe = &ptes[i];   struct pte *pe = &ptes[i];
# Line 1543  get_existing_partition(int warn, int max Line 1581  get_existing_partition(int warn, int max
1581   }   }
1582   }   }
1583   if (pno >= 0) {   if (pno >= 0) {
1584   printf("Selected partition %d\n", pno+1);   printf("Selected partition %u\n", pno+1);
1585   return pno;   return pno;
1586   }   }
1587   printf("No partition is defined yet!\n");   printf("No partition is defined yet!\n");
# Line 1554  get_existing_partition(int warn, int max Line 1592  get_existing_partition(int warn, int max
1592  }  }
1593    
1594  static int  static int
1595  get_nonexisting_partition(int warn, int max)  get_nonexisting_partition(int warn, unsigned max)
1596  {  {
1597   int pno = -1;   int pno = -1;
1598   int i;   unsigned i;
1599    
1600   for (i = 0; i < max; i++) {   for (i = 0; i < max; i++) {
1601   struct pte *pe = &ptes[i];   struct pte *pe = &ptes[i];
# Line 1570  get_nonexisting_partition(int warn, int Line 1608  get_nonexisting_partition(int warn, int
1608   }   }
1609   }   }
1610   if (pno >= 0) {   if (pno >= 0) {
1611   printf("Selected partition %d\n", pno+1);   printf("Selected partition %u\n", pno+1);
1612   return pno;   return pno;
1613   }   }
1614   printf("All primary partitions have been defined already!\n");   printf("All primary partitions have been defined already!\n");
# Line 1597  toggle_active(int i) Line 1635  toggle_active(int i)
1635   struct partition *p = pe->part_table;   struct partition *p = pe->part_table;
1636    
1637   if (IS_EXTENDED(p->sys_ind) && !p->boot_ind)   if (IS_EXTENDED(p->sys_ind) && !p->boot_ind)
1638   printf("WARNING: Partition %d is an extended partition\n", i + 1);   printf("WARNING: Partition %u is an extended partition\n", i + 1);
1639   p->boot_ind = (p->boot_ind ? 0 : ACTIVE_FLAG);   p->boot_ind = (p->boot_ind ? 0 : ACTIVE_FLAG);
1640   pe->changed = 1;   pe->changed = 1;
1641  }  }
# Line 1670  delete_partition(int i) Line 1708  delete_partition(int i)
1708    
1709   if (pe->part_table) /* prevent SEGFAULT */   if (pe->part_table) /* prevent SEGFAULT */
1710   set_start_sect(pe->part_table,   set_start_sect(pe->part_table,
1711     get_partition_start(pe) -   get_partition_start(pe) -
1712     extended_offset);   extended_offset);
1713   pe->offset = extended_offset;   pe->offset = extended_offset;
1714   pe->changed = 1;   pe->changed = 1;
1715   }   }
# Line 1710  change_sysid(void) Line 1748  change_sysid(void)
1748   /* if changing types T to 0 is allowed, then   /* if changing types T to 0 is allowed, then
1749     the reverse change must be allowed, too */     the reverse change must be allowed, too */
1750   if (!sys && !LABEL_IS_SGI && !LABEL_IS_SUN && !get_nr_sects(p)) {   if (!sys && !LABEL_IS_SGI && !LABEL_IS_SUN && !get_nr_sects(p)) {
1751   printf("Partition %d does not exist yet!\n", i + 1);   printf("Partition %u does not exist yet!\n", i + 1);
1752   return;   return;
1753   }   }
1754   while (1) {   while (1) {
# Line 1761  change_sysid(void) Line 1799  change_sysid(void)
1799   } else   } else
1800   p->sys_ind = sys;   p->sys_ind = sys;
1801    
1802   printf("Changed system type of partition %d "   printf("Changed system type of partition %u "
1803   "to %x (%s)\n", i + 1, sys,   "to %x (%s)\n", i + 1, sys,
1804   partition_type(sys));   partition_type(sys));
1805   ptes[i].changed = 1;   ptes[i].changed = 1;
# Line 1819  check_consistency(const struct partition Line 1857  check_consistency(const struct partition
1857    
1858  /* Same physical / logical beginning? */  /* Same physical / logical beginning? */
1859   if (g_cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) {   if (g_cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) {
1860   printf("Partition %d has different physical/logical "   printf("Partition %u has different physical/logical "
1861   "beginnings (non-Linux?):\n", partition + 1);   "beginnings (non-Linux?):\n", partition + 1);
1862   printf("     phys=(%d, %d, %d) ", pbc, pbh, pbs);   printf("     phys=(%u, %u, %u) ", pbc, pbh, pbs);
1863   printf("logical=(%d, %d, %d)\n", lbc, lbh, lbs);   printf("logical=(%u, %u, %u)\n", lbc, lbh, lbs);
1864   }   }
1865    
1866  /* Same physical / logical ending? */  /* Same physical / logical ending? */
1867   if (g_cylinders <= 1024 && (pec != lec || peh != leh || pes != les)) {   if (g_cylinders <= 1024 && (pec != lec || peh != leh || pes != les)) {
1868   printf("Partition %d has different physical/logical "   printf("Partition %u has different physical/logical "
1869   "endings:\n", partition + 1);   "endings:\n", partition + 1);
1870   printf("     phys=(%d, %d, %d) ", pec, peh, pes);   printf("     phys=(%u, %u, %u) ", pec, peh, pes);
1871   printf("logical=(%d, %d, %d)\n", lec, leh, les);   printf("logical=(%u, %u, %u)\n", lec, leh, les);
1872   }   }
1873    
1874  /* Ending on cylinder boundary? */  /* Ending on cylinder boundary? */
1875   if (peh != (g_heads - 1) || pes != g_sectors) {   if (peh != (g_heads - 1) || pes != g_sectors) {
1876   printf("Partition %i does not end on cylinder boundary\n",   printf("Partition %u does not end on cylinder boundary\n",
1877   partition + 1);   partition + 1);
1878   }   }
1879  }  }
# Line 1843  check_consistency(const struct partition Line 1881  check_consistency(const struct partition
1881  static void  static void
1882  list_disk_geometry(void)  list_disk_geometry(void)
1883  {  {
1884   long long bytes = (total_number_of_sectors << 9);   ullong bytes = ((ullong)total_number_of_sectors << 9);
1885   long megabytes = bytes/1000000;   long megabytes = bytes / 1000000;
1886    
1887   if (megabytes < 10000)   if (megabytes < 10000)
1888   printf("\nDisk %s: %ld MB, %lld bytes\n",   printf("\nDisk %s: %lu MB, %llu bytes\n",
1889     disk_device, megabytes, bytes);   disk_device, megabytes, bytes);
1890   else   else
1891   printf("\nDisk %s: %ld.%ld GB, %lld bytes\n",   printf("\nDisk %s: %lu.%lu GB, %llu bytes\n",
1892     disk_device, megabytes/1000, (megabytes/100)%10, bytes);   disk_device, megabytes/1000, (megabytes/100)%10, bytes);
1893   printf("%d heads, %d sectors/track, %d cylinders",   printf("%u heads, %u sectors/track, %u cylinders",
1894     g_heads, g_sectors, g_cylinders);     g_heads, g_sectors, g_cylinders);
1895   if (units_per_sector == 1)   if (units_per_sector == 1)
1896   printf(", total %llu sectors",   printf(", total %"SECT_FMT"u sectors",
1897     total_number_of_sectors / (sector_size/512));   total_number_of_sectors / (sector_size/512));
1898   printf("\nUnits = %s of %d * %d = %d bytes\n\n",   printf("\nUnits = %s of %u * %u = %u bytes\n\n",
1899     str_units(PLURAL),   str_units(PLURAL),
1900     units_per_sector, sector_size, units_per_sector * sector_size);   units_per_sector, sector_size, units_per_sector * sector_size);
1901  }  }
1902    
1903  /*  /*
# Line 1872  wrong_p_order(int *prev) Line 1910  wrong_p_order(int *prev)
1910  {  {
1911   const struct pte *pe;   const struct pte *pe;
1912   const struct partition *p;   const struct partition *p;
1913   ullong last_p_start_pos = 0, p_start_pos;   sector_t last_p_start_pos = 0, p_start_pos;
1914   int i, last_i = 0;   unsigned i, last_i = 0;
1915    
1916   for (i = 0; i < g_partitions; i++) {   for (i = 0; i < g_partitions; i++) {
1917   if (i == 4) {   if (i == 4) {
# Line 2041  list_table(int xtra) Line 2079  list_table(int xtra)
2079    
2080   for (i = 0; i < g_partitions; i++) {   for (i = 0; i < g_partitions; i++) {
2081   const struct pte *pe = &ptes[i];   const struct pte *pe = &ptes[i];
2082   ullong psects;   sector_t psects;
2083   ullong pblocks;   sector_t pblocks;
2084   unsigned podd;   unsigned podd;
2085    
2086   p = pe->part_table;   p = pe->part_table;
# Line 2060  list_table(int xtra) Line 2098  list_table(int xtra)
2098   if (sector_size > 1024)   if (sector_size > 1024)
2099   pblocks *= (sector_size / 1024);   pblocks *= (sector_size / 1024);
2100    
2101   printf("%s  %c %11llu %11llu %11llu%c %2x %s\n",   printf("%s  %c %11"SECT_FMT"u %11"SECT_FMT"u %11"SECT_FMT"u%c %2x %s\n",
2102   partname(disk_device, i+1, w+2),   partname(disk_device, i+1, w+2),
2103   !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG /* boot flag */   !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG /* boot flag */
2104   ? '*' : '?',   ? '*' : '?',
2105   (ullong) cround(get_partition_start(pe)),           /* start */   cround(get_partition_start(pe)),           /* start */
2106   (ullong) cround(get_partition_start(pe) + psects    /* end */   cround(get_partition_start(pe) + psects    /* end */
2107   - (psects ? 1 : 0)),   - (psects ? 1 : 0)),
2108   (ullong) pblocks, podd ? '+' : ' ', /* odd flag on end */   pblocks, podd ? '+' : ' ', /* odd flag on end */
2109   p->sys_ind,                                     /* type id */   p->sys_ind,                                     /* type id */
2110   partition_type(p->sys_ind));                    /* type name */   partition_type(p->sys_ind));                    /* type name */
2111    
# Line 2075  list_table(int xtra) Line 2113  list_table(int xtra)
2113   }   }
2114    
2115   /* Is partition table in disk order? It need not be, but... */   /* Is partition table in disk order? It need not be, but... */
2116   /* partition table entries are not checked for correct order if this   /* partition table entries are not checked for correct order
2117     is a sgi, sun or aix labeled disk... */   * if this is a sgi, sun or aix labeled disk... */
2118   if (LABEL_IS_DOS && wrong_p_order(NULL)) {   if (LABEL_IS_DOS && wrong_p_order(NULL)) {
2119   /* FIXME */   /* FIXME */
2120   printf("\nPartition table entries are not in disk order\n");   printf("\nPartition table entries are not in disk order\n");
# Line 2091  x_list_table(int extend) Line 2129  x_list_table(int extend)
2129   const struct partition *p;   const struct partition *p;
2130   int i;   int i;
2131    
2132   printf("\nDisk %s: %d heads, %d sectors, %d cylinders\n\n",   printf("\nDisk %s: %u heads, %u sectors, %u cylinders\n\n",
2133   disk_device, g_heads, g_sectors, g_cylinders);   disk_device, g_heads, g_sectors, g_cylinders);
2134   printf("Nr AF  Hd Sec  Cyl  Hd Sec  Cyl      Start       Size ID\n");   printf("Nr AF  Hd Sec  Cyl  Hd Sec  Cyl      Start       Size ID\n");
2135   for (i = 0; i < g_partitions; i++) {   for (i = 0; i < g_partitions; i++) {
2136   pe = &ptes[i];   pe = &ptes[i];
2137   p = (extend ? pe->ext_pointer : pe->part_table);   p = (extend ? pe->ext_pointer : pe->part_table);
2138   if (p != NULL) {   if (p != NULL) {
2139   printf("%2d %02x%4d%4d%5d%4d%4d%5d%11u%11u %02x\n",   printf("%2u %02x%4u%4u%5u%4u%4u%5u%11"SECT_FMT"u%11"SECT_FMT"u %02x\n",
2140   i + 1, p->boot_ind, p->head,   i + 1, p->boot_ind, p->head,
2141   sector(p->sector),   sector(p->sector),
2142   cylinder(p->sector, p->cyl), p->end_head,   cylinder(p->sector, p->cyl), p->end_head,
2143   sector(p->end_sector),   sector(p->end_sector),
2144   cylinder(p->end_sector, p->end_cyl),   cylinder(p->end_sector, p->end_cyl),
2145   get_start_sect(p), get_nr_sects(p), p->sys_ind);   get_start_sect(p), get_nr_sects(p),
2146     p->sys_ind);
2147   if (p->sys_ind)   if (p->sys_ind)
2148   check_consistency(p, i);   check_consistency(p, i);
2149   }   }
# Line 2114  x_list_table(int extend) Line 2153  x_list_table(int extend)
2153    
2154  #if ENABLE_FEATURE_FDISK_WRITABLE  #if ENABLE_FEATURE_FDISK_WRITABLE
2155  static void  static void
2156  fill_bounds(ullong *first, ullong *last)  fill_bounds(sector_t *first, sector_t *last)
2157  {  {
2158   int i;   unsigned i;
2159   const struct pte *pe = &ptes[0];   const struct pte *pe = &ptes[0];
2160   const struct partition *p;   const struct partition *p;
2161    
# Line 2133  fill_bounds(ullong *first, ullong *last) Line 2172  fill_bounds(ullong *first, ullong *last)
2172  }  }
2173    
2174  static void  static void
2175  check(int n, unsigned h, unsigned s, unsigned c, ullong start)  check(int n, unsigned h, unsigned s, unsigned c, sector_t start)
2176  {  {
2177   ullong total, real_s, real_c;   sector_t total, real_s, real_c;
2178    
2179   real_s = sector(s) - 1;   real_s = sector(s) - 1;
2180   real_c = cylinder(s, c);   real_c = cylinder(s, c);
2181   total = (real_c * g_sectors + real_s) * g_heads + h;   total = (real_c * g_sectors + real_s) * g_heads + h;
2182   if (!total)   if (!total)
2183   printf("Partition %d contains sector 0\n", n);   printf("Partition %u contains sector 0\n", n);
2184   if (h >= g_heads)   if (h >= g_heads)
2185   printf("Partition %d: head %d greater than maximum %d\n",   printf("Partition %u: head %u greater than maximum %u\n",
2186   n, h + 1, g_heads);   n, h + 1, g_heads);
2187   if (real_s >= g_sectors)   if (real_s >= g_sectors)
2188   printf("Partition %d: sector %d greater than "   printf("Partition %u: sector %u greater than "
2189   "maximum %d\n", n, s, g_sectors);   "maximum %u\n", n, s, g_sectors);
2190   if (real_c >= g_cylinders)   if (real_c >= g_cylinders)
2191   printf("Partition %d: cylinder %llu greater than "   printf("Partition %u: cylinder %"SECT_FMT"u greater than "
2192   "maximum %d\n", n, real_c + 1, g_cylinders);   "maximum %u\n", n, real_c + 1, g_cylinders);
2193   if (g_cylinders <= 1024 && start != total)   if (g_cylinders <= 1024 && start != total)
2194   printf("Partition %d: previous sectors %llu disagrees with "   printf("Partition %u: previous sectors %"SECT_FMT"u disagrees with "
2195   "total %llu\n", n, start, total);   "total %"SECT_FMT"u\n", n, start, total);
2196  }  }
2197    
2198  static void  static void
2199  verify(void)  verify(void)
2200  {  {
2201   int i, j;   int i, j;
2202   unsigned total = 1;   sector_t total = 1;
2203   ullong first[g_partitions], last[g_partitions];   sector_t first[g_partitions], last[g_partitions];
2204   struct partition *p;   struct partition *p;
2205    
2206   if (warn_geometry())   if (warn_geometry())
# Line 2185  verify(void) Line 2224  verify(void)
2224   check_consistency(p, i);   check_consistency(p, i);
2225   if (get_partition_start(pe) < first[i])   if (get_partition_start(pe) < first[i])
2226   printf("Warning: bad start-of-data in "   printf("Warning: bad start-of-data in "
2227   "partition %d\n", i + 1);   "partition %u\n", i + 1);
2228   check(i + 1, p->end_head, p->end_sector, p->end_cyl,   check(i + 1, p->end_head, p->end_sector, p->end_cyl,
2229   last[i]);   last[i]);
2230   total += last[i] + 1 - first[i];   total += last[i] + 1 - first[i];
2231   for (j = 0; j < i; j++) {   for (j = 0; j < i; j++) {
2232   if ((first[i] >= first[j] && first[i] <= last[j])   if ((first[i] >= first[j] && first[i] <= last[j])
2233   || ((last[i] <= last[j] && last[i] >= first[j]))) {   || ((last[i] <= last[j] && last[i] >= first[j]))) {
2234   printf("Warning: partition %d overlaps "   printf("Warning: partition %u overlaps "
2235   "partition %d\n", j + 1, i + 1);   "partition %u\n", j + 1, i + 1);
2236   total += first[i] >= first[j] ?   total += first[i] >= first[j] ?
2237   first[i] : first[j];   first[i] : first[j];
2238   total -= last[i] <= last[j] ?   total -= last[i] <= last[j] ?
# Line 2205  verify(void) Line 2244  verify(void)
2244    
2245   if (extended_offset) {   if (extended_offset) {
2246   struct pte *pex = &ptes[ext_index];   struct pte *pex = &ptes[ext_index];
2247   ullong e_last = get_start_sect(pex->part_table) +   sector_t e_last = get_start_sect(pex->part_table) +
2248   get_nr_sects(pex->part_table) - 1;   get_nr_sects(pex->part_table) - 1;
2249    
2250   for (i = 4; i < g_partitions; i++) {   for (i = 4; i < g_partitions; i++) {
# Line 2213  verify(void) Line 2252  verify(void)
2252   p = ptes[i].part_table;   p = ptes[i].part_table;
2253   if (!p->sys_ind) {   if (!p->sys_ind) {
2254   if (i != 4 || i + 1 < g_partitions)   if (i != 4 || i + 1 < g_partitions)
2255   printf("Warning: partition %d "   printf("Warning: partition %u "
2256   "is empty\n", i + 1);   "is empty\n", i + 1);
2257   } else if (first[i] < extended_offset || last[i] > e_last) {   } else if (first[i] < extended_offset || last[i] > e_last) {
2258   printf("Logical partition %d not entirely in "   printf("Logical partition %u not entirely in "
2259   "partition %d\n", i + 1, ext_index + 1);   "partition %u\n", i + 1, ext_index + 1);
2260   }   }
2261   }   }
2262   }   }
2263    
2264   if (total > g_heads * g_sectors * g_cylinders)   if (total > g_heads * g_sectors * g_cylinders)
2265   printf("Total allocated sectors %d greater than the maximum "   printf("Total allocated sectors %u greater than the maximum "
2266   "%d\n", total, g_heads * g_sectors * g_cylinders);   "%u\n", total, g_heads * g_sectors * g_cylinders);
2267   else {   else {
2268   total = g_heads * g_sectors * g_cylinders - total;   total = g_heads * g_sectors * g_cylinders - total;
2269   if (total != 0)   if (total != 0)
2270   printf("%d unallocated sectors\n", total);   printf("%"SECT_FMT"u unallocated sectors\n", total);
2271   }   }
2272  }  }
2273    
# Line 2239  add_partition(int n, int sys) Line 2278  add_partition(int n, int sys)
2278   int i, num_read = 0;   int i, num_read = 0;
2279   struct partition *p = ptes[n].part_table;   struct partition *p = ptes[n].part_table;
2280   struct partition *q = ptes[ext_index].part_table;   struct partition *q = ptes[ext_index].part_table;
2281   ullong limit, temp;   sector_t limit, temp;
2282   ullong start, stop = 0;   sector_t start, stop = 0;
2283   ullong first[g_partitions], last[g_partitions];   sector_t first[g_partitions], last[g_partitions];
2284    
2285   if (p && p->sys_ind) {   if (p && p->sys_ind) {
2286   printf(msg_part_already_defined, n + 1);   printf(msg_part_already_defined, n + 1);
# Line 2251  add_partition(int n, int sys) Line 2290  add_partition(int n, int sys)
2290   if (n < 4) {   if (n < 4) {
2291   start = sector_offset;   start = sector_offset;
2292   if (display_in_cyl_units || !total_number_of_sectors)   if (display_in_cyl_units || !total_number_of_sectors)
2293   limit = (ullong) g_heads * g_sectors * g_cylinders - 1;   limit = (sector_t) g_heads * g_sectors * g_cylinders - 1;
2294   else   else
2295   limit = total_number_of_sectors - 1;   limit = total_number_of_sectors - 1;
2296   if (extended_offset) {   if (extended_offset) {
# Line 2282  add_partition(int n, int sys) Line 2321  add_partition(int n, int sys)
2321   if (start > limit)   if (start > limit)
2322   break;   break;
2323   if (start >= temp+units_per_sector && num_read) {   if (start >= temp+units_per_sector && num_read) {
2324   printf("Sector %lld is already allocated\n", temp);   printf("Sector %"SECT_FMT"u is already allocated\n", temp);
2325   temp = start;   temp = start;
2326   num_read = 0;   num_read = 0;
2327   }   }
2328   if (!num_read && start == temp) {   if (!num_read && start == temp) {
2329   ullong saved_start;   sector_t saved_start;
2330    
2331   saved_start = start;   saved_start = start;
2332   start = read_int(cround(saved_start), cround(saved_start), cround(limit),   start = read_int(cround(saved_start), cround(saved_start), cround(limit),
2333   0, mesg);   0, mesg);
2334   if (display_in_cyl_units) {   if (display_in_cyl_units) {
2335   start = (start - 1) * units_per_sector;   start = (start - 1) * units_per_sector;
2336   if (start < saved_start) start = saved_start;   if (start < saved_start)
2337     start = saved_start;
2338   }   }
2339   num_read = 1;   num_read = 1;
2340   }   }
# Line 2542  print_raw(void) Line 2582  print_raw(void)
2582  }  }
2583    
2584  static void  static void
2585  move_begin(int i)  move_begin(unsigned i)
2586  {  {
2587   struct pte *pe = &ptes[i];   struct pte *pe = &ptes[i];
2588   struct partition *p = pe->part_table;   struct partition *p = pe->part_table;
2589   ullong new, first;   sector_t new, first;
2590    
2591   if (warn_geometry())   if (warn_geometry())
2592   return;   return;
2593   if (!p->sys_ind || !get_nr_sects(p) || IS_EXTENDED(p->sys_ind)) {   if (!p->sys_ind || !get_nr_sects(p) || IS_EXTENDED(p->sys_ind)) {
2594   printf("Partition %d has no data area\n", i + 1);   printf("Partition %u has no data area\n", i + 1);
2595   return;   return;
2596   }   }
2597   first = get_partition_start(pe);   first = get_partition_start(pe);
# Line 2757  list_devs_in_proc_partititons(void) Line 2797  list_devs_in_proc_partititons(void)
2797   procpt = fopen_or_warn("/proc/partitions", "r");   procpt = fopen_or_warn("/proc/partitions", "r");
2798    
2799   while (fgets(line, sizeof(line), procpt)) {   while (fgets(line, sizeof(line), procpt)) {
2800   if (sscanf(line, " %d %d %d %[^\n ]",   if (sscanf(line, " %u %u %u %[^\n ]",
2801   &ma, &mi, &sz, ptname) != 4)   &ma, &mi, &sz, ptname) != 4)
2802   continue;   continue;
2803   for (s = ptname; *s; s++)   for (s = ptname; *s; s++)
# Line 2781  unknown_command(int c) Line 2821  unknown_command(int c)
2821  #endif  #endif
2822    
2823  int fdisk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;  int fdisk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
2824  int fdisk_main(int argc, char **argv)  int fdisk_main(int argc UNUSED_PARAM, char **argv)
2825  {  {
2826   unsigned opt;   unsigned opt;
2827   /*   /*
# Line 2797  int fdisk_main(int argc, char **argv) Line 2837  int fdisk_main(int argc, char **argv)
2837   close_dev_fd(); /* needed: fd 3 must not stay closed */   close_dev_fd(); /* needed: fd 3 must not stay closed */
2838    
2839   opt_complementary = "b+:C+:H+:S+"; /* numeric params */   opt_complementary = "b+:C+:H+:S+"; /* numeric params */
2840   opt = getopt32(argv, "b:C:H:lS:u" USE_FEATURE_FDISK_BLKSIZE("s"),   opt = getopt32(argv, "b:C:H:lS:u" IF_FEATURE_FDISK_BLKSIZE("s"),
2841   &sector_size, &user_cylinders, &user_heads, &user_sectors);   &sector_size, &user_cylinders, &user_heads, &user_sectors);
  argc -= optind;  
2842   argv += optind;   argv += optind;
2843   if (opt & OPT_b) { // -b   if (opt & OPT_b) { // -b
2844   /* Ugly: this sector size is really per device,   /* Ugly: this sector size is really per device,
# Line 2843  int fdisk_main(int argc, char **argv) Line 2882  int fdisk_main(int argc, char **argv)
2882   int j;   int j;
2883    
2884   nowarn = 1;   nowarn = 1;
2885   if (argc <= 0)   if (!argv[0])
2886   bb_show_usage();   bb_show_usage();
2887   for (j = 0; j < argc; j++) {   for (j = 0; argv[j]; j++) {
2888   unsigned long long size;   unsigned long long size;
2889   fd = xopen(argv[j], O_RDONLY);   fd = xopen(argv[j], O_RDONLY);
2890   size = bb_BLKGETSIZE_sectors(fd) / 2;   size = bb_BLKGETSIZE_sectors(fd) / 2;
2891   close(fd);   close(fd);
2892   if (argc == 1)   if (argv[1])
2893   printf("%lld\n", size);   printf("%llu\n", size);
2894   else   else
2895   printf("%s: %lld\n", argv[j], size);   printf("%s: %llu\n", argv[j], size);
2896   }   }
2897   return 0;   return 0;
2898   }   }
2899  #endif  #endif
2900    
2901  #if ENABLE_FEATURE_FDISK_WRITABLE  #if ENABLE_FEATURE_FDISK_WRITABLE
2902   if (argc != 1)   if (!argv[0] || argv[1])
2903   bb_show_usage();   bb_show_usage();
2904    
2905   disk_device = argv[0];   disk_device = argv[0];

Legend:
Removed from v.983  
changed lines
  Added in v.984