svn commit: trunk/busybox/util-linux

vda at busybox.net vda at busybox.net
Sun Mar 18 14:42:45 UTC 2007


Author: vda
Date: 2007-03-18 07:42:45 -0700 (Sun, 18 Mar 2007)
New Revision: 18136

Log:
fdisk: move 2k ptes[] array into bb_common_bufsiz1


Modified:
   trunk/busybox/util-linux/fdisk.c


Changeset:
Modified: trunk/busybox/util-linux/fdisk.c
===================================================================
--- trunk/busybox/util-linux/fdisk.c	2007-03-18 11:53:16 UTC (rev 18135)
+++ trunk/busybox/util-linux/fdisk.c	2007-03-18 14:42:45 UTC (rev 18136)
@@ -58,16 +58,6 @@
 static unsigned user_set_sector_size;
 static unsigned sector_offset = 1;
 
-/*
- * Raw disk label. For DOS-type partition tables the MBR,
- * with descriptions of the primary partitions.
- */
-#if (MAX_SECTOR_SIZE) > (BUFSIZ+1)
-static char MBRbuffer[MAX_SECTOR_SIZE];
-#else
-# define MBRbuffer bb_common_bufsiz1
-#endif
-
 #if ENABLE_FEATURE_OSF_LABEL
 static int possibly_osf_label;
 #endif
@@ -201,7 +191,6 @@
 				tolower(_c) + 10 - 'a'; \
 			})
 
-
 #define LINE_LENGTH     80
 #define pt_offset(b, n) ((struct partition *)((b) + 0x1be + \
 				(n) * sizeof(struct partition)))
@@ -210,16 +199,16 @@
 
 #define hsc2sector(h,s,c) (sector(s) - 1 + sectors * \
 				((h) + heads * cylinder(s,c)))
-#define set_hsc(h,s,c,sector) { \
-				s = sector % sectors + 1;       \
-				sector /= sectors;      \
-				h = sector % heads;     \
-				sector /= heads;        \
-				c = sector & 0xff;      \
-				s |= (sector >> 2) & 0xc0;      \
-			}
+#define set_hsc(h,s,c,sector) \
+	do { \
+		s = sector % sectors + 1;  \
+		sector /= sectors;         \
+		h = sector % heads;        \
+		sector /= heads;           \
+		c = sector & 0xff;         \
+		s |= (sector >> 2) & 0xc0; \
+	} while (0)
 
-
 static unsigned get_start_sect(const struct partition *p);
 static unsigned get_nr_sects(const struct partition *p);
 
@@ -231,17 +220,28 @@
  * Each logical partition table entry has two pointers, one for the
  * partition and one link to the next one.
  */
-static struct pte {
+struct pte {
 	struct partition *part_table;   /* points into sectorbuffer */
 	struct partition *ext_pointer;  /* points into sectorbuffer */
 #if ENABLE_FEATURE_FDISK_WRITABLE
 	char changed;           /* boolean */
 #endif
-	off_t offset;            /* disk sector number */
+	off_t offset;           /* disk sector number */
 	char *sectorbuffer;     /* disk sector contents */
-} ptes[MAXIMUM_PARTS];
+};
 
+struct globals {
+	/* Raw disk label. For DOS-type partition tables the MBR,
+	 * with descriptions of the primary partitions. */
+	char MBRbuffer[MAX_SECTOR_SIZE];
+	/* Partition tables */
+	struct pte ptes[MAXIMUM_PARTS];
+};
 
+#define G (*(struct globals*)bb_common_bufsiz1)
+#define MBRbuffer (G.MBRbuffer)
+#define ptes      (G.ptes)
+
 #if ENABLE_FEATURE_FDISK_WRITABLE
 static void
 set_all_unchanged(void)
@@ -297,7 +297,7 @@
 {
 	int sz;
 
-	sz = read_line_input(prompt, line_buffer, LINE_LENGTH, NULL);
+	sz = read_line_input(prompt, line_buffer, sizeof(line_buffer), NULL);
 	if (sz <= 0)
 		exit(0); /* Ctrl-D or Ctrl-C */
 
@@ -994,7 +994,8 @@
 	return 1;
 }
 
-static void update_units(void)
+static void
+update_units(void)
 {
 	int cyl_units = heads * sectors;
 
@@ -2784,6 +2785,8 @@
 }
 #endif
 
+void BUG_fdisk_globals_overflow(void);
+
 int fdisk_main(int argc, char **argv);
 int fdisk_main(int argc, char **argv)
 {
@@ -2806,6 +2809,10 @@
 		OPT_u = 1 << 5,
 		OPT_s = (1 << 6) * ENABLE_FEATURE_FDISK_BLKSIZE,
 	};
+
+	if (sizeof(G) > sizeof(bb_common_bufsiz1))
+		BUG_fdisk_globals_overflow();
+
 	opt = getopt32(argc, argv, "b:C:H:lS:u" USE_FEATURE_FDISK_BLKSIZE("s"),
 				&str_b, &str_C, &str_H, &str_S);
 	argc -= optind;




More information about the busybox-cvs mailing list