diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-18 14:42:45 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-18 14:42:45 +0000 |
commit | 40744b33d216b3193a0592cf88b393b3e3eba46b (patch) | |
tree | f5b0049e53ce27f4a6b15c69cfaef0b9364baf84 | |
parent | 35ad95f83b1431a93999a01dbb7334e7e15c843f (diff) | |
download | busybox-w32-40744b33d216b3193a0592cf88b393b3e3eba46b.tar.gz busybox-w32-40744b33d216b3193a0592cf88b393b3e3eba46b.tar.bz2 busybox-w32-40744b33d216b3193a0592cf88b393b3e3eba46b.zip |
fdisk: move 2k ptes[] array into bb_common_bufsiz1
git-svn-id: svn://busybox.net/trunk/busybox@18136 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | util-linux/fdisk.c | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 66acb088f..6f1ba96de 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -58,16 +58,6 @@ static unsigned sector_size = DEFAULT_SECTOR_SIZE; | |||
58 | static unsigned user_set_sector_size; | 58 | static unsigned user_set_sector_size; |
59 | static unsigned sector_offset = 1; | 59 | static unsigned sector_offset = 1; |
60 | 60 | ||
61 | /* | ||
62 | * Raw disk label. For DOS-type partition tables the MBR, | ||
63 | * with descriptions of the primary partitions. | ||
64 | */ | ||
65 | #if (MAX_SECTOR_SIZE) > (BUFSIZ+1) | ||
66 | static char MBRbuffer[MAX_SECTOR_SIZE]; | ||
67 | #else | ||
68 | # define MBRbuffer bb_common_bufsiz1 | ||
69 | #endif | ||
70 | |||
71 | #if ENABLE_FEATURE_OSF_LABEL | 61 | #if ENABLE_FEATURE_OSF_LABEL |
72 | static int possibly_osf_label; | 62 | static int possibly_osf_label; |
73 | #endif | 63 | #endif |
@@ -201,7 +191,6 @@ static int get_boot(enum action what); | |||
201 | tolower(_c) + 10 - 'a'; \ | 191 | tolower(_c) + 10 - 'a'; \ |
202 | }) | 192 | }) |
203 | 193 | ||
204 | |||
205 | #define LINE_LENGTH 80 | 194 | #define LINE_LENGTH 80 |
206 | #define pt_offset(b, n) ((struct partition *)((b) + 0x1be + \ | 195 | #define pt_offset(b, n) ((struct partition *)((b) + 0x1be + \ |
207 | (n) * sizeof(struct partition))) | 196 | (n) * sizeof(struct partition))) |
@@ -210,15 +199,15 @@ static int get_boot(enum action what); | |||
210 | 199 | ||
211 | #define hsc2sector(h,s,c) (sector(s) - 1 + sectors * \ | 200 | #define hsc2sector(h,s,c) (sector(s) - 1 + sectors * \ |
212 | ((h) + heads * cylinder(s,c))) | 201 | ((h) + heads * cylinder(s,c))) |
213 | #define set_hsc(h,s,c,sector) { \ | 202 | #define set_hsc(h,s,c,sector) \ |
214 | s = sector % sectors + 1; \ | 203 | do { \ |
215 | sector /= sectors; \ | 204 | s = sector % sectors + 1; \ |
216 | h = sector % heads; \ | 205 | sector /= sectors; \ |
217 | sector /= heads; \ | 206 | h = sector % heads; \ |
218 | c = sector & 0xff; \ | 207 | sector /= heads; \ |
219 | s |= (sector >> 2) & 0xc0; \ | 208 | c = sector & 0xff; \ |
220 | } | 209 | s |= (sector >> 2) & 0xc0; \ |
221 | 210 | } while (0) | |
222 | 211 | ||
223 | static unsigned get_start_sect(const struct partition *p); | 212 | static unsigned get_start_sect(const struct partition *p); |
224 | static unsigned get_nr_sects(const struct partition *p); | 213 | static unsigned get_nr_sects(const struct partition *p); |
@@ -231,16 +220,27 @@ static unsigned get_nr_sects(const struct partition *p); | |||
231 | * Each logical partition table entry has two pointers, one for the | 220 | * Each logical partition table entry has two pointers, one for the |
232 | * partition and one link to the next one. | 221 | * partition and one link to the next one. |
233 | */ | 222 | */ |
234 | static struct pte { | 223 | struct pte { |
235 | struct partition *part_table; /* points into sectorbuffer */ | 224 | struct partition *part_table; /* points into sectorbuffer */ |
236 | struct partition *ext_pointer; /* points into sectorbuffer */ | 225 | struct partition *ext_pointer; /* points into sectorbuffer */ |
237 | #if ENABLE_FEATURE_FDISK_WRITABLE | 226 | #if ENABLE_FEATURE_FDISK_WRITABLE |
238 | char changed; /* boolean */ | 227 | char changed; /* boolean */ |
239 | #endif | 228 | #endif |
240 | off_t offset; /* disk sector number */ | 229 | off_t offset; /* disk sector number */ |
241 | char *sectorbuffer; /* disk sector contents */ | 230 | char *sectorbuffer; /* disk sector contents */ |
242 | } ptes[MAXIMUM_PARTS]; | 231 | }; |
232 | |||
233 | struct globals { | ||
234 | /* Raw disk label. For DOS-type partition tables the MBR, | ||
235 | * with descriptions of the primary partitions. */ | ||
236 | char MBRbuffer[MAX_SECTOR_SIZE]; | ||
237 | /* Partition tables */ | ||
238 | struct pte ptes[MAXIMUM_PARTS]; | ||
239 | }; | ||
243 | 240 | ||
241 | #define G (*(struct globals*)bb_common_bufsiz1) | ||
242 | #define MBRbuffer (G.MBRbuffer) | ||
243 | #define ptes (G.ptes) | ||
244 | 244 | ||
245 | #if ENABLE_FEATURE_FDISK_WRITABLE | 245 | #if ENABLE_FEATURE_FDISK_WRITABLE |
246 | static void | 246 | static void |
@@ -297,7 +297,7 @@ read_line(const char *prompt) | |||
297 | { | 297 | { |
298 | int sz; | 298 | int sz; |
299 | 299 | ||
300 | sz = read_line_input(prompt, line_buffer, LINE_LENGTH, NULL); | 300 | sz = read_line_input(prompt, line_buffer, sizeof(line_buffer), NULL); |
301 | if (sz <= 0) | 301 | if (sz <= 0) |
302 | exit(0); /* Ctrl-D or Ctrl-C */ | 302 | exit(0); /* Ctrl-D or Ctrl-C */ |
303 | 303 | ||
@@ -994,7 +994,8 @@ warn_geometry(void) | |||
994 | return 1; | 994 | return 1; |
995 | } | 995 | } |
996 | 996 | ||
997 | static void update_units(void) | 997 | static void |
998 | update_units(void) | ||
998 | { | 999 | { |
999 | int cyl_units = heads * sectors; | 1000 | int cyl_units = heads * sectors; |
1000 | 1001 | ||
@@ -2784,6 +2785,8 @@ unknown_command(int c) | |||
2784 | } | 2785 | } |
2785 | #endif | 2786 | #endif |
2786 | 2787 | ||
2788 | void BUG_fdisk_globals_overflow(void); | ||
2789 | |||
2787 | int fdisk_main(int argc, char **argv); | 2790 | int fdisk_main(int argc, char **argv); |
2788 | int fdisk_main(int argc, char **argv) | 2791 | int fdisk_main(int argc, char **argv) |
2789 | { | 2792 | { |
@@ -2806,6 +2809,10 @@ int fdisk_main(int argc, char **argv) | |||
2806 | OPT_u = 1 << 5, | 2809 | OPT_u = 1 << 5, |
2807 | OPT_s = (1 << 6) * ENABLE_FEATURE_FDISK_BLKSIZE, | 2810 | OPT_s = (1 << 6) * ENABLE_FEATURE_FDISK_BLKSIZE, |
2808 | }; | 2811 | }; |
2812 | |||
2813 | if (sizeof(G) > sizeof(bb_common_bufsiz1)) | ||
2814 | BUG_fdisk_globals_overflow(); | ||
2815 | |||
2809 | opt = getopt32(argc, argv, "b:C:H:lS:u" USE_FEATURE_FDISK_BLKSIZE("s"), | 2816 | opt = getopt32(argc, argv, "b:C:H:lS:u" USE_FEATURE_FDISK_BLKSIZE("s"), |
2810 | &str_b, &str_C, &str_H, &str_S); | 2817 | &str_b, &str_C, &str_H, &str_S); |
2811 | argc -= optind; | 2818 | argc -= optind; |