diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-12-16 17:22:33 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-12-16 17:22:33 +0000 |
commit | f77f369ce89549ae3b0b70bfbac4e9c242ec5298 (patch) | |
tree | b7b9979a4dc949a9bd7f8db90c48ba5491eb1844 | |
parent | c794c51a1aa23d2edcff8e1ab4edf96194d3208c (diff) | |
download | busybox-w32-f77f369ce89549ae3b0b70bfbac4e9c242ec5298.tar.gz busybox-w32-f77f369ce89549ae3b0b70bfbac4e9c242ec5298.tar.bz2 busybox-w32-f77f369ce89549ae3b0b70bfbac4e9c242ec5298.zip |
fdisk: reduce global data/bss usage. 8k data+bss build is achievable soon ;)
(add/remove: 0/13 grow/shrink: 6/19 up/down: 74/-492) Total: -418 bytes
text data bss dec hex filename
778330 860 7408 786598 c00a6 busybox_old
777970 840 7376 786186 bff0a busybox_unstripped
-rw-r--r-- | util-linux/fdisk.c | 290 | ||||
-rw-r--r-- | util-linux/fdisk_aix.c | 2 | ||||
-rw-r--r-- | util-linux/fdisk_osf.c | 12 | ||||
-rw-r--r-- | util-linux/fdisk_sgi.c | 32 | ||||
-rw-r--r-- | util-linux/fdisk_sun.c | 102 |
5 files changed, 225 insertions, 213 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 3b60847c9..8271f60f2 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -57,18 +57,6 @@ static const char msg_part_already_defined[] ALIGN1 = | |||
57 | "Partition %d is already defined, delete it before re-adding\n"; | 57 | "Partition %d is already defined, delete it before re-adding\n"; |
58 | 58 | ||
59 | 59 | ||
60 | static unsigned sector_size = DEFAULT_SECTOR_SIZE; | ||
61 | static unsigned user_set_sector_size; | ||
62 | static unsigned sector_offset = 1; | ||
63 | |||
64 | #if ENABLE_FEATURE_OSF_LABEL | ||
65 | static int possibly_osf_label; | ||
66 | #endif | ||
67 | |||
68 | static unsigned heads, sectors, cylinders; | ||
69 | static void update_units(void); | ||
70 | |||
71 | |||
72 | struct partition { | 60 | struct partition { |
73 | unsigned char boot_ind; /* 0x80 - active */ | 61 | unsigned char boot_ind; /* 0x80 - active */ |
74 | unsigned char head; /* starting head */ | 62 | unsigned char head; /* starting head */ |
@@ -129,13 +117,7 @@ enum label_type { | |||
129 | 117 | ||
130 | enum action { fdisk, require, try_only, create_empty_dos, create_empty_sun }; | 118 | enum action { fdisk, require, try_only, create_empty_dos, create_empty_sun }; |
131 | 119 | ||
132 | static enum label_type current_label_type; | 120 | static void update_units(void); |
133 | |||
134 | static const char *disk_device; | ||
135 | static int fd; /* the disk */ | ||
136 | static int partitions = 4; /* maximum partition + 1 */ | ||
137 | static int display_in_cyl_units = 1; | ||
138 | static unsigned units_per_sector = 1; | ||
139 | #if ENABLE_FEATURE_FDISK_WRITABLE | 121 | #if ENABLE_FEATURE_FDISK_WRITABLE |
140 | static void change_units(void); | 122 | static void change_units(void); |
141 | static void reread_partition_table(int leave); | 123 | static void reread_partition_table(int leave); |
@@ -282,28 +264,60 @@ static const char *const i386_sys_types[] = { | |||
282 | 264 | ||
283 | struct globals { | 265 | struct globals { |
284 | char *line_ptr; | 266 | char *line_ptr; |
267 | |||
268 | const char *disk_device; | ||
269 | int fd; /* the disk */ | ||
270 | int g_partitions; // = 4; /* maximum partition + 1 */ | ||
271 | unsigned units_per_sector; // = 1; | ||
272 | unsigned sector_size; // = DEFAULT_SECTOR_SIZE; | ||
273 | unsigned user_set_sector_size; | ||
274 | unsigned sector_offset; // = 1; | ||
275 | unsigned g_heads, g_sectors, g_cylinders; | ||
276 | enum label_type current_label_type; | ||
277 | smallint display_in_cyl_units; // = 1; | ||
278 | #if ENABLE_FEATURE_OSF_LABEL | ||
279 | smallint possibly_osf_label; | ||
280 | #endif | ||
281 | |||
282 | jmp_buf listingbuf; | ||
285 | char line_buffer[80]; | 283 | char line_buffer[80]; |
286 | char partname_buffer[80]; | 284 | char partname_buffer[80]; |
287 | jmp_buf listingbuf; | ||
288 | /* Raw disk label. For DOS-type partition tables the MBR, | 285 | /* Raw disk label. For DOS-type partition tables the MBR, |
289 | * with descriptions of the primary partitions. */ | 286 | * with descriptions of the primary partitions. */ |
290 | char MBRbuffer[MAX_SECTOR_SIZE]; | 287 | char MBRbuffer[MAX_SECTOR_SIZE]; |
291 | /* Partition tables */ | 288 | /* Partition tables */ |
292 | struct pte ptes[MAXIMUM_PARTS]; | 289 | struct pte ptes[MAXIMUM_PARTS]; |
293 | }; | 290 | }; |
294 | /* bb_common_bufsiz1 is too small for this on 64 bit CPUs */ | ||
295 | #define G (*ptr_to_globals) | 291 | #define G (*ptr_to_globals) |
296 | |||
297 | #define line_ptr (G.line_ptr) | 292 | #define line_ptr (G.line_ptr) |
293 | #define disk_device (G.disk_device ) | ||
294 | #define fd (G.fd ) | ||
295 | #define g_partitions (G.g_partitions ) | ||
296 | #define units_per_sector (G.units_per_sector ) | ||
297 | #define sector_size (G.sector_size ) | ||
298 | #define user_set_sector_size (G.user_set_sector_size) | ||
299 | #define sector_offset (G.sector_offset ) | ||
300 | #define g_heads (G.g_heads ) | ||
301 | #define g_sectors (G.g_sectors ) | ||
302 | #define g_cylinders (G.g_cylinders ) | ||
303 | #define current_label_type (G.current_label_type ) | ||
304 | #define display_in_cyl_units (G.display_in_cyl_units) | ||
305 | #define possibly_osf_label (G.possibly_osf_label ) | ||
298 | #define listingbuf (G.listingbuf) | 306 | #define listingbuf (G.listingbuf) |
299 | #define line_buffer (G.line_buffer) | 307 | #define line_buffer (G.line_buffer) |
300 | #define partname_buffer (G.partname_buffer) | 308 | #define partname_buffer (G.partname_buffer) |
301 | #define MBRbuffer (G.MBRbuffer) | 309 | #define MBRbuffer (G.MBRbuffer) |
302 | #define ptes (G.ptes) | 310 | #define ptes (G.ptes) |
311 | #define INIT_G() do { \ | ||
312 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); \ | ||
313 | sector_size = DEFAULT_SECTOR_SIZE; \ | ||
314 | sector_offset = 1; \ | ||
315 | g_partitions = 4; \ | ||
316 | display_in_cyl_units = 1; \ | ||
317 | units_per_sector = 1; \ | ||
318 | } while (0) | ||
303 | 319 | ||
304 | 320 | ||
305 | /* Code */ | ||
306 | |||
307 | #define IS_EXTENDED(i) \ | 321 | #define IS_EXTENDED(i) \ |
308 | ((i) == EXTENDED || (i) == WIN98_EXTENDED || (i) == LINUX_EXTENDED) | 322 | ((i) == EXTENDED || (i) == WIN98_EXTENDED || (i) == LINUX_EXTENDED) |
309 | 323 | ||
@@ -323,12 +337,12 @@ struct globals { | |||
323 | 337 | ||
324 | #define set_hsc(h,s,c,sector) \ | 338 | #define set_hsc(h,s,c,sector) \ |
325 | do { \ | 339 | do { \ |
326 | s = sector % sectors + 1; \ | 340 | s = sector % g_sectors + 1; \ |
327 | sector /= sectors; \ | 341 | sector /= g_sectors; \ |
328 | h = sector % heads; \ | 342 | h = sector % g_heads; \ |
329 | sector /= heads; \ | 343 | sector /= g_heads; \ |
330 | c = sector & 0xff; \ | 344 | c = sector & 0xff; \ |
331 | s |= (sector >> 2) & 0xc0; \ | 345 | s |= (sector >> 2) & 0xc0; \ |
332 | } while (0) | 346 | } while (0) |
333 | 347 | ||
334 | #if ENABLE_FEATURE_FDISK_WRITABLE | 348 | #if ENABLE_FEATURE_FDISK_WRITABLE |
@@ -611,11 +625,11 @@ get_nr_sects(const struct partition *p) | |||
611 | static int type_open = O_RDWR; | 625 | static int type_open = O_RDWR; |
612 | 626 | ||
613 | static int ext_index; /* the prime extended partition */ | 627 | static int ext_index; /* the prime extended partition */ |
614 | static int listing; /* no aborts for fdisk -l */ | 628 | static smallint listing; /* no aborts for fdisk -l */ |
615 | static int dos_compatible_flag = ~0; | 629 | static int dos_compatible_flag = ~0; |
616 | #if ENABLE_FEATURE_FDISK_WRITABLE | 630 | #if ENABLE_FEATURE_FDISK_WRITABLE |
617 | static int dos_changed; | 631 | //static int dos_changed; |
618 | static int nowarn; /* no warnings for fdisk -l/-s */ | 632 | static smallint nowarn; /* no warnings for fdisk -l/-s */ |
619 | #endif | 633 | #endif |
620 | 634 | ||
621 | static unsigned user_cylinders, user_heads, user_sectors; | 635 | static unsigned user_cylinders, user_heads, user_sectors; |
@@ -930,11 +944,11 @@ set_partition(int i, int doext, ullong start, ullong stop, int sysid) | |||
930 | p->sys_ind = sysid; | 944 | p->sys_ind = sysid; |
931 | set_start_sect(p, start - offset); | 945 | set_start_sect(p, start - offset); |
932 | set_nr_sects(p, stop - start + 1); | 946 | set_nr_sects(p, stop - start + 1); |
933 | if (dos_compatible_flag && (start/(sectors*heads) > 1023)) | 947 | if (dos_compatible_flag && (start / (g_sectors * g_heads) > 1023)) |
934 | start = heads*sectors*1024 - 1; | 948 | start = g_heads * g_sectors * 1024 - 1; |
935 | set_hsc(p->head, p->sector, p->cyl, start); | 949 | set_hsc(p->head, p->sector, p->cyl, start); |
936 | if (dos_compatible_flag && (stop/(sectors*heads) > 1023)) | 950 | if (dos_compatible_flag && (stop / (g_sectors * g_heads) > 1023)) |
937 | stop = heads*sectors*1024 - 1; | 951 | stop = g_heads * g_sectors * 1024 - 1; |
938 | set_hsc(p->end_head, p->end_sector, p->end_cyl, stop); | 952 | set_hsc(p->end_head, p->end_sector, p->end_cyl, stop); |
939 | ptes[i].changed = 1; | 953 | ptes[i].changed = 1; |
940 | } | 954 | } |
@@ -943,15 +957,15 @@ set_partition(int i, int doext, ullong start, ullong stop, int sysid) | |||
943 | static int | 957 | static int |
944 | warn_geometry(void) | 958 | warn_geometry(void) |
945 | { | 959 | { |
946 | if (heads && sectors && cylinders) | 960 | if (g_heads && g_sectors && g_cylinders) |
947 | return 0; | 961 | return 0; |
948 | 962 | ||
949 | printf("Unknown value(s) for:"); | 963 | printf("Unknown value(s) for:"); |
950 | if (!heads) | 964 | if (!g_heads) |
951 | printf(" heads"); | 965 | printf(" heads"); |
952 | if (!sectors) | 966 | if (!g_sectors) |
953 | printf(" sectors"); | 967 | printf(" sectors"); |
954 | if (!cylinders) | 968 | if (!g_cylinders) |
955 | printf(" cylinders"); | 969 | printf(" cylinders"); |
956 | printf( | 970 | printf( |
957 | #if ENABLE_FEATURE_FDISK_WRITABLE | 971 | #if ENABLE_FEATURE_FDISK_WRITABLE |
@@ -964,7 +978,7 @@ warn_geometry(void) | |||
964 | static void | 978 | static void |
965 | update_units(void) | 979 | update_units(void) |
966 | { | 980 | { |
967 | int cyl_units = heads * sectors; | 981 | int cyl_units = g_heads * g_sectors; |
968 | 982 | ||
969 | if (display_in_cyl_units && cyl_units) | 983 | if (display_in_cyl_units && cyl_units) |
970 | units_per_sector = cyl_units; | 984 | units_per_sector = cyl_units; |
@@ -976,7 +990,7 @@ update_units(void) | |||
976 | static void | 990 | static void |
977 | warn_cylinders(void) | 991 | warn_cylinders(void) |
978 | { | 992 | { |
979 | if (LABEL_IS_DOS && cylinders > 1024 && !nowarn) | 993 | if (LABEL_IS_DOS && g_cylinders > 1024 && !nowarn) |
980 | printf("\n" | 994 | printf("\n" |
981 | "The number of cylinders for this disk is set to %d.\n" | 995 | "The number of cylinders for this disk is set to %d.\n" |
982 | "There is nothing wrong with that, but this is larger than 1024,\n" | 996 | "There is nothing wrong with that, but this is larger than 1024,\n" |
@@ -984,7 +998,7 @@ warn_cylinders(void) | |||
984 | "1) software that runs at boot time (e.g., old versions of LILO)\n" | 998 | "1) software that runs at boot time (e.g., old versions of LILO)\n" |
985 | "2) booting and partitioning software from other OSs\n" | 999 | "2) booting and partitioning software from other OSs\n" |
986 | " (e.g., DOS FDISK, OS/2 FDISK)\n", | 1000 | " (e.g., DOS FDISK, OS/2 FDISK)\n", |
987 | cylinders); | 1001 | g_cylinders); |
988 | } | 1002 | } |
989 | #endif | 1003 | #endif |
990 | 1004 | ||
@@ -1006,16 +1020,16 @@ read_extended(int ext) | |||
1006 | } | 1020 | } |
1007 | 1021 | ||
1008 | while (IS_EXTENDED(p->sys_ind)) { | 1022 | while (IS_EXTENDED(p->sys_ind)) { |
1009 | struct pte *pe = &ptes[partitions]; | 1023 | struct pte *pe = &ptes[g_partitions]; |
1010 | 1024 | ||
1011 | if (partitions >= MAXIMUM_PARTS) { | 1025 | if (g_partitions >= MAXIMUM_PARTS) { |
1012 | /* This is not a Linux restriction, but | 1026 | /* This is not a Linux restriction, but |
1013 | this program uses arrays of size MAXIMUM_PARTS. | 1027 | this program uses arrays of size MAXIMUM_PARTS. |
1014 | Do not try to 'improve' this test. */ | 1028 | Do not try to 'improve' this test. */ |
1015 | struct pte *pre = &ptes[partitions-1]; | 1029 | struct pte *pre = &ptes[g_partitions - 1]; |
1016 | #if ENABLE_FEATURE_FDISK_WRITABLE | 1030 | #if ENABLE_FEATURE_FDISK_WRITABLE |
1017 | printf("Warning: deleting partitions after %d\n", | 1031 | printf("Warning: deleting partitions after %d\n", |
1018 | partitions); | 1032 | g_partitions); |
1019 | pre->changed = 1; | 1033 | pre->changed = 1; |
1020 | #endif | 1034 | #endif |
1021 | clear_partition(pre->ext_pointer); | 1035 | clear_partition(pre->ext_pointer); |
@@ -1033,14 +1047,14 @@ read_extended(int ext) | |||
1033 | if (pe->ext_pointer) | 1047 | if (pe->ext_pointer) |
1034 | printf("Warning: extra link " | 1048 | printf("Warning: extra link " |
1035 | "pointer in partition table" | 1049 | "pointer in partition table" |
1036 | " %d\n", partitions + 1); | 1050 | " %d\n", g_partitions + 1); |
1037 | else | 1051 | else |
1038 | pe->ext_pointer = p; | 1052 | pe->ext_pointer = p; |
1039 | } else if (p->sys_ind) { | 1053 | } else if (p->sys_ind) { |
1040 | if (pe->part_table) | 1054 | if (pe->part_table) |
1041 | printf("Warning: ignoring extra " | 1055 | printf("Warning: ignoring extra " |
1042 | "data in partition table" | 1056 | "data in partition table" |
1043 | " %d\n", partitions + 1); | 1057 | " %d\n", g_partitions + 1); |
1044 | else | 1058 | else |
1045 | pe->part_table = p; | 1059 | pe->part_table = p; |
1046 | } | 1060 | } |
@@ -1061,17 +1075,17 @@ read_extended(int ext) | |||
1061 | } | 1075 | } |
1062 | 1076 | ||
1063 | p = pe->ext_pointer; | 1077 | p = pe->ext_pointer; |
1064 | partitions++; | 1078 | g_partitions++; |
1065 | } | 1079 | } |
1066 | 1080 | ||
1067 | #if ENABLE_FEATURE_FDISK_WRITABLE | 1081 | #if ENABLE_FEATURE_FDISK_WRITABLE |
1068 | /* remove empty links */ | 1082 | /* remove empty links */ |
1069 | remove: | 1083 | remove: |
1070 | for (i = 4; i < partitions; i++) { | 1084 | for (i = 4; i < g_partitions; i++) { |
1071 | struct pte *pe = &ptes[i]; | 1085 | struct pte *pe = &ptes[i]; |
1072 | 1086 | ||
1073 | if (!get_nr_sects(pe->part_table) | 1087 | if (!get_nr_sects(pe->part_table) |
1074 | && (partitions > 5 || ptes[4].part_table->sys_ind) | 1088 | && (g_partitions > 5 || ptes[4].part_table->sys_ind) |
1075 | ) { | 1089 | ) { |
1076 | printf("Omitting empty partition (%d)\n", i+1); | 1090 | printf("Omitting empty partition (%d)\n", i+1); |
1077 | delete_partition(i); | 1091 | delete_partition(i); |
@@ -1094,7 +1108,7 @@ create_doslabel(void) | |||
1094 | #if ENABLE_FEATURE_OSF_LABEL | 1108 | #if ENABLE_FEATURE_OSF_LABEL |
1095 | possibly_osf_label = 0; | 1109 | possibly_osf_label = 0; |
1096 | #endif | 1110 | #endif |
1097 | partitions = 4; | 1111 | g_partitions = 4; |
1098 | 1112 | ||
1099 | for (i = 510-64; i < 510; i++) | 1113 | for (i = 510-64; i < 510; i++) |
1100 | MBRbuffer[i] = 0; | 1114 | MBRbuffer[i] = 0; |
@@ -1175,17 +1189,17 @@ get_geometry(void) | |||
1175 | #if ENABLE_FEATURE_SUN_LABEL | 1189 | #if ENABLE_FEATURE_SUN_LABEL |
1176 | guess_device_type(); | 1190 | guess_device_type(); |
1177 | #endif | 1191 | #endif |
1178 | heads = cylinders = sectors = 0; | 1192 | g_heads = g_cylinders = g_sectors = 0; |
1179 | kern_heads = kern_sectors = 0; | 1193 | kern_heads = kern_sectors = 0; |
1180 | pt_heads = pt_sectors = 0; | 1194 | pt_heads = pt_sectors = 0; |
1181 | 1195 | ||
1182 | get_kernel_geometry(); | 1196 | get_kernel_geometry(); |
1183 | get_partition_table_geometry(); | 1197 | get_partition_table_geometry(); |
1184 | 1198 | ||
1185 | heads = user_heads ? user_heads : | 1199 | g_heads = user_heads ? user_heads : |
1186 | pt_heads ? pt_heads : | 1200 | pt_heads ? pt_heads : |
1187 | kern_heads ? kern_heads : 255; | 1201 | kern_heads ? kern_heads : 255; |
1188 | sectors = user_sectors ? user_sectors : | 1202 | g_sectors = user_sectors ? user_sectors : |
1189 | pt_sectors ? pt_sectors : | 1203 | pt_sectors ? pt_sectors : |
1190 | kern_sectors ? kern_sectors : 63; | 1204 | kern_sectors ? kern_sectors : 63; |
1191 | if (ioctl(fd, BLKGETSIZE64, &v64) == 0) { | 1205 | if (ioctl(fd, BLKGETSIZE64, &v64) == 0) { |
@@ -1200,11 +1214,11 @@ get_geometry(void) | |||
1200 | 1214 | ||
1201 | sector_offset = 1; | 1215 | sector_offset = 1; |
1202 | if (dos_compatible_flag) | 1216 | if (dos_compatible_flag) |
1203 | sector_offset = sectors; | 1217 | sector_offset = g_sectors; |
1204 | 1218 | ||
1205 | cylinders = total_number_of_sectors / (heads * sectors * sec_fac); | 1219 | g_cylinders = total_number_of_sectors / (g_heads * g_sectors * sec_fac); |
1206 | if (!cylinders) | 1220 | if (!g_cylinders) |
1207 | cylinders = user_cylinders; | 1221 | g_cylinders = user_cylinders; |
1208 | } | 1222 | } |
1209 | 1223 | ||
1210 | /* | 1224 | /* |
@@ -1218,7 +1232,7 @@ get_boot(enum action what) | |||
1218 | { | 1232 | { |
1219 | int i; | 1233 | int i; |
1220 | 1234 | ||
1221 | partitions = 4; | 1235 | g_partitions = 4; |
1222 | 1236 | ||
1223 | for (i = 0; i < 4; i++) { | 1237 | for (i = 0; i < 4; i++) { |
1224 | struct pte *pe = &ptes[i]; | 1238 | struct pte *pe = &ptes[i]; |
@@ -1342,7 +1356,7 @@ get_boot(enum action what) | |||
1342 | struct pte *pe = &ptes[i]; | 1356 | struct pte *pe = &ptes[i]; |
1343 | 1357 | ||
1344 | if (IS_EXTENDED(pe->part_table->sys_ind)) { | 1358 | if (IS_EXTENDED(pe->part_table->sys_ind)) { |
1345 | if (partitions != 4) | 1359 | if (g_partitions != 4) |
1346 | printf("Ignoring extra extended " | 1360 | printf("Ignoring extra extended " |
1347 | "partition %d\n", i + 1); | 1361 | "partition %d\n", i + 1); |
1348 | else | 1362 | else |
@@ -1350,7 +1364,7 @@ get_boot(enum action what) | |||
1350 | } | 1364 | } |
1351 | } | 1365 | } |
1352 | 1366 | ||
1353 | for (i = 3; i < partitions; i++) { | 1367 | for (i = 3; i < g_partitions; i++) { |
1354 | struct pte *pe = &ptes[i]; | 1368 | struct pte *pe = &ptes[i]; |
1355 | 1369 | ||
1356 | if (!valid_part_table_flag(pe->sectorbuffer)) { | 1370 | if (!valid_part_table_flag(pe->sectorbuffer)) { |
@@ -1411,7 +1425,7 @@ read_int(unsigned low, unsigned dflt, unsigned high, unsigned base, const char * | |||
1411 | case 'c': | 1425 | case 'c': |
1412 | case 'C': | 1426 | case 'C': |
1413 | if (!display_in_cyl_units) | 1427 | if (!display_in_cyl_units) |
1414 | i *= heads * sectors; | 1428 | i *= g_heads * g_sectors; |
1415 | break; | 1429 | break; |
1416 | case 'K': | 1430 | case 'K': |
1417 | absolute = 1024; | 1431 | absolute = 1024; |
@@ -1562,7 +1576,7 @@ toggle_dos_compatibility_flag(void) | |||
1562 | { | 1576 | { |
1563 | dos_compatible_flag = ~dos_compatible_flag; | 1577 | dos_compatible_flag = ~dos_compatible_flag; |
1564 | if (dos_compatible_flag) { | 1578 | if (dos_compatible_flag) { |
1565 | sector_offset = sectors; | 1579 | sector_offset = g_sectors; |
1566 | printf("DOS Compatibility flag is set\n"); | 1580 | printf("DOS Compatibility flag is set\n"); |
1567 | } else { | 1581 | } else { |
1568 | sector_offset = 1; | 1582 | sector_offset = 1; |
@@ -1596,7 +1610,7 @@ delete_partition(int i) | |||
1596 | 1610 | ||
1597 | if (i < 4) { | 1611 | if (i < 4) { |
1598 | if (IS_EXTENDED(p->sys_ind) && i == ext_index) { | 1612 | if (IS_EXTENDED(p->sys_ind) && i == ext_index) { |
1599 | partitions = 4; | 1613 | g_partitions = 4; |
1600 | ptes[ext_index].ext_pointer = NULL; | 1614 | ptes[ext_index].ext_pointer = NULL; |
1601 | extended_offset = 0; | 1615 | extended_offset = 0; |
1602 | } | 1616 | } |
@@ -1606,7 +1620,7 @@ delete_partition(int i) | |||
1606 | 1620 | ||
1607 | if (!q->sys_ind && i > 4) { | 1621 | if (!q->sys_ind && i > 4) { |
1608 | /* the last one in the chain - just delete */ | 1622 | /* the last one in the chain - just delete */ |
1609 | --partitions; | 1623 | --g_partitions; |
1610 | --i; | 1624 | --i; |
1611 | clear_partition(ptes[i].ext_pointer); | 1625 | clear_partition(ptes[i].ext_pointer); |
1612 | ptes[i].changed = 1; | 1626 | ptes[i].changed = 1; |
@@ -1619,7 +1633,7 @@ delete_partition(int i) | |||
1619 | set_start_sect(p, get_start_sect(q)); | 1633 | set_start_sect(p, get_start_sect(q)); |
1620 | set_nr_sects(p, get_nr_sects(q)); | 1634 | set_nr_sects(p, get_nr_sects(q)); |
1621 | ptes[i-1].changed = 1; | 1635 | ptes[i-1].changed = 1; |
1622 | } else if (partitions > 5) { /* 5 will be moved to 4 */ | 1636 | } else if (g_partitions > 5) { /* 5 will be moved to 4 */ |
1623 | /* the first logical in a longer chain */ | 1637 | /* the first logical in a longer chain */ |
1624 | pe = &ptes[5]; | 1638 | pe = &ptes[5]; |
1625 | 1639 | ||
@@ -1631,9 +1645,9 @@ delete_partition(int i) | |||
1631 | pe->changed = 1; | 1645 | pe->changed = 1; |
1632 | } | 1646 | } |
1633 | 1647 | ||
1634 | if (partitions > 5) { | 1648 | if (g_partitions > 5) { |
1635 | partitions--; | 1649 | g_partitions--; |
1636 | while (i < partitions) { | 1650 | while (i < g_partitions) { |
1637 | ptes[i] = ptes[i+1]; | 1651 | ptes[i] = ptes[i+1]; |
1638 | i++; | 1652 | i++; |
1639 | } | 1653 | } |
@@ -1653,9 +1667,9 @@ change_sysid(void) | |||
1653 | let the user select a partition, since get_existing_partition() | 1667 | let the user select a partition, since get_existing_partition() |
1654 | only works for Linux like partition tables. */ | 1668 | only works for Linux like partition tables. */ |
1655 | if (!LABEL_IS_SGI) { | 1669 | if (!LABEL_IS_SGI) { |
1656 | i = get_existing_partition(0, partitions); | 1670 | i = get_existing_partition(0, g_partitions); |
1657 | } else { | 1671 | } else { |
1658 | i = get_partition(0, partitions); | 1672 | i = get_partition(0, g_partitions); |
1659 | } | 1673 | } |
1660 | if (i == -1) | 1674 | if (i == -1) |
1661 | return; | 1675 | return; |
@@ -1722,7 +1736,7 @@ change_sysid(void) | |||
1722 | ptes[i].changed = 1; | 1736 | ptes[i].changed = 1; |
1723 | if (is_dos_partition(origsys) || | 1737 | if (is_dos_partition(origsys) || |
1724 | is_dos_partition(sys)) | 1738 | is_dos_partition(sys)) |
1725 | dos_changed = 1; | 1739 | //dos_changed = 1; |
1726 | break; | 1740 | break; |
1727 | } | 1741 | } |
1728 | } | 1742 | } |
@@ -1738,12 +1752,12 @@ change_sysid(void) | |||
1738 | static void | 1752 | static void |
1739 | linear2chs(unsigned ls, unsigned *c, unsigned *h, unsigned *s) | 1753 | linear2chs(unsigned ls, unsigned *c, unsigned *h, unsigned *s) |
1740 | { | 1754 | { |
1741 | int spc = heads * sectors; | 1755 | int spc = g_heads * g_sectors; |
1742 | 1756 | ||
1743 | *c = ls / spc; | 1757 | *c = ls / spc; |
1744 | ls = ls % spc; | 1758 | ls = ls % spc; |
1745 | *h = ls / sectors; | 1759 | *h = ls / g_sectors; |
1746 | *s = ls % sectors + 1; /* sectors count from 1 */ | 1760 | *s = ls % g_sectors + 1; /* sectors count from 1 */ |
1747 | } | 1761 | } |
1748 | 1762 | ||
1749 | static void | 1763 | static void |
@@ -1754,7 +1768,7 @@ check_consistency(const struct partition *p, int partition) | |||
1754 | unsigned lbc, lbh, lbs; /* logical beginning c, h, s */ | 1768 | unsigned lbc, lbh, lbs; /* logical beginning c, h, s */ |
1755 | unsigned lec, leh, les; /* logical ending c, h, s */ | 1769 | unsigned lec, leh, les; /* logical ending c, h, s */ |
1756 | 1770 | ||
1757 | if (!heads || !sectors || (partition >= 4)) | 1771 | if (!g_heads || !g_sectors || (partition >= 4)) |
1758 | return; /* do not check extended partitions */ | 1772 | return; /* do not check extended partitions */ |
1759 | 1773 | ||
1760 | /* physical beginning c, h, s */ | 1774 | /* physical beginning c, h, s */ |
@@ -1774,7 +1788,7 @@ check_consistency(const struct partition *p, int partition) | |||
1774 | linear2chs(get_start_sect(p) + get_nr_sects(p) - 1, &lec, &leh, &les); | 1788 | linear2chs(get_start_sect(p) + get_nr_sects(p) - 1, &lec, &leh, &les); |
1775 | 1789 | ||
1776 | /* Same physical / logical beginning? */ | 1790 | /* Same physical / logical beginning? */ |
1777 | if (cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) { | 1791 | if (g_cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) { |
1778 | printf("Partition %d has different physical/logical " | 1792 | printf("Partition %d has different physical/logical " |
1779 | "beginnings (non-Linux?):\n", partition + 1); | 1793 | "beginnings (non-Linux?):\n", partition + 1); |
1780 | printf(" phys=(%d, %d, %d) ", pbc, pbh, pbs); | 1794 | printf(" phys=(%d, %d, %d) ", pbc, pbh, pbs); |
@@ -1782,7 +1796,7 @@ check_consistency(const struct partition *p, int partition) | |||
1782 | } | 1796 | } |
1783 | 1797 | ||
1784 | /* Same physical / logical ending? */ | 1798 | /* Same physical / logical ending? */ |
1785 | if (cylinders <= 1024 && (pec != lec || peh != leh || pes != les)) { | 1799 | if (g_cylinders <= 1024 && (pec != lec || peh != leh || pes != les)) { |
1786 | printf("Partition %d has different physical/logical " | 1800 | printf("Partition %d has different physical/logical " |
1787 | "endings:\n", partition + 1); | 1801 | "endings:\n", partition + 1); |
1788 | printf(" phys=(%d, %d, %d) ", pec, peh, pes); | 1802 | printf(" phys=(%d, %d, %d) ", pec, peh, pes); |
@@ -1790,7 +1804,7 @@ check_consistency(const struct partition *p, int partition) | |||
1790 | } | 1804 | } |
1791 | 1805 | ||
1792 | /* Ending on cylinder boundary? */ | 1806 | /* Ending on cylinder boundary? */ |
1793 | if (peh != (heads - 1) || pes != sectors) { | 1807 | if (peh != (g_heads - 1) || pes != g_sectors) { |
1794 | printf("Partition %i does not end on cylinder boundary\n", | 1808 | printf("Partition %i does not end on cylinder boundary\n", |
1795 | partition + 1); | 1809 | partition + 1); |
1796 | } | 1810 | } |
@@ -1809,7 +1823,7 @@ list_disk_geometry(void) | |||
1809 | printf("\nDisk %s: %ld.%ld GB, %lld bytes\n", | 1823 | printf("\nDisk %s: %ld.%ld GB, %lld bytes\n", |
1810 | disk_device, megabytes/1000, (megabytes/100)%10, bytes); | 1824 | disk_device, megabytes/1000, (megabytes/100)%10, bytes); |
1811 | printf("%d heads, %d sectors/track, %d cylinders", | 1825 | printf("%d heads, %d sectors/track, %d cylinders", |
1812 | heads, sectors, cylinders); | 1826 | g_heads, g_sectors, g_cylinders); |
1813 | if (units_per_sector == 1) | 1827 | if (units_per_sector == 1) |
1814 | printf(", total %llu sectors", | 1828 | printf(", total %llu sectors", |
1815 | total_number_of_sectors / (sector_size/512)); | 1829 | total_number_of_sectors / (sector_size/512)); |
@@ -1831,7 +1845,7 @@ wrong_p_order(int *prev) | |||
1831 | ullong last_p_start_pos = 0, p_start_pos; | 1845 | ullong last_p_start_pos = 0, p_start_pos; |
1832 | int i, last_i = 0; | 1846 | int i, last_i = 0; |
1833 | 1847 | ||
1834 | for (i = 0; i < partitions; i++) { | 1848 | for (i = 0; i < g_partitions; i++) { |
1835 | if (i == 4) { | 1849 | if (i == 4) { |
1836 | last_i = 4; | 1850 | last_i = 4; |
1837 | last_p_start_pos = 0; | 1851 | last_p_start_pos = 0; |
@@ -1877,7 +1891,7 @@ fix_chain_of_logicals(void) | |||
1877 | /* Stage 1: sort sectors but leave sector of part 4 */ | 1891 | /* Stage 1: sort sectors but leave sector of part 4 */ |
1878 | /* (Its sector is the global extended_offset.) */ | 1892 | /* (Its sector is the global extended_offset.) */ |
1879 | stage1: | 1893 | stage1: |
1880 | for (j = 5; j < partitions-1; j++) { | 1894 | for (j = 5; j < g_partitions - 1; j++) { |
1881 | oj = ptes[j].offset; | 1895 | oj = ptes[j].offset; |
1882 | ojj = ptes[j+1].offset; | 1896 | ojj = ptes[j+1].offset; |
1883 | if (oj > ojj) { | 1897 | if (oj > ojj) { |
@@ -1897,7 +1911,7 @@ fix_chain_of_logicals(void) | |||
1897 | 1911 | ||
1898 | /* Stage 2: sort starting sectors */ | 1912 | /* Stage 2: sort starting sectors */ |
1899 | stage2: | 1913 | stage2: |
1900 | for (j = 4; j < partitions-1; j++) { | 1914 | for (j = 4; j < g_partitions - 1; j++) { |
1901 | pj = ptes[j].part_table; | 1915 | pj = ptes[j].part_table; |
1902 | pjj = ptes[j+1].part_table; | 1916 | pjj = ptes[j+1].part_table; |
1903 | sj = get_start_sect(pj); | 1917 | sj = get_start_sect(pj); |
@@ -1915,7 +1929,7 @@ fix_chain_of_logicals(void) | |||
1915 | } | 1929 | } |
1916 | 1930 | ||
1917 | /* Probably something was changed */ | 1931 | /* Probably something was changed */ |
1918 | for (j = 4; j < partitions; j++) | 1932 | for (j = 4; j < g_partitions; j++) |
1919 | ptes[j].changed = 1; | 1933 | ptes[j].changed = 1; |
1920 | } | 1934 | } |
1921 | 1935 | ||
@@ -1995,7 +2009,7 @@ list_table(int xtra) | |||
1995 | printf("%*s Boot Start End Blocks Id System\n", | 2009 | printf("%*s Boot Start End Blocks Id System\n", |
1996 | w+1, "Device"); | 2010 | w+1, "Device"); |
1997 | 2011 | ||
1998 | for (i = 0; i < partitions; i++) { | 2012 | for (i = 0; i < g_partitions; i++) { |
1999 | const struct pte *pe = &ptes[i]; | 2013 | const struct pte *pe = &ptes[i]; |
2000 | ullong psects; | 2014 | ullong psects; |
2001 | ullong pblocks; | 2015 | ullong pblocks; |
@@ -2048,9 +2062,9 @@ x_list_table(int extend) | |||
2048 | int i; | 2062 | int i; |
2049 | 2063 | ||
2050 | printf("\nDisk %s: %d heads, %d sectors, %d cylinders\n\n", | 2064 | printf("\nDisk %s: %d heads, %d sectors, %d cylinders\n\n", |
2051 | disk_device, heads, sectors, cylinders); | 2065 | disk_device, g_heads, g_sectors, g_cylinders); |
2052 | printf("Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID\n"); | 2066 | printf("Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID\n"); |
2053 | for (i = 0; i < partitions; i++) { | 2067 | for (i = 0; i < g_partitions; i++) { |
2054 | pe = &ptes[i]; | 2068 | pe = &ptes[i]; |
2055 | p = (extend ? pe->ext_pointer : pe->part_table); | 2069 | p = (extend ? pe->ext_pointer : pe->part_table); |
2056 | if (p != NULL) { | 2070 | if (p != NULL) { |
@@ -2076,7 +2090,7 @@ fill_bounds(ullong *first, ullong *last) | |||
2076 | const struct pte *pe = &ptes[0]; | 2090 | const struct pte *pe = &ptes[0]; |
2077 | const struct partition *p; | 2091 | const struct partition *p; |
2078 | 2092 | ||
2079 | for (i = 0; i < partitions; pe++,i++) { | 2093 | for (i = 0; i < g_partitions; pe++,i++) { |
2080 | p = pe->part_table; | 2094 | p = pe->part_table; |
2081 | if (!p->sys_ind || IS_EXTENDED(p->sys_ind)) { | 2095 | if (!p->sys_ind || IS_EXTENDED(p->sys_ind)) { |
2082 | first[i] = 0xffffffff; | 2096 | first[i] = 0xffffffff; |
@@ -2095,19 +2109,19 @@ check(int n, unsigned h, unsigned s, unsigned c, ullong start) | |||
2095 | 2109 | ||
2096 | real_s = sector(s) - 1; | 2110 | real_s = sector(s) - 1; |
2097 | real_c = cylinder(s, c); | 2111 | real_c = cylinder(s, c); |
2098 | total = (real_c * sectors + real_s) * heads + h; | 2112 | total = (real_c * g_sectors + real_s) * g_heads + h; |
2099 | if (!total) | 2113 | if (!total) |
2100 | printf("Partition %d contains sector 0\n", n); | 2114 | printf("Partition %d contains sector 0\n", n); |
2101 | if (h >= heads) | 2115 | if (h >= g_heads) |
2102 | printf("Partition %d: head %d greater than maximum %d\n", | 2116 | printf("Partition %d: head %d greater than maximum %d\n", |
2103 | n, h + 1, heads); | 2117 | n, h + 1, g_heads); |
2104 | if (real_s >= sectors) | 2118 | if (real_s >= g_sectors) |
2105 | printf("Partition %d: sector %d greater than " | 2119 | printf("Partition %d: sector %d greater than " |
2106 | "maximum %d\n", n, s, sectors); | 2120 | "maximum %d\n", n, s, g_sectors); |
2107 | if (real_c >= cylinders) | 2121 | if (real_c >= g_cylinders) |
2108 | printf("Partition %d: cylinder %llu greater than " | 2122 | printf("Partition %d: cylinder %llu greater than " |
2109 | "maximum %d\n", n, real_c + 1, cylinders); | 2123 | "maximum %d\n", n, real_c + 1, g_cylinders); |
2110 | if (cylinders <= 1024 && start != total) | 2124 | if (g_cylinders <= 1024 && start != total) |
2111 | printf("Partition %d: previous sectors %llu disagrees with " | 2125 | printf("Partition %d: previous sectors %llu disagrees with " |
2112 | "total %llu\n", n, start, total); | 2126 | "total %llu\n", n, start, total); |
2113 | } | 2127 | } |
@@ -2117,7 +2131,7 @@ verify(void) | |||
2117 | { | 2131 | { |
2118 | int i, j; | 2132 | int i, j; |
2119 | unsigned total = 1; | 2133 | unsigned total = 1; |
2120 | ullong first[partitions], last[partitions]; | 2134 | ullong first[g_partitions], last[g_partitions]; |
2121 | struct partition *p; | 2135 | struct partition *p; |
2122 | 2136 | ||
2123 | if (warn_geometry()) | 2137 | if (warn_geometry()) |
@@ -2133,7 +2147,7 @@ verify(void) | |||
2133 | } | 2147 | } |
2134 | 2148 | ||
2135 | fill_bounds(first, last); | 2149 | fill_bounds(first, last); |
2136 | for (i = 0; i < partitions; i++) { | 2150 | for (i = 0; i < g_partitions; i++) { |
2137 | struct pte *pe = &ptes[i]; | 2151 | struct pte *pe = &ptes[i]; |
2138 | 2152 | ||
2139 | p = pe->part_table; | 2153 | p = pe->part_table; |
@@ -2164,11 +2178,11 @@ verify(void) | |||
2164 | ullong e_last = get_start_sect(pex->part_table) + | 2178 | ullong e_last = get_start_sect(pex->part_table) + |
2165 | get_nr_sects(pex->part_table) - 1; | 2179 | get_nr_sects(pex->part_table) - 1; |
2166 | 2180 | ||
2167 | for (i = 4; i < partitions; i++) { | 2181 | for (i = 4; i < g_partitions; i++) { |
2168 | total++; | 2182 | total++; |
2169 | p = ptes[i].part_table; | 2183 | p = ptes[i].part_table; |
2170 | if (!p->sys_ind) { | 2184 | if (!p->sys_ind) { |
2171 | if (i != 4 || i + 1 < partitions) | 2185 | if (i != 4 || i + 1 < g_partitions) |
2172 | printf("Warning: partition %d " | 2186 | printf("Warning: partition %d " |
2173 | "is empty\n", i + 1); | 2187 | "is empty\n", i + 1); |
2174 | } else if (first[i] < extended_offset || last[i] > e_last) { | 2188 | } else if (first[i] < extended_offset || last[i] > e_last) { |
@@ -2178,11 +2192,11 @@ verify(void) | |||
2178 | } | 2192 | } |
2179 | } | 2193 | } |
2180 | 2194 | ||
2181 | if (total > heads * sectors * cylinders) | 2195 | if (total > g_heads * g_sectors * g_cylinders) |
2182 | printf("Total allocated sectors %d greater than the maximum " | 2196 | printf("Total allocated sectors %d greater than the maximum " |
2183 | "%d\n", total, heads * sectors * cylinders); | 2197 | "%d\n", total, g_heads * g_sectors * g_cylinders); |
2184 | else { | 2198 | else { |
2185 | total = heads * sectors * cylinders - total; | 2199 | total = g_heads * g_sectors * g_cylinders - total; |
2186 | if (total != 0) | 2200 | if (total != 0) |
2187 | printf("%d unallocated sectors\n", total); | 2201 | printf("%d unallocated sectors\n", total); |
2188 | } | 2202 | } |
@@ -2197,7 +2211,7 @@ add_partition(int n, int sys) | |||
2197 | struct partition *q = ptes[ext_index].part_table; | 2211 | struct partition *q = ptes[ext_index].part_table; |
2198 | ullong limit, temp; | 2212 | ullong limit, temp; |
2199 | ullong start, stop = 0; | 2213 | ullong start, stop = 0; |
2200 | ullong first[partitions], last[partitions]; | 2214 | ullong first[g_partitions], last[g_partitions]; |
2201 | 2215 | ||
2202 | if (p && p->sys_ind) { | 2216 | if (p && p->sys_ind) { |
2203 | printf(msg_part_already_defined, n + 1); | 2217 | printf(msg_part_already_defined, n + 1); |
@@ -2207,7 +2221,7 @@ add_partition(int n, int sys) | |||
2207 | if (n < 4) { | 2221 | if (n < 4) { |
2208 | start = sector_offset; | 2222 | start = sector_offset; |
2209 | if (display_in_cyl_units || !total_number_of_sectors) | 2223 | if (display_in_cyl_units || !total_number_of_sectors) |
2210 | limit = (ullong) heads * sectors * cylinders - 1; | 2224 | limit = (ullong) g_heads * g_sectors * g_cylinders - 1; |
2211 | else | 2225 | else |
2212 | limit = total_number_of_sectors - 1; | 2226 | limit = total_number_of_sectors - 1; |
2213 | if (extended_offset) { | 2227 | if (extended_offset) { |
@@ -2220,13 +2234,13 @@ add_partition(int n, int sys) | |||
2220 | limit = get_start_sect(q) + get_nr_sects(q) - 1; | 2234 | limit = get_start_sect(q) + get_nr_sects(q) - 1; |
2221 | } | 2235 | } |
2222 | if (display_in_cyl_units) | 2236 | if (display_in_cyl_units) |
2223 | for (i = 0; i < partitions; i++) | 2237 | for (i = 0; i < g_partitions; i++) |
2224 | first[i] = (cround(first[i]) - 1) * units_per_sector; | 2238 | first[i] = (cround(first[i]) - 1) * units_per_sector; |
2225 | 2239 | ||
2226 | snprintf(mesg, sizeof(mesg), "First %s", str_units(SINGULAR)); | 2240 | snprintf(mesg, sizeof(mesg), "First %s", str_units(SINGULAR)); |
2227 | do { | 2241 | do { |
2228 | temp = start; | 2242 | temp = start; |
2229 | for (i = 0; i < partitions; i++) { | 2243 | for (i = 0; i < g_partitions; i++) { |
2230 | int lastplusoff; | 2244 | int lastplusoff; |
2231 | 2245 | ||
2232 | if (start == ptes[i].offset) | 2246 | if (start == ptes[i].offset) |
@@ -2266,7 +2280,7 @@ add_partition(int n, int sys) | |||
2266 | } | 2280 | } |
2267 | } | 2281 | } |
2268 | 2282 | ||
2269 | for (i = 0; i < partitions; i++) { | 2283 | for (i = 0; i < g_partitions; i++) { |
2270 | struct pte *pe = &ptes[i]; | 2284 | struct pte *pe = &ptes[i]; |
2271 | 2285 | ||
2272 | if (start < pe->offset && limit >= pe->offset) | 2286 | if (start < pe->offset && limit >= pe->offset) |
@@ -2277,7 +2291,7 @@ add_partition(int n, int sys) | |||
2277 | if (start > limit) { | 2291 | if (start > limit) { |
2278 | printf("No free sectors available\n"); | 2292 | printf("No free sectors available\n"); |
2279 | if (n > 4) | 2293 | if (n > 4) |
2280 | partitions--; | 2294 | g_partitions--; |
2281 | return; | 2295 | return; |
2282 | } | 2296 | } |
2283 | if (cround(start) == cround(limit)) { | 2297 | if (cround(start) == cround(limit)) { |
@@ -2310,24 +2324,24 @@ add_partition(int n, int sys) | |||
2310 | pe4->part_table = pt_offset(pe4->sectorbuffer, 0); | 2324 | pe4->part_table = pt_offset(pe4->sectorbuffer, 0); |
2311 | pe4->ext_pointer = pe4->part_table + 1; | 2325 | pe4->ext_pointer = pe4->part_table + 1; |
2312 | pe4->changed = 1; | 2326 | pe4->changed = 1; |
2313 | partitions = 5; | 2327 | g_partitions = 5; |
2314 | } | 2328 | } |
2315 | } | 2329 | } |
2316 | 2330 | ||
2317 | static void | 2331 | static void |
2318 | add_logical(void) | 2332 | add_logical(void) |
2319 | { | 2333 | { |
2320 | if (partitions > 5 || ptes[4].part_table->sys_ind) { | 2334 | if (g_partitions > 5 || ptes[4].part_table->sys_ind) { |
2321 | struct pte *pe = &ptes[partitions]; | 2335 | struct pte *pe = &ptes[g_partitions]; |
2322 | 2336 | ||
2323 | pe->sectorbuffer = xzalloc(sector_size); | 2337 | pe->sectorbuffer = xzalloc(sector_size); |
2324 | pe->part_table = pt_offset(pe->sectorbuffer, 0); | 2338 | pe->part_table = pt_offset(pe->sectorbuffer, 0); |
2325 | pe->ext_pointer = pe->part_table + 1; | 2339 | pe->ext_pointer = pe->part_table + 1; |
2326 | pe->offset = 0; | 2340 | pe->offset = 0; |
2327 | pe->changed = 1; | 2341 | pe->changed = 1; |
2328 | partitions++; | 2342 | g_partitions++; |
2329 | } | 2343 | } |
2330 | add_partition(partitions - 1, LINUX_NATIVE); | 2344 | add_partition(g_partitions - 1, LINUX_NATIVE); |
2331 | } | 2345 | } |
2332 | 2346 | ||
2333 | static void | 2347 | static void |
@@ -2339,11 +2353,11 @@ new_partition(void) | |||
2339 | return; | 2353 | return; |
2340 | 2354 | ||
2341 | if (LABEL_IS_SUN) { | 2355 | if (LABEL_IS_SUN) { |
2342 | add_sun_partition(get_partition(0, partitions), LINUX_NATIVE); | 2356 | add_sun_partition(get_partition(0, g_partitions), LINUX_NATIVE); |
2343 | return; | 2357 | return; |
2344 | } | 2358 | } |
2345 | if (LABEL_IS_SGI) { | 2359 | if (LABEL_IS_SGI) { |
2346 | sgi_add_partition(get_partition(0, partitions), LINUX_NATIVE); | 2360 | sgi_add_partition(get_partition(0, g_partitions), LINUX_NATIVE); |
2347 | return; | 2361 | return; |
2348 | } | 2362 | } |
2349 | if (LABEL_IS_AIX) { | 2363 | if (LABEL_IS_AIX) { |
@@ -2356,7 +2370,7 @@ new_partition(void) | |||
2356 | for (i = 0; i < 4; i++) | 2370 | for (i = 0; i < 4; i++) |
2357 | free_primary += !ptes[i].part_table->sys_ind; | 2371 | free_primary += !ptes[i].part_table->sys_ind; |
2358 | 2372 | ||
2359 | if (!free_primary && partitions >= MAXIMUM_PARTS) { | 2373 | if (!free_primary && g_partitions >= MAXIMUM_PARTS) { |
2360 | printf("The maximum number of partitions has been created\n"); | 2374 | printf("The maximum number of partitions has been created\n"); |
2361 | return; | 2375 | return; |
2362 | } | 2376 | } |
@@ -2408,7 +2422,7 @@ write_table(void) | |||
2408 | for (i = 0; i < 3; i++) | 2422 | for (i = 0; i < 3; i++) |
2409 | if (ptes[i].changed) | 2423 | if (ptes[i].changed) |
2410 | ptes[3].changed = 1; | 2424 | ptes[3].changed = 1; |
2411 | for (i = 3; i < partitions; i++) { | 2425 | for (i = 3; i < g_partitions; i++) { |
2412 | struct pte *pe = &ptes[i]; | 2426 | struct pte *pe = &ptes[i]; |
2413 | 2427 | ||
2414 | if (pe->changed) { | 2428 | if (pe->changed) { |
@@ -2492,7 +2506,7 @@ print_raw(void) | |||
2492 | if (LABEL_IS_SGI || LABEL_IS_SUN) | 2506 | if (LABEL_IS_SGI || LABEL_IS_SUN) |
2493 | print_buffer(MBRbuffer); | 2507 | print_buffer(MBRbuffer); |
2494 | else { | 2508 | else { |
2495 | for (i = 3; i < partitions; i++) | 2509 | for (i = 3; i < g_partitions; i++) |
2496 | print_buffer(ptes[i].sectorbuffer); | 2510 | print_buffer(ptes[i].sectorbuffer); |
2497 | } | 2511 | } |
2498 | } | 2512 | } |
@@ -2537,14 +2551,14 @@ xselect(void) | |||
2537 | break; | 2551 | break; |
2538 | case 'b': | 2552 | case 'b': |
2539 | if (LABEL_IS_DOS) | 2553 | if (LABEL_IS_DOS) |
2540 | move_begin(get_partition(0, partitions)); | 2554 | move_begin(get_partition(0, g_partitions)); |
2541 | break; | 2555 | break; |
2542 | case 'c': | 2556 | case 'c': |
2543 | user_cylinders = cylinders = | 2557 | user_cylinders = g_cylinders = |
2544 | read_int(1, cylinders, 1048576, 0, | 2558 | read_int(1, g_cylinders, 1048576, 0, |
2545 | "Number of cylinders"); | 2559 | "Number of cylinders"); |
2546 | if (LABEL_IS_SUN) | 2560 | if (LABEL_IS_SUN) |
2547 | sun_set_ncyl(cylinders); | 2561 | sun_set_ncyl(g_cylinders); |
2548 | if (LABEL_IS_DOS) | 2562 | if (LABEL_IS_DOS) |
2549 | warn_cylinders(); | 2563 | warn_cylinders(); |
2550 | break; | 2564 | break; |
@@ -2569,7 +2583,7 @@ xselect(void) | |||
2569 | #endif | 2583 | #endif |
2570 | break; | 2584 | break; |
2571 | case 'h': | 2585 | case 'h': |
2572 | user_heads = heads = read_int(1, heads, 256, 0, | 2586 | user_heads = g_heads = read_int(1, g_heads, 256, 0, |
2573 | "Number of heads"); | 2587 | "Number of heads"); |
2574 | update_units(); | 2588 | update_units(); |
2575 | break; | 2589 | break; |
@@ -2594,10 +2608,10 @@ xselect(void) | |||
2594 | case 'r': | 2608 | case 'r': |
2595 | return; | 2609 | return; |
2596 | case 's': | 2610 | case 's': |
2597 | user_sectors = sectors = read_int(1, sectors, 63, 0, | 2611 | user_sectors = g_sectors = read_int(1, g_sectors, 63, 0, |
2598 | "Number of sectors"); | 2612 | "Number of sectors"); |
2599 | if (dos_compatible_flag) { | 2613 | if (dos_compatible_flag) { |
2600 | sector_offset = sectors; | 2614 | sector_offset = g_sectors; |
2601 | printf("Warning: setting sector offset for DOS " | 2615 | printf("Warning: setting sector offset for DOS " |
2602 | "compatiblity\n"); | 2616 | "compatiblity\n"); |
2603 | } | 2617 | } |
@@ -2686,7 +2700,7 @@ trydev(const char *device, int user_specified) | |||
2686 | close(fd); | 2700 | close(fd); |
2687 | list_table(0); | 2701 | list_table(0); |
2688 | #if ENABLE_FEATURE_FDISK_WRITABLE | 2702 | #if ENABLE_FEATURE_FDISK_WRITABLE |
2689 | if (!LABEL_IS_SUN && partitions > 4){ | 2703 | if (!LABEL_IS_SUN && g_partitions > 4){ |
2690 | delete_partition(ext_index); | 2704 | delete_partition(ext_index); |
2691 | } | 2705 | } |
2692 | #endif | 2706 | #endif |
@@ -2759,7 +2773,7 @@ int fdisk_main(int argc, char **argv) | |||
2759 | OPT_s = (1 << 6) * ENABLE_FEATURE_FDISK_BLKSIZE, | 2773 | OPT_s = (1 << 6) * ENABLE_FEATURE_FDISK_BLKSIZE, |
2760 | }; | 2774 | }; |
2761 | 2775 | ||
2762 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); | 2776 | INIT_G(); |
2763 | 2777 | ||
2764 | opt = getopt32(argv, "b:C:H:lS:u" USE_FEATURE_FDISK_BLKSIZE("s"), | 2778 | opt = getopt32(argv, "b:C:H:lS:u" USE_FEATURE_FDISK_BLKSIZE("s"), |
2765 | &str_b, &str_C, &str_H, &str_S); | 2779 | &str_b, &str_C, &str_H, &str_S); |
@@ -2873,13 +2887,13 @@ int fdisk_main(int argc, char **argv) | |||
2873 | switch (c) { | 2887 | switch (c) { |
2874 | case 'a': | 2888 | case 'a': |
2875 | if (LABEL_IS_DOS) | 2889 | if (LABEL_IS_DOS) |
2876 | toggle_active(get_partition(1, partitions)); | 2890 | toggle_active(get_partition(1, g_partitions)); |
2877 | else if (LABEL_IS_SUN) | 2891 | else if (LABEL_IS_SUN) |
2878 | toggle_sunflags(get_partition(1, partitions), | 2892 | toggle_sunflags(get_partition(1, g_partitions), |
2879 | 0x01); | 2893 | 0x01); |
2880 | else if (LABEL_IS_SGI) | 2894 | else if (LABEL_IS_SGI) |
2881 | sgi_set_bootpartition( | 2895 | sgi_set_bootpartition( |
2882 | get_partition(1, partitions)); | 2896 | get_partition(1, g_partitions)); |
2883 | else | 2897 | else |
2884 | unknown_command(c); | 2898 | unknown_command(c); |
2885 | break; | 2899 | break; |
@@ -2902,11 +2916,11 @@ int fdisk_main(int argc, char **argv) | |||
2902 | if (LABEL_IS_DOS) | 2916 | if (LABEL_IS_DOS) |
2903 | toggle_dos_compatibility_flag(); | 2917 | toggle_dos_compatibility_flag(); |
2904 | else if (LABEL_IS_SUN) | 2918 | else if (LABEL_IS_SUN) |
2905 | toggle_sunflags(get_partition(1, partitions), | 2919 | toggle_sunflags(get_partition(1, g_partitions), |
2906 | 0x10); | 2920 | 0x10); |
2907 | else if (LABEL_IS_SGI) | 2921 | else if (LABEL_IS_SGI) |
2908 | sgi_set_swappartition( | 2922 | sgi_set_swappartition( |
2909 | get_partition(1, partitions)); | 2923 | get_partition(1, g_partitions)); |
2910 | else | 2924 | else |
2911 | unknown_command(c); | 2925 | unknown_command(c); |
2912 | break; | 2926 | break; |
@@ -2918,9 +2932,9 @@ int fdisk_main(int argc, char **argv) | |||
2918 | get_existing_partition() only works for Linux-like | 2932 | get_existing_partition() only works for Linux-like |
2919 | partition tables */ | 2933 | partition tables */ |
2920 | if (!LABEL_IS_SGI) { | 2934 | if (!LABEL_IS_SGI) { |
2921 | j = get_existing_partition(1, partitions); | 2935 | j = get_existing_partition(1, g_partitions); |
2922 | } else { | 2936 | } else { |
2923 | j = get_partition(1, partitions); | 2937 | j = get_partition(1, g_partitions); |
2924 | } | 2938 | } |
2925 | if (j >= 0) | 2939 | if (j >= 0) |
2926 | delete_partition(j); | 2940 | delete_partition(j); |
diff --git a/util-linux/fdisk_aix.c b/util-linux/fdisk_aix.c index 8095fc4ab..69aef97f5 100644 --- a/util-linux/fdisk_aix.c +++ b/util-linux/fdisk_aix.c | |||
@@ -63,7 +63,7 @@ check_aix_label(void) | |||
63 | aix_other_endian = (aixlabel->magic == AIX_LABEL_MAGIC_SWAPPED); | 63 | aix_other_endian = (aixlabel->magic == AIX_LABEL_MAGIC_SWAPPED); |
64 | update_units(); | 64 | update_units(); |
65 | current_label_type = label_aix; | 65 | current_label_type = label_aix; |
66 | partitions = 1016; | 66 | g_partitions = 1016; |
67 | aix_volumes = 15; | 67 | aix_volumes = 15; |
68 | aix_info(); | 68 | aix_info(); |
69 | /*aix_nolabel();*/ /* %% */ | 69 | /*aix_nolabel();*/ /* %% */ |
diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c index 726138265..5a7e6323d 100644 --- a/util-linux/fdisk_osf.c +++ b/util-linux/fdisk_osf.c | |||
@@ -240,8 +240,6 @@ static const char *const xbsd_fstypes[] = { | |||
240 | Also fixed unaligned accesses in alpha_bootblock_checksum() | 240 | Also fixed unaligned accesses in alpha_bootblock_checksum() |
241 | */ | 241 | */ |
242 | 242 | ||
243 | static int possibly_osf_label; | ||
244 | |||
245 | #define FREEBSD_PARTITION 0xa5 | 243 | #define FREEBSD_PARTITION 0xa5 |
246 | #define NETBSD_PARTITION 0xa9 | 244 | #define NETBSD_PARTITION 0xa9 |
247 | 245 | ||
@@ -876,10 +874,10 @@ xbsd_initlabel(struct partition *p) | |||
876 | d->d_flags = 0; | 874 | d->d_flags = 0; |
877 | #endif | 875 | #endif |
878 | d->d_secsize = SECTOR_SIZE; /* bytes/sector */ | 876 | d->d_secsize = SECTOR_SIZE; /* bytes/sector */ |
879 | d->d_nsectors = sectors; /* sectors/track */ | 877 | d->d_nsectors = g_sectors; /* sectors/track */ |
880 | d->d_ntracks = heads; /* tracks/cylinder (heads) */ | 878 | d->d_ntracks = g_heads; /* tracks/cylinder (heads) */ |
881 | d->d_ncylinders = cylinders; | 879 | d->d_ncylinders = g_cylinders; |
882 | d->d_secpercyl = sectors * heads; /* sectors/cylinder */ | 880 | d->d_secpercyl = g_sectors * g_heads;/* sectors/cylinder */ |
883 | if (d->d_secpercyl == 0) | 881 | if (d->d_secpercyl == 0) |
884 | d->d_secpercyl = 1; /* avoid segfaults */ | 882 | d->d_secpercyl = 1; /* avoid segfaults */ |
885 | d->d_secperunit = d->d_secpercyl * d->d_ncylinders; | 883 | d->d_secperunit = d->d_secpercyl * d->d_ncylinders; |
@@ -1027,7 +1025,7 @@ xbsd_link_part(void) | |||
1027 | int k, i; | 1025 | int k, i; |
1028 | struct partition *p; | 1026 | struct partition *p; |
1029 | 1027 | ||
1030 | k = get_partition(1, partitions); | 1028 | k = get_partition(1, g_partitions); |
1031 | 1029 | ||
1032 | if (!xbsd_check_new_partition(&i)) | 1030 | if (!xbsd_check_new_partition(&i)) |
1033 | return; | 1031 | return; |
diff --git a/util-linux/fdisk_sgi.c b/util-linux/fdisk_sgi.c index 25e75b06c..f0bd195a1 100644 --- a/util-linux/fdisk_sgi.c +++ b/util-linux/fdisk_sgi.c | |||
@@ -248,7 +248,7 @@ check_sgi_label(void) | |||
248 | } | 248 | } |
249 | update_units(); | 249 | update_units(); |
250 | current_label_type = label_sgi; | 250 | current_label_type = label_sgi; |
251 | partitions = 16; | 251 | g_partitions = 16; |
252 | sgi_volumes = 15; | 252 | sgi_volumes = 15; |
253 | return 1; | 253 | return 1; |
254 | } | 254 | } |
@@ -295,7 +295,7 @@ sgi_list_table(int xtra) | |||
295 | "%d extra sects/cyl, interleave %d:1\n" | 295 | "%d extra sects/cyl, interleave %d:1\n" |
296 | "%s\n" | 296 | "%s\n" |
297 | "Units = %s of %d * 512 bytes\n\n", | 297 | "Units = %s of %d * 512 bytes\n\n", |
298 | disk_device, heads, sectors, cylinders, | 298 | disk_device, g_heads, g_sectors, g_cylinders, |
299 | SGI_SSWAP16(sgiparam.pcylcount), | 299 | SGI_SSWAP16(sgiparam.pcylcount), |
300 | SGI_SSWAP16(sgiparam.sparecyl), | 300 | SGI_SSWAP16(sgiparam.sparecyl), |
301 | SGI_SSWAP16(sgiparam.ilfact), | 301 | SGI_SSWAP16(sgiparam.ilfact), |
@@ -305,7 +305,7 @@ sgi_list_table(int xtra) | |||
305 | printf("\nDisk %s (SGI disk label): " | 305 | printf("\nDisk %s (SGI disk label): " |
306 | "%d heads, %d sectors, %d cylinders\n" | 306 | "%d heads, %d sectors, %d cylinders\n" |
307 | "Units = %s of %d * 512 bytes\n\n", | 307 | "Units = %s of %d * 512 bytes\n\n", |
308 | disk_device, heads, sectors, cylinders, | 308 | disk_device, g_heads, g_sectors, g_cylinders, |
309 | str_units(PLURAL), units_per_sector ); | 309 | str_units(PLURAL), units_per_sector ); |
310 | } | 310 | } |
311 | 311 | ||
@@ -317,7 +317,7 @@ sgi_list_table(int xtra) | |||
317 | printf("----- partitions -----\n" | 317 | printf("----- partitions -----\n" |
318 | "Pt# %*s Info Start End Sectors Id System\n", | 318 | "Pt# %*s Info Start End Sectors Id System\n", |
319 | w + 2, "Device"); | 319 | w + 2, "Device"); |
320 | for (i = 0; i < partitions; i++) { | 320 | for (i = 0; i < g_partitions; i++) { |
321 | if (sgi_get_num_sectors(i) || debug ) { | 321 | if (sgi_get_num_sectors(i) || debug ) { |
322 | uint32_t start = sgi_get_start_sector(i); | 322 | uint32_t start = sgi_get_start_sector(i); |
323 | uint32_t len = sgi_get_num_sectors(i); | 323 | uint32_t len = sgi_get_num_sectors(i); |
@@ -359,7 +359,7 @@ sgi_set_bootpartition(int i) | |||
359 | static unsigned int | 359 | static unsigned int |
360 | sgi_get_lastblock(void) | 360 | sgi_get_lastblock(void) |
361 | { | 361 | { |
362 | return heads * sectors * cylinders; | 362 | return g_heads * g_sectors * g_cylinders; |
363 | } | 363 | } |
364 | 364 | ||
365 | static void | 365 | static void |
@@ -660,7 +660,7 @@ sgi_set_entire(void) | |||
660 | { | 660 | { |
661 | int n; | 661 | int n; |
662 | 662 | ||
663 | for (n = 10; n < partitions; n++) { | 663 | for (n = 10; n < g_partitions; n++) { |
664 | if (!sgi_get_num_sectors(n) ) { | 664 | if (!sgi_get_num_sectors(n) ) { |
665 | sgi_set_partition(n, 0, sgi_get_lastblock(), SGI_VOLUME); | 665 | sgi_set_partition(n, 0, sgi_get_lastblock(), SGI_VOLUME); |
666 | break; | 666 | break; |
@@ -673,7 +673,7 @@ sgi_set_volhdr(void) | |||
673 | { | 673 | { |
674 | int n; | 674 | int n; |
675 | 675 | ||
676 | for (n = 8; n < partitions; n++) { | 676 | for (n = 8; n < g_partitions; n++) { |
677 | if (!sgi_get_num_sectors(n)) { | 677 | if (!sgi_get_num_sectors(n)) { |
678 | /* | 678 | /* |
679 | * 5 cylinders is an arbitrary value I like | 679 | * 5 cylinders is an arbitrary value I like |
@@ -681,8 +681,8 @@ sgi_set_volhdr(void) | |||
681 | * (like sash, symmon, fx, ide) with ca. 3200 | 681 | * (like sash, symmon, fx, ide) with ca. 3200 |
682 | * sectors. | 682 | * sectors. |
683 | */ | 683 | */ |
684 | if (heads * sectors * 5 < sgi_get_lastblock()) | 684 | if (g_heads * g_sectors * 5 < sgi_get_lastblock()) |
685 | sgi_set_partition(n, 0, heads * sectors * 5, SGI_VOLHDR); | 685 | sgi_set_partition(n, 0, g_heads * g_sectors * 5, SGI_VOLHDR); |
686 | break; | 686 | break; |
687 | } | 687 | } |
688 | } | 688 | } |
@@ -783,18 +783,18 @@ create_sgilabel(void) | |||
783 | sgi_other_endian = (BYTE_ORDER == LITTLE_ENDIAN); | 783 | sgi_other_endian = (BYTE_ORDER == LITTLE_ENDIAN); |
784 | res = ioctl(fd, BLKGETSIZE, &longsectors); | 784 | res = ioctl(fd, BLKGETSIZE, &longsectors); |
785 | if (!ioctl(fd, HDIO_GETGEO, &geometry)) { | 785 | if (!ioctl(fd, HDIO_GETGEO, &geometry)) { |
786 | heads = geometry.heads; | 786 | g_heads = geometry.heads; |
787 | sectors = geometry.sectors; | 787 | g_sectors = geometry.sectors; |
788 | if (res == 0) { | 788 | if (res == 0) { |
789 | /* the get device size ioctl was successful */ | 789 | /* the get device size ioctl was successful */ |
790 | cylinders = longsectors / (heads * sectors); | 790 | g_cylinders = longsectors / (g_heads * g_sectors); |
791 | cylinders /= sec_fac; | 791 | g_cylinders /= sec_fac; |
792 | } else { | 792 | } else { |
793 | /* otherwise print error and use truncated version */ | 793 | /* otherwise print error and use truncated version */ |
794 | cylinders = geometry.cylinders; | 794 | g_cylinders = geometry.cylinders; |
795 | printf( | 795 | printf( |
796 | "Warning: BLKGETSIZE ioctl failed on %s. Using geometry cylinder value of %d.\n" | 796 | "Warning: BLKGETSIZE ioctl failed on %s. Using geometry cylinder value of %d.\n" |
797 | "This value may be truncated for devices > 33.8 GB.\n", disk_device, cylinders); | 797 | "This value may be truncated for devices > 33.8 GB.\n", disk_device, g_cylinders); |
798 | } | 798 | } |
799 | } | 799 | } |
800 | for (i = 0; i < 4; i++) { | 800 | for (i = 0; i < 4; i++) { |
@@ -851,7 +851,7 @@ create_sgilabel(void) | |||
851 | //memset( &(sgilabel->directory), 0, sizeof(struct volume_directory)*15 ); | 851 | //memset( &(sgilabel->directory), 0, sizeof(struct volume_directory)*15 ); |
852 | //memset( &(sgilabel->partitions), 0, sizeof(struct sgi_partinfo)*16 ); | 852 | //memset( &(sgilabel->partitions), 0, sizeof(struct sgi_partinfo)*16 ); |
853 | current_label_type = label_sgi; | 853 | current_label_type = label_sgi; |
854 | partitions = 16; | 854 | g_partitions = 16; |
855 | sgi_volumes = 15; | 855 | sgi_volumes = 15; |
856 | sgi_set_entire(); | 856 | sgi_set_entire(); |
857 | sgi_set_volhdr(); | 857 | sgi_set_volhdr(); |
diff --git a/util-linux/fdisk_sun.c b/util-linux/fdisk_sun.c index 274b10345..fcd3818d2 100644 --- a/util-linux/fdisk_sun.c +++ b/util-linux/fdisk_sun.c | |||
@@ -84,7 +84,7 @@ set_sun_partition(int i, uint start, uint stop, int sysid) | |||
84 | { | 84 | { |
85 | sunlabel->infos[i].id = sysid; | 85 | sunlabel->infos[i].id = sysid; |
86 | sunlabel->partitions[i].start_cylinder = | 86 | sunlabel->partitions[i].start_cylinder = |
87 | SUN_SSWAP32(start / (heads * sectors)); | 87 | SUN_SSWAP32(start / (g_heads * g_sectors)); |
88 | sunlabel->partitions[i].num_sectors = | 88 | sunlabel->partitions[i].num_sectors = |
89 | SUN_SSWAP32(stop - start); | 89 | SUN_SSWAP32(stop - start); |
90 | set_changed(i); | 90 | set_changed(i); |
@@ -111,13 +111,13 @@ check_sun_label(void) | |||
111 | "e.g. heads, sectors, cylinders and partitions\n" | 111 | "e.g. heads, sectors, cylinders and partitions\n" |
112 | "or force a fresh label (s command in main menu)\n"); | 112 | "or force a fresh label (s command in main menu)\n"); |
113 | } else { | 113 | } else { |
114 | heads = SUN_SSWAP16(sunlabel->ntrks); | 114 | g_heads = SUN_SSWAP16(sunlabel->ntrks); |
115 | cylinders = SUN_SSWAP16(sunlabel->ncyl); | 115 | g_cylinders = SUN_SSWAP16(sunlabel->ncyl); |
116 | sectors = SUN_SSWAP16(sunlabel->nsect); | 116 | g_sectors = SUN_SSWAP16(sunlabel->nsect); |
117 | } | 117 | } |
118 | update_units(); | 118 | update_units(); |
119 | current_label_type = label_sun; | 119 | current_label_type = label_sun; |
120 | partitions = 8; | 120 | g_partitions = 8; |
121 | return 1; | 121 | return 1; |
122 | } | 122 | } |
123 | 123 | ||
@@ -273,32 +273,32 @@ create_sunlabel(void) | |||
273 | } | 273 | } |
274 | if (!p || floppy) { | 274 | if (!p || floppy) { |
275 | if (!ioctl(fd, HDIO_GETGEO, &geometry)) { | 275 | if (!ioctl(fd, HDIO_GETGEO, &geometry)) { |
276 | heads = geometry.heads; | 276 | g_heads = geometry.heads; |
277 | sectors = geometry.sectors; | 277 | g_sectors = geometry.sectors; |
278 | cylinders = geometry.cylinders; | 278 | g_cylinders = geometry.cylinders; |
279 | } else { | 279 | } else { |
280 | heads = 0; | 280 | g_heads = 0; |
281 | sectors = 0; | 281 | g_sectors = 0; |
282 | cylinders = 0; | 282 | g_cylinders = 0; |
283 | } | 283 | } |
284 | if (floppy) { | 284 | if (floppy) { |
285 | sunlabel->nacyl = 0; | 285 | sunlabel->nacyl = 0; |
286 | sunlabel->pcylcount = SUN_SSWAP16(cylinders); | 286 | sunlabel->pcylcount = SUN_SSWAP16(g_cylinders); |
287 | sunlabel->rspeed = SUN_SSWAP16(300); | 287 | sunlabel->rspeed = SUN_SSWAP16(300); |
288 | sunlabel->ilfact = SUN_SSWAP16(1); | 288 | sunlabel->ilfact = SUN_SSWAP16(1); |
289 | sunlabel->sparecyl = 0; | 289 | sunlabel->sparecyl = 0; |
290 | } else { | 290 | } else { |
291 | heads = read_int(1, heads, 1024, 0, "Heads"); | 291 | g_heads = read_int(1, g_heads, 1024, 0, "Heads"); |
292 | sectors = read_int(1, sectors, 1024, 0, "Sectors/track"); | 292 | g_sectors = read_int(1, g_sectors, 1024, 0, "Sectors/track"); |
293 | if (cylinders) | 293 | if (g_cylinders) |
294 | cylinders = read_int(1, cylinders-2, 65535, 0, "Cylinders"); | 294 | g_cylinders = read_int(1, g_cylinders - 2, 65535, 0, "Cylinders"); |
295 | else | 295 | else |
296 | cylinders = read_int(1, 0, 65535, 0, "Cylinders"); | 296 | g_cylinders = read_int(1, 0, 65535, 0, "Cylinders"); |
297 | sunlabel->nacyl = SUN_SSWAP16(read_int(0, 2, 65535, 0, "Alternate cylinders")); | 297 | sunlabel->nacyl = SUN_SSWAP16(read_int(0, 2, 65535, 0, "Alternate cylinders")); |
298 | sunlabel->pcylcount = SUN_SSWAP16(read_int(0, cylinders+SUN_SSWAP16(sunlabel->nacyl), 65535, 0, "Physical cylinders")); | 298 | sunlabel->pcylcount = SUN_SSWAP16(read_int(0, g_cylinders + SUN_SSWAP16(sunlabel->nacyl), 65535, 0, "Physical cylinders")); |
299 | sunlabel->rspeed = SUN_SSWAP16(read_int(1, 5400, 100000, 0, "Rotation speed (rpm)")); | 299 | sunlabel->rspeed = SUN_SSWAP16(read_int(1, 5400, 100000, 0, "Rotation speed (rpm)")); |
300 | sunlabel->ilfact = SUN_SSWAP16(read_int(1, 1, 32, 0, "Interleave factor")); | 300 | sunlabel->ilfact = SUN_SSWAP16(read_int(1, 1, 32, 0, "Interleave factor")); |
301 | sunlabel->sparecyl = SUN_SSWAP16(read_int(0, 0, sectors, 0, "Extra sectors per cylinder")); | 301 | sunlabel->sparecyl = SUN_SSWAP16(read_int(0, 0, g_sectors, 0, "Extra sectors per cylinder")); |
302 | } | 302 | } |
303 | } else { | 303 | } else { |
304 | sunlabel->sparecyl = SUN_SSWAP16(p->sparecyl); | 304 | sunlabel->sparecyl = SUN_SSWAP16(p->sparecyl); |
@@ -309,9 +309,9 @@ create_sunlabel(void) | |||
309 | sunlabel->nsect = SUN_SSWAP16(p->nsect); | 309 | sunlabel->nsect = SUN_SSWAP16(p->nsect); |
310 | sunlabel->rspeed = SUN_SSWAP16(p->rspeed); | 310 | sunlabel->rspeed = SUN_SSWAP16(p->rspeed); |
311 | sunlabel->ilfact = SUN_SSWAP16(1); | 311 | sunlabel->ilfact = SUN_SSWAP16(1); |
312 | cylinders = p->ncyl; | 312 | g_cylinders = p->ncyl; |
313 | heads = p->ntrks; | 313 | g_heads = p->ntrks; |
314 | sectors = p->nsect; | 314 | g_sectors = p->nsect; |
315 | puts("You may change all the disk params from the x menu"); | 315 | puts("You may change all the disk params from the x menu"); |
316 | } | 316 | } |
317 | 317 | ||
@@ -319,23 +319,23 @@ create_sunlabel(void) | |||
319 | "%s%s%s cyl %d alt %d hd %d sec %d", | 319 | "%s%s%s cyl %d alt %d hd %d sec %d", |
320 | p ? p->vendor : "", (p && *p->vendor) ? " " : "", | 320 | p ? p->vendor : "", (p && *p->vendor) ? " " : "", |
321 | p ? p->model : (floppy ? "3,5\" floppy" : "Linux custom"), | 321 | p ? p->model : (floppy ? "3,5\" floppy" : "Linux custom"), |
322 | cylinders, SUN_SSWAP16(sunlabel->nacyl), heads, sectors); | 322 | g_cylinders, SUN_SSWAP16(sunlabel->nacyl), g_heads, g_sectors); |
323 | 323 | ||
324 | sunlabel->ntrks = SUN_SSWAP16(heads); | 324 | sunlabel->ntrks = SUN_SSWAP16(g_heads); |
325 | sunlabel->nsect = SUN_SSWAP16(sectors); | 325 | sunlabel->nsect = SUN_SSWAP16(g_sectors); |
326 | sunlabel->ncyl = SUN_SSWAP16(cylinders); | 326 | sunlabel->ncyl = SUN_SSWAP16(g_cylinders); |
327 | if (floppy) | 327 | if (floppy) |
328 | set_sun_partition(0, 0, cylinders * heads * sectors, LINUX_NATIVE); | 328 | set_sun_partition(0, 0, g_cylinders * g_heads * g_sectors, LINUX_NATIVE); |
329 | else { | 329 | else { |
330 | if (cylinders * heads * sectors >= 150 * 2048) { | 330 | if (g_cylinders * g_heads * g_sectors >= 150 * 2048) { |
331 | ndiv = cylinders - (50 * 2048 / (heads * sectors)); /* 50M swap */ | 331 | ndiv = g_cylinders - (50 * 2048 / (g_heads * g_sectors)); /* 50M swap */ |
332 | } else | 332 | } else |
333 | ndiv = cylinders * 2 / 3; | 333 | ndiv = g_cylinders * 2 / 3; |
334 | set_sun_partition(0, 0, ndiv * heads * sectors, LINUX_NATIVE); | 334 | set_sun_partition(0, 0, ndiv * g_heads * g_sectors, LINUX_NATIVE); |
335 | set_sun_partition(1, ndiv * heads * sectors, cylinders * heads * sectors, LINUX_SWAP); | 335 | set_sun_partition(1, ndiv * g_heads * g_sectors, g_cylinders * g_heads * g_sectors, LINUX_SWAP); |
336 | sunlabel->infos[1].flags |= 0x01; /* Not mountable */ | 336 | sunlabel->infos[1].flags |= 0x01; /* Not mountable */ |
337 | } | 337 | } |
338 | set_sun_partition(2, 0, cylinders * heads * sectors, SUN_WHOLE_DISK); | 338 | set_sun_partition(2, 0, g_cylinders * g_heads * g_sectors, SUN_WHOLE_DISK); |
339 | { | 339 | { |
340 | unsigned short *ush = (unsigned short *)sunlabel; | 340 | unsigned short *ush = (unsigned short *)sunlabel; |
341 | unsigned short csum = 0; | 341 | unsigned short csum = 0; |
@@ -365,12 +365,12 @@ fetch_sun(uint *starts, uint *lens, uint *start, uint *stop) | |||
365 | int i, continuous = 1; | 365 | int i, continuous = 1; |
366 | 366 | ||
367 | *start = 0; | 367 | *start = 0; |
368 | *stop = cylinders * heads * sectors; | 368 | *stop = g_cylinders * g_heads * g_sectors; |
369 | for (i = 0; i < partitions; i++) { | 369 | for (i = 0; i < g_partitions; i++) { |
370 | if (sunlabel->partitions[i].num_sectors | 370 | if (sunlabel->partitions[i].num_sectors |
371 | && sunlabel->infos[i].id | 371 | && sunlabel->infos[i].id |
372 | && sunlabel->infos[i].id != SUN_WHOLE_DISK) { | 372 | && sunlabel->infos[i].id != SUN_WHOLE_DISK) { |
373 | starts[i] = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors; | 373 | starts[i] = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * g_heads * g_sectors; |
374 | lens[i] = SUN_SSWAP32(sunlabel->partitions[i].num_sectors); | 374 | lens[i] = SUN_SSWAP32(sunlabel->partitions[i].num_sectors); |
375 | if (continuous) { | 375 | if (continuous) { |
376 | if (starts[i] == *start) | 376 | if (starts[i] == *start) |
@@ -408,10 +408,10 @@ verify_sun(void) | |||
408 | int array[8]; | 408 | int array[8]; |
409 | 409 | ||
410 | verify_sun_starts = starts; | 410 | verify_sun_starts = starts; |
411 | fetch_sun(starts,lens,&start,&stop); | 411 | fetch_sun(starts, lens, &start, &stop); |
412 | for (k = 0; k < 7; k++) { | 412 | for (k = 0; k < 7; k++) { |
413 | for (i = 0; i < 8; i++) { | 413 | for (i = 0; i < 8; i++) { |
414 | if (k && (lens[i] % (heads * sectors))) { | 414 | if (k && (lens[i] % (g_heads * g_sectors))) { |
415 | printf("Partition %d doesn't end on cylinder boundary\n", i+1); | 415 | printf("Partition %d doesn't end on cylinder boundary\n", i+1); |
416 | } | 416 | } |
417 | if (lens[i]) { | 417 | if (lens[i]) { |
@@ -452,7 +452,7 @@ verify_sun(void) | |||
452 | printf("No partitions defined\n"); | 452 | printf("No partitions defined\n"); |
453 | return; | 453 | return; |
454 | } | 454 | } |
455 | stop = cylinders * heads * sectors; | 455 | stop = g_cylinders * g_heads * g_sectors; |
456 | if (starts[array[0]]) | 456 | if (starts[array[0]]) |
457 | printf("Unused gap - sectors 0-%d\n", starts[array[0]]); | 457 | printf("Unused gap - sectors 0-%d\n", starts[array[0]]); |
458 | for (i = 0; i < 7 && array[i+1] != -1; i++) { | 458 | for (i = 0; i < 7 && array[i+1] != -1; i++) { |
@@ -499,7 +499,7 @@ add_sun_partition(int n, int sys) | |||
499 | first *= units_per_sector; | 499 | first *= units_per_sector; |
500 | else | 500 | else |
501 | /* Starting sector has to be properly aligned */ | 501 | /* Starting sector has to be properly aligned */ |
502 | first = (first + heads * sectors - 1) / (heads * sectors); | 502 | first = (first + g_heads * g_sectors - 1) / (g_heads * g_sectors); |
503 | if (n == 2 && first != 0) | 503 | if (n == 2 && first != 0) |
504 | printf("\ | 504 | printf("\ |
505 | It is highly recommended that the third partition covers the whole disk\n\ | 505 | It is highly recommended that the third partition covers the whole disk\n\ |
@@ -520,10 +520,10 @@ and is of type 'Whole disk'\n"); | |||
520 | /* On the other hand, one should not use partitions | 520 | /* On the other hand, one should not use partitions |
521 | starting at block 0 in an md, or the label will | 521 | starting at block 0 in an md, or the label will |
522 | be trashed. */ | 522 | be trashed. */ |
523 | for (i = 0; i < partitions; i++) | 523 | for (i = 0; i < g_partitions; i++) |
524 | if (lens[i] && starts[i] <= first && starts[i] + lens[i] > first) | 524 | if (lens[i] && starts[i] <= first && starts[i] + lens[i] > first) |
525 | break; | 525 | break; |
526 | if (i < partitions && !whole_disk) { | 526 | if (i < g_partitions && !whole_disk) { |
527 | if (n == 2 && !first) { | 527 | if (n == 2 && !first) { |
528 | whole_disk = 1; | 528 | whole_disk = 1; |
529 | break; | 529 | break; |
@@ -532,9 +532,9 @@ and is of type 'Whole disk'\n"); | |||
532 | } else | 532 | } else |
533 | break; | 533 | break; |
534 | } | 534 | } |
535 | stop = cylinders * heads * sectors; | 535 | stop = g_cylinders * g_heads * g_sectors; |
536 | stop2 = stop; | 536 | stop2 = stop; |
537 | for (i = 0; i < partitions; i++) { | 537 | for (i = 0; i < g_partitions; i++) { |
538 | if (starts[i] > first && starts[i] < stop) | 538 | if (starts[i] > first && starts[i] < stop) |
539 | stop = starts[i]; | 539 | stop = starts[i]; |
540 | } | 540 | } |
@@ -581,7 +581,7 @@ sun_delete_partition(int i) | |||
581 | if (i == 2 | 581 | if (i == 2 |
582 | && sunlabel->infos[i].id == SUN_WHOLE_DISK | 582 | && sunlabel->infos[i].id == SUN_WHOLE_DISK |
583 | && !sunlabel->partitions[i].start_cylinder | 583 | && !sunlabel->partitions[i].start_cylinder |
584 | && (nsec = SUN_SSWAP32(sunlabel->partitions[i].num_sectors)) == heads * sectors * cylinders) | 584 | && (nsec = SUN_SSWAP32(sunlabel->partitions[i].num_sectors)) == g_heads * g_sectors * g_cylinders) |
585 | printf("If you want to maintain SunOS/Solaris compatibility, " | 585 | printf("If you want to maintain SunOS/Solaris compatibility, " |
586 | "consider leaving this\n" | 586 | "consider leaving this\n" |
587 | "partition as Whole disk (5), starting at 0, with %u " | 587 | "partition as Whole disk (5), starting at 0, with %u " |
@@ -631,8 +631,8 @@ sun_list_table(int xtra) | |||
631 | "%d extra sects/cyl, interleave %d:1\n" | 631 | "%d extra sects/cyl, interleave %d:1\n" |
632 | "%s\n" | 632 | "%s\n" |
633 | "Units = %s of %d * 512 bytes\n\n", | 633 | "Units = %s of %d * 512 bytes\n\n", |
634 | disk_device, heads, sectors, SUN_SSWAP16(sunlabel->rspeed), | 634 | disk_device, g_heads, g_sectors, SUN_SSWAP16(sunlabel->rspeed), |
635 | cylinders, SUN_SSWAP16(sunlabel->nacyl), | 635 | g_cylinders, SUN_SSWAP16(sunlabel->nacyl), |
636 | SUN_SSWAP16(sunlabel->pcylcount), | 636 | SUN_SSWAP16(sunlabel->pcylcount), |
637 | SUN_SSWAP16(sunlabel->sparecyl), | 637 | SUN_SSWAP16(sunlabel->sparecyl), |
638 | SUN_SSWAP16(sunlabel->ilfact), | 638 | SUN_SSWAP16(sunlabel->ilfact), |
@@ -642,14 +642,14 @@ sun_list_table(int xtra) | |||
642 | printf( | 642 | printf( |
643 | "\nDisk %s (Sun disk label): %d heads, %d sectors, %d cylinders\n" | 643 | "\nDisk %s (Sun disk label): %d heads, %d sectors, %d cylinders\n" |
644 | "Units = %s of %d * 512 bytes\n\n", | 644 | "Units = %s of %d * 512 bytes\n\n", |
645 | disk_device, heads, sectors, cylinders, | 645 | disk_device, g_heads, g_sectors, g_cylinders, |
646 | str_units(PLURAL), units_per_sector); | 646 | str_units(PLURAL), units_per_sector); |
647 | 647 | ||
648 | printf("%*s Flag Start End Blocks Id System\n", | 648 | printf("%*s Flag Start End Blocks Id System\n", |
649 | w + 1, "Device"); | 649 | w + 1, "Device"); |
650 | for (i = 0; i < partitions; i++) { | 650 | for (i = 0; i < g_partitions; i++) { |
651 | if (sunlabel->partitions[i].num_sectors) { | 651 | if (sunlabel->partitions[i].num_sectors) { |
652 | uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors; | 652 | uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * g_heads * g_sectors; |
653 | uint32_t len = SUN_SSWAP32(sunlabel->partitions[i].num_sectors); | 653 | uint32_t len = SUN_SSWAP32(sunlabel->partitions[i].num_sectors); |
654 | printf("%s %c%c %9ld %9ld %9ld%c %2x %s\n", | 654 | printf("%s %c%c %9ld %9ld %9ld%c %2x %s\n", |
655 | partname(disk_device, i+1, w), /* device */ | 655 | partname(disk_device, i+1, w), /* device */ |
@@ -684,7 +684,7 @@ static void | |||
684 | sun_set_xcyl(void) | 684 | sun_set_xcyl(void) |
685 | { | 685 | { |
686 | sunlabel->sparecyl = | 686 | sunlabel->sparecyl = |
687 | SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->sparecyl), sectors, 0, | 687 | SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->sparecyl), g_sectors, 0, |
688 | "Extra sectors per cylinder")); | 688 | "Extra sectors per cylinder")); |
689 | } | 689 | } |
690 | 690 | ||