aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util-linux/fdisk.c110
1 files changed, 54 insertions, 56 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 3072f7570..916ab1fd8 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -41,15 +41,13 @@
41#include <scsi/scsi.h> /* SCSI_IOCTL_GET_IDLUN */ 41#include <scsi/scsi.h> /* SCSI_IOCTL_GET_IDLUN */
42#undef u_char 42#undef u_char
43 43
44#ifdef HAVE_blkpg_h
45#include <linux/blkpg.h>
46#endif
47
48#include <sys/ioctl.h> 44#include <sys/ioctl.h>
49#include <sys/param.h> 45#include <sys/param.h>
50 46
51#include <linux/types.h> /* for __u32, __u16, __u8, __s16 */ 47#include <stdint.h> /* for uint32_t, uint16_t, uint8_t, int16_t, etc */
52#include <linux/major.h> /* FLOPPY_MAJOR */ 48
49/* Copied from linux/major.h */
50#define FLOPPY_MAJOR 2
53 51
54#include <sys/utsname.h> 52#include <sys/utsname.h>
55 53
@@ -497,7 +495,7 @@ check_aix_label( void )
497 495
498 496
499#ifndef BSD_DISKMAGIC 497#ifndef BSD_DISKMAGIC
500#define BSD_DISKMAGIC ((__u32) 0x82564557) 498#define BSD_DISKMAGIC ((uint32_t) 0x82564557)
501#endif 499#endif
502 500
503#ifndef BSD_MAXPARTITIONS 501#ifndef BSD_MAXPARTITIONS
@@ -520,31 +518,31 @@ check_aix_label( void )
520#define BSD_SBSIZE 8192 /* max size of fs superblock */ 518#define BSD_SBSIZE 8192 /* max size of fs superblock */
521 519
522struct xbsd_disklabel { 520struct xbsd_disklabel {
523 __u32 d_magic; /* the magic number */ 521 uint32_t d_magic; /* the magic number */
524 __s16 d_type; /* drive type */ 522 int16_t d_type; /* drive type */
525 __s16 d_subtype; /* controller/d_type specific */ 523 int16_t d_subtype; /* controller/d_type specific */
526 char d_typename[16]; /* type name, e.g. "eagle" */ 524 char d_typename[16]; /* type name, e.g. "eagle" */
527 char d_packname[16]; /* pack identifier */ 525 char d_packname[16]; /* pack identifier */
528 /* disk geometry: */ 526 /* disk geometry: */
529 __u32 d_secsize; /* # of bytes per sector */ 527 uint32_t d_secsize; /* # of bytes per sector */
530 __u32 d_nsectors; /* # of data sectors per track */ 528 uint32_t d_nsectors; /* # of data sectors per track */
531 __u32 d_ntracks; /* # of tracks per cylinder */ 529 uint32_t d_ntracks; /* # of tracks per cylinder */
532 __u32 d_ncylinders; /* # of data cylinders per unit */ 530 uint32_t d_ncylinders; /* # of data cylinders per unit */
533 __u32 d_secpercyl; /* # of data sectors per cylinder */ 531 uint32_t d_secpercyl; /* # of data sectors per cylinder */
534 __u32 d_secperunit; /* # of data sectors per unit */ 532 uint32_t d_secperunit; /* # of data sectors per unit */
535 /* 533 /*
536 * Spares (bad sector replacements) below 534 * Spares (bad sector replacements) below
537 * are not counted in d_nsectors or d_secpercyl. 535 * are not counted in d_nsectors or d_secpercyl.
538 * Spare sectors are assumed to be physical sectors 536 * Spare sectors are assumed to be physical sectors
539 * which occupy space at the end of each track and/or cylinder. 537 * which occupy space at the end of each track and/or cylinder.
540 */ 538 */
541 __u16 d_sparespertrack; /* # of spare sectors per track */ 539 uint16_t d_sparespertrack; /* # of spare sectors per track */
542 __u16 d_sparespercyl; /* # of spare sectors per cylinder */ 540 uint16_t d_sparespercyl; /* # of spare sectors per cylinder */
543 /* 541 /*
544 * Alternate cylinders include maintenance, replacement, 542 * Alternate cylinders include maintenance, replacement,
545 * configuration description areas, etc. 543 * configuration description areas, etc.
546 */ 544 */
547 __u32 d_acylinders; /* # of alt. cylinders per unit */ 545 uint32_t d_acylinders; /* # of alt. cylinders per unit */
548 546
549 /* hardware characteristics: */ 547 /* hardware characteristics: */
550 /* 548 /*
@@ -563,30 +561,30 @@ struct xbsd_disklabel {
563 * Finally, d_cylskew is the offset of sector 0 on cylinder N 561 * Finally, d_cylskew is the offset of sector 0 on cylinder N
564 * relative to sector 0 on cylinder N-1. 562 * relative to sector 0 on cylinder N-1.
565 */ 563 */
566 __u16 d_rpm; /* rotational speed */ 564 uint16_t d_rpm; /* rotational speed */
567 __u16 d_interleave; /* hardware sector interleave */ 565 uint16_t d_interleave; /* hardware sector interleave */
568 __u16 d_trackskew; /* sector 0 skew, per track */ 566 uint16_t d_trackskew; /* sector 0 skew, per track */
569 __u16 d_cylskew; /* sector 0 skew, per cylinder */ 567 uint16_t d_cylskew; /* sector 0 skew, per cylinder */
570 __u32 d_headswitch; /* head switch time, usec */ 568 uint32_t d_headswitch; /* head switch time, usec */
571 __u32 d_trkseek; /* track-to-track seek, usec */ 569 uint32_t d_trkseek; /* track-to-track seek, usec */
572 __u32 d_flags; /* generic flags */ 570 uint32_t d_flags; /* generic flags */
573#define NDDATA 5 571#define NDDATA 5
574 __u32 d_drivedata[NDDATA]; /* drive-type specific information */ 572 uint32_t d_drivedata[NDDATA]; /* drive-type specific information */
575#define NSPARE 5 573#define NSPARE 5
576 __u32 d_spare[NSPARE]; /* reserved for future use */ 574 uint32_t d_spare[NSPARE]; /* reserved for future use */
577 __u32 d_magic2; /* the magic number (again) */ 575 uint32_t d_magic2; /* the magic number (again) */
578 __u16 d_checksum; /* xor of data incl. partitions */ 576 uint16_t d_checksum; /* xor of data incl. partitions */
579 /* filesystem and partition information: */ 577 /* filesystem and partition information: */
580 __u16 d_npartitions; /* number of partitions in following */ 578 uint16_t d_npartitions; /* number of partitions in following */
581 __u32 d_bbsize; /* size of boot area at sn0, bytes */ 579 uint32_t d_bbsize; /* size of boot area at sn0, bytes */
582 __u32 d_sbsize; /* max size of fs superblock, bytes */ 580 uint32_t d_sbsize; /* max size of fs superblock, bytes */
583 struct xbsd_partition { /* the partition table */ 581 struct xbsd_partition { /* the partition table */
584 __u32 p_size; /* number of sectors in partition */ 582 uint32_t p_size; /* number of sectors in partition */
585 __u32 p_offset; /* starting sector */ 583 uint32_t p_offset; /* starting sector */
586 __u32 p_fsize; /* filesystem basic fragment size */ 584 uint32_t p_fsize; /* filesystem basic fragment size */
587 __u8 p_fstype; /* filesystem type, see below */ 585 uint8_t p_fstype; /* filesystem type, see below */
588 __u8 p_frag; /* filesystem fragments per block */ 586 uint8_t p_frag; /* filesystem fragments per block */
589 __u16 p_cpg; /* filesystem cylinders per group */ 587 uint16_t p_cpg; /* filesystem cylinders per group */
590 } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */ 588 } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
591}; 589};
592 590
@@ -792,9 +790,9 @@ typedef struct {
792#define SGI_INFO_MAGIC 0x00072959 790#define SGI_INFO_MAGIC 0x00072959
793#define SGI_INFO_MAGIC_SWAPPED 0x59290700 791#define SGI_INFO_MAGIC_SWAPPED 0x59290700
794#define SGI_SSWAP16(x) (sgi_other_endian ? __swap16(x) \ 792#define SGI_SSWAP16(x) (sgi_other_endian ? __swap16(x) \
795 : (__u16)(x)) 793 : (uint16_t)(x))
796#define SGI_SSWAP32(x) (sgi_other_endian ? __swap32(x) \ 794#define SGI_SSWAP32(x) (sgi_other_endian ? __swap32(x) \
797 : (__u32)(x)) 795 : (uint32_t)(x))
798 796
799#define sgilabel ((sgi_partition *)MBRbuffer) 797#define sgilabel ((sgi_partition *)MBRbuffer)
800#define sgiparam (sgilabel->devparam) 798#define sgiparam (sgilabel->devparam)
@@ -820,8 +818,8 @@ typedef struct {
820 unsigned short nsect; /* Sectors per track */ 818 unsigned short nsect; /* Sectors per track */
821 unsigned char spare3[4]; /* Even more magic... */ 819 unsigned char spare3[4]; /* Even more magic... */
822 struct sun_partition { 820 struct sun_partition {
823 __u32 start_cylinder; 821 uint32_t start_cylinder;
824 __u32 num_sectors; 822 uint32_t num_sectors;
825 } partitions[8]; 823 } partitions[8];
826 unsigned short magic; /* Magic number */ 824 unsigned short magic; /* Magic number */
827 unsigned short csum; /* Label xor'd checksum */ 825 unsigned short csum; /* Label xor'd checksum */
@@ -831,9 +829,9 @@ typedef struct {
831#define SUN_LABEL_MAGIC_SWAPPED 0xBEDA 829#define SUN_LABEL_MAGIC_SWAPPED 0xBEDA
832#define sunlabel ((sun_partition *)MBRbuffer) 830#define sunlabel ((sun_partition *)MBRbuffer)
833#define SUN_SSWAP16(x) (sun_other_endian ? __swap16(x) \ 831#define SUN_SSWAP16(x) (sun_other_endian ? __swap16(x) \
834 : (__u16)(x)) 832 : (uint16_t)(x))
835#define SUN_SSWAP32(x) (sun_other_endian ? __swap32(x) \ 833#define SUN_SSWAP32(x) (sun_other_endian ? __swap32(x) \
836 : (__u32)(x)) 834 : (uint32_t)(x))
837 835
838/* 836/*
839 * llseek.c -- stub calling the llseek system call 837 * llseek.c -- stub calling the llseek system call
@@ -855,7 +853,7 @@ typedef struct {
855#define my_llseek lseek 853#define my_llseek lseek
856 854
857#else 855#else
858#include <linux/unistd.h> /* for __NR__llseek */ 856#include <asm/unistd.h> /* for __NR__llseek */
859 857
860static int _llseek (unsigned int, unsigned long, 858static int _llseek (unsigned int, unsigned long,
861 unsigned long, ext2_loff_t *, unsigned int); 859 unsigned long, ext2_loff_t *, unsigned int);
@@ -1761,12 +1759,12 @@ alpha_bootblock_checksum (char *boot)
1761#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL) 1759#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL)
1762static inline unsigned short 1760static inline unsigned short
1763__swap16(unsigned short x) { 1761__swap16(unsigned short x) {
1764 return (((__u16)(x) & 0xFF) << 8) | (((__u16)(x) & 0xFF00) >> 8); 1762 return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8);
1765} 1763}
1766 1764
1767static inline __u32 1765static inline uint32_t
1768__swap32(__u32 x) { 1766__swap32(uint32_t x) {
1769 return (((__u32)(x) & 0xFF) << 24) | (((__u32)(x) & 0xFF00) << 8) | (((__u32)(x) & 0xFF0000) >> 8) | (((__u32)(x) & 0xFF000000) >> 24); 1767 return (((uint32_t)(x) & 0xFF) << 24) | (((uint32_t)(x) & 0xFF00) << 8) | (((uint32_t)(x) & 0xFF0000) >> 8) | (((uint32_t)(x) & 0xFF000000) >> 24);
1770} 1768}
1771#endif 1769#endif
1772 1770
@@ -1987,8 +1985,8 @@ sgi_list_table( int xtra ) {
1987 w + 1, _("Device")); 1985 w + 1, _("Device"));
1988 for (i = 0 ; i < partitions; i++) { 1986 for (i = 0 ; i < partitions; i++) {
1989 if( sgi_get_num_sectors(i) || debug ) { 1987 if( sgi_get_num_sectors(i) || debug ) {
1990 __u32 start = sgi_get_start_sector(i); 1988 uint32_t start = sgi_get_start_sector(i);
1991 __u32 len = sgi_get_num_sectors(i); 1989 uint32_t len = sgi_get_num_sectors(i);
1992 kpi++; /* only count nonempty partitions */ 1990 kpi++; /* only count nonempty partitions */
1993 printf( 1991 printf(
1994 "%2d: %s %4s %9ld %9ld %9ld %2x %s\n", 1992 "%2d: %s %4s %9ld %9ld %9ld %2x %s\n",
@@ -2011,8 +2009,8 @@ sgi_list_table( int xtra ) {
2011 { 2009 {
2012 if (sgilabel->directory[i].vol_file_size) 2010 if (sgilabel->directory[i].vol_file_size)
2013 { 2011 {
2014 __u32 start = SGI_SSWAP32(sgilabel->directory[i].vol_file_start); 2012 uint32_t start = SGI_SSWAP32(sgilabel->directory[i].vol_file_start);
2015 __u32 len = SGI_SSWAP32(sgilabel->directory[i].vol_file_size); 2013 uint32_t len = SGI_SSWAP32(sgilabel->directory[i].vol_file_size);
2016 char*name = sgilabel->directory[i].vol_file_name; 2014 char*name = sgilabel->directory[i].vol_file_name;
2017 printf(_("%2d: %-10s sector%5u size%8u\n"), 2015 printf(_("%2d: %-10s sector%5u size%8u\n"),
2018 i, name, (unsigned int) start, (unsigned int) len); 2016 i, name, (unsigned int) start, (unsigned int) len);
@@ -3222,8 +3220,8 @@ sun_list_table(int xtra) {
3222 w + 1, _("Device")); 3220 w + 1, _("Device"));
3223 for (i = 0 ; i < partitions; i++) { 3221 for (i = 0 ; i < partitions; i++) {
3224 if (sunlabel->partitions[i].num_sectors) { 3222 if (sunlabel->partitions[i].num_sectors) {
3225 __u32 start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors; 3223 uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors;
3226 __u32 len = SUN_SSWAP32(sunlabel->partitions[i].num_sectors); 3224 uint32_t len = SUN_SSWAP32(sunlabel->partitions[i].num_sectors);
3227 printf( 3225 printf(
3228 "%s %c%c %9ld %9ld %9ld%c %2x %s\n", 3226 "%s %c%c %9ld %9ld %9ld%c %2x %s\n",
3229/* device */ partname(disk_device, i+1, w), 3227/* device */ partname(disk_device, i+1, w),