[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] split fdisk.c 1/3
From:       Denis Vlasenko <vda () ilport ! com ! ua>
Date:       2006-02-27 14:50:33
Message-ID: 200602271650.33758.vda () ilport ! com ! ua
[Download RAW message or body]

On Monday 27 February 2006 16:49, Denis Vlasenko wrote:
> Please apply or comment.
> Patches will be sent in separate mails.

["fdisk_split.patch" (text/x-diff)]

diff -urpN busybox.org/util-linux/fdisk.c busybox.fdisk2/util-linux/fdisk.c
--- busybox.org/util-linux/fdisk.c	Mon Feb 27 08:57:47 2006
+++ busybox.fdisk2/util-linux/fdisk.c	Mon Feb 27 16:14:16 2006
@@ -83,9 +83,7 @@
 #define cround(n)       (display_in_cyl_units ? ((n)/units_per_sector)+1 : (n))
 #define scround(x)      (((x)+units_per_sector-1)/units_per_sector)
 
-#ifdef CONFIG_FEATURE_SUN_LABEL
 #define SCSI_IOCTL_GET_IDLUN 0x5382
-#endif
 
 
 /* including <linux/hdreg.h> also fails */
@@ -182,9 +180,30 @@ enum failure {
 	unable_to_write
 };
 
-enum label_type{
+enum label_type {
 	label_dos, label_sun, label_sgi, label_aix, label_osf
 };
+#define LABEL_IS_DOS	(label_dos == current_label_type)
+#ifdef CONFIG_FEATURE_SUN_LABEL
+#define LABEL_IS_SUN	(label_sun == current_label_type)
+#else
+#define LABEL_IS_SUN	0
+#endif
+#ifdef CONFIG_FEATURE_SGI_LABEL
+#define LABEL_IS_SGI	(label_sgi == current_label_type)
+#else
+#define LABEL_IS_SGI	0
+#endif
+#ifdef CONFIG_FEATURE_AIX_LABEL
+#define LABEL_IS_AIX	(label_aix == current_label_type)
+#else
+#define LABEL_IS_AIX	0
+#endif
+#ifdef CONFIG_FEATURE_OSF_LABEL
+#define LABEL_IS_OSF	(label_osf == current_label_type)
+#else
+#define LABEL_IS_OSF	0
+#endif
 
 enum action { fdisk, require, try_only, create_empty_dos, create_empty_sun };
 
@@ -276,13 +295,11 @@ set_changed(int i)
 }
 #endif /* CONFIG_FEATURE_FDISK_WRITABLE */
 
-#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_OSF_LABEL)
-static struct partition *
+static inline struct partition *
 get_part_table(int i)
 {
 	return ptes[i].part_table;
 }
-#endif
 
 static const char *
 str_units(int n)
@@ -364,6 +381,21 @@ read_hex(const struct systypes *sys)
 }
 #endif /* CONFIG_FEATURE_FDISK_WRITABLE */
 
+static inline unsigned short
+__swap16(unsigned short x)
+{
+	return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8);
+}
+
+static inline uint32_t
+__swap32(uint32_t x)
+{
+	return (((x & 0xFF) << 24) |
+		((x & 0xFF00) << 8) |
+		((x & 0xFF0000) >> 8) |
+		((x & 0xFF000000) >> 24));
+}
+
 #ifdef CONFIG_FEATURE_AIX_LABEL
 /*
  * Copyright (C) Andreas Neuper, Sep 1998.
@@ -441,6 +473,7 @@ check_aix_label(void)
 }
 #endif  /* AIX_LABEL */
 
+static void bselect(void);
 #ifdef CONFIG_FEATURE_OSF_LABEL
 /*
  * Copyright (c) 1987, 1988 Regents of the University of California.
@@ -676,151 +709,6 @@ static const struct systypes xbsd_fstype
 #define BSD_D_CHAIN     0x10            /* can do back-back transfers */
 #define BSD_D_DOSPART   0x20            /* within MSDOS partition */
 
-#endif /* OSF_LABEL */
-
-/*
- * Copyright (C) Andreas Neuper, Sep 1998.
- *      This file may be modified and redistributed under
- *      the terms of the GNU Public License.
- */
-
-struct device_parameter { /* 48 bytes */
-	unsigned char  skew;
-	unsigned char  gap1;
-	unsigned char  gap2;
-	unsigned char  sparecyl;
-	unsigned short pcylcount;
-	unsigned short head_vol0;
-	unsigned short ntrks;   /* tracks in cyl 0 or vol 0 */
-	unsigned char  cmd_tag_queue_depth;
-	unsigned char  unused0;
-	unsigned short unused1;
-	unsigned short nsect;   /* sectors/tracks in cyl 0 or vol 0 */
-	unsigned short bytes;
-	unsigned short ilfact;
-	unsigned int   flags;           /* controller flags */
-	unsigned int   datarate;
-	unsigned int   retries_on_error;
-	unsigned int   ms_per_word;
-	unsigned short xylogics_gap1;
-	unsigned short xylogics_syncdelay;
-	unsigned short xylogics_readdelay;
-	unsigned short xylogics_gap2;
-	unsigned short xylogics_readgate;
-	unsigned short xylogics_writecont;
-};
-
-#define SGI_VOLHDR      0x00
-/* 1 and 2 were used for drive types no longer supported by SGI */
-#define SGI_SWAP        0x03
-/* 4 and 5 were for filesystem types SGI haven't ever supported on MIPS CPUs */
-#define SGI_VOLUME      0x06
-#define SGI_EFS         0x07
-#define SGI_LVOL        0x08
-#define SGI_RLVOL       0x09
-#define SGI_XFS         0x0a
-#define SGI_XFSLOG      0x0b
-#define SGI_XLV         0x0c
-#define SGI_XVM         0x0d
-#define ENTIRE_DISK     SGI_VOLUME
-/*
- * controller flags
- */
-#define SECTOR_SLIP     0x01
-#define SECTOR_FWD      0x02
-#define TRACK_FWD       0x04
-#define TRACK_MULTIVOL  0x08
-#define IGNORE_ERRORS   0x10
-#define RESEEK          0x20
-#define ENABLE_CMDTAGQ  0x40
-
-typedef struct {
-	unsigned int   magic;            /* expect SGI_LABEL_MAGIC */
-	unsigned short boot_part;        /* active boot partition */
-	unsigned short swap_part;        /* active swap partition */
-	unsigned char  boot_file[16];    /* name of the bootfile */
-	struct device_parameter devparam;       /*  1 * 48 bytes */
-	struct volume_directory {               /* 15 * 16 bytes */
-		unsigned char vol_file_name[8]; /* a character array */
-		unsigned int  vol_file_start;   /* number of logical block */
-		unsigned int  vol_file_size;    /* number of bytes */
-	} directory[15];
-	struct sgi_partition {                  /* 16 * 12 bytes */
-		unsigned int num_sectors;       /* number of blocks */
-		unsigned int start_sector;      /* must be cylinder aligned */
-		unsigned int id;
-	} partitions[16];
-	unsigned int   csum;
-	unsigned int   fillbytes;
-} sgi_partition;
-
-typedef struct {
-	unsigned int   magic;           /* looks like a magic number */
-	unsigned int   a2;
-	unsigned int   a3;
-	unsigned int   a4;
-	unsigned int   b1;
-	unsigned short b2;
-	unsigned short b3;
-	unsigned int   c[16];
-	unsigned short d[3];
-	unsigned char  scsi_string[50];
-	unsigned char  serial[137];
-	unsigned short check1816;
-	unsigned char  installer[225];
-} sgiinfo;
-
-#define SGI_LABEL_MAGIC         0x0be5a941
-#define SGI_LABEL_MAGIC_SWAPPED 0x41a9e50b
-#define SGI_INFO_MAGIC          0x00072959
-#define SGI_INFO_MAGIC_SWAPPED  0x59290700
-#define SGI_SSWAP16(x) (sgi_other_endian ? __swap16(x) \
-				 : (uint16_t)(x))
-#define SGI_SSWAP32(x) (sgi_other_endian ? __swap32(x) \
-				 : (uint32_t)(x))
-
-#define sgilabel ((sgi_partition *)MBRbuffer)
-#define sgiparam (sgilabel->devparam)
-
-typedef struct {
-	unsigned char info[128];   /* Informative text string */
-	unsigned char spare0[14];
-	struct sun_info {
-		unsigned char spare1;
-		unsigned char id;
-		unsigned char spare2;
-		unsigned char flags;
-	} infos[8];
-	unsigned char spare1[246]; /* Boot information etc. */
-	unsigned short rspeed;     /* Disk rotational speed */
-	unsigned short pcylcount;  /* Physical cylinder count */
-	unsigned short sparecyl;   /* extra sects per cylinder */
-	unsigned char spare2[4];   /* More magic... */
-	unsigned short ilfact;     /* Interleave factor */
-	unsigned short ncyl;       /* Data cylinder count */
-	unsigned short nacyl;      /* Alt. cylinder count */
-	unsigned short ntrks;      /* Tracks per cylinder */
-	unsigned short nsect;      /* Sectors per track */
-	unsigned char spare3[4];   /* Even more magic... */
-	struct sun_partition {
-		uint32_t start_cylinder;
-		uint32_t num_sectors;
-	} partitions[8];
-	unsigned short magic;      /* Magic number */
-	unsigned short csum;       /* Label xor'd checksum */
-} sun_partition;
-
-
-#define SUN_LABEL_MAGIC          0xDABE
-#define SUN_LABEL_MAGIC_SWAPPED  0xBEDA
-#define sunlabel ((sun_partition *)MBRbuffer)
-#define SUN_SSWAP16(x) (sun_other_endian ? __swap16(x) \
-				 : (uint16_t)(x))
-#define SUN_SSWAP32(x) (sun_other_endian ? __swap32(x) \
-				 : (uint32_t)(x))
-
-
-#ifdef CONFIG_FEATURE_OSF_LABEL
 /*
    Changes:
    19990319 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> - i18n/nls
@@ -830,6 +718,8 @@ typedef struct {
    Also fixed unaligned accesses in alpha_bootblock_checksum()
 */
 
+static int possibly_osf_label;
+
 #define FREEBSD_PARTITION       0xa5
 #define NETBSD_PARTITION        0xa9
 
@@ -1231,7 +1121,7 @@ edit_int(int def, char *mesg)
 		if (!read_line())
 			return def;
 	}
-	while (!isdigit(*line_ptr));	/* FIXME: ?!! */
+	while (!isdigit(*line_ptr));	/* FIXME: BUG?!! */
 	return atoi(line_ptr);
 }
 
@@ -1642,24 +1532,126 @@ alpha_bootblock_checksum(char *boot)
 
 #endif /* OSF_LABEL */
 
-#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL)
-static inline unsigned short
-__swap16(unsigned short x)
-{
-	return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8);
-}
+static const struct systypes sgi_sys_types[];
+static unsigned int sgi_get_num_sectors(int i);
+static int sgi_get_sysid(int i);
+static void sgi_delete_partition(int i);
+static void sgi_change_sysid(int i, int sys);
+static void sgi_list_table(int xtra);
+static void sgi_set_xcyl(void);
+static int verify_sgi(int verbose);
+static void sgi_add_partition(int n, int sys);
+static void sgi_set_swappartition(int i);
+static const char *sgi_get_bootfile(void);
+static void sgi_set_bootfile(const char* aFile);
+static void create_sgiinfo(void);
+#ifdef CONFIG_FEATURE_SGI_LABEL
 
-static inline uint32_t
-__swap32(uint32_t x)
-{
-	return (((x & 0xFF) << 24) |
-		((x & 0xFF00) << 8) |
-		((x & 0xFF0000) >> 8) |
-		((x & 0xFF000000) >> 24));
-}
-#endif
+/*
+ * Copyright (C) Andreas Neuper, Sep 1998.
+ *      This file may be modified and redistributed under
+ *      the terms of the GNU Public License.
+ */
+
+struct device_parameter { /* 48 bytes */
+	unsigned char  skew;
+	unsigned char  gap1;
+	unsigned char  gap2;
+	unsigned char  sparecyl;
+	unsigned short pcylcount;
+	unsigned short head_vol0;
+	unsigned short ntrks;   /* tracks in cyl 0 or vol 0 */
+	unsigned char  cmd_tag_queue_depth;
+	unsigned char  unused0;
+	unsigned short unused1;
+	unsigned short nsect;   /* sectors/tracks in cyl 0 or vol 0 */
+	unsigned short bytes;
+	unsigned short ilfact;
+	unsigned int   flags;           /* controller flags */
+	unsigned int   datarate;
+	unsigned int   retries_on_error;
+	unsigned int   ms_per_word;
+	unsigned short xylogics_gap1;
+	unsigned short xylogics_syncdelay;
+	unsigned short xylogics_readdelay;
+	unsigned short xylogics_gap2;
+	unsigned short xylogics_readgate;
+	unsigned short xylogics_writecont;
+};
+
+#define SGI_VOLHDR      0x00
+/* 1 and 2 were used for drive types no longer supported by SGI */
+#define SGI_SWAP        0x03
+/* 4 and 5 were for filesystem types SGI haven't ever supported on MIPS CPUs */
+#define SGI_VOLUME      0x06
+#define SGI_EFS         0x07
+#define SGI_LVOL        0x08
+#define SGI_RLVOL       0x09
+#define SGI_XFS         0x0a
+#define SGI_XFSLOG      0x0b
+#define SGI_XLV         0x0c
+#define SGI_XVM         0x0d
+#define ENTIRE_DISK     SGI_VOLUME
+/*
+ * controller flags
+ */
+#define SECTOR_SLIP     0x01
+#define SECTOR_FWD      0x02
+#define TRACK_FWD       0x04
+#define TRACK_MULTIVOL  0x08
+#define IGNORE_ERRORS   0x10
+#define RESEEK          0x20
+#define ENABLE_CMDTAGQ  0x40
+
+typedef struct {
+	unsigned int   magic;            /* expect SGI_LABEL_MAGIC */
+	unsigned short boot_part;        /* active boot partition */
+	unsigned short swap_part;        /* active swap partition */
+	unsigned char  boot_file[16];    /* name of the bootfile */
+	struct device_parameter devparam;       /*  1 * 48 bytes */
+	struct volume_directory {               /* 15 * 16 bytes */
+		unsigned char vol_file_name[8]; /* a character array */
+		unsigned int  vol_file_start;   /* number of logical block */
+		unsigned int  vol_file_size;    /* number of bytes */
+	} directory[15];
+	struct sgi_partinfo {                  /* 16 * 12 bytes */
+		unsigned int num_sectors;       /* number of blocks */
+		unsigned int start_sector;      /* must be cylinder aligned */
+		unsigned int id;
+	} partitions[16];
+	unsigned int   csum;
+	unsigned int   fillbytes;
+} sgi_partition;
+
+typedef struct {
+	unsigned int   magic;           /* looks like a magic number */
+	unsigned int   a2;
+	unsigned int   a3;
+	unsigned int   a4;
+	unsigned int   b1;
+	unsigned short b2;
+	unsigned short b3;
+	unsigned int   c[16];
+	unsigned short d[3];
+	unsigned char  scsi_string[50];
+	unsigned char  serial[137];
+	unsigned short check1816;
+	unsigned char  installer[225];
+} sgiinfo;
+
+#define SGI_LABEL_MAGIC         0x0be5a941
+#define SGI_LABEL_MAGIC_SWAPPED 0x41a9e50b
+#define SGI_INFO_MAGIC          0x00072959
+#define SGI_INFO_MAGIC_SWAPPED  0x59290700
+
+#define SGI_SSWAP16(x) (sgi_other_endian ? __swap16(x) \
+				 : (uint16_t)(x))
+#define SGI_SSWAP32(x) (sgi_other_endian ? __swap32(x) \
+				 : (uint32_t)(x))
+
+#define sgilabel ((sgi_partition *)MBRbuffer)
+#define sgiparam (sgilabel->devparam)
 
-#ifdef CONFIG_FEATURE_SGI_LABEL
 /*
  *
  * fdisksgilabel.c
@@ -2413,7 +2405,7 @@ create_sgilabel(void)
 	sgilabel->devparam.xylogics_readgate        = SGI_SSWAP16(0);
 	sgilabel->devparam.xylogics_writecont       = SGI_SSWAP16(0);
 	memset( &(sgilabel->directory), 0, sizeof(struct volume_directory)*15 );
-	memset( &(sgilabel->partitions), 0, sizeof(struct sgi_partition)*16 );
+	memset( &(sgilabel->partitions), 0, sizeof(struct sgi_partinfo)*16 );
 	current_label_type = label_sgi;
 	partitions = 16;
 	sgi_volumes = 15;
@@ -2454,8 +2446,57 @@ fill_sgiinfo(void)
 }
 #endif /* SGI_LABEL */
 
-
+static const struct systypes sun_sys_types[];
+static void sun_delete_partition(int i);
+static void sun_change_sysid(int i, int sys);
+static void sun_list_table(int xtra);
+static void sun_set_xcyl(void);
+static void add_sun_partition(int n, int sys);
+static void sun_set_alt_cyl(void);
+static void sun_set_ncyl(int cyl);
+static void sun_set_xcyl(void);
+static void sun_set_ilfact(void);
+static void sun_set_rspeed(void);
+static void sun_set_pcylcount(void);
+static void toggle_sunflags(int i, unsigned char mask);
 #ifdef CONFIG_FEATURE_SUN_LABEL
+
+typedef struct {
+	unsigned char info[128];   /* Informative text string */
+	unsigned char spare0[14];
+	struct sun_info {
+		unsigned char spare1;
+		unsigned char id;
+		unsigned char spare2;
+		unsigned char flags;
+	} infos[8];
+	unsigned char spare1[246]; /* Boot information etc. */
+	unsigned short rspeed;     /* Disk rotational speed */
+	unsigned short pcylcount;  /* Physical cylinder count */
+	unsigned short sparecyl;   /* extra sects per cylinder */
+	unsigned char spare2[4];   /* More magic... */
+	unsigned short ilfact;     /* Interleave factor */
+	unsigned short ncyl;       /* Data cylinder count */
+	unsigned short nacyl;      /* Alt. cylinder count */
+	unsigned short ntrks;      /* Tracks per cylinder */
+	unsigned short nsect;      /* Sectors per track */
+	unsigned char spare3[4];   /* Even more magic... */
+	struct sun_partinfo {
+		uint32_t start_cylinder;
+		uint32_t num_sectors;
+	} partitions[8];
+	unsigned short magic;      /* Magic number */
+	unsigned short csum;       /* Label xor'd checksum */
+} sun_partition;
+
+#define SUN_LABEL_MAGIC          0xDABE
+#define SUN_LABEL_MAGIC_SWAPPED  0xBEDA
+#define sunlabel ((sun_partition *)MBRbuffer)
+#define SUN_SSWAP16(x) (sun_other_endian ? __swap16(x) \
+				 : (uint16_t)(x))
+#define SUN_SSWAP32(x) (sun_other_endian ? __swap32(x) \
+				 : (uint32_t)(x))
+
 /*
  * fdisksunlabel.c
  *
@@ -3465,8 +3506,7 @@ is_dos_partition(int t)
 static void
 menu(void)
 {
-#ifdef CONFIG_FEATURE_SUN_LABEL
-	if (label_sun == current_label_type) {
+	if (LABEL_IS_SUN) {
 		puts(_("Command action"));
 		puts(_("\ta\ttoggle a read only flag"));           /* sun */
 		puts(_("\tb\tedit bsd disklabel"));
@@ -3487,9 +3527,7 @@ menu(void)
 		puts(_("\tx\textra functionality (experts only)"));
 #endif
 	} else
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-	if (label_sgi == current_label_type) {
+	if (LABEL_IS_SGI) {
 		puts(_("Command action"));
 		puts(_("\ta\tselect bootable partition"));    /* sgi flavour */
 		puts(_("\tb\tedit bootfile entry"));          /* sgi */
@@ -3507,16 +3545,13 @@ menu(void)
 		puts(_("\tv\tverify the partition table"));
 		puts(_("\tw\twrite table to disk and exit"));
 	} else
-#endif
-#ifdef CONFIG_FEATURE_AIX_LABEL
-	if (label_aix == current_label_type) {
+	if (LABEL_IS_AIX) {
 		puts(_("Command action"));
 		puts(_("\tm\tprint this menu"));
 		puts(_("\to\tcreate a new empty DOS partition table"));
 		puts(_("\tq\tquit without saving changes"));
 		puts(_("\ts\tcreate a new empty Sun disklabel"));  /* sun */
 	} else
-#endif
 	{
 		puts(_("Command action"));
 		puts(_("\ta\ttoggle a bootable flag"));
@@ -3546,28 +3581,25 @@ menu(void)
 static void
 xmenu(void)
 {
-#ifdef CONFIG_FEATURE_SUN_LABEL
-	if (label_sun == current_label_type) {
-	puts(_("Command action"));
-	puts(_("\ta\tchange number of alternate cylinders"));      /*sun*/
-	puts(_("\tc\tchange number of cylinders"));
-	puts(_("\td\tprint the raw data in the partition table"));
-	puts(_("\te\tchange number of extra sectors per cylinder"));/*sun*/
-	puts(_("\th\tchange number of heads"));
-	puts(_("\ti\tchange interleave factor"));                  /*sun*/
-	puts(_("\to\tchange rotation speed (rpm)"));               /*sun*/
-	puts(_("\tm\tprint this menu"));
-	puts(_("\tp\tprint the partition table"));
-	puts(_("\tq\tquit without saving changes"));
-	puts(_("\tr\treturn to main menu"));
-	puts(_("\ts\tchange number of sectors/track"));
-	puts(_("\tv\tverify the partition table"));
-	puts(_("\tw\twrite table to disk and exit"));
-	puts(_("\ty\tchange number of physical cylinders"));       /*sun*/
+	if (LABEL_IS_SUN) {
+		puts(_("Command action"));
+		puts(_("\ta\tchange number of alternate cylinders"));      /*sun*/
+		puts(_("\tc\tchange number of cylinders"));
+		puts(_("\td\tprint the raw data in the partition table"));
+		puts(_("\te\tchange number of extra sectors per cylinder"));/*sun*/
+		puts(_("\th\tchange number of heads"));
+		puts(_("\ti\tchange interleave factor"));                  /*sun*/
+		puts(_("\to\tchange rotation speed (rpm)"));               /*sun*/
+		puts(_("\tm\tprint this menu"));
+		puts(_("\tp\tprint the partition table"));
+		puts(_("\tq\tquit without saving changes"));
+		puts(_("\tr\treturn to main menu"));
+		puts(_("\ts\tchange number of sectors/track"));
+		puts(_("\tv\tverify the partition table"));
+		puts(_("\tw\twrite table to disk and exit"));
+		puts(_("\ty\tchange number of physical cylinders"));       /*sun*/
 	}  else
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-	if (label_sgi == current_label_type) {
+	if (LABEL_IS_SGI) {
 		puts(_("Command action"));
 		puts(_("\tb\tmove beginning of data in a partition")); /* !sun */
 		puts(_("\tc\tchange number of cylinders"));
@@ -3583,9 +3615,7 @@ xmenu(void)
 		puts(_("\tv\tverify the partition table"));
 		puts(_("\tw\twrite table to disk and exit"));
 	} else
-#endif
-#ifdef CONFIG_FEATURE_AIX_LABEL
-	if (label_aix == current_label_type) {
+	if (LABEL_IS_AIX) {
 		puts(_("Command action"));
 		puts(_("\tb\tmove beginning of data in a partition")); /* !sun */
 		puts(_("\tc\tchange number of cylinders"));
@@ -3600,9 +3630,7 @@ xmenu(void)
 		puts(_("\ts\tchange number of sectors/track"));
 		puts(_("\tv\tverify the partition table"));
 		puts(_("\tw\twrite table to disk and exit"));
-	}  else
-#endif
-	{
+	}  else {
 		puts(_("Command action"));
 		puts(_("\tb\tmove beginning of data in a partition")); /* !sun */
 		puts(_("\tc\tchange number of cylinders"));
@@ -3629,12 +3657,8 @@ static const struct systypes *
 get_sys_types(void)
 {
 	return (
-#ifdef CONFIG_FEATURE_SUN_LABEL
-		label_sun == current_label_type ? sun_sys_types :
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-		label_sgi == current_label_type ? sgi_sys_types :
-#endif
+		LABEL_IS_SUN ? sun_sys_types :
+		LABEL_IS_SGI ? sgi_sys_types :
 		i386_sys_types);
 }
 #else
@@ -3658,14 +3682,9 @@ static const char *partition_type(unsign
 static int
 get_sysid(int i)
 {
-	return (
-#ifdef CONFIG_FEATURE_SUN_LABEL
-		label_sun == current_label_type ? sunlabel->infos[i].id :
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-		label_sgi == current_label_type ? sgi_get_sysid(i) :
-#endif
-		ptes[i].part_table->sys_ind);
+	return LABEL_IS_SUN ? sunlabel->infos[i].id :
+			(LABEL_IS_SGI ? sgi_get_sysid(i) :
+				ptes[i].part_table->sys_ind);
 }
 
 void list_types(const struct systypes *sys)
@@ -3790,7 +3809,7 @@ static void update_units(void)
 static void
 warn_cylinders(void)
 {
-	if (label_dos == current_label_type && cylinders > 1024 && !nowarn)
+	if (LABEL_IS_DOS && cylinders > 1024 && !nowarn)
 		fprintf(stderr, _("\n"
 "The number of cylinders for this disk is set to %d.\n"
 "There is nothing wrong with that, but this is larger than 1024,\n"
@@ -4298,28 +4317,10 @@ get_partition(int warn, int max)
 	pe = &ptes[i];
 
 	if (warn) {
-		if (
-			(
-				label_sun != current_label_type && 
-				label_sgi != current_label_type && 
-				!pe->part_table->sys_ind
-			)
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			|| (
-				label_sun == current_label_type &&
-				(
-					!sunlabel->partitions[i].num_sectors
-					|| !sunlabel->infos[i].id
-				)
-			)
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-			|| (
-				label_sgi == current_label_type &&
-				 !sgi_get_num_sectors(i)
-			)
-#endif
-		){
+		if ((!LABEL_IS_SUN && !LABEL_IS_SGI && !pe->part_table->sys_ind)
+		 || (LABEL_IS_SUN && (!sunlabel->partitions[i].num_sectors || !sunlabel->infos[i].id))
+		 || (LABEL_IS_SGI && !sgi_get_num_sectors(i))
+		) {
 			fprintf(stderr,
 				_("Warning: partition %d has empty type\n"),
 				i+1
@@ -4435,18 +4436,14 @@ delete_partition(int i)
 		return;         /* C/H/S not set */
 	pe->changed = 1;
 
-#ifdef CONFIG_FEATURE_SUN_LABEL
-	if (label_sun == current_label_type) {
+	if (LABEL_IS_SUN) {
 		sun_delete_partition(i);
 		return;
 	}
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-	if (label_sgi == current_label_type) {
+	if (LABEL_IS_SGI) {
 		sgi_delete_partition(i);
 		return;
 	}
-#endif
 
 	if (i < 4) {
 		if (IS_EXTENDED(p->sys_ind) && i == ext_index) {
@@ -4503,18 +4500,14 @@ change_sysid(void)
 	int i, sys, origsys;
 	struct partition *p;
 
-#ifdef CONFIG_FEATURE_SGI_LABEL
 	/* If sgi_label then don't use get_existing_partition,
 	   let the user select a partition, since get_existing_partition()
 	   only works for Linux like partition tables. */
-	if (label_sgi != current_label_type) {
+	if (!LABEL_IS_SGI) {
 		i = get_existing_partition(0, partitions);
 	} else {
 		i = get_partition(0, partitions);
 	}
-#else
-	i = get_existing_partition(0, partitions);
-#endif
 	if (i == -1)
 		return;
 	p = ptes[i].part_table;
@@ -4522,17 +4515,13 @@ change_sysid(void)
 
 	/* if changing types T to 0 is allowed, then
 	   the reverse change must be allowed, too */
-	if (!sys && label_sgi != current_label_type &&
-		label_sun != current_label_type && !get_nr_sects(p))
-	{
+	if (!sys && !LABEL_IS_SGI && !LABEL_IS_SUN && !get_nr_sects(p))	{
 		printf(_("Partition %d does not exist yet!\n"), i + 1);
-	}else{
+	} else {
 	    while (1) {
 		sys = read_hex (get_sys_types());
 
-		if (!sys && label_sgi != current_label_type &&
-			label_sun != current_label_type)
-		{
+		if (!sys && !LABEL_IS_SGI && !LABEL_IS_SUN) {
 			printf(_("Type 0 means free space to many systems\n"
 				   "(but not to Linux). Having partitions of\n"
 				   "type 0 is probably unwise. You can delete\n"
@@ -4540,7 +4529,7 @@ change_sysid(void)
 			/* break; */
 		}
 
-		if (label_sun != current_label_type && label_sgi != current_label_type) {
+		if (!LABEL_IS_SUN && !LABEL_IS_SGI) {
 			if (IS_EXTENDED(sys) != IS_EXTENDED(p->sys_ind)) {
 				printf(_("You cannot change a partition into"
 					   " an extended one or vice versa\n"
@@ -4550,15 +4539,12 @@ change_sysid(void)
 		}
 
 		if (sys < 256) {
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			if (label_sun == current_label_type && i == 2 && sys != WHOLE_DISK)
+			if (LABEL_IS_SUN && i == 2 && sys != WHOLE_DISK)
 				printf(_("Consider leaving partition 3 "
 					   "as Whole disk (5),\n"
 					   "as SunOS/Solaris expects it and "
 					   "even Linux likes it.\n\n"));
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-			if (label_sgi == current_label_type &&
+			if (LABEL_IS_SGI &&
 				(
 					(i == 10 && sys != ENTIRE_DISK) ||
 					(i == 8 && sys != 0)
@@ -4569,19 +4555,13 @@ change_sysid(void)
 					   "partition 11 as entire volume (6)"
 					   "as IRIX expects it.\n\n"));
 			}
-#endif
 			if (sys == origsys)
 				break;
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			if (label_sun == current_label_type) {
+			if (LABEL_IS_SUN) {
 				sun_change_sysid(i, sys);
-			} else
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-			if (label_sgi == current_label_type) {
+			} else if (LABEL_IS_SGI) {
 				sgi_change_sysid(i, sys);
 			} else
-#endif
 				p->sys_ind = sys;
 
 			printf(_("Changed system type of partition %d "
@@ -4849,28 +4829,21 @@ list_table(int xtra)
 	const struct partition *p;
 	int i, w;
 
-#ifdef CONFIG_FEATURE_SUN_LABEL
-	if (label_sun == current_label_type) {
+	if (LABEL_IS_SUN) {
 		sun_list_table(xtra);
 		return;
 	}
-#endif
-
-#ifdef CONFIG_FEATURE_SGI_LABEL
-	if (label_sgi == current_label_type) {
+	if (LABEL_IS_SUN) {
 		sgi_list_table(xtra);
 		return;
 	}
-#endif
 
 	list_disk_geometry();
 
-#ifdef CONFIG_FEATURE_OSF_LABEL
-	if (label_osf == current_label_type) {
+	if (LABEL_IS_OSF) {
 		xbsd_print_disklabel(xtra);
 		return;
 	}
-#endif
 
 	/* Heuristic: we list partition 3 of /dev/foo as /dev/foo3,
 	   but if the device name ends in a digit, say /dev/foo1,
@@ -4917,7 +4890,7 @@ list_table(int xtra)
 	/* Is partition table in disk order? It need not be, but... */
 	/* partition table entries are not checked for correct order if this
 	   is a sgi, sun or aix labeled disk... */
-	if (label_dos == current_label_type && wrong_p_order(NULL)) {
+	if (LABEL_IS_DOS && wrong_p_order(NULL)) {
 		/* FIXME */
 		printf(_("\nPartition table entries are not in disk order\n"));
 	}
@@ -5009,18 +4982,14 @@ verify(void)
 	if (warn_geometry())
 		return;
 
-#ifdef CONFIG_FEATURE_SUN_LABEL
-	if (label_sun == current_label_type) {
+	if (LABEL_IS_SUN) {
 		verify_sun();
 		return;
 	}
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-	if (label_sgi == current_label_type) {
+	if (LABEL_IS_SGI) {
 		verify_sgi(1);
 		return;
 	}
-#endif
 
 	fill_bounds(first, last);
 	for (i = 0; i < partitions; i++) {
@@ -5229,20 +5198,15 @@ new_partition(void)
 	if (warn_geometry())
 		return;
 
-#ifdef CONFIG_FEATURE_SUN_LABEL
-	if (label_sun == current_label_type) {
+	if (LABEL_IS_SUN) {
 		add_sun_partition(get_partition(0, partitions), LINUX_NATIVE);
 		return;
 	}
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-	if (label_sgi == current_label_type) {
+	if (LABEL_IS_SGI) {
 		sgi_add_partition(get_partition(0, partitions), LINUX_NATIVE);
 		return;
 	}
-#endif
-#ifdef CONFIG_FEATURE_AIX_LABEL
-	if (label_aix == current_label_type) {
+	if (LABEL_IS_AIX) {
 		printf(_("\tSorry - this fdisk cannot handle AIX disk labels."
 			 "\n\tIf you want to add DOS-type partitions, create"
 			 "\n\ta new empty DOS partition table first. (Use o.)"
@@ -5250,7 +5214,6 @@ new_partition(void)
 			 "This will destroy the present disk contents.\n"));
 		return;
 	}
-#endif
 
 	for (i = 0; i < 4; i++)
 		free_primary += !ptes[i].part_table->sys_ind;
@@ -5301,7 +5264,7 @@ write_table(void)
 {
 	int i;
 
-	if (label_dos == current_label_type) {
+	if (LABEL_IS_DOS) {
 		for (i = 0; i < 3; i++)
 			if (ptes[i].changed)
 				ptes[3].changed = 1;
@@ -5314,14 +5277,11 @@ write_table(void)
 			}
 		}
 	}
-#ifdef CONFIG_FEATURE_SGI_LABEL
-	else if (label_sgi == current_label_type) {
+	else if (LABEL_IS_SGI) {
 		/* no test on change? the printf below might be mistaken */
 		sgi_write_table();
 	}
-#endif
-#ifdef CONFIG_FEATURE_SUN_LABEL
-	else if (label_sun == current_label_type) {
+	else if (LABEL_IS_SUN) {
 		int needw = 0;
 
 		for (i = 0; i < 8; i++)
@@ -5330,7 +5290,6 @@ write_table(void)
 		if (needw)
 			sun_write_table();
 	}
-#endif
 
 	printf(_("The partition table has been altered!\n\n"));
 	reread_partition_table(1);
@@ -5411,13 +5370,12 @@ print_raw(void)
 	int i;
 
 	printf(_("Device: %s\n"), disk_device);
-#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL)
-	if (label_sun == current_label_type || label_sgi == current_label_type)
+	if (LABEL_IS_SGI || LABEL_IS_SUN)
 		print_buffer(MBRbuffer);
-	else
-#endif
+	else {
 		for (i = 3; i < partitions; i++)
 			print_buffer(ptes[i].sectorbuffer);
+	}
 }
 
 static void
@@ -5455,45 +5413,35 @@ xselect(void)
 		c = tolower(read_char(_("Expert command (m for help): ")));
 		switch (c) {
 		case 'a':
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			if (label_sun == current_label_type)
+			if (LABEL_IS_SUN)
 				sun_set_alt_cyl();
-#endif
 			break;
 		case 'b':
-			if (label_dos == current_label_type)
+			if (LABEL_IS_DOS)
 				move_begin(get_partition(0, partitions));
 			break;
 		case 'c':
 			user_cylinders = cylinders =
 				read_int(1, cylinders, 1048576, 0,
 					_("Number of cylinders"));
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			if (label_sun == current_label_type)
+			if (LABEL_IS_SUN)
 				sun_set_ncyl(cylinders);
-#endif
-			if (label_dos == current_label_type)
+			if (LABEL_IS_DOS)
 				warn_cylinders();
 			break;
 		case 'd':
 			print_raw();
 			break;
 		case 'e':
-#ifdef CONFIG_FEATURE_SGI_LABEL
-			if (label_sgi == current_label_type)
+			if (LABEL_IS_SGI)
 				sgi_set_xcyl();
-			else
-#endif
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			 if (label_sun == current_label_type)
+			else if (LABEL_IS_SUN)
 				sun_set_xcyl();
-			 else
-#endif
-			if (label_dos == current_label_type)
+			else if (LABEL_IS_DOS)
 				x_list_table(1);
 			break;
 		case 'f':
-			if (label_dos == current_label_type)
+			if (LABEL_IS_DOS)
 				fix_partition_table_order();
 			break;
 		case 'g':
@@ -5507,23 +5455,17 @@ xselect(void)
 			update_units();
 			break;
 		case 'i':
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			if (label_sun == current_label_type)
+			if (LABEL_IS_SUN)
 				sun_set_ilfact();
-#endif
 			break;
 		case 'o':
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			if (label_sun == current_label_type)
+			if (LABEL_IS_SUN)
 				sun_set_rspeed();
-#endif
 			break;
 		case 'p':
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			if (label_sun == current_label_type)
+			if (LABEL_IS_SUN)
 				list_table(1);
 			else
-#endif
 				x_list_table(0);
 			break;
 		case 'q':
@@ -5550,10 +5492,8 @@ xselect(void)
 			write_table();  /* does not return */
 			break;
 		case 'y':
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			if (label_sun == current_label_type)
+			if (LABEL_IS_SUN)
 				sun_set_pcylcount();
-#endif
 			break;
 		default:
 			xmenu();
@@ -5614,7 +5554,7 @@ try(const char *device, int user_specifi
 			close(fd);
 		} else if (gb < 0) { /* no DOS signature */
 			list_disk_geometry();
-			if (label_aix == current_label_type){
+			if (LABEL_IS_AIX) {
 				return;
 			}
 #ifdef CONFIG_FEATURE_OSF_LABEL
@@ -5628,7 +5568,7 @@ try(const char *device, int user_specifi
 			close(fd);
 			list_table(0);
 #ifdef CONFIG_FEATURE_FDISK_WRITABLE
-			if (label_sun != current_label_type && partitions > 4){
+			if (!LABEL_IS_SUN && partitions > 4){
 				delete_partition(ext_index);
 			}
 #endif
@@ -5820,8 +5760,7 @@ int fdisk_main(int argc, char **argv)
 
 	get_boot(fdisk);
 
-#ifdef CONFIG_FEATURE_OSF_LABEL
-	if (label_osf == current_label_type) {
+	if (LABEL_IS_OSF) {
 		/* OSF label, and no DOS label */
 		printf(_("Detected an OSF/1 disklabel on %s, entering "
 			 "disklabel mode.\n"),
@@ -5831,31 +5770,25 @@ int fdisk_main(int argc, char **argv)
 		current_label_type = label_dos;
 		/* If we return we may want to make an empty DOS label? */
 	}
-#endif
 
 	while (1) {
 		putchar('\n');
 		c = tolower(read_char(_("Command (m for help): ")));
 		switch (c) {
 		case 'a':
-			if (label_dos == current_label_type)
+			if (LABEL_IS_DOS)
 				toggle_active(get_partition(1, partitions));
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			else if (label_sun == current_label_type)
+			else if (LABEL_IS_SUN)
 				toggle_sunflags(get_partition(1, partitions),
 						0x01);
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-			else if (label_sgi == current_label_type)
+			else if (LABEL_IS_SGI)
 				sgi_set_bootpartition(
 					get_partition(1, partitions));
-#endif
 			else
 				unknown_command(c);
 			break;
 		case 'b':
-#ifdef CONFIG_FEATURE_SGI_LABEL
-			if (label_sgi == current_label_type) {
+			if (LABEL_IS_SGI) {
 				printf(_("\nThe current boot file is: %s\n"),
 					sgi_get_bootfile());
 				if (read_chars(_("Please enter the name of the "
@@ -5864,53 +5797,45 @@ int fdisk_main(int argc, char **argv)
 				else
 					sgi_set_bootfile(line_ptr);
 			} else
-#endif
 #ifdef CONFIG_FEATURE_OSF_LABEL
 				bselect();
 #endif
+
+/* BUG!? Think what will happen if !CONFIG_FEATURE_OSF_LABEL !!! */
+
 			break;
 		case 'c':
-			if (label_dos == current_label_type)
+			if (LABEL_IS_DOS)
 				toggle_dos_compatibility_flag();
-#ifdef CONFIG_FEATURE_SUN_LABEL
-			else if (label_sun == current_label_type)
+			else if (LABEL_IS_SUN)
 				toggle_sunflags(get_partition(1, partitions),
 						0x10);
-#endif
-#ifdef CONFIG_FEATURE_SGI_LABEL
-			else if (label_sgi == current_label_type)
+			else if (LABEL_IS_SGI)
 				sgi_set_swappartition(
 						get_partition(1, partitions));
-#endif
 			else
 				unknown_command(c);
 			break;
 		case 'd':
 			{
 				int j;
-#ifdef CONFIG_FEATURE_SGI_LABEL
 			/* If sgi_label then don't use get_existing_partition,
 			   let the user select a partition, since
 			   get_existing_partition() only works for Linux-like
 			   partition tables */
-				if (label_sgi != current_label_type) {
+				if (!LABEL_IS_SGI) {
 					j = get_existing_partition(1, partitions);
 				} else {
 					j = get_partition(1, partitions);
 				}
-#else
-				j = get_existing_partition(1, partitions);
-#endif
 				if (j >= 0)
 					delete_partition(j);
 			}
 			break;
 		case 'i':
-#ifdef CONFIG_FEATURE_SGI_LABEL
-			if (label_sgi == current_label_type)
+			if (LABEL_IS_SGI)
 				create_sgiinfo();
 			else
-#endif
 				unknown_command(c);
 		case 'l':
 			list_types(get_sys_types());
@@ -5950,14 +5875,11 @@ int fdisk_main(int argc, char **argv)
 			break;
 #ifdef CONFIG_FEATURE_FDISK_ADVANCED
 		case 'x':
-#ifdef CONFIG_FEATURE_SGI_LABEL
-			if (label_sgi == current_label_type) {
+			if (LABEL_IS_SGI) {
 				fprintf(stderr,
 					_("\n\tSorry, no experts menu for SGI "
 					"partition tables available.\n\n"));
 			} else
-#endif
-
 				xselect();
 			break;
 #endif


_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic