aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-02-24 16:29:00 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-02-24 16:29:00 +0000
commit7e2b232ef6a3bb4ef5c66874ada42e09266d795e (patch)
tree6ccffbfd704418ee029b1aff63ddc1b71f2e114b
parent1b58c162e8c50853aa98e553326c6d2cb6b33409 (diff)
downloadbusybox-w32-7e2b232ef6a3bb4ef5c66874ada42e09266d795e.tar.gz
busybox-w32-7e2b232ef6a3bb4ef5c66874ada42e09266d795e.tar.bz2
busybox-w32-7e2b232ef6a3bb4ef5c66874ada42e09266d795e.zip
Cleanup from Denis Vlasenko.
git-svn-id: svn://busybox.net/trunk/busybox@14260 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--util-linux/fdisk.c3917
1 files changed, 2013 insertions, 1904 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 8a5340aad..33ad84702 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -1,10 +1,9 @@
1/* fdisk.c -- Partition table manipulator for Linux. 1/* fdisk.c -- Partition table manipulator for Linux.
2 * 2 *
3 * Copyright (C) 1992 A. V. Le Blanc (LeBlanc@mcc.ac.uk) 3 * Copyright (C) 1992 A. V. Le Blanc (LeBlanc@mcc.ac.uk)
4 * Copyright (C) 2001,2002 Vladimir Oleynik <dzo@simtreas.ru> (Busybox port)
4 * 5 *
5 * Licensed under the GPL v1 or later, see the file LICENSE in this tarball. 6 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6 *
7 * Vladimir Oleynik <dzo@simtreas.ru> 2001,2002 Busybox port
8 */ 7 */
9 8
10#define UTIL_LINUX_VERSION "2.12" 9#define UTIL_LINUX_VERSION "2.12"
@@ -91,10 +90,10 @@
91 90
92/* including <linux/hdreg.h> also fails */ 91/* including <linux/hdreg.h> also fails */
93struct hd_geometry { 92struct hd_geometry {
94 unsigned char heads; 93 unsigned char heads;
95 unsigned char sectors; 94 unsigned char sectors;
96 unsigned short cylinders; 95 unsigned short cylinders;
97 unsigned long start; 96 unsigned long start;
98}; 97};
99 98
100#define HDIO_GETGEO 0x0301 /* get device geometry */ 99#define HDIO_GETGEO 0x0301 /* get device geometry */
@@ -104,9 +103,9 @@ struct systypes {
104 const char *name; 103 const char *name;
105}; 104};
106 105
107static uint sector_size = DEFAULT_SECTOR_SIZE, 106static uint sector_size = DEFAULT_SECTOR_SIZE;
108 user_set_sector_size, 107static uint user_set_sector_size;
109 sector_offset = 1; 108static uint sector_offset = 1;
110 109
111/* 110/*
112 * Raw disk label. For DOS-type partition tables the MBR, 111 * Raw disk label. For DOS-type partition tables the MBR,
@@ -119,23 +118,23 @@ static char MBRbuffer[MAX_SECTOR_SIZE];
119#endif 118#endif
120 119
121#ifdef CONFIG_FEATURE_SUN_LABEL 120#ifdef CONFIG_FEATURE_SUN_LABEL
122static int sun_label; /* looking at sun disklabel */ 121static int sun_label; /* looking at sun disklabel */
123#else 122#else
124#define sun_label 0 123#define sun_label 0
125#endif 124#endif
126#ifdef CONFIG_FEATURE_SGI_LABEL 125#ifdef CONFIG_FEATURE_SGI_LABEL
127static int sgi_label; /* looking at sgi disklabel */ 126static int sgi_label; /* looking at sgi disklabel */
128#else 127#else
129#define sgi_label 0 128#define sgi_label 0
130#endif 129#endif
131#ifdef CONFIG_FEATURE_AIX_LABEL 130#ifdef CONFIG_FEATURE_AIX_LABEL
132static int aix_label; /* looking at aix disklabel */ 131static int aix_label; /* looking at aix disklabel */
133#else 132#else
134#define aix_label 0 133#define aix_label 0
135#endif 134#endif
136#ifdef CONFIG_FEATURE_OSF_LABEL 135#ifdef CONFIG_FEATURE_OSF_LABEL
137static int osf_label; /* looking at OSF/1 disklabel */ 136static int osf_label; /* looking at OSF/1 disklabel */
138static int possibly_osf_label; 137static int possibly_osf_label;
139#else 138#else
140#define osf_label 0 139#define osf_label 0
141#endif 140#endif
@@ -150,7 +149,8 @@ static void update_units(void);
150 * return partition name - uses static storage unless buf is supplied 149 * return partition name - uses static storage unless buf is supplied
151 */ 150 */
152static const char * 151static const char *
153partname(const char *dev, int pno, int lth) { 152partname(const char *dev, int pno, int lth)
153{
154 static char buffer[80]; 154 static char buffer[80];
155 const char *p; 155 const char *p;
156 int w, wp; 156 int w, wp;
@@ -168,7 +168,7 @@ partname(const char *dev, int pno, int lth) {
168 168
169 /* devfs kludge - note: fdisk partition names are not supposed 169 /* devfs kludge - note: fdisk partition names are not supposed
170 to equal kernel names, so there is no reason to do this */ 170 to equal kernel names, so there is no reason to do this */
171 if (strcmp (dev + w - 4, "disc") == 0) { 171 if (strcmp(dev + w - 4, "disc") == 0) {
172 w -= 4; 172 w -= 4;
173 p = "part"; 173 p = "part";
174 } 174 }
@@ -202,7 +202,7 @@ enum failure {
202 unable_to_write 202 unable_to_write
203}; 203};
204 204
205enum action {fdisk, require, try_only, create_empty_dos, create_empty_sun}; 205enum action { fdisk, require, try_only, create_empty_dos, create_empty_sun };
206 206
207static const char *disk_device; 207static const char *disk_device;
208static int fd; /* the disk */ 208static int fd; /* the disk */
@@ -214,7 +214,7 @@ static char *line_ptr;
214static void change_units(void); 214static void change_units(void);
215static void reread_partition_table(int leave); 215static void reread_partition_table(int leave);
216static void delete_partition(int i); 216static void delete_partition(int i);
217static int get_partition(int warn, int max); 217static int get_partition(int warn, int max);
218static void list_types(const struct systypes *sys); 218static void list_types(const struct systypes *sys);
219static uint read_int(uint low, uint dflt, uint high, uint base, char *mesg); 219static uint read_int(uint low, uint dflt, uint high, uint base, char *mesg);
220#endif 220#endif
@@ -275,7 +275,8 @@ static struct pte {
275 275
276#ifdef CONFIG_FEATURE_FDISK_WRITABLE 276#ifdef CONFIG_FEATURE_FDISK_WRITABLE
277static void 277static void
278set_all_unchanged(void) { 278set_all_unchanged(void)
279{
279 int i; 280 int i;
280 281
281 for (i = 0; i < MAXIMUM_PARTS; i++) 282 for (i = 0; i < MAXIMUM_PARTS; i++)
@@ -283,20 +284,23 @@ set_all_unchanged(void) {
283} 284}
284 285
285static void 286static void
286set_changed(int i) { 287set_changed(int i)
288{
287 ptes[i].changed = 1; 289 ptes[i].changed = 1;
288} 290}
289#endif /* CONFIG_FEATURE_FDISK_WRITABLE */ 291#endif /* CONFIG_FEATURE_FDISK_WRITABLE */
290 292
291#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_OSF_LABEL) 293#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_OSF_LABEL)
292static struct partition * 294static struct partition *
293get_part_table(int i) { 295get_part_table(int i)
296{
294 return ptes[i].part_table; 297 return ptes[i].part_table;
295} 298}
296#endif 299#endif
297 300
298static const char * 301static const char *
299str_units(int n) { /* n==1: use singular */ 302str_units(int n)
303{ /* n==1: use singular */
300 if (n == 1) 304 if (n == 1)
301 return display_in_cyl_units ? _("cylinder") : _("sector"); 305 return display_in_cyl_units ? _("cylinder") : _("sector");
302 else 306 else
@@ -359,19 +363,17 @@ read_hex(const struct systypes *sys)
359{ 363{
360 int hex; 364 int hex;
361 365
362 while (1) 366 while (1) {
363 { 367 read_char(_("Hex code (type L to list codes): "));
364 read_char(_("Hex code (type L to list codes): ")); 368 if (*line_ptr == 'l' || *line_ptr == 'L')
365 if (*line_ptr == 'l' || *line_ptr == 'L') 369 list_types(sys);
366 list_types(sys); 370 else if (isxdigit (*line_ptr)) {
367 else if (isxdigit (*line_ptr)) 371 hex = 0;
368 { 372 do
369 hex = 0; 373 hex = hex << 4 | hex_val(*line_ptr++);
370 do 374 while (isxdigit(*line_ptr));
371 hex = hex << 4 | hex_val(*line_ptr++); 375 return hex;
372 while (isxdigit(*line_ptr)); 376 }
373 return hex;
374 }
375 } 377 }
376} 378}
377#endif /* CONFIG_FEATURE_FDISK_WRITABLE */ 379#endif /* CONFIG_FEATURE_FDISK_WRITABLE */
@@ -407,58 +409,59 @@ typedef struct {
407 * Some fixes 409 * Some fixes
408*/ 410*/
409 411
410static int aix_other_endian; 412static int aix_other_endian;
411static short aix_volumes=1; 413static short aix_volumes = 1;
412 414
413/* 415/*
414 * only dealing with free blocks here 416 * only dealing with free blocks here
415 */ 417 */
416 418
417static void 419static void
418aix_info( void ) { 420aix_info(void)
419 puts( 421{
420 _("\n\tThere is a valid AIX label on this disk.\n" 422 puts(
421 "\tUnfortunately Linux cannot handle these\n" 423 _("\n\tThere is a valid AIX label on this disk.\n"
422 "\tdisks at the moment. Nevertheless some\n" 424 "\tUnfortunately Linux cannot handle these\n"
423 "\tadvice:\n" 425 "\tdisks at the moment. Nevertheless some\n"
424 "\t1. fdisk will destroy its contents on write.\n" 426 "\tadvice:\n"
425 "\t2. Be sure that this disk is NOT a still vital\n" 427 "\t1. fdisk will destroy its contents on write.\n"
426 "\t part of a volume group. (Otherwise you may\n" 428 "\t2. Be sure that this disk is NOT a still vital\n"
427 "\t erase the other disks as well, if unmirrored.)\n" 429 "\t part of a volume group. (Otherwise you may\n"
428 "\t3. Before deleting this physical volume be sure\n" 430 "\t erase the other disks as well, if unmirrored.)\n"
429 "\t to remove the disk logically from your AIX\n" 431 "\t3. Before deleting this physical volume be sure\n"
430 "\t machine. (Otherwise you become an AIXpert).") 432 "\t to remove the disk logically from your AIX\n"
431 ); 433 "\t machine. (Otherwise you become an AIXpert).")
434 );
432} 435}
433 436
434static void 437static void
435aix_nolabel( void ) 438aix_nolabel(void)
436{ 439{
437 aixlabel->magic = 0; 440 aixlabel->magic = 0;
438 aix_label = 0; 441 aix_label = 0;
439 partitions = 4; 442 partitions = 4;
440 memset( MBRbuffer, 0, sizeof(MBRbuffer) ); /* avoid fdisk cores */ 443 memset(MBRbuffer, 0, sizeof(MBRbuffer)); /* avoid fdisk cores */
441 return; 444 return;
442} 445}
443 446
444static int 447static int
445check_aix_label( void ) 448check_aix_label(void)
446{ 449{
447 if (aixlabel->magic != AIX_LABEL_MAGIC && 450 if (aixlabel->magic != AIX_LABEL_MAGIC &&
448 aixlabel->magic != AIX_LABEL_MAGIC_SWAPPED) { 451 aixlabel->magic != AIX_LABEL_MAGIC_SWAPPED) {
449 aix_label = 0; 452 aix_label = 0;
450 aix_other_endian = 0; 453 aix_other_endian = 0;
451 return 0; 454 return 0;
452 } 455 }
453 aix_other_endian = (aixlabel->magic == AIX_LABEL_MAGIC_SWAPPED); 456 aix_other_endian = (aixlabel->magic == AIX_LABEL_MAGIC_SWAPPED);
454 update_units(); 457 update_units();
455 aix_label = 1; 458 aix_label = 1;
456 partitions= 1016; 459 partitions = 1016;
457 aix_volumes = 15; 460 aix_volumes = 15;
458 aix_info(); 461 aix_info();
459 aix_nolabel(); /* %% */ 462 aix_nolabel(); /* %% */
460 aix_label = 1; /* %% */ 463 aix_label = 1; /* %% */
461 return 1; 464 return 1;
462} 465}
463#endif /* AIX_LABEL */ 466#endif /* AIX_LABEL */
464 467
@@ -525,10 +528,10 @@ check_aix_label( void )
525 528
526struct xbsd_disklabel { 529struct xbsd_disklabel {
527 uint32_t d_magic; /* the magic number */ 530 uint32_t d_magic; /* the magic number */
528 int16_t d_type; /* drive type */ 531 int16_t d_type; /* drive type */
529 int16_t d_subtype; /* controller/d_type specific */ 532 int16_t d_subtype; /* controller/d_type specific */
530 char d_typename[16]; /* type name, e.g. "eagle" */ 533 char d_typename[16]; /* type name, e.g. "eagle" */
531 char d_packname[16]; /* pack identifier */ 534 char d_packname[16]; /* pack identifier */
532 /* disk geometry: */ 535 /* disk geometry: */
533 uint32_t d_secsize; /* # of bytes per sector */ 536 uint32_t d_secsize; /* # of bytes per sector */
534 uint32_t d_nsectors; /* # of data sectors per track */ 537 uint32_t d_nsectors; /* # of data sectors per track */
@@ -660,28 +663,28 @@ static const char * const xbsd_dktypenames[] = {
660 663
661#ifdef DKTYPENAMES 664#ifdef DKTYPENAMES
662static const struct systypes xbsd_fstypes[] = { 665static const struct systypes xbsd_fstypes[] = {
663/* BSD_FS_UNUSED */ {"\x00" "unused"}, 666 { "\x00" "unused" }, /* BSD_FS_UNUSED */
664/* BSD_FS_SWAP */ {"\x01" "swap"}, 667 { "\x01" "swap" }, /* BSD_FS_SWAP */
665/* BSD_FS_V6 */ {"\x02" "Version 6"}, 668 { "\x02" "Version 6" }, /* BSD_FS_V6 */
666/* BSD_FS_V7 */ {"\x03" "Version 7"}, 669 { "\x03" "Version 7" }, /* BSD_FS_V7 */
667/* BSD_FS_SYSV */ {"\x04" "System V"}, 670 { "\x04" "System V" }, /* BSD_FS_SYSV */
668/* BSD_FS_V71K */ {"\x05" "4.1BSD"}, 671 { "\x05" "4.1BSD" }, /* BSD_FS_V71K */
669/* BSD_FS_V8 */ {"\x06" "Eighth Edition"}, 672 { "\x06" "Eighth Edition" }, /* BSD_FS_V8 */
670/* BSD_FS_BSDFFS */ {"\x07" "4.2BSD"}, 673 { "\x07" "4.2BSD" }, /* BSD_FS_BSDFFS */
671#ifdef __alpha__ 674#ifdef __alpha__
672/* BSD_FS_EXT2 */ {"\x08" "ext2"}, 675 { "\x08" "ext2" }, /* BSD_FS_EXT2 */
673#else 676#else
674/* BSD_FS_MSDOS */ {"\x08" "MS-DOS"}, 677 { "\x08" "MS-DOS" }, /* BSD_FS_MSDOS */
675#endif 678#endif
676/* BSD_FS_BSDLFS */ {"\x09" "4.4LFS"}, 679 { "\x09" "4.4LFS" }, /* BSD_FS_BSDLFS */
677/* BSD_FS_OTHER */ {"\x0a" "unknown"}, 680 { "\x0a" "unknown" }, /* BSD_FS_OTHER */
678/* BSD_FS_HPFS */ {"\x0b" "HPFS"}, 681 { "\x0b" "HPFS" }, /* BSD_FS_HPFS */
679/* BSD_FS_ISO9660 */ {"\x0c" "ISO-9660"}, 682 { "\x0c" "ISO-9660" }, /* BSD_FS_ISO9660 */
680/* BSD_FS_BOOT */ {"\x0d" "boot"}, 683 { "\x0d" "boot" }, /* BSD_FS_BOOT */
681/* BSD_FS_ADOS */ {"\x0e" "ADOS"}, 684 { "\x0e" "ADOS" }, /* BSD_FS_ADOS */
682/* BSD_FS_HFS */ {"\x0f" "HFS"}, 685 { "\x0f" "HFS" }, /* BSD_FS_HFS */
683/* BSD_FS_ADVFS */ {"\x10" "AdvFS"}, 686 { "\x10" "AdvFS" }, /* BSD_FS_ADVFS */
684 { NULL } 687 { NULL }
685}; 688};
686#define BSD_FSMAXTYPES (SIZE(xbsd_fstypes)-1) 689#define BSD_FSMAXTYPES (SIZE(xbsd_fstypes)-1)
687 690
@@ -854,28 +857,28 @@ typedef struct {
854#define FREEBSD_PARTITION 0xa5 857#define FREEBSD_PARTITION 0xa5
855#define NETBSD_PARTITION 0xa9 858#define NETBSD_PARTITION 0xa9
856 859
857static void xbsd_delete_part (void); 860static void xbsd_delete_part(void);
858static void xbsd_new_part (void); 861static void xbsd_new_part(void);
859static void xbsd_write_disklabel (void); 862static void xbsd_write_disklabel(void);
860static int xbsd_create_disklabel (void); 863static int xbsd_create_disklabel(void);
861static void xbsd_edit_disklabel (void); 864static void xbsd_edit_disklabel(void);
862static void xbsd_write_bootstrap (void); 865static void xbsd_write_bootstrap(void);
863static void xbsd_change_fstype (void); 866static void xbsd_change_fstype(void);
864static int xbsd_get_part_index (int max); 867static int xbsd_get_part_index(int max);
865static int xbsd_check_new_partition (int *i); 868static int xbsd_check_new_partition(int *i);
866static void xbsd_list_types (void); 869static void xbsd_list_types(void);
867static u_short xbsd_dkcksum (struct xbsd_disklabel *lp); 870static u_short xbsd_dkcksum(struct xbsd_disklabel *lp);
868static int xbsd_initlabel (struct partition *p, struct xbsd_disklabel *d); 871static int xbsd_initlabel(struct partition *p, struct xbsd_disklabel *d);
869static int xbsd_readlabel (struct partition *p, struct xbsd_disklabel *d); 872static int xbsd_readlabel(struct partition *p, struct xbsd_disklabel *d);
870static int xbsd_writelabel (struct partition *p, struct xbsd_disklabel *d); 873static int xbsd_writelabel(struct partition *p, struct xbsd_disklabel *d);
871 874
872#if defined (__alpha__) 875#if defined (__alpha__)
873static void alpha_bootblock_checksum (char *boot); 876static void alpha_bootblock_checksum(char *boot);
874#endif 877#endif
875 878
876#if !defined (__alpha__) 879#if !defined (__alpha__)
877static int xbsd_translate_fstype (int linux_type); 880static int xbsd_translate_fstype(int linux_type);
878static void xbsd_link_part (void); 881static void xbsd_link_part(void);
879static struct partition *xbsd_part; 882static struct partition *xbsd_part;
880static int xbsd_part_index; 883static int xbsd_part_index;
881#endif 884#endif
@@ -899,8 +902,9 @@ static struct xbsd_disklabel xbsd_dlabel;
899 * so this does not mean that there is a BSD disk label. 902 * so this does not mean that there is a BSD disk label.
900 */ 903 */
901static int 904static int
902check_osf_label(void) { 905check_osf_label(void)
903 if (xbsd_readlabel (NULL, &xbsd_dlabel) == 0) 906{
907 if (xbsd_readlabel(NULL, &xbsd_dlabel) == 0)
904 return 0; 908 return 0;
905 return 1; 909 return 1;
906} 910}
@@ -908,7 +912,8 @@ check_osf_label(void) {
908static void xbsd_print_disklabel(int); 912static void xbsd_print_disklabel(int);
909 913
910static int 914static int
911btrydev (const char * dev) { 915btrydev(const char * dev)
916{
912 if (xbsd_readlabel (NULL, &xbsd_dlabel) == 0) 917 if (xbsd_readlabel (NULL, &xbsd_dlabel) == 0)
913 return -1; 918 return -1;
914 printf(_("\nBSD label for device: %s\n"), dev); 919 printf(_("\nBSD label for device: %s\n"), dev);
@@ -917,34 +922,37 @@ btrydev (const char * dev) {
917} 922}
918 923
919static void 924static void
920bmenu (void) { 925bmenu(void)
921 puts (_("Command action")); 926{
922 puts (_("\td\tdelete a BSD partition")); 927 puts (_("Command action"));
923 puts (_("\te\tedit drive data")); 928 puts (_("\td\tdelete a BSD partition"));
924 puts (_("\ti\tinstall bootstrap")); 929 puts (_("\te\tedit drive data"));
925 puts (_("\tl\tlist known filesystem types")); 930 puts (_("\ti\tinstall bootstrap"));
926 puts (_("\tm\tprint this menu")); 931 puts (_("\tl\tlist known filesystem types"));
927 puts (_("\tn\tadd a new BSD partition")); 932 puts (_("\tm\tprint this menu"));
928 puts (_("\tp\tprint BSD partition table")); 933 puts (_("\tn\tadd a new BSD partition"));
929 puts (_("\tq\tquit without saving changes")); 934 puts (_("\tp\tprint BSD partition table"));
930 puts (_("\tr\treturn to main menu")); 935 puts (_("\tq\tquit without saving changes"));
931 puts (_("\ts\tshow complete disklabel")); 936 puts (_("\tr\treturn to main menu"));
932 puts (_("\tt\tchange a partition's filesystem id")); 937 puts (_("\ts\tshow complete disklabel"));
933 puts (_("\tu\tchange units (cylinders/sectors)")); 938 puts (_("\tt\tchange a partition's filesystem id"));
934 puts (_("\tw\twrite disklabel to disk")); 939 puts (_("\tu\tchange units (cylinders/sectors)"));
940 puts (_("\tw\twrite disklabel to disk"));
935#if !defined (__alpha__) 941#if !defined (__alpha__)
936 puts (_("\tx\tlink BSD partition to non-BSD partition")); 942 puts (_("\tx\tlink BSD partition to non-BSD partition"));
937#endif 943#endif
938} 944}
939 945
940#if !defined (__alpha__) 946#if !defined (__alpha__)
941static int 947static int
942hidden(int type) { 948hidden(int type)
949{
943 return type ^ 0x10; 950 return type ^ 0x10;
944} 951}
945 952
946static int 953static int
947is_bsd_partition_type(int type) { 954is_bsd_partition_type(int type)
955{
948 return (type == FREEBSD_PARTITION || 956 return (type == FREEBSD_PARTITION ||
949 type == hidden(FREEBSD_PARTITION) || 957 type == hidden(FREEBSD_PARTITION) ||
950 type == NETBSD_PARTITION || 958 type == NETBSD_PARTITION ||
@@ -953,273 +961,277 @@ is_bsd_partition_type(int type) {
953#endif 961#endif
954 962
955static void 963static void
956bselect (void) { 964bselect(void)
965{
957#if !defined (__alpha__) 966#if !defined (__alpha__)
958 int t, ss; 967 int t, ss;
959 struct partition *p; 968 struct partition *p;
960 969
961 for (t=0; t<4; t++) { 970 for (t = 0; t < 4; t++) {
962 p = get_part_table(t); 971 p = get_part_table(t);
963 if (p && is_bsd_partition_type(p->sys_ind)) { 972 if (p && is_bsd_partition_type(p->sys_ind)) {
964 xbsd_part = p; 973 xbsd_part = p;
965 xbsd_part_index = t; 974 xbsd_part_index = t;
966 ss = get_start_sect(xbsd_part); 975 ss = get_start_sect(xbsd_part);
967 if (ss == 0) { 976 if (ss == 0) {
968 fprintf (stderr, _("Partition %s has invalid starting sector 0.\n"), 977 fprintf(stderr, _("Partition %s has invalid starting sector 0.\n"),
969 partname(disk_device, t+1, 0)); 978 partname(disk_device, t+1, 0));
970 return; 979 return;
971 } 980 }
972 printf (_("Reading disklabel of %s at sector %d.\n"), 981 printf(_("Reading disklabel of %s at sector %d.\n"),
973 partname(disk_device, t+1, 0), ss + BSD_LABELSECTOR); 982 partname(disk_device, t+1, 0), ss + BSD_LABELSECTOR);
974 if (xbsd_readlabel (xbsd_part, &xbsd_dlabel) == 0) 983 if (xbsd_readlabel(xbsd_part, &xbsd_dlabel) == 0)
975 if (xbsd_create_disklabel () == 0) 984 if (xbsd_create_disklabel() == 0)
976 return; 985 return;
977 break; 986 break;
978 } 987 }
979 } 988 }
980 989
981 if (t == 4) { 990 if (t == 4) {
982 printf (_("There is no *BSD partition on %s.\n"), disk_device); 991 printf(_("There is no *BSD partition on %s.\n"), disk_device);
983 return; 992 return;
984 } 993 }
985 994
986#elif defined (__alpha__) 995#elif defined (__alpha__)
987 996
988 if (xbsd_readlabel (NULL, &xbsd_dlabel) == 0) 997 if (xbsd_readlabel(NULL, &xbsd_dlabel) == 0)
989 if (xbsd_create_disklabel () == 0) 998 if (xbsd_create_disklabel() == 0)
990 exit ( EXIT_SUCCESS ); 999 exit (EXIT_SUCCESS);
991 1000
992#endif 1001#endif
993 1002
994 while (1) { 1003 while (1) {
995 putchar ('\n'); 1004 putchar('\n');
996 switch (tolower (read_char (_("BSD disklabel command (m for help): ")))) { 1005 switch (tolower(read_char(_("BSD disklabel command (m for help): ")))) {
997 case 'd': 1006 case 'd':
998 xbsd_delete_part (); 1007 xbsd_delete_part();
999 break; 1008 break;
1000 case 'e': 1009 case 'e':
1001 xbsd_edit_disklabel (); 1010 xbsd_edit_disklabel();
1002 break; 1011 break;
1003 case 'i': 1012 case 'i':
1004 xbsd_write_bootstrap (); 1013 xbsd_write_bootstrap();
1005 break; 1014 break;
1006 case 'l': 1015 case 'l':
1007 xbsd_list_types (); 1016 xbsd_list_types();
1008 break; 1017 break;
1009 case 'n': 1018 case 'n':
1010 xbsd_new_part (); 1019 xbsd_new_part();
1011 break; 1020 break;
1012 case 'p': 1021 case 'p':
1013 xbsd_print_disklabel (0); 1022 xbsd_print_disklabel(0);
1014 break; 1023 break;
1015 case 'q': 1024 case 'q':
1016 close (fd); 1025 close(fd);
1017 exit ( EXIT_SUCCESS ); 1026 exit(EXIT_SUCCESS);
1018 case 'r': 1027 case 'r':
1019 return; 1028 return;
1020 case 's': 1029 case 's':
1021 xbsd_print_disklabel (1); 1030 xbsd_print_disklabel(1);
1022 break; 1031 break;
1023 case 't': 1032 case 't':
1024 xbsd_change_fstype (); 1033 xbsd_change_fstype();
1025 break; 1034 break;
1026 case 'u': 1035 case 'u':
1027 change_units(); 1036 change_units();
1028 break; 1037 break;
1029 case 'w': 1038 case 'w':
1030 xbsd_write_disklabel (); 1039 xbsd_write_disklabel();
1031 break; 1040 break;
1032#if !defined (__alpha__) 1041#if !defined (__alpha__)
1033 case 'x': 1042 case 'x':
1034 xbsd_link_part (); 1043 xbsd_link_part();
1035 break; 1044 break;
1036#endif 1045#endif
1037 default: 1046 default:
1038 bmenu (); 1047 bmenu();
1039 break; 1048 break;
1040 } 1049 }
1041 } 1050 }
1042} 1051}
1043 1052
1044static void 1053static void
1045xbsd_delete_part (void) 1054xbsd_delete_part(void)
1046{ 1055{
1047 int i; 1056 int i;
1048 1057
1049 i = xbsd_get_part_index (xbsd_dlabel.d_npartitions); 1058 i = xbsd_get_part_index(xbsd_dlabel.d_npartitions);
1050 xbsd_dlabel.d_partitions[i].p_size = 0; 1059 xbsd_dlabel.d_partitions[i].p_size = 0;
1051 xbsd_dlabel.d_partitions[i].p_offset = 0; 1060 xbsd_dlabel.d_partitions[i].p_offset = 0;
1052 xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED; 1061 xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED;
1053 if (xbsd_dlabel.d_npartitions == i + 1) 1062 if (xbsd_dlabel.d_npartitions == i + 1)
1054 while (xbsd_dlabel.d_partitions[xbsd_dlabel.d_npartitions-1].p_size == 0) 1063 while (xbsd_dlabel.d_partitions[xbsd_dlabel.d_npartitions-1].p_size == 0)
1055 xbsd_dlabel.d_npartitions--; 1064 xbsd_dlabel.d_npartitions--;
1056} 1065}
1057 1066
1058static void 1067static void
1059xbsd_new_part (void) 1068xbsd_new_part(void)
1060{ 1069{
1061 off_t begin, end; 1070 off_t begin, end;
1062 char mesg[256]; 1071 char mesg[256];
1063 int i; 1072 int i;
1064 1073
1065 if (!xbsd_check_new_partition (&i)) 1074 if (!xbsd_check_new_partition(&i))
1066 return; 1075 return;
1067 1076
1068#if !defined (__alpha__) && !defined (__powerpc__) && !defined (__hppa__) 1077#if !defined (__alpha__) && !defined (__powerpc__) && !defined (__hppa__)
1069 begin = get_start_sect(xbsd_part); 1078 begin = get_start_sect(xbsd_part);
1070 end = begin + get_nr_sects(xbsd_part) - 1; 1079 end = begin + get_nr_sects(xbsd_part) - 1;
1071#else 1080#else
1072 begin = 0; 1081 begin = 0;
1073 end = xbsd_dlabel.d_secperunit - 1; 1082 end = xbsd_dlabel.d_secperunit - 1;
1074#endif 1083#endif
1075 1084
1076 snprintf (mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR)); 1085 snprintf(mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));
1077 begin = read_int (bsd_cround (begin), bsd_cround (begin), bsd_cround (end), 1086 begin = read_int(bsd_cround(begin), bsd_cround(begin), bsd_cround(end),
1078 0, mesg); 1087 0, mesg);
1079 1088
1080 if (display_in_cyl_units) 1089 if (display_in_cyl_units)
1081 begin = (begin - 1) * xbsd_dlabel.d_secpercyl; 1090 begin = (begin - 1) * xbsd_dlabel.d_secpercyl;
1082 1091
1083 snprintf (mesg, sizeof(mesg), _("Last %s or +size or +sizeM or +sizeK"), 1092 snprintf(mesg, sizeof(mesg), _("Last %s or +size or +sizeM or +sizeK"),
1084 str_units(SINGULAR)); 1093 str_units(SINGULAR));
1085 end = read_int (bsd_cround (begin), bsd_cround (end), bsd_cround (end), 1094 end = read_int(bsd_cround (begin), bsd_cround (end), bsd_cround (end),
1086 bsd_cround (begin), mesg); 1095 bsd_cround (begin), mesg);
1087 1096
1088 if (display_in_cyl_units) 1097 if (display_in_cyl_units)
1089 end = end * xbsd_dlabel.d_secpercyl - 1; 1098 end = end * xbsd_dlabel.d_secpercyl - 1;
1090 1099
1091 xbsd_dlabel.d_partitions[i].p_size = end - begin + 1; 1100 xbsd_dlabel.d_partitions[i].p_size = end - begin + 1;
1092 xbsd_dlabel.d_partitions[i].p_offset = begin; 1101 xbsd_dlabel.d_partitions[i].p_offset = begin;
1093 xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED; 1102 xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED;
1094} 1103}
1095 1104
1096static void 1105static void
1097xbsd_print_disklabel (int show_all) { 1106xbsd_print_disklabel(int show_all)
1098 struct xbsd_disklabel *lp = &xbsd_dlabel; 1107{
1099 struct xbsd_partition *pp; 1108 struct xbsd_disklabel *lp = &xbsd_dlabel;
1100 int i, j; 1109 struct xbsd_partition *pp;
1110 int i, j;
1101 1111
1102 if (show_all) { 1112 if (show_all) {
1103#if defined (__alpha__) 1113#if defined (__alpha__)
1104 printf("# %s:\n", disk_device); 1114 printf("# %s:\n", disk_device);
1105#else 1115#else
1106 printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0)); 1116 printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0));
1107#endif 1117#endif
1108 if ((unsigned) lp->d_type < BSD_DKMAXTYPES) 1118 if ((unsigned) lp->d_type < BSD_DKMAXTYPES)
1109 printf(_("type: %s\n"), xbsd_dktypenames[lp->d_type]); 1119 printf(_("type: %s\n"), xbsd_dktypenames[lp->d_type]);
1110 else 1120 else
1111 printf(_("type: %d\n"), lp->d_type); 1121 printf(_("type: %d\n"), lp->d_type);
1112 printf(_("disk: %.*s\n"), (int) sizeof(lp->d_typename), lp->d_typename); 1122 printf(_("disk: %.*s\n"), (int) sizeof(lp->d_typename), lp->d_typename);
1113 printf(_("label: %.*s\n"), (int) sizeof(lp->d_packname), lp->d_packname); 1123 printf(_("label: %.*s\n"), (int) sizeof(lp->d_packname), lp->d_packname);
1114 printf(_("flags:")); 1124 printf(_("flags:"));
1115 if (lp->d_flags & BSD_D_REMOVABLE) 1125 if (lp->d_flags & BSD_D_REMOVABLE)
1116 printf(_(" removable")); 1126 printf(_(" removable"));
1117 if (lp->d_flags & BSD_D_ECC) 1127 if (lp->d_flags & BSD_D_ECC)
1118 printf(_(" ecc")); 1128 printf(_(" ecc"));
1119 if (lp->d_flags & BSD_D_BADSECT) 1129 if (lp->d_flags & BSD_D_BADSECT)
1120 printf(_(" badsect")); 1130 printf(_(" badsect"));
1121 printf("\n"); 1131 printf("\n");
1122 /* On various machines the fields of *lp are short/int/long */ 1132 /* On various machines the fields of *lp are short/int/long */
1123 /* In order to avoid problems, we cast them all to long. */ 1133 /* In order to avoid problems, we cast them all to long. */
1124 printf(_("bytes/sector: %ld\n"), (long) lp->d_secsize); 1134 printf(_("bytes/sector: %ld\n"), (long) lp->d_secsize);
1125 printf(_("sectors/track: %ld\n"), (long) lp->d_nsectors); 1135 printf(_("sectors/track: %ld\n"), (long) lp->d_nsectors);
1126 printf(_("tracks/cylinder: %ld\n"), (long) lp->d_ntracks); 1136 printf(_("tracks/cylinder: %ld\n"), (long) lp->d_ntracks);
1127 printf(_("sectors/cylinder: %ld\n"), (long) lp->d_secpercyl); 1137 printf(_("sectors/cylinder: %ld\n"), (long) lp->d_secpercyl);
1128 printf(_("cylinders: %ld\n"), (long) lp->d_ncylinders); 1138 printf(_("cylinders: %ld\n"), (long) lp->d_ncylinders);
1129 printf(_("rpm: %d\n"), lp->d_rpm); 1139 printf(_("rpm: %d\n"), lp->d_rpm);
1130 printf(_("interleave: %d\n"), lp->d_interleave); 1140 printf(_("interleave: %d\n"), lp->d_interleave);
1131 printf(_("trackskew: %d\n"), lp->d_trackskew); 1141 printf(_("trackskew: %d\n"), lp->d_trackskew);
1132 printf(_("cylinderskew: %d\n"), lp->d_cylskew); 1142 printf(_("cylinderskew: %d\n"), lp->d_cylskew);
1133 printf(_("headswitch: %ld\t\t# milliseconds\n"), 1143 printf(_("headswitch: %ld\t\t# milliseconds\n"),
1134 (long) lp->d_headswitch); 1144 (long) lp->d_headswitch);
1135 printf(_("track-to-track seek: %ld\t# milliseconds\n"), 1145 printf(_("track-to-track seek: %ld\t# milliseconds\n"),
1136 (long) lp->d_trkseek); 1146 (long) lp->d_trkseek);
1137 printf(_("drivedata: ")); 1147 printf(_("drivedata: "));
1138 for (i = NDDATA - 1; i >= 0; i--) 1148 for (i = NDDATA - 1; i >= 0; i--)
1139 if (lp->d_drivedata[i]) 1149 if (lp->d_drivedata[i])
1140 break; 1150 break;
1141 if (i < 0) 1151 if (i < 0)
1142 i = 0; 1152 i = 0;
1143 for (j = 0; j <= i; j++) 1153 for (j = 0; j <= i; j++)
1144 printf("%ld ", (long) lp->d_drivedata[j]); 1154 printf("%ld ", (long) lp->d_drivedata[j]);
1145 } 1155 }
1146 printf(_("\n%d partitions:\n"), lp->d_npartitions); 1156 printf(_("\n%d partitions:\n"), lp->d_npartitions);
1147 printf(_("# start end size fstype [fsize bsize cpg]\n")); 1157 printf(_("# start end size fstype [fsize bsize cpg]\n"));
1148 pp = lp->d_partitions; 1158 pp = lp->d_partitions;
1149 for (i = 0; i < lp->d_npartitions; i++, pp++) { 1159 for (i = 0; i < lp->d_npartitions; i++, pp++) {
1150 if (pp->p_size) { 1160 if (pp->p_size) {
1151 if (display_in_cyl_units && lp->d_secpercyl) { 1161 if (display_in_cyl_units && lp->d_secpercyl) {
1152 printf(" %c: %8ld%c %8ld%c %8ld%c ", 1162 printf(" %c: %8ld%c %8ld%c %8ld%c ",
1153 'a' + i, 1163 'a' + i,
1154 (long) pp->p_offset / lp->d_secpercyl + 1, 1164 (long) pp->p_offset / lp->d_secpercyl + 1,
1155 (pp->p_offset % lp->d_secpercyl) ? '*' : ' ', 1165 (pp->p_offset % lp->d_secpercyl) ? '*' : ' ',
1156 (long) (pp->p_offset + pp->p_size + lp->d_secpercyl - 1) 1166 (long) (pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl,
1157 / lp->d_secpercyl, 1167 ((pp->p_offset + pp->p_size) % lp->d_secpercyl) ? '*' : ' ',
1158 ((pp->p_offset + pp->p_size) % lp->d_secpercyl) ? '*' : ' ', 1168 (long) pp->p_size / lp->d_secpercyl,
1159 (long) pp->p_size / lp->d_secpercyl, 1169 (pp->p_size % lp->d_secpercyl) ? '*' : ' '
1160 (pp->p_size % lp->d_secpercyl) ? '*' : ' '); 1170 );
1161 } else { 1171 } else {
1162 printf(" %c: %8ld %8ld %8ld ", 1172 printf(" %c: %8ld %8ld %8ld ",
1163 'a' + i, 1173 'a' + i,
1164 (long) pp->p_offset, 1174 (long) pp->p_offset,
1165 (long) pp->p_offset + pp->p_size - 1, 1175 (long) pp->p_offset + pp->p_size - 1,
1166 (long) pp->p_size); 1176 (long) pp->p_size
1167 } 1177 );
1168 if ((unsigned) pp->p_fstype < BSD_FSMAXTYPES) 1178 }
1169 printf("%8.8s", xbsd_fstypes[pp->p_fstype].name);
1170 else
1171 printf("%8x", pp->p_fstype);
1172 switch (pp->p_fstype) {
1173 case BSD_FS_UNUSED:
1174 printf(" %5ld %5ld %5.5s ",
1175 (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, "");
1176 break;
1177
1178 case BSD_FS_BSDFFS:
1179 printf(" %5ld %5ld %5d ",
1180 (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag,
1181 pp->p_cpg);
1182 break;
1183 1179
1184 default: 1180 if ((unsigned) pp->p_fstype < BSD_FSMAXTYPES)
1185 printf("%22.22s", ""); 1181 printf("%8.8s", xbsd_fstypes[pp->p_fstype].name);
1186 break; 1182 else
1187 } 1183 printf("%8x", pp->p_fstype);
1188 printf("\n"); 1184
1189 } 1185 switch (pp->p_fstype) {
1190 } 1186 case BSD_FS_UNUSED:
1187 printf(" %5ld %5ld %5.5s ",
1188 (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, "");
1189 break;
1190 case BSD_FS_BSDFFS:
1191 printf(" %5ld %5ld %5d ",
1192 (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, pp->p_cpg);
1193 break;
1194 default:
1195 printf("%22.22s", "");
1196 break;
1197 }
1198 printf("\n");
1199 }
1200 }
1191} 1201}
1192 1202
1193static void 1203static void
1194xbsd_write_disklabel (void) { 1204xbsd_write_disklabel(void)
1205{
1195#if defined (__alpha__) 1206#if defined (__alpha__)
1196 printf (_("Writing disklabel to %s.\n"), disk_device); 1207 printf(_("Writing disklabel to %s.\n"), disk_device);
1197 xbsd_writelabel (NULL, &xbsd_dlabel); 1208 xbsd_writelabel(NULL, &xbsd_dlabel);
1198#else 1209#else
1199 printf (_("Writing disklabel to %s.\n"), 1210 printf(_("Writing disklabel to %s.\n"),
1200 partname(disk_device, xbsd_part_index+1, 0)); 1211 partname(disk_device, xbsd_part_index + 1, 0));
1201 xbsd_writelabel (xbsd_part, &xbsd_dlabel); 1212 xbsd_writelabel(xbsd_part, &xbsd_dlabel);
1202#endif 1213#endif
1203 reread_partition_table(0); /* no exit yet */ 1214 reread_partition_table(0); /* no exit yet */
1204} 1215}
1205 1216
1206static int 1217static int
1207xbsd_create_disklabel (void) { 1218xbsd_create_disklabel(void)
1219{
1208 char c; 1220 char c;
1209 1221
1210#if defined (__alpha__) 1222#if defined (__alpha__)
1211 fprintf (stderr, _("%s contains no disklabel.\n"), disk_device); 1223 fprintf(stderr, _("%s contains no disklabel.\n"), disk_device);
1212#else 1224#else
1213 fprintf (stderr, _("%s contains no disklabel.\n"), 1225 fprintf(stderr, _("%s contains no disklabel.\n"),
1214 partname(disk_device, xbsd_part_index+1, 0)); 1226 partname(disk_device, xbsd_part_index + 1, 0));
1215#endif 1227#endif
1216 1228
1217 while (1) { 1229 while (1) {
1218 c = read_char (_("Do you want to create a disklabel? (y/n) ")); 1230 c = read_char(_("Do you want to create a disklabel? (y/n) "));
1219 if (c == 'y' || c == 'Y') { 1231 if (c == 'y' || c == 'Y') {
1220 if (xbsd_initlabel ( 1232 if (xbsd_initlabel(
1221#if defined (__alpha__) || defined (__powerpc__) || defined (__hppa__) || \ 1233#if defined (__alpha__) || defined (__powerpc__) || defined (__hppa__) || \
1222 defined (__s390__) || defined (__s390x__) 1234 defined (__s390__) || defined (__s390x__)
1223 NULL, &xbsd_dlabel 1235 NULL, &xbsd_dlabel
1224#else 1236#else
1225 xbsd_part, &xbsd_dlabel/* not used, xbsd_part_index*/ 1237 xbsd_part, &xbsd_dlabel/* not used, xbsd_part_index*/
@@ -1235,176 +1247,173 @@ xbsd_create_disklabel (void) {
1235} 1247}
1236 1248
1237static int 1249static int
1238edit_int (int def, char *mesg) 1250edit_int(int def, char *mesg)
1239{ 1251{
1240 do { 1252 do {
1241 fputs (mesg, stdout); 1253 fputs(mesg, stdout);
1242 printf (" (%d): ", def); 1254 printf(" (%d): ", def);
1243 if (!read_line ()) 1255 if (!read_line())
1244 return def; 1256 return def;
1245 } 1257 }
1246 while (!isdigit (*line_ptr)); 1258 while (!isdigit(*line_ptr)); /* FIXME: ?!! */
1247 return atoi (line_ptr); 1259 return atoi(line_ptr);
1248} 1260}
1249 1261
1250static void 1262static void
1251xbsd_edit_disklabel (void) 1263xbsd_edit_disklabel(void)
1252{ 1264{
1253 struct xbsd_disklabel *d; 1265 struct xbsd_disklabel *d;
1254 1266
1255 d = &xbsd_dlabel; 1267 d = &xbsd_dlabel;
1256 1268
1257#if defined (__alpha__) || defined (__ia64__) 1269#if defined (__alpha__) || defined (__ia64__)
1258 d -> d_secsize = (u_long) edit_int ((u_long) d -> d_secsize ,_("bytes/sector")); 1270 d->d_secsize = (u_long) edit_int((u_long) d->d_secsize ,_("bytes/sector"));
1259 d -> d_nsectors = (u_long) edit_int ((u_long) d -> d_nsectors ,_("sectors/track")); 1271 d->d_nsectors = (u_long) edit_int((u_long) d->d_nsectors ,_("sectors/track"));
1260 d -> d_ntracks = (u_long) edit_int ((u_long) d -> d_ntracks ,_("tracks/cylinder")); 1272 d->d_ntracks = (u_long) edit_int((u_long) d->d_ntracks ,_("tracks/cylinder"));
1261 d -> d_ncylinders = (u_long) edit_int ((u_long) d -> d_ncylinders ,_("cylinders")); 1273 d->d_ncylinders = (u_long) edit_int((u_long) d->d_ncylinders ,_("cylinders"));
1262#endif 1274#endif
1263 1275
1264 /* d -> d_secpercyl can be != d -> d_nsectors * d -> d_ntracks */ 1276 /* d->d_secpercyl can be != d->d_nsectors * d->d_ntracks */
1265 while (1) 1277 while (1) {
1266 { 1278 d->d_secpercyl = (u_long) edit_int((u_long) d->d_nsectors * d->d_ntracks,
1267 d -> d_secpercyl = (u_long) edit_int ((u_long) d -> d_nsectors * d -> d_ntracks, 1279 _("sectors/cylinder"));
1268 _("sectors/cylinder")); 1280 if (d->d_secpercyl <= d->d_nsectors * d->d_ntracks)
1269 if (d -> d_secpercyl <= d -> d_nsectors * d -> d_ntracks) 1281 break;
1270 break;
1271 1282
1272 printf (_("Must be <= sectors/track * tracks/cylinder (default).\n")); 1283 printf(_("Must be <= sectors/track * tracks/cylinder (default).\n"));
1273 } 1284 }
1274 d -> d_rpm = (u_short) edit_int ((u_short) d -> d_rpm ,_("rpm")); 1285 d->d_rpm = (u_short) edit_int((u_short) d->d_rpm ,_("rpm"));
1275 d -> d_interleave = (u_short) edit_int ((u_short) d -> d_interleave,_("interleave")); 1286 d->d_interleave = (u_short) edit_int((u_short) d->d_interleave,_("interleave"));
1276 d -> d_trackskew = (u_short) edit_int ((u_short) d -> d_trackskew ,_("trackskew")); 1287 d->d_trackskew = (u_short) edit_int((u_short) d->d_trackskew ,_("trackskew"));
1277 d -> d_cylskew = (u_short) edit_int ((u_short) d -> d_cylskew ,_("cylinderskew")); 1288 d->d_cylskew = (u_short) edit_int((u_short) d->d_cylskew ,_("cylinderskew"));
1278 d -> d_headswitch = (u_long) edit_int ((u_long) d -> d_headswitch ,_("headswitch")); 1289 d->d_headswitch = (u_long) edit_int((u_long) d->d_headswitch ,_("headswitch"));
1279 d -> d_trkseek = (u_long) edit_int ((u_long) d -> d_trkseek ,_("track-to-track seek")); 1290 d->d_trkseek = (u_long) edit_int((u_long) d->d_trkseek ,_("track-to-track seek"));
1280 1291
1281 d -> d_secperunit = d -> d_secpercyl * d -> d_ncylinders; 1292 d->d_secperunit = d->d_secpercyl * d->d_ncylinders;
1282} 1293}
1283 1294
1284static int 1295static int
1285xbsd_get_bootstrap (char *path, void *ptr, int size) 1296xbsd_get_bootstrap (char *path, void *ptr, int size)
1286{ 1297{
1287 int fdb; 1298 int fdb;
1288 1299
1289 if ((fdb = open (path, O_RDONLY)) < 0) 1300 if ((fdb = open (path, O_RDONLY)) < 0) {
1290 { 1301 perror(path);
1291 perror (path); 1302 return 0;
1292 return 0; 1303 }
1293 } 1304 if (read(fdb, ptr, size) < 0) {
1294 if (read (fdb, ptr, size) < 0) 1305 perror(path);
1295 { 1306 close(fdb);
1296 perror (path); 1307 return 0;
1297 close (fdb); 1308 }
1298 return 0; 1309 printf(" ... %s\n", path);
1299 } 1310 close(fdb);
1300 printf (" ... %s\n", path); 1311 return 1;
1301 close (fdb);
1302 return 1;
1303} 1312}
1304 1313
1305static void 1314static void
1306sync_disks (void) 1315sync_disks(void)
1307{ 1316{
1308 printf (_("\nSyncing disks.\n")); 1317 printf(_("\nSyncing disks.\n"));
1309 sync (); 1318 sync();
1310 sleep (4); 1319 sleep(4); /* What? */
1311} 1320}
1312 1321
1313static void 1322static void
1314xbsd_write_bootstrap (void) 1323xbsd_write_bootstrap(void)
1315{ 1324{
1316 char *bootdir = BSD_LINUX_BOOTDIR; 1325 char *bootdir = BSD_LINUX_BOOTDIR;
1317 char path[MAXPATHLEN]; 1326 char path[MAXPATHLEN];
1318 char *dkbasename; 1327 char *dkbasename;
1319 struct xbsd_disklabel dl; 1328 struct xbsd_disklabel dl;
1320 char *d, *p, *e; 1329 char *d, *p, *e;
1321 int sector; 1330 int sector;
1322 1331
1323 if (xbsd_dlabel.d_type == BSD_DTYPE_SCSI) 1332 if (xbsd_dlabel.d_type == BSD_DTYPE_SCSI)
1324 dkbasename = "sd"; 1333 dkbasename = "sd";
1325 else 1334 else
1326 dkbasename = "wd"; 1335 dkbasename = "wd";
1327 1336
1328 printf (_("Bootstrap: %sboot -> boot%s (%s): "), 1337 printf(_("Bootstrap: %sboot -> boot%s (%s): "),
1329 dkbasename, dkbasename, dkbasename); 1338 dkbasename, dkbasename, dkbasename);
1330 if (read_line ()) { 1339 if (read_line()) {
1331 line_ptr[strlen (line_ptr)-1] = '\0'; 1340 line_ptr[strlen(line_ptr)-1] = '\0';
1332 dkbasename = line_ptr; 1341 dkbasename = line_ptr;
1333 } 1342 }
1334 snprintf (path, sizeof(path), "%s/%sboot", bootdir, dkbasename); 1343 snprintf(path, sizeof(path), "%s/%sboot", bootdir, dkbasename);
1335 if (!xbsd_get_bootstrap (path, disklabelbuffer, (int) xbsd_dlabel.d_secsize)) 1344 if (!xbsd_get_bootstrap(path, disklabelbuffer, (int) xbsd_dlabel.d_secsize))
1336 return; 1345 return;
1337 1346
1338 /* We need a backup of the disklabel (xbsd_dlabel might have changed). */ 1347/* We need a backup of the disklabel (xbsd_dlabel might have changed). */
1339 d = &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE]; 1348 d = &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE];
1340 bcopy (d, &dl, sizeof (struct xbsd_disklabel)); 1349 bcopy(d, &dl, sizeof(struct xbsd_disklabel));
1341 1350
1342 /* The disklabel will be overwritten by 0's from bootxx anyway */ 1351/* The disklabel will be overwritten by 0's from bootxx anyway */
1343 memset (d, 0, sizeof (struct xbsd_disklabel)); 1352 memset(d, 0, sizeof(struct xbsd_disklabel));
1344 1353
1345 snprintf (path, sizeof(path), "%s/boot%s", bootdir, dkbasename); 1354 snprintf(path, sizeof(path), "%s/boot%s", bootdir, dkbasename);
1346 if (!xbsd_get_bootstrap (path, &disklabelbuffer[xbsd_dlabel.d_secsize], 1355 if (!xbsd_get_bootstrap (path, &disklabelbuffer[xbsd_dlabel.d_secsize],
1347 (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize)) 1356 (int) xbsd_dlabel.d_bbsize - xbsd_dlabel.d_secsize))
1348 return; 1357 return;
1349 1358
1350 e = d + sizeof (struct xbsd_disklabel); 1359 e = d + sizeof(struct xbsd_disklabel);
1351 for (p=d; p < e; p++) 1360 for (p = d; p < e; p++)
1352 if (*p) { 1361 if (*p) {
1353 fprintf (stderr, _("Bootstrap overlaps with disk label!\n")); 1362 fprintf(stderr, _("Bootstrap overlaps with disk label!\n"));
1354 exit ( EXIT_FAILURE ); 1363 exit(EXIT_FAILURE);
1355 } 1364 }
1356 1365
1357 bcopy (&dl, d, sizeof (struct xbsd_disklabel)); 1366 bcopy(&dl, d, sizeof(struct xbsd_disklabel));
1358 1367
1359#if defined (__powerpc__) || defined (__hppa__) 1368#if defined (__powerpc__) || defined (__hppa__)
1360 sector = 0; 1369 sector = 0;
1361#elif defined (__alpha__) 1370#elif defined (__alpha__)
1362 sector = 0; 1371 sector = 0;
1363 alpha_bootblock_checksum (disklabelbuffer); 1372 alpha_bootblock_checksum(disklabelbuffer);
1364#else 1373#else
1365 sector = get_start_sect(xbsd_part); 1374 sector = get_start_sect(xbsd_part);
1366#endif 1375#endif
1367 1376
1368 if (lseek (fd, sector * SECTOR_SIZE, SEEK_SET) == -1) 1377 if (lseek(fd, sector * SECTOR_SIZE, SEEK_SET) == -1)
1369 fdisk_fatal (unable_to_seek); 1378 fdisk_fatal(unable_to_seek);
1370 if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE)) 1379 if (BSD_BBSIZE != write(fd, disklabelbuffer, BSD_BBSIZE))
1371 fdisk_fatal (unable_to_write); 1380 fdisk_fatal(unable_to_write);
1372 1381
1373#if defined (__alpha__) 1382#if defined (__alpha__)
1374 printf (_("Bootstrap installed on %s.\n"), disk_device); 1383 printf(_("Bootstrap installed on %s.\n"), disk_device);
1375#else 1384#else
1376 printf (_("Bootstrap installed on %s.\n"), 1385 printf(_("Bootstrap installed on %s.\n"),
1377 partname (disk_device, xbsd_part_index+1, 0)); 1386 partname (disk_device, xbsd_part_index+1, 0));
1378#endif 1387#endif
1379 1388
1380 sync_disks (); 1389 sync_disks();
1381} 1390}
1382 1391
1383static void 1392static void
1384xbsd_change_fstype (void) 1393xbsd_change_fstype(void)
1385{ 1394{
1386 int i; 1395 int i;
1387 1396
1388 i = xbsd_get_part_index (xbsd_dlabel.d_npartitions); 1397 i = xbsd_get_part_index(xbsd_dlabel.d_npartitions);
1389 xbsd_dlabel.d_partitions[i].p_fstype = read_hex (xbsd_fstypes); 1398 xbsd_dlabel.d_partitions[i].p_fstype = read_hex(xbsd_fstypes);
1390} 1399}
1391 1400
1392static int 1401static int
1393xbsd_get_part_index (int max) 1402xbsd_get_part_index(int max)
1394{ 1403{
1395 char prompt[256]; 1404 char prompt[256];
1396 char l; 1405 char l;
1397 1406
1398 snprintf (prompt, sizeof(prompt), _("Partition (a-%c): "), 'a' + max - 1); 1407 snprintf(prompt, sizeof(prompt), _("Partition (a-%c): "), 'a' + max - 1);
1399 do 1408 do
1400 l = tolower (read_char (prompt)); 1409 l = tolower(read_char(prompt));
1401 while (l < 'a' || l > 'a' + max - 1); 1410 while (l < 'a' || l > 'a' + max - 1);
1402 return l - 'a'; 1411 return l - 'a';
1403} 1412}
1404 1413
1405static int 1414static int
1406xbsd_check_new_partition (int *i) { 1415xbsd_check_new_partition(int *i)
1407 1416{
1408 /* room for more? various BSD flavours have different maxima */ 1417 /* room for more? various BSD flavours have different maxima */
1409 if (xbsd_dlabel.d_npartitions == BSD_MAXPARTITIONS) { 1418 if (xbsd_dlabel.d_npartitions == BSD_MAXPARTITIONS) {
1410 int t; 1419 int t;
@@ -1414,7 +1423,7 @@ xbsd_check_new_partition (int *i) {
1414 break; 1423 break;
1415 1424
1416 if (t == BSD_MAXPARTITIONS) { 1425 if (t == BSD_MAXPARTITIONS) {
1417 fprintf (stderr, _("The maximum number of partitions " 1426 fprintf(stderr, _("The maximum number of partitions "
1418 "has been created\n")); 1427 "has been created\n"));
1419 return 0; 1428 return 0;
1420 } 1429 }
@@ -1426,7 +1435,7 @@ xbsd_check_new_partition (int *i) {
1426 xbsd_dlabel.d_npartitions = (*i) + 1; 1435 xbsd_dlabel.d_npartitions = (*i) + 1;
1427 1436
1428 if (xbsd_dlabel.d_partitions[*i].p_size != 0) { 1437 if (xbsd_dlabel.d_partitions[*i].p_size != 0) {
1429 fprintf (stderr, _("This partition already exists.\n")); 1438 fprintf(stderr, _("This partition already exists.\n"));
1430 return 0; 1439 return 0;
1431 } 1440 }
1432 1441
@@ -1434,12 +1443,14 @@ xbsd_check_new_partition (int *i) {
1434} 1443}
1435 1444
1436static void 1445static void
1437xbsd_list_types (void) { 1446xbsd_list_types(void)
1438 list_types (xbsd_fstypes); 1447{
1448 list_types(xbsd_fstypes);
1439} 1449}
1440 1450
1441static u_short 1451static u_short
1442xbsd_dkcksum (struct xbsd_disklabel *lp) { 1452xbsd_dkcksum(struct xbsd_disklabel *lp)
1453{
1443 u_short *start, *end; 1454 u_short *start, *end;
1444 u_short sum = 0; 1455 u_short sum = 0;
1445 1456
@@ -1451,67 +1462,68 @@ xbsd_dkcksum (struct xbsd_disklabel *lp) {
1451} 1462}
1452 1463
1453static int 1464static int
1454xbsd_initlabel (struct partition *p, struct xbsd_disklabel *d) { 1465xbsd_initlabel(struct partition *p, struct xbsd_disklabel *d)
1466{
1455 struct xbsd_partition *pp; 1467 struct xbsd_partition *pp;
1456 1468
1457 get_geometry (); 1469 get_geometry();
1458 memset (d, 0, sizeof (struct xbsd_disklabel)); 1470 memset(d, 0, sizeof(struct xbsd_disklabel));
1459 1471
1460 d -> d_magic = BSD_DISKMAGIC; 1472 d->d_magic = BSD_DISKMAGIC;
1461 1473
1462 if (strncmp (disk_device, "/dev/sd", 7) == 0) 1474 if (strncmp(disk_device, "/dev/sd", 7) == 0)
1463 d -> d_type = BSD_DTYPE_SCSI; 1475 d->d_type = BSD_DTYPE_SCSI;
1464 else 1476 else
1465 d -> d_type = BSD_DTYPE_ST506; 1477 d->d_type = BSD_DTYPE_ST506;
1466 1478
1467#if 0 /* not used (at least not written to disk) by NetBSD/i386 1.0 */ 1479#if 0 /* not used (at least not written to disk) by NetBSD/i386 1.0 */
1468 d -> d_subtype = BSD_DSTYPE_INDOSPART & pindex; 1480 d->d_subtype = BSD_DSTYPE_INDOSPART & pindex;
1469#endif 1481#endif
1470 1482
1471#if !defined (__alpha__) 1483#if !defined (__alpha__)
1472 d -> d_flags = BSD_D_DOSPART; 1484 d->d_flags = BSD_D_DOSPART;
1473#else 1485#else
1474 d -> d_flags = 0; 1486 d->d_flags = 0;
1475#endif 1487#endif
1476 d -> d_secsize = SECTOR_SIZE; /* bytes/sector */ 1488 d->d_secsize = SECTOR_SIZE; /* bytes/sector */
1477 d -> d_nsectors = sectors; /* sectors/track */ 1489 d->d_nsectors = sectors; /* sectors/track */
1478 d -> d_ntracks = heads; /* tracks/cylinder (heads) */ 1490 d->d_ntracks = heads; /* tracks/cylinder (heads) */
1479 d -> d_ncylinders = cylinders; 1491 d->d_ncylinders = cylinders;
1480 d -> d_secpercyl = sectors * heads;/* sectors/cylinder */ 1492 d->d_secpercyl = sectors * heads;/* sectors/cylinder */
1481 if (d -> d_secpercyl == 0) 1493 if (d->d_secpercyl == 0)
1482 d -> d_secpercyl = 1; /* avoid segfaults */ 1494 d->d_secpercyl = 1; /* avoid segfaults */
1483 d -> d_secperunit = d -> d_secpercyl * d -> d_ncylinders; 1495 d->d_secperunit = d->d_secpercyl * d->d_ncylinders;
1484 1496
1485 d -> d_rpm = 3600; 1497 d->d_rpm = 3600;
1486 d -> d_interleave = 1; 1498 d->d_interleave = 1;
1487 d -> d_trackskew = 0; 1499 d->d_trackskew = 0;
1488 d -> d_cylskew = 0; 1500 d->d_cylskew = 0;
1489 d -> d_headswitch = 0; 1501 d->d_headswitch = 0;
1490 d -> d_trkseek = 0; 1502 d->d_trkseek = 0;
1491 1503
1492 d -> d_magic2 = BSD_DISKMAGIC; 1504 d->d_magic2 = BSD_DISKMAGIC;
1493 d -> d_bbsize = BSD_BBSIZE; 1505 d->d_bbsize = BSD_BBSIZE;
1494 d -> d_sbsize = BSD_SBSIZE; 1506 d->d_sbsize = BSD_SBSIZE;
1495 1507
1496#if !defined (__alpha__) 1508#if !defined (__alpha__)
1497 d -> d_npartitions = 4; 1509 d->d_npartitions = 4;
1498 pp = &d -> d_partitions[2]; /* Partition C should be 1510 pp = &d->d_partitions[2]; /* Partition C should be
1499 the NetBSD partition */ 1511 the NetBSD partition */
1500 pp -> p_offset = get_start_sect(p); 1512 pp->p_offset = get_start_sect(p);
1501 pp -> p_size = get_nr_sects(p); 1513 pp->p_size = get_nr_sects(p);
1502 pp -> p_fstype = BSD_FS_UNUSED; 1514 pp->p_fstype = BSD_FS_UNUSED;
1503 pp = &d -> d_partitions[3]; /* Partition D should be 1515 pp = &d->d_partitions[3]; /* Partition D should be
1504 the whole disk */ 1516 the whole disk */
1505 pp -> p_offset = 0; 1517 pp->p_offset = 0;
1506 pp -> p_size = d -> d_secperunit; 1518 pp->p_size = d->d_secperunit;
1507 pp -> p_fstype = BSD_FS_UNUSED; 1519 pp->p_fstype = BSD_FS_UNUSED;
1508#elif defined (__alpha__) 1520#elif defined (__alpha__)
1509 d -> d_npartitions = 3; 1521 d->d_npartitions = 3;
1510 pp = &d -> d_partitions[2]; /* Partition C should be 1522 pp = &d->d_partitions[2]; /* Partition C should be
1511 the whole disk */ 1523 the whole disk */
1512 pp -> p_offset = 0; 1524 pp->p_offset = 0;
1513 pp -> p_size = d -> d_secperunit; 1525 pp->p_size = d->d_secperunit;
1514 pp -> p_fstype = BSD_FS_UNUSED; 1526 pp->p_fstype = BSD_FS_UNUSED;
1515#endif 1527#endif
1516 1528
1517 return 1; 1529 return 1;
@@ -1533,106 +1545,102 @@ xbsd_readlabel (struct partition *p, struct xbsd_disklabel *d)
1533 sector = 0; 1545 sector = 0;
1534#endif 1546#endif
1535 1547
1536 if (lseek (fd, sector * SECTOR_SIZE, SEEK_SET) == -1) 1548 if (lseek(fd, sector * SECTOR_SIZE, SEEK_SET) == -1)
1537 fdisk_fatal (unable_to_seek); 1549 fdisk_fatal(unable_to_seek);
1538 if (BSD_BBSIZE != read (fd, disklabelbuffer, BSD_BBSIZE)) 1550 if (BSD_BBSIZE != read(fd, disklabelbuffer, BSD_BBSIZE))
1539 fdisk_fatal (unable_to_read); 1551 fdisk_fatal(unable_to_read);
1540 1552
1541 bcopy (&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], 1553 bcopy(&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
1542 d, sizeof (struct xbsd_disklabel)); 1554 d, sizeof(struct xbsd_disklabel));
1543 1555
1544 if (d -> d_magic != BSD_DISKMAGIC || d -> d_magic2 != BSD_DISKMAGIC) 1556 if (d->d_magic != BSD_DISKMAGIC || d->d_magic2 != BSD_DISKMAGIC)
1545 return 0; 1557 return 0;
1546 1558
1547 for (t = d -> d_npartitions; t < BSD_MAXPARTITIONS; t++) { 1559 for (t = d->d_npartitions; t < BSD_MAXPARTITIONS; t++) {
1548 d -> d_partitions[t].p_size = 0; 1560 d->d_partitions[t].p_size = 0;
1549 d -> d_partitions[t].p_offset = 0; 1561 d->d_partitions[t].p_offset = 0;
1550 d -> d_partitions[t].p_fstype = BSD_FS_UNUSED; 1562 d->d_partitions[t].p_fstype = BSD_FS_UNUSED;
1551 } 1563 }
1552 1564
1553 if (d -> d_npartitions > BSD_MAXPARTITIONS) 1565 if (d->d_npartitions > BSD_MAXPARTITIONS)
1554 fprintf (stderr, _("Warning: too many partitions " 1566 fprintf(stderr, _("Warning: too many partitions "
1555 "(%d, maximum is %d).\n"), 1567 "(%d, maximum is %d).\n"),
1556 d -> d_npartitions, BSD_MAXPARTITIONS); 1568 d->d_npartitions, BSD_MAXPARTITIONS);
1557 return 1; 1569 return 1;
1558} 1570}
1559 1571
1560static int 1572static int
1561xbsd_writelabel (struct partition *p, struct xbsd_disklabel *d) 1573xbsd_writelabel (struct partition *p, struct xbsd_disklabel *d)
1562{ 1574{
1563 unsigned int sector; 1575 unsigned int sector;
1564 1576
1565#if !defined (__alpha__) && !defined (__powerpc__) && !defined (__hppa__) 1577#if !defined (__alpha__) && !defined (__powerpc__) && !defined (__hppa__)
1566 sector = get_start_sect(p) + BSD_LABELSECTOR; 1578 sector = get_start_sect(p) + BSD_LABELSECTOR;
1567#else 1579#else
1568 sector = BSD_LABELSECTOR; 1580 sector = BSD_LABELSECTOR;
1569#endif 1581#endif
1570 1582
1571 d -> d_checksum = 0; 1583 d->d_checksum = 0;
1572 d -> d_checksum = xbsd_dkcksum (d); 1584 d->d_checksum = xbsd_dkcksum (d);
1573 1585
1574 /* This is necessary if we want to write the bootstrap later, 1586 /* This is necessary if we want to write the bootstrap later,
1575 otherwise we'd write the old disklabel with the bootstrap. 1587 otherwise we'd write the old disklabel with the bootstrap.
1576 */ 1588 */
1577 bcopy (d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], 1589 bcopy(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
1578 sizeof (struct xbsd_disklabel)); 1590 sizeof(struct xbsd_disklabel));
1579 1591
1580#if defined (__alpha__) && BSD_LABELSECTOR == 0 1592#if defined (__alpha__) && BSD_LABELSECTOR == 0
1581 alpha_bootblock_checksum (disklabelbuffer); 1593 alpha_bootblock_checksum (disklabelbuffer);
1582 if (lseek (fd, 0, SEEK_SET) == -1) 1594 if (lseek(fd, 0, SEEK_SET) == -1)
1583 fdisk_fatal (unable_to_seek); 1595 fdisk_fatal(unable_to_seek);
1584 if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE)) 1596 if (BSD_BBSIZE != write(fd, disklabelbuffer, BSD_BBSIZE))
1585 fdisk_fatal (unable_to_write); 1597 fdisk_fatal(unable_to_write);
1586#else 1598#else
1587 if (lseek (fd, sector * SECTOR_SIZE + BSD_LABELOFFSET, 1599 if (lseek(fd, sector * SECTOR_SIZE + BSD_LABELOFFSET, SEEK_SET) == -1)
1588 SEEK_SET) == -1) 1600 fdisk_fatal(unable_to_seek);
1589 fdisk_fatal (unable_to_seek); 1601 if (sizeof(struct xbsd_disklabel) != write(fd, d, sizeof(struct xbsd_disklabel)))
1590 if (sizeof (struct xbsd_disklabel) != write (fd, d, sizeof (struct xbsd_disklabel))) 1602 fdisk_fatal(unable_to_write);
1591 fdisk_fatal (unable_to_write);
1592#endif 1603#endif
1593 1604 sync_disks();
1594 sync_disks (); 1605 return 1;
1595
1596 return 1;
1597} 1606}
1598 1607
1599 1608
1600#if !defined (__alpha__) 1609#if !defined (__alpha__)
1601static int 1610static int
1602xbsd_translate_fstype (int linux_type) 1611xbsd_translate_fstype(int linux_type)
1603{ 1612{
1604 switch (linux_type) 1613 switch (linux_type) {
1605 { 1614 case 0x01: /* DOS 12-bit FAT */
1606 case 0x01: /* DOS 12-bit FAT */ 1615 case 0x04: /* DOS 16-bit <32M */
1607 case 0x04: /* DOS 16-bit <32M */ 1616 case 0x06: /* DOS 16-bit >=32M */
1608 case 0x06: /* DOS 16-bit >=32M */ 1617 case 0xe1: /* DOS access */
1609 case 0xe1: /* DOS access */ 1618 case 0xe3: /* DOS R/O */
1610 case 0xe3: /* DOS R/O */ 1619 case 0xf2: /* DOS secondary */
1611 case 0xf2: /* DOS secondary */ 1620 return BSD_FS_MSDOS;
1612 return BSD_FS_MSDOS; 1621 case 0x07: /* OS/2 HPFS */
1613 case 0x07: /* OS/2 HPFS */ 1622 return BSD_FS_HPFS;
1614 return BSD_FS_HPFS; 1623 default:
1615 default: 1624 return BSD_FS_OTHER;
1616 return BSD_FS_OTHER; 1625 }
1617 }
1618} 1626}
1619 1627
1620static void 1628static void
1621xbsd_link_part (void) 1629xbsd_link_part(void)
1622{ 1630{
1623 int k, i; 1631 int k, i;
1624 struct partition *p; 1632 struct partition *p;
1625 1633
1626 k = get_partition (1, partitions); 1634 k = get_partition(1, partitions);
1627 1635
1628 if (!xbsd_check_new_partition (&i)) 1636 if (!xbsd_check_new_partition(&i))
1629 return; 1637 return;
1630 1638
1631 p = get_part_table(k); 1639 p = get_part_table(k);
1632 1640
1633 xbsd_dlabel.d_partitions[i].p_size = get_nr_sects(p); 1641 xbsd_dlabel.d_partitions[i].p_size = get_nr_sects(p);
1634 xbsd_dlabel.d_partitions[i].p_offset = get_start_sect(p); 1642 xbsd_dlabel.d_partitions[i].p_offset = get_start_sect(p);
1635 xbsd_dlabel.d_partitions[i].p_fstype = xbsd_translate_fstype(p->sys_ind); 1643 xbsd_dlabel.d_partitions[i].p_fstype = xbsd_translate_fstype(p->sys_ind);
1636} 1644}
1637#endif 1645#endif
1638 1646
@@ -1643,16 +1651,16 @@ typedef unsigned long long uint64_t;
1643#endif 1651#endif
1644 1652
1645static void 1653static void
1646alpha_bootblock_checksum (char *boot) 1654alpha_bootblock_checksum(char *boot)
1647{ 1655{
1648 uint64_t *dp, sum; 1656 uint64_t *dp, sum;
1649 int i; 1657 int i;
1650 1658
1651 dp = (uint64_t *)boot; 1659 dp = (uint64_t *)boot;
1652 sum = 0; 1660 sum = 0;
1653 for (i = 0; i < 63; i++) 1661 for (i = 0; i < 63; i++)
1654 sum += dp[i]; 1662 sum += dp[i];
1655 dp[63] = sum; 1663 dp[63] = sum;
1656} 1664}
1657#endif /* __alpha__ */ 1665#endif /* __alpha__ */
1658 1666
@@ -1660,13 +1668,15 @@ alpha_bootblock_checksum (char *boot)
1660 1668
1661#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL) 1669#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL)
1662static inline unsigned short 1670static inline unsigned short
1663__swap16(unsigned short x) { 1671__swap16(unsigned short x)
1672{
1664 return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8); 1673 return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8);
1665} 1674}
1666 1675
1667static inline uint32_t 1676static inline uint32_t
1668__swap32(uint32_t x) { 1677__swap32(uint32_t x)
1669 return (((x & 0xFF) << 24) | 1678{
1679 return (((x & 0xFF) << 24) |
1670 ((x & 0xFF00) << 8) | 1680 ((x & 0xFF00) << 8) |
1671 ((x & 0xFF0000) >> 8) | 1681 ((x & 0xFF0000) >> 8) |
1672 ((x & 0xFF000000) >> 24)); 1682 ((x & 0xFF000000) >> 24));
@@ -1687,34 +1697,40 @@ __swap32(uint32_t x) {
1687 */ 1697 */
1688 1698
1689 1699
1690static int sgi_other_endian; 1700static int sgi_other_endian;
1691static int debug; 1701static int debug;
1692static short sgi_volumes=1; 1702static short sgi_volumes = 1;
1693 1703
1694/* 1704/*
1695 * only dealing with free blocks here 1705 * only dealing with free blocks here
1696 */ 1706 */
1697 1707
1698typedef struct { unsigned int first; unsigned int last; } freeblocks; 1708typedef struct {
1709 unsigned int first;
1710 unsigned int last;
1711} freeblocks;
1699static freeblocks freelist[17]; /* 16 partitions can produce 17 vacant slots */ 1712static freeblocks freelist[17]; /* 16 partitions can produce 17 vacant slots */
1700 1713
1701static void 1714static void
1702setfreelist(int i, unsigned int f, unsigned int l) { 1715setfreelist(int i, unsigned int f, unsigned int l)
1716{
1703 freelist[i].first = f; 1717 freelist[i].first = f;
1704 freelist[i].last = l; 1718 freelist[i].last = l;
1705} 1719}
1706 1720
1707static void 1721static void
1708add2freelist(unsigned int f, unsigned int l) { 1722add2freelist(unsigned int f, unsigned int l)
1709 int i = 0; 1723{
1710 for ( ; i < 17 ; i++) 1724 int i;
1725 for (i = 0; i < 17 ; i++)
1711 if (freelist[i].last == 0) 1726 if (freelist[i].last == 0)
1712 break; 1727 break;
1713 setfreelist(i, f, l); 1728 setfreelist(i, f, l);
1714} 1729}
1715 1730
1716static void 1731static void
1717clearfreelist(void) { 1732clearfreelist(void)
1733{
1718 int i; 1734 int i;
1719 1735
1720 for (i = 0; i < 17 ; i++) 1736 for (i = 0; i < 17 ; i++)
@@ -1722,7 +1738,8 @@ clearfreelist(void) {
1722} 1738}
1723 1739
1724static unsigned int 1740static unsigned int
1725isinfreelist(unsigned int b) { 1741isinfreelist(unsigned int b)
1742{
1726 int i; 1743 int i;
1727 1744
1728 for (i = 0; i < 17 ; i++) 1745 for (i = 0; i < 17 ; i++)
@@ -1737,701 +1754,715 @@ isinfreelist(unsigned int b) {
1737 */ 1754 */
1738 1755
1739static const struct systypes sgi_sys_types[] = { 1756static const struct systypes sgi_sys_types[] = {
1740/* SGI_VOLHDR */ {"\x00" "SGI volhdr" }, 1757/* SGI_VOLHDR */ { "\x00" "SGI volhdr" },
1741/* 0x01 */ {"\x01" "SGI trkrepl" }, 1758/* 0x01 */ { "\x01" "SGI trkrepl" },
1742/* 0x02 */ {"\x02" "SGI secrepl" }, 1759/* 0x02 */ { "\x02" "SGI secrepl" },
1743/* SGI_SWAP */ {"\x03" "SGI raw" }, 1760/* SGI_SWAP */ { "\x03" "SGI raw" },
1744/* 0x04 */ {"\x04" "SGI bsd" }, 1761/* 0x04 */ { "\x04" "SGI bsd" },
1745/* 0x05 */ {"\x05" "SGI sysv" }, 1762/* 0x05 */ { "\x05" "SGI sysv" },
1746/* ENTIRE_DISK */ {"\x06" "SGI volume" }, 1763/* ENTIRE_DISK */ { "\x06" "SGI volume" },
1747/* SGI_EFS */ {"\x07" "SGI efs" }, 1764/* SGI_EFS */ { "\x07" "SGI efs" },
1748/* 0x08 */ {"\x08" "SGI lvol" }, 1765/* 0x08 */ { "\x08" "SGI lvol" },
1749/* 0x09 */ {"\x09" "SGI rlvol" }, 1766/* 0x09 */ { "\x09" "SGI rlvol" },
1750/* SGI_XFS */ {"\x0a" "SGI xfs" }, 1767/* SGI_XFS */ { "\x0a" "SGI xfs" },
1751/* SGI_XFSLOG */ {"\x0b" "SGI xfslog" }, 1768/* SGI_XFSLOG */ { "\x0b" "SGI xfslog" },
1752/* SGI_XLV */ {"\x0c" "SGI xlv" }, 1769/* SGI_XLV */ { "\x0c" "SGI xlv" },
1753/* SGI_XVM */ {"\x0d" "SGI xvm" }, 1770/* SGI_XVM */ { "\x0d" "SGI xvm" },
1754/* LINUX_SWAP */ {"\x82" "Linux swap" }, 1771/* LINUX_SWAP */ { "\x82" "Linux swap" },
1755/* LINUX_NATIVE */ {"\x83" "Linux native" }, 1772/* LINUX_NATIVE */ { "\x83" "Linux native" },
1756/* LINUX_LVM */ {"\x8d" "Linux LVM" }, 1773/* LINUX_LVM */ { "\x8d" "Linux LVM" },
1757/* LINUX_RAID */ {"\xfd" "Linux RAID" }, 1774/* LINUX_RAID */ { "\xfd" "Linux RAID" },
1758 { NULL } 1775 { NULL }
1759}; 1776};
1760 1777
1761 1778
1762static int 1779static int
1763sgi_get_nsect(void) { 1780sgi_get_nsect(void)
1764 return SGI_SSWAP16(sgilabel->devparam.nsect); 1781{
1782 return SGI_SSWAP16(sgilabel->devparam.nsect);
1765} 1783}
1766 1784
1767static int 1785static int
1768sgi_get_ntrks(void) { 1786sgi_get_ntrks(void)
1769 return SGI_SSWAP16(sgilabel->devparam.ntrks); 1787{
1788 return SGI_SSWAP16(sgilabel->devparam.ntrks);
1770} 1789}
1771 1790
1772static void 1791static void
1773sgi_nolabel(void) { 1792sgi_nolabel(void)
1774 sgilabel->magic = 0; 1793{
1775 sgi_label = 0; 1794 sgilabel->magic = 0;
1776 partitions = 4; 1795 sgi_label = 0;
1796 partitions = 4;
1777} 1797}
1778 1798
1779static unsigned int 1799static unsigned int
1780two_s_complement_32bit_sum(unsigned int* base, int size /* in bytes */) { 1800two_s_complement_32bit_sum(unsigned int* base, int size /* in bytes */)
1781 int i=0; 1801{
1782 unsigned int sum=0; 1802 int i = 0;
1803 unsigned int sum = 0;
1783 1804
1784 size /= sizeof(unsigned int); 1805 size /= sizeof(unsigned int);
1785 for (i = 0; i < size; i++) 1806 for (i = 0; i < size; i++)
1786 sum -= SGI_SSWAP32(base[i]); 1807 sum -= SGI_SSWAP32(base[i]);
1787 return sum; 1808 return sum;
1788} 1809}
1789 1810
1790static int 1811static int
1791check_sgi_label(void) { 1812check_sgi_label(void)
1792 if (sizeof(sgilabel) > 512) { 1813{
1793 fprintf(stderr, 1814 if (sizeof(sgilabel) > 512) {
1794 _("According to MIPS Computer Systems, Inc the " 1815 fprintf(stderr,
1795 "Label must not contain more than 512 bytes\n")); 1816 _("According to MIPS Computer Systems, Inc the "
1796 exit(1); 1817 "Label must not contain more than 512 bytes\n"));
1797 } 1818 exit(1);
1798 1819 }
1799 if (sgilabel->magic != SGI_LABEL_MAGIC && 1820
1800 sgilabel->magic != SGI_LABEL_MAGIC_SWAPPED) { 1821 if (sgilabel->magic != SGI_LABEL_MAGIC
1801 sgi_label = 0; 1822 && sgilabel->magic != SGI_LABEL_MAGIC_SWAPPED) {
1802 sgi_other_endian = 0; 1823 sgi_label = 0;
1803 return 0; 1824 sgi_other_endian = 0;
1804 } 1825 return 0;
1805 1826 }
1806 sgi_other_endian = (sgilabel->magic == SGI_LABEL_MAGIC_SWAPPED); 1827
1807 /* 1828 sgi_other_endian = (sgilabel->magic == SGI_LABEL_MAGIC_SWAPPED);
1808 * test for correct checksum 1829 /*
1809 */ 1830 * test for correct checksum
1810 if (two_s_complement_32bit_sum((unsigned int*)sgilabel, 1831 */
1811 sizeof(*sgilabel))) { 1832 if (two_s_complement_32bit_sum((unsigned int*)sgilabel,
1833 sizeof(*sgilabel))) {
1812 fprintf(stderr, 1834 fprintf(stderr,
1813 _("Detected sgi disklabel with wrong checksum.\n")); 1835 _("Detected sgi disklabel with wrong checksum.\n"));
1814 } 1836 }
1815 update_units(); 1837 update_units();
1816 sgi_label = 1; 1838 sgi_label = 1;
1817 partitions= 16; 1839 partitions = 16;
1818 sgi_volumes = 15; 1840 sgi_volumes = 15;
1819 return 1; 1841 return 1;
1820} 1842}
1821 1843
1822static unsigned int 1844static unsigned int
1823sgi_get_start_sector(int i) { 1845sgi_get_start_sector(int i)
1824 return SGI_SSWAP32(sgilabel->partitions[i].start_sector); 1846{
1847 return SGI_SSWAP32(sgilabel->partitions[i].start_sector);
1825} 1848}
1826 1849
1827static unsigned int 1850static unsigned int
1828sgi_get_num_sectors(int i) { 1851sgi_get_num_sectors(int i)
1829 return SGI_SSWAP32(sgilabel->partitions[i].num_sectors); 1852{
1853 return SGI_SSWAP32(sgilabel->partitions[i].num_sectors);
1830} 1854}
1831 1855
1832static int 1856static int
1833sgi_get_sysid(int i) 1857sgi_get_sysid(int i)
1834{ 1858{
1835 return SGI_SSWAP32(sgilabel->partitions[i].id); 1859 return SGI_SSWAP32(sgilabel->partitions[i].id);
1836} 1860}
1837 1861
1838static int 1862static int
1839sgi_get_bootpartition(void) 1863sgi_get_bootpartition(void)
1840{ 1864{
1841 return SGI_SSWAP16(sgilabel->boot_part); 1865 return SGI_SSWAP16(sgilabel->boot_part);
1842} 1866}
1843 1867
1844static int 1868static int
1845sgi_get_swappartition(void) 1869sgi_get_swappartition(void)
1846{ 1870{
1847 return SGI_SSWAP16(sgilabel->swap_part); 1871 return SGI_SSWAP16(sgilabel->swap_part);
1848} 1872}
1849 1873
1850static void 1874static void
1851sgi_list_table(int xtra) { 1875sgi_list_table(int xtra)
1852 int i, w, wd; 1876{
1853 int kpi = 0; /* kernel partition ID */ 1877 int i, w, wd;
1854 1878 int kpi = 0; /* kernel partition ID */
1855 if(xtra) { 1879
1856 printf(_("\nDisk %s (SGI disk label): %d heads, %d sectors\n" 1880 if(xtra) {
1857 "%d cylinders, %d physical cylinders\n" 1881 printf(_("\nDisk %s (SGI disk label): %d heads, %d sectors\n"
1858 "%d extra sects/cyl, interleave %d:1\n" 1882 "%d cylinders, %d physical cylinders\n"
1859 "%s\n" 1883 "%d extra sects/cyl, interleave %d:1\n"
1860 "Units = %s of %d * 512 bytes\n\n"), 1884 "%s\n"
1861 disk_device, heads, sectors, cylinders, 1885 "Units = %s of %d * 512 bytes\n\n"),
1862 SGI_SSWAP16(sgiparam.pcylcount), 1886 disk_device, heads, sectors, cylinders,
1863 SGI_SSWAP16(sgiparam.sparecyl), 1887 SGI_SSWAP16(sgiparam.pcylcount),
1864 SGI_SSWAP16(sgiparam.ilfact), 1888 SGI_SSWAP16(sgiparam.sparecyl),
1865 (char *)sgilabel, 1889 SGI_SSWAP16(sgiparam.ilfact),
1866 str_units(PLURAL), units_per_sector); 1890 (char *)sgilabel,
1867 } else { 1891 str_units(PLURAL), units_per_sector);
1868 printf( _("\nDisk %s (SGI disk label): " 1892 } else {
1869 "%d heads, %d sectors, %d cylinders\n" 1893 printf( _("\nDisk %s (SGI disk label): "
1870 "Units = %s of %d * 512 bytes\n\n"), 1894 "%d heads, %d sectors, %d cylinders\n"
1871 disk_device, heads, sectors, cylinders, 1895 "Units = %s of %d * 512 bytes\n\n"),
1872 str_units(PLURAL), units_per_sector ); 1896 disk_device, heads, sectors, cylinders,
1873 } 1897 str_units(PLURAL), units_per_sector );
1898 }
1874 1899
1875 w = strlen(disk_device); 1900 w = strlen(disk_device);
1876 wd = strlen(_("Device")); 1901 wd = strlen(_("Device"));
1877 if (w < wd) 1902 if (w < wd)
1878 w = wd; 1903 w = wd;
1879 1904
1880 printf(_("----- partitions -----\n" 1905 printf(_("----- partitions -----\n"
1881 "Pt# %*s Info Start End Sectors Id System\n"), 1906 "Pt# %*s Info Start End Sectors Id System\n"),
1882 w + 2, _("Device")); 1907 w + 2, _("Device"));
1883 for (i = 0 ; i < partitions; i++) { 1908 for (i = 0 ; i < partitions; i++) {
1884 if( sgi_get_num_sectors(i) || debug ) { 1909 if( sgi_get_num_sectors(i) || debug ) {
1885 uint32_t start = sgi_get_start_sector(i); 1910 uint32_t start = sgi_get_start_sector(i);
1886 uint32_t len = sgi_get_num_sectors(i); 1911 uint32_t len = sgi_get_num_sectors(i);
1887 kpi++; /* only count nonempty partitions */ 1912 kpi++; /* only count nonempty partitions */
1888 printf( 1913 printf(
1889 "%2d: %s %4s %9ld %9ld %9ld %2x %s\n", 1914 "%2d: %s %4s %9ld %9ld %9ld %2x %s\n",
1890/* fdisk part number */ i+1, 1915/* fdisk part number */ i+1,
1891/* device */ partname(disk_device, kpi, w+3), 1916/* device */ partname(disk_device, kpi, w+3),
1892/* flags */ (sgi_get_swappartition() == i) ? "swap" : 1917/* flags */ (sgi_get_swappartition() == i) ? "swap" :
1893/* flags */ (sgi_get_bootpartition() == i) ? "boot" : " ", 1918/* flags */ (sgi_get_bootpartition() == i) ? "boot" : " ",
1894/* start */ (long) scround(start), 1919/* start */ (long) scround(start),
1895/* end */ (long) scround(start+len)-1, 1920/* end */ (long) scround(start+len)-1,
1896/* no odd flag on end */ (long) len, 1921/* no odd flag on end */(long) len,
1897/* type id */ sgi_get_sysid(i), 1922/* type id */ sgi_get_sysid(i),
1898/* type name */ partition_type(sgi_get_sysid(i))); 1923/* type name */ partition_type(sgi_get_sysid(i)));
1899 } 1924 }
1900 } 1925 }
1901 printf(_("----- Bootinfo -----\nBootfile: %s\n" 1926 printf(_("----- Bootinfo -----\nBootfile: %s\n"
1902 "----- Directory Entries -----\n"), 1927 "----- Directory Entries -----\n"),
1903 sgilabel->boot_file); 1928 sgilabel->boot_file);
1904 for (i = 0 ; i < sgi_volumes; i++) { 1929 for (i = 0 ; i < sgi_volumes; i++) {
1905 if (sgilabel->directory[i].vol_file_size) { 1930 if (sgilabel->directory[i].vol_file_size) {
1906 uint32_t start = SGI_SSWAP32(sgilabel->directory[i].vol_file_start); 1931 uint32_t start = SGI_SSWAP32(sgilabel->directory[i].vol_file_start);
1907 uint32_t len = SGI_SSWAP32(sgilabel->directory[i].vol_file_size); 1932 uint32_t len = SGI_SSWAP32(sgilabel->directory[i].vol_file_size);
1908 unsigned char*name = sgilabel->directory[i].vol_file_name; 1933 unsigned char *name = sgilabel->directory[i].vol_file_name;
1909 1934
1910 printf(_("%2d: %-10s sector%5u size%8u\n"), 1935 printf(_("%2d: %-10s sector%5u size%8u\n"),
1911 i, (char*)name, (unsigned int) start, (unsigned int) len); 1936 i, (char*)name, (unsigned int) start, (unsigned int) len);
1937 }
1912 } 1938 }
1913 }
1914} 1939}
1915 1940
1916static void 1941static void
1917sgi_set_bootpartition( int i ) 1942sgi_set_bootpartition(int i)
1918{ 1943{
1919 sgilabel->boot_part = SGI_SSWAP16(((short)i)); 1944 sgilabel->boot_part = SGI_SSWAP16(((short)i));
1920} 1945}
1921 1946
1922static unsigned int 1947static unsigned int
1923sgi_get_lastblock(void) { 1948sgi_get_lastblock(void)
1924 return heads * sectors * cylinders; 1949{
1950 return heads * sectors * cylinders;
1925} 1951}
1926 1952
1927static void 1953static void
1928sgi_set_swappartition( int i ) { 1954sgi_set_swappartition(int i)
1929 sgilabel->swap_part = SGI_SSWAP16(((short)i)); 1955{
1956 sgilabel->swap_part = SGI_SSWAP16(((short)i));
1930} 1957}
1931 1958
1932static int 1959static int
1933sgi_check_bootfile(const char* aFile) { 1960sgi_check_bootfile(const char* aFile)
1934 1961{
1935 if (strlen(aFile) < 3) /* "/a\n" is minimum */ { 1962 if (strlen(aFile) < 3) /* "/a\n" is minimum */ {
1936 printf(_("\nInvalid Bootfile!\n" 1963 printf(_("\nInvalid Bootfile!\n"
1937 "\tThe bootfile must be an absolute non-zero pathname,\n" 1964 "\tThe bootfile must be an absolute non-zero pathname,\n"
1938 "\te.g. \"/unix\" or \"/unix.save\".\n")); 1965 "\te.g. \"/unix\" or \"/unix.save\".\n"));
1939 return 0; 1966 return 0;
1940 } else { 1967 } else {
1941 if (strlen(aFile) > 16) { 1968 if (strlen(aFile) > 16) {
1942 printf(_("\n\tName of Bootfile too long: " 1969 printf(_("\n\tName of Bootfile too long: "
1943 "16 bytes maximum.\n")); 1970 "16 bytes maximum.\n"));
1944 return 0; 1971 return 0;
1945 } else { 1972 } else {
1946 if (aFile[0] != '/') { 1973 if (aFile[0] != '/') {
1947 printf(_("\n\tBootfile must have a " 1974 printf(_("\n\tBootfile must have a "
1948 "fully qualified pathname.\n")); 1975 "fully qualified pathname.\n"));
1949 return 0; 1976 return 0;
1950 } 1977 }
1951 } 1978 }
1952 } 1979 }
1953 if (strncmp(aFile, (char*)sgilabel->boot_file, 16)) { 1980 if (strncmp(aFile, (char*)sgilabel->boot_file, 16)) {
1954 printf(_("\n\tBe aware, that the bootfile is not checked for existence.\n\t" 1981 printf(_("\n\tBe aware, that the bootfile is not checked for existence.\n\t"
1955 "SGI's default is \"/unix\" and for backup \"/unix.save\".\n")); 1982 "SGI's default is \"/unix\" and for backup \"/unix.save\".\n"));
1956 /* filename is correct and did change */ 1983 /* filename is correct and did change */
1957 return 1; 1984 return 1;
1958 } 1985 }
1959 return 0; /* filename did not change */ 1986 return 0; /* filename did not change */
1960} 1987}
1961 1988
1962static const char * 1989static const char *
1963sgi_get_bootfile(void) { 1990sgi_get_bootfile(void)
1991{
1964 return (char*)sgilabel->boot_file; 1992 return (char*)sgilabel->boot_file;
1965} 1993}
1966 1994
1967static void 1995static void
1968sgi_set_bootfile(const char* aFile) { 1996sgi_set_bootfile(const char* aFile)
1969 int i = 0; 1997{
1998 int i = 0;
1970 1999
1971 if (sgi_check_bootfile(aFile)) { 2000 if (sgi_check_bootfile(aFile)) {
1972 while (i < 16) { 2001 while (i < 16) {
1973 if ((aFile[i] != '\n') /* in principle caught again by next line */ 2002 if ((aFile[i] != '\n') /* in principle caught again by next line */
1974 && (strlen(aFile) > i)) 2003 && (strlen(aFile) > i))
1975 sgilabel->boot_file[i] = aFile[i]; 2004 sgilabel->boot_file[i] = aFile[i];
1976 else 2005 else
1977 sgilabel->boot_file[i] = 0; 2006 sgilabel->boot_file[i] = 0;
1978 i++; 2007 i++;
2008 }
2009 printf(_("\n\tBootfile is changed to \"%s\".\n"), sgilabel->boot_file);
1979 } 2010 }
1980 printf(_("\n\tBootfile is changed to \"%s\".\n"), sgilabel->boot_file);
1981 }
1982} 2011}
1983 2012
1984static void 2013static void
1985create_sgiinfo(void) 2014create_sgiinfo(void)
1986{ 2015{
1987 /* I keep SGI's habit to write the sgilabel to the second block */ 2016 /* I keep SGI's habit to write the sgilabel to the second block */
1988 sgilabel->directory[0].vol_file_start = SGI_SSWAP32(2); 2017 sgilabel->directory[0].vol_file_start = SGI_SSWAP32(2);
1989 sgilabel->directory[0].vol_file_size = SGI_SSWAP32(sizeof(sgiinfo)); 2018 sgilabel->directory[0].vol_file_size = SGI_SSWAP32(sizeof(sgiinfo));
1990 strncpy((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8); 2019 strncpy((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8);
1991} 2020}
1992 2021
1993static sgiinfo *fill_sgiinfo(void); 2022static sgiinfo *fill_sgiinfo(void);
1994 2023
1995static void 2024static void
1996sgi_write_table(void) { 2025sgi_write_table(void)
1997 sgilabel->csum = 0; 2026{
1998 sgilabel->csum = SGI_SSWAP32(two_s_complement_32bit_sum( 2027 sgilabel->csum = 0;
1999 (unsigned int*)sgilabel, 2028 sgilabel->csum = SGI_SSWAP32(two_s_complement_32bit_sum(
2000 sizeof(*sgilabel))); 2029 (unsigned int*)sgilabel, sizeof(*sgilabel)));
2001 assert(two_s_complement_32bit_sum( 2030 assert(two_s_complement_32bit_sum(
2002 (unsigned int*)sgilabel, sizeof(*sgilabel)) == 0); 2031 (unsigned int*)sgilabel, sizeof(*sgilabel)) == 0);
2003 if (lseek(fd, 0, SEEK_SET) < 0) 2032
2004 fdisk_fatal(unable_to_seek); 2033 if (lseek(fd, 0, SEEK_SET) < 0)
2005 if (write(fd, sgilabel, SECTOR_SIZE) != SECTOR_SIZE) 2034 fdisk_fatal(unable_to_seek);
2006 fdisk_fatal(unable_to_write); 2035 if (write(fd, sgilabel, SECTOR_SIZE) != SECTOR_SIZE)
2007 if (! strncmp((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8)) { 2036 fdisk_fatal(unable_to_write);
2008 /* 2037 if (!strncmp((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8)) {
2009 * keep this habit of first writing the "sgilabel". 2038 /*
2010 * I never tested whether it works without (AN 981002). 2039 * keep this habit of first writing the "sgilabel".
2011 */ 2040 * I never tested whether it works without (AN 981002).
2012 sgiinfo *info = fill_sgiinfo(); 2041 */
2013 int infostartblock = SGI_SSWAP32(sgilabel->directory[0].vol_file_start); 2042 sgiinfo *info = fill_sgiinfo();
2014 if (lseek(fd, infostartblock*SECTOR_SIZE, SEEK_SET) < 0) 2043 int infostartblock = SGI_SSWAP32(sgilabel->directory[0].vol_file_start);
2015 fdisk_fatal(unable_to_seek); 2044 if (lseek(fd, infostartblock*SECTOR_SIZE, SEEK_SET) < 0)
2016 if (write(fd, info, SECTOR_SIZE) != SECTOR_SIZE) 2045 fdisk_fatal(unable_to_seek);
2017 fdisk_fatal(unable_to_write); 2046 if (write(fd, info, SECTOR_SIZE) != SECTOR_SIZE)
2018 free(info); 2047 fdisk_fatal(unable_to_write);
2019 } 2048 free(info);
2049 }
2020} 2050}
2021 2051
2022static int 2052static int
2023compare_start(int *x, int *y) { 2053compare_start(int *x, int *y)
2024 /* 2054{
2025 * sort according to start sectors 2055 /*
2026 * and prefers largest partition: 2056 * sort according to start sectors
2027 * entry zero is entire disk entry 2057 * and prefers largest partition:
2028 */ 2058 * entry zero is entire disk entry
2029 unsigned int i = *x; 2059 */
2030 unsigned int j = *y; 2060 unsigned int i = *x;
2031 unsigned int a = sgi_get_start_sector(i); 2061 unsigned int j = *y;
2032 unsigned int b = sgi_get_start_sector(j); 2062 unsigned int a = sgi_get_start_sector(i);
2033 unsigned int c = sgi_get_num_sectors(i); 2063 unsigned int b = sgi_get_start_sector(j);
2034 unsigned int d = sgi_get_num_sectors(j); 2064 unsigned int c = sgi_get_num_sectors(i);
2065 unsigned int d = sgi_get_num_sectors(j);
2035 2066
2036 if (a == b) 2067 if (a == b)
2037 return (d > c) ? 1 : (d == c) ? 0 : -1; 2068 return (d > c) ? 1 : (d == c) ? 0 : -1;
2038 return (a > b) ? 1 : -1; 2069 return (a > b) ? 1 : -1;
2039} 2070}
2040 2071
2041 2072
2042static int 2073static int
2043verify_sgi(int verbose) 2074verify_sgi(int verbose)
2044{ 2075{
2045 int Index[16]; /* list of valid partitions */ 2076 int Index[16]; /* list of valid partitions */
2046 int sortcount = 0; /* number of used partitions, i.e. non-zero lengths */ 2077 int sortcount = 0; /* number of used partitions, i.e. non-zero lengths */
2047 int entire = 0, i = 0; 2078 int entire = 0, i = 0;
2048 unsigned int start = 0; 2079 unsigned int start = 0;
2049 long long gap = 0; /* count unused blocks */ 2080 long long gap = 0; /* count unused blocks */
2050 unsigned int lastblock = sgi_get_lastblock(); 2081 unsigned int lastblock = sgi_get_lastblock();
2051 2082
2052 clearfreelist(); 2083 clearfreelist();
2053 for (i=0; i<16; i++) { 2084 for (i = 0; i < 16; i++) {
2054 if (sgi_get_num_sectors(i) != 0) { 2085 if (sgi_get_num_sectors(i) != 0) {
2055 Index[sortcount++]=i; 2086 Index[sortcount++] = i;
2056 if (sgi_get_sysid(i) == ENTIRE_DISK) { 2087 if (sgi_get_sysid(i) == ENTIRE_DISK) {
2057 if (entire++ == 1) { 2088 if (entire++ == 1) {
2058 if (verbose) 2089 if (verbose)
2059 printf(_("More than one entire disk entry present.\n")); 2090 printf(_("More than one entire disk entry present.\n"));
2091 }
2092 }
2060 } 2093 }
2061 } 2094 }
2062 } 2095 if (sortcount == 0) {
2063 } 2096 if (verbose)
2064 if (sortcount == 0) { 2097 printf(_("No partitions defined\n"));
2065 if (verbose) 2098 return (lastblock > 0) ? 1 : (lastblock == 0) ? 0 : -1;
2066 printf(_("No partitions defined\n")); 2099 }
2067 return (lastblock > 0) ? 1 : (lastblock == 0) ? 0 : -1; 2100 qsort(Index, sortcount, sizeof(Index[0]), (void*)compare_start);
2068 } 2101 if (sgi_get_sysid(Index[0]) == ENTIRE_DISK) {
2069 qsort(Index, sortcount, sizeof(Index[0]), (void*)compare_start); 2102 if ((Index[0] != 10) && verbose)
2070 if (sgi_get_sysid(Index[0]) == ENTIRE_DISK) { 2103 printf(_("IRIX likes when Partition 11 covers the entire disk.\n"));
2071 if ((Index[0] != 10) && verbose) 2104 if ((sgi_get_start_sector(Index[0]) != 0) && verbose)
2072 printf(_("IRIX likes when Partition 11 covers the entire disk.\n")); 2105 printf(_("The entire disk partition should start "
2073 if ((sgi_get_start_sector(Index[0]) != 0) && verbose)
2074 printf(_("The entire disk partition should start "
2075 "at block 0,\n" 2106 "at block 0,\n"
2076 "not at diskblock %d.\n"), 2107 "not at diskblock %d.\n"),
2077 sgi_get_start_sector(Index[0])); 2108 sgi_get_start_sector(Index[0]));
2078 if (debug) /* I do not understand how some disks fulfil it */ 2109 if (debug) /* I do not understand how some disks fulfil it */
2079 if ((sgi_get_num_sectors(Index[0]) != lastblock) && verbose) 2110 if ((sgi_get_num_sectors(Index[0]) != lastblock) && verbose)
2080 printf(_("The entire disk partition is only %d diskblock large,\n" 2111 printf(_("The entire disk partition is only %d diskblock large,\n"
2081 "but the disk is %d diskblocks long.\n"), 2112 "but the disk is %d diskblocks long.\n"),
2082 sgi_get_num_sectors(Index[0]), lastblock); 2113 sgi_get_num_sectors(Index[0]), lastblock);
2083 lastblock = sgi_get_num_sectors(Index[0]); 2114 lastblock = sgi_get_num_sectors(Index[0]);
2084 } else { 2115 } else {
2085 if (verbose)
2086 printf(_("One Partition (#11) should cover the entire disk.\n"));
2087 if (debug>2)
2088 printf("sysid=%d\tpartition=%d\n",
2089 sgi_get_sysid(Index[0]), Index[0]+1);
2090 }
2091 for (i=1, start=0; i<sortcount; i++) {
2092 int cylsize = sgi_get_nsect() * sgi_get_ntrks();
2093
2094 if ((sgi_get_start_sector(Index[i]) % cylsize) != 0) {
2095 if (debug) /* I do not understand how some disks fulfil it */
2096 if (verbose)
2097 printf(_("Partition %d does not start on cylinder boundary.\n"),
2098 Index[i]+1);
2099 }
2100 if (sgi_get_num_sectors(Index[i]) % cylsize != 0) {
2101 if (debug) /* I do not understand how some disks fulfil it */
2102 if (verbose)
2103 printf(_("Partition %d does not end on cylinder boundary.\n"),
2104 Index[i]+1);
2105 }
2106 /* We cannot handle several "entire disk" entries. */
2107 if (sgi_get_sysid(Index[i]) == ENTIRE_DISK) continue;
2108 if (start > sgi_get_start_sector(Index[i])) {
2109 if (verbose)
2110 printf(_("The Partition %d and %d overlap by %d sectors.\n"),
2111 Index[i-1]+1, Index[i]+1,
2112 start - sgi_get_start_sector(Index[i]));
2113 if (gap > 0) gap = -gap;
2114 if (gap == 0) gap = -1;
2115 }
2116 if (start < sgi_get_start_sector(Index[i])) {
2117 if (verbose) 2116 if (verbose)
2118 printf(_("Unused gap of %8u sectors - sectors %8u-%u\n"), 2117 printf(_("One Partition (#11) should cover the entire disk.\n"));
2119 sgi_get_start_sector(Index[i]) - start, 2118 if (debug > 2)
2120 start, sgi_get_start_sector(Index[i])-1); 2119 printf("sysid=%d\tpartition=%d\n",
2121 gap += sgi_get_start_sector(Index[i]) - start; 2120 sgi_get_sysid(Index[0]), Index[0]+1);
2122 add2freelist(start, sgi_get_start_sector(Index[i])); 2121 }
2123 } 2122 for (i = 1, start = 0; i < sortcount; i++) {
2124 start = sgi_get_start_sector(Index[i]) 2123 int cylsize = sgi_get_nsect() * sgi_get_ntrks();
2125 + sgi_get_num_sectors(Index[i]); 2124
2126 if (debug > 1) { 2125 if ((sgi_get_start_sector(Index[i]) % cylsize) != 0) {
2126 if (debug) /* I do not understand how some disks fulfil it */
2127 if (verbose)
2128 printf(_("Partition %d does not start on cylinder boundary.\n"),
2129 Index[i]+1);
2130 }
2131 if (sgi_get_num_sectors(Index[i]) % cylsize != 0) {
2132 if (debug) /* I do not understand how some disks fulfil it */
2133 if (verbose)
2134 printf(_("Partition %d does not end on cylinder boundary.\n"),
2135 Index[i]+1);
2136 }
2137 /* We cannot handle several "entire disk" entries. */
2138 if (sgi_get_sysid(Index[i]) == ENTIRE_DISK) continue;
2139 if (start > sgi_get_start_sector(Index[i])) {
2140 if (verbose)
2141 printf(_("The Partition %d and %d overlap by %d sectors.\n"),
2142 Index[i-1]+1, Index[i]+1,
2143 start - sgi_get_start_sector(Index[i]));
2144 if (gap > 0) gap = -gap;
2145 if (gap == 0) gap = -1;
2146 }
2147 if (start < sgi_get_start_sector(Index[i])) {
2148 if (verbose)
2149 printf(_("Unused gap of %8u sectors - sectors %8u-%u\n"),
2150 sgi_get_start_sector(Index[i]) - start,
2151 start, sgi_get_start_sector(Index[i])-1);
2152 gap += sgi_get_start_sector(Index[i]) - start;
2153 add2freelist(start, sgi_get_start_sector(Index[i]));
2154 }
2155 start = sgi_get_start_sector(Index[i])
2156 + sgi_get_num_sectors(Index[i]);
2157 if (debug > 1) {
2158 if (verbose)
2159 printf("%2d:%12d\t%12d\t%12d\n", Index[i],
2160 sgi_get_start_sector(Index[i]),
2161 sgi_get_num_sectors(Index[i]),
2162 sgi_get_sysid(Index[i]));
2163 }
2164 }
2165 if (start < lastblock) {
2127 if (verbose) 2166 if (verbose)
2128 printf("%2d:%12d\t%12d\t%12d\n", Index[i], 2167 printf(_("Unused gap of %8u sectors - sectors %8u-%u\n"),
2129 sgi_get_start_sector(Index[i]), 2168 lastblock - start, start, lastblock-1);
2130 sgi_get_num_sectors(Index[i]), 2169 gap += lastblock - start;
2131 sgi_get_sysid(Index[i])); 2170 add2freelist(start, lastblock);
2132 }
2133 }
2134 if (start < lastblock) {
2135 if (verbose)
2136 printf(_("Unused gap of %8u sectors - sectors %8u-%u\n"),
2137 lastblock - start, start, lastblock-1);
2138 gap += lastblock - start;
2139 add2freelist(start, lastblock);
2140 }
2141 /*
2142 * Done with arithmetics
2143 * Go for details now
2144 */
2145 if (verbose) {
2146 if (!sgi_get_num_sectors(sgi_get_bootpartition())) {
2147 printf(_("\nThe boot partition does not exist.\n"));
2148 }
2149 if (!sgi_get_num_sectors(sgi_get_swappartition())) {
2150 printf(_("\nThe swap partition does not exist.\n"));
2151 } else {
2152 if ((sgi_get_sysid(sgi_get_swappartition()) != SGI_SWAP)
2153 && (sgi_get_sysid(sgi_get_swappartition()) != LINUX_SWAP))
2154 printf(_("\nThe swap partition has no swap type.\n"));
2155 } 2171 }
2156 if (sgi_check_bootfile("/unix")) 2172 /*
2157 printf(_("\tYou have chosen an unusual boot file name.\n")); 2173 * Done with arithmetics
2158 } 2174 * Go for details now
2159 return (gap > 0) ? 1 : (gap == 0) ? 0 : -1; 2175 */
2176 if (verbose) {
2177 if (!sgi_get_num_sectors(sgi_get_bootpartition())) {
2178 printf(_("\nThe boot partition does not exist.\n"));
2179 }
2180 if (!sgi_get_num_sectors(sgi_get_swappartition())) {
2181 printf(_("\nThe swap partition does not exist.\n"));
2182 } else {
2183 if ((sgi_get_sysid(sgi_get_swappartition()) != SGI_SWAP)
2184 && (sgi_get_sysid(sgi_get_swappartition()) != LINUX_SWAP))
2185 printf(_("\nThe swap partition has no swap type.\n"));
2186 }
2187 if (sgi_check_bootfile("/unix"))
2188 printf(_("\tYou have chosen an unusual boot file name.\n"));
2189 }
2190 return (gap > 0) ? 1 : (gap == 0) ? 0 : -1;
2160} 2191}
2161 2192
2162static int 2193static int
2163sgi_gaps(void) { 2194sgi_gaps(void)
2164 /* 2195{
2165 * returned value is: 2196 /*
2166 * = 0 : disk is properly filled to the rim 2197 * returned value is:
2167 * < 0 : there is an overlap 2198 * = 0 : disk is properly filled to the rim
2168 * > 0 : there is still some vacant space 2199 * < 0 : there is an overlap
2169 */ 2200 * > 0 : there is still some vacant space
2170 return verify_sgi(0); 2201 */
2202 return verify_sgi(0);
2171} 2203}
2172 2204
2173static void 2205static void
2174sgi_change_sysid( int i, int sys ) 2206sgi_change_sysid(int i, int sys)
2175{ 2207{
2176 if( sgi_get_num_sectors(i) == 0 ) /* caught already before, ... */ 2208 if( sgi_get_num_sectors(i) == 0 ) { /* caught already before, ... */
2177 { 2209 printf(_("Sorry You may change the Tag of non-empty partitions.\n"));
2178 printf(_("Sorry You may change the Tag of non-empty partitions.\n")); 2210 return;
2179 return; 2211 }
2180 } 2212 if (((sys != ENTIRE_DISK ) && (sys != SGI_VOLHDR))
2181 if( ((sys != ENTIRE_DISK ) && (sys != SGI_VOLHDR)) 2213 && (sgi_get_start_sector(i) < 1) ) {
2182 && (sgi_get_start_sector(i)<1) ) 2214 read_chars(
2183 { 2215 _("It is highly recommended that the partition at offset 0\n"
2184 read_chars( 2216 "is of type \"SGI volhdr\", the IRIX system will rely on it to\n"
2185 _("It is highly recommended that the partition at offset 0\n" 2217 "retrieve from its directory standalone tools like sash and fx.\n"
2186 "is of type \"SGI volhdr\", the IRIX system will rely on it to\n" 2218 "Only the \"SGI volume\" entire disk section may violate this.\n"
2187 "retrieve from its directory standalone tools like sash and fx.\n" 2219 "Type YES if you are sure about tagging this partition differently.\n"));
2188 "Only the \"SGI volume\" entire disk section may violate this.\n" 2220 if (strcmp(line_ptr, _("YES\n")))
2189 "Type YES if you are sure about tagging this partition differently.\n")); 2221 return;
2190 if (strcmp (line_ptr, _("YES\n"))) 2222 }
2191 return; 2223 sgilabel->partitions[i].id = SGI_SSWAP32(sys);
2192 }
2193 sgilabel->partitions[i].id = SGI_SSWAP32(sys);
2194} 2224}
2195 2225
2196/* returns partition index of first entry marked as entire disk */ 2226/* returns partition index of first entry marked as entire disk */
2197static int 2227static int
2198sgi_entire(void) { 2228sgi_entire(void)
2199 int i; 2229{
2230 int i;
2200 2231
2201 for(i=0; i<16; i++) 2232 for (i = 0; i < 16; i++)
2202 if(sgi_get_sysid(i) == SGI_VOLUME) 2233 if (sgi_get_sysid(i) == SGI_VOLUME)
2203 return i; 2234 return i;
2204 return -1; 2235 return -1;
2205} 2236}
2206 2237
2207static void 2238static void
2208sgi_set_partition(int i, unsigned int start, unsigned int length, int sys) { 2239sgi_set_partition(int i, unsigned int start, unsigned int length, int sys)
2209 2240{
2210 sgilabel->partitions[i].id = SGI_SSWAP32(sys); 2241 sgilabel->partitions[i].id = SGI_SSWAP32(sys);
2211 sgilabel->partitions[i].num_sectors = SGI_SSWAP32(length); 2242 sgilabel->partitions[i].num_sectors = SGI_SSWAP32(length);
2212 sgilabel->partitions[i].start_sector = SGI_SSWAP32(start); 2243 sgilabel->partitions[i].start_sector = SGI_SSWAP32(start);
2213 set_changed(i); 2244 set_changed(i);
2214 if (sgi_gaps() < 0) /* rebuild freelist */ 2245 if (sgi_gaps() < 0) /* rebuild freelist */
2215 printf(_("Do You know, You got a partition overlap on the disk?\n")); 2246 printf(_("Do You know, You got a partition overlap on the disk?\n"));
2216} 2247}
2217 2248
2218static void 2249static void
2219sgi_set_entire(void) { 2250sgi_set_entire(void)
2220 int n; 2251{
2252 int n;
2221 2253
2222 for(n=10; n < partitions; n++) { 2254 for (n = 10; n < partitions; n++) {
2223 if(!sgi_get_num_sectors(n) ) { 2255 if(!sgi_get_num_sectors(n) ) {
2224 sgi_set_partition(n, 0, sgi_get_lastblock(), SGI_VOLUME); 2256 sgi_set_partition(n, 0, sgi_get_lastblock(), SGI_VOLUME);
2225 break; 2257 break;
2258 }
2226 } 2259 }
2227 }
2228} 2260}
2229 2261
2230static void 2262static void
2231sgi_set_volhdr(void) 2263sgi_set_volhdr(void)
2232{ 2264{
2233 int n; 2265 int n;
2234 for( n=8; n<partitions; n++ ) 2266
2235 { 2267 for (n = 8; n < partitions; n++) {
2236 if(!sgi_get_num_sectors( n ) ) 2268 if (!sgi_get_num_sectors(n)) {
2237 { 2269 /*
2238 /* 2270 * 5 cylinders is an arbitrary value I like
2239 * 5 cylinders is an arbitrary value I like 2271 * IRIX 5.3 stored files in the volume header
2240 * IRIX 5.3 stored files in the volume header 2272 * (like sash, symmon, fx, ide) with ca. 3200
2241 * (like sash, symmon, fx, ide) with ca. 3200 2273 * sectors.
2242 * sectors. 2274 */
2243 */ 2275 if (heads * sectors * 5 < sgi_get_lastblock())
2244 if( heads * sectors * 5 < sgi_get_lastblock() ) 2276 sgi_set_partition(n, 0, heads * sectors * 5, SGI_VOLHDR);
2245 sgi_set_partition( n, 0, heads * sectors * 5, SGI_VOLHDR ); 2277 break;
2246 break; 2278 }
2247 } 2279 }
2248 }
2249} 2280}
2250 2281
2251static void 2282static void
2252sgi_delete_partition( int i ) 2283sgi_delete_partition(int i)
2253{ 2284{
2254 sgi_set_partition( i, 0, 0, 0 ); 2285 sgi_set_partition(i, 0, 0, 0);
2255} 2286}
2256 2287
2257static void 2288static void
2258sgi_add_partition( int n, int sys ) 2289sgi_add_partition(int n, int sys)
2259{ 2290{
2260 char mesg[256]; 2291 char mesg[256];
2261 unsigned int first=0, last=0; 2292 unsigned int first = 0, last = 0;
2262 2293
2263 if( n == 10 ) { 2294 if (n == 10) {
2264 sys = SGI_VOLUME; 2295 sys = SGI_VOLUME;
2265 } else if ( n == 8 ) { 2296 } else if (n == 8) {
2266 sys = 0; 2297 sys = 0;
2267 } 2298 }
2268 if(sgi_get_num_sectors(n)) { 2299 if(sgi_get_num_sectors(n)) {
2269 printf(_("Partition %d is already defined. Delete " 2300 printf(_("Partition %d is already defined. Delete "
2270 "it before re-adding it.\n"), n + 1); 2301 "it before re-adding it.\n"), n + 1);
2271 return; 2302 return;
2272 } 2303 }
2273 if( (sgi_entire() == -1) && (sys != SGI_VOLUME) ) { 2304 if ((sgi_entire() == -1) && (sys != SGI_VOLUME)) {
2274 printf(_("Attempting to generate entire disk entry automatically.\n")); 2305 printf(_("Attempting to generate entire disk entry automatically.\n"));
2275 sgi_set_entire(); 2306 sgi_set_entire();
2276 sgi_set_volhdr(); 2307 sgi_set_volhdr();
2277 } 2308 }
2278 if( (sgi_gaps() == 0) && (sys != SGI_VOLUME) ) { 2309 if ((sgi_gaps() == 0) && (sys != SGI_VOLUME)) {
2279 printf(_("The entire disk is already covered with partitions.\n")); 2310 printf(_("The entire disk is already covered with partitions.\n"));
2280 return; 2311 return;
2281 }
2282 if(sgi_gaps() < 0) {
2283 printf(_("You got a partition overlap on the disk. Fix it first!\n"));
2284 return;
2285 }
2286 snprintf(mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));
2287 for(;;) {
2288 if(sys == SGI_VOLUME) {
2289 last = sgi_get_lastblock();
2290 first = read_int(0, 0, last-1, 0, mesg);
2291 if( first != 0 ) {
2292 printf(_("It is highly recommended that eleventh partition\n"
2293 "covers the entire disk and is of type `SGI volume'\n"));
2294 }
2295 } else {
2296 first = freelist[0].first;
2297 last = freelist[0].last;
2298 first = read_int(scround(first), scround(first), scround(last)-1,
2299 0, mesg);
2300 } 2312 }
2313 if (sgi_gaps() < 0) {
2314 printf(_("You got a partition overlap on the disk. Fix it first!\n"));
2315 return;
2316 }
2317 snprintf(mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));
2318 while (1) {
2319 if(sys == SGI_VOLUME) {
2320 last = sgi_get_lastblock();
2321 first = read_int(0, 0, last-1, 0, mesg);
2322 if (first != 0) {
2323 printf(_("It is highly recommended that eleventh partition\n"
2324 "covers the entire disk and is of type `SGI volume'\n"));
2325 }
2326 } else {
2327 first = freelist[0].first;
2328 last = freelist[0].last;
2329 first = read_int(scround(first), scround(first), scround(last)-1,
2330 0, mesg);
2331 }
2332 if (display_in_cyl_units)
2333 first *= units_per_sector;
2334 else
2335 first = first; /* align to cylinder if you know how ... */
2336 if(!last )
2337 last = isinfreelist(first);
2338 if(last == 0) {
2339 printf(_("You will get a partition overlap on the disk. "
2340 "Fix it first!\n"));
2341 } else
2342 break;
2343 }
2344 snprintf(mesg, sizeof(mesg), _(" Last %s"), str_units(SINGULAR));
2345 last = read_int(scround(first), scround(last)-1, scround(last)-1,
2346 scround(first), mesg)+1;
2301 if (display_in_cyl_units) 2347 if (display_in_cyl_units)
2302 first *= units_per_sector; 2348 last *= units_per_sector;
2303 else 2349 else
2304 first = first; /* align to cylinder if you know how ... */ 2350 last = last; /* align to cylinder if You know how ... */
2305 if( !last ) 2351 if ( (sys == SGI_VOLUME) && (first != 0 || last != sgi_get_lastblock() ) )
2306 last = isinfreelist(first); 2352 printf(_("It is highly recommended that eleventh partition\n"
2307 if( last == 0 ) { 2353 "covers the entire disk and is of type `SGI volume'\n"));
2308 printf(_("You will get a partition overlap on the disk. " 2354 sgi_set_partition(n, first, last-first, sys);
2309 "Fix it first!\n"));
2310 } else
2311 break;
2312 }
2313 snprintf(mesg, sizeof(mesg), _(" Last %s"), str_units(SINGULAR));
2314 last = read_int(scround(first), scround(last)-1, scround(last)-1,
2315 scround(first), mesg)+1;
2316 if (display_in_cyl_units)
2317 last *= units_per_sector;
2318 else
2319 last = last; /* align to cylinder if You know how ... */
2320 if( (sys == SGI_VOLUME) && ( first != 0 || last != sgi_get_lastblock() ) )
2321 printf(_("It is highly recommended that eleventh partition\n"
2322 "covers the entire disk and is of type `SGI volume'\n"));
2323 sgi_set_partition( n, first, last-first, sys );
2324} 2355}
2325 2356
2326#ifdef CONFIG_FEATURE_FDISK_ADVANCED 2357#ifdef CONFIG_FEATURE_FDISK_ADVANCED
2327static void 2358static void
2328create_sgilabel(void) 2359create_sgilabel(void)
2329{ 2360{
2330 struct hd_geometry geometry; 2361 struct hd_geometry geometry;
2331 struct { 2362 struct {
2332 unsigned int start; 2363 unsigned int start;
2333 unsigned int nsect; 2364 unsigned int nsect;
2334 int sysid; 2365 int sysid;
2335 } old[4]; 2366 } old[4];
2336 int i=0; 2367 int i = 0;
2337 long longsectors; /* the number of sectors on the device */ 2368 long longsectors; /* the number of sectors on the device */
2338 int res; /* the result from the ioctl */ 2369 int res; /* the result from the ioctl */
2339 int sec_fac; /* the sector factor */ 2370 int sec_fac; /* the sector factor */
2340 2371
2341 sec_fac = sector_size / 512; /* determine the sector factor */ 2372 sec_fac = sector_size / 512; /* determine the sector factor */
2342 2373
2343 fprintf( stderr, 2374 fprintf( stderr,
2344 _("Building a new SGI disklabel. Changes will remain in memory only,\n" 2375 _("Building a new SGI disklabel. Changes will remain in memory only,\n"
2345 "until you decide to write them. After that, of course, the previous\n" 2376 "until you decide to write them. After that, of course, the previous\n"
2346 "content will be unrecoverably lost.\n\n")); 2377 "content will be unrecoverably lost.\n\n"));
2347 2378
2348 sgi_other_endian = (BYTE_ORDER == LITTLE_ENDIAN); 2379 sgi_other_endian = (BYTE_ORDER == LITTLE_ENDIAN);
2349 res = ioctl(fd, BLKGETSIZE, &longsectors); 2380 res = ioctl(fd, BLKGETSIZE, &longsectors);
2350 if (!ioctl(fd, HDIO_GETGEO, &geometry)) { 2381 if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
2351 heads = geometry.heads; 2382 heads = geometry.heads;
2352 sectors = geometry.sectors; 2383 sectors = geometry.sectors;
2353 if (res == 0) { 2384 if (res == 0) {
2354 /* the get device size ioctl was successful */ 2385 /* the get device size ioctl was successful */
2355 cylinders = longsectors / (heads * sectors); 2386 cylinders = longsectors / (heads * sectors);
2356 cylinders /= sec_fac; 2387 cylinders /= sec_fac;
2357 } else { 2388 } else {
2358 /* otherwise print error and use truncated version */ 2389 /* otherwise print error and use truncated version */
2359 cylinders = geometry.cylinders; 2390 cylinders = geometry.cylinders;
2360 fprintf(stderr, 2391 fprintf(stderr,
2361 _("Warning: BLKGETSIZE ioctl failed on %s. " 2392 _("Warning: BLKGETSIZE ioctl failed on %s. "
2362 "Using geometry cylinder value of %d.\n" 2393 "Using geometry cylinder value of %d.\n"
2363 "This value may be truncated for devices" 2394 "This value may be truncated for devices"
2364 " > 33.8 GB.\n"), disk_device, cylinders); 2395 " > 33.8 GB.\n"), disk_device, cylinders);
2365 } 2396 }
2366 } 2397 }
2367 for (i = 0; i < 4; i++) { 2398 for (i = 0; i < 4; i++) {
2368 old[i].sysid = 0; 2399 old[i].sysid = 0;
2369 if(valid_part_table_flag(MBRbuffer)) { 2400 if (valid_part_table_flag(MBRbuffer)) {
2370 if(get_part_table(i)->sys_ind) { 2401 if(get_part_table(i)->sys_ind) {
2371 old[i].sysid = get_part_table(i)->sys_ind; 2402 old[i].sysid = get_part_table(i)->sys_ind;
2372 old[i].start = get_start_sect(get_part_table(i)); 2403 old[i].start = get_start_sect(get_part_table(i));
2373 old[i].nsect = get_nr_sects(get_part_table(i)); 2404 old[i].nsect = get_nr_sects(get_part_table(i));
2374 printf(_("Trying to keep parameters of partition %d.\n"), i); 2405 printf(_("Trying to keep parameters of partition %d.\n"), i);
2375 if (debug) 2406 if (debug)
2376 printf(_("ID=%02x\tSTART=%d\tLENGTH=%d\n"), 2407 printf(_("ID=%02x\tSTART=%d\tLENGTH=%d\n"),
2377 old[i].sysid, old[i].start, old[i].nsect); 2408 old[i].sysid, old[i].start, old[i].nsect);
2378 } 2409 }
2379 } 2410 }
2380 } 2411 }
2381 2412
2382 memset(MBRbuffer, 0, sizeof(MBRbuffer)); 2413 memset(MBRbuffer, 0, sizeof(MBRbuffer));
2383 sgilabel->magic = SGI_SSWAP32(SGI_LABEL_MAGIC); 2414 sgilabel->magic = SGI_SSWAP32(SGI_LABEL_MAGIC);
2384 sgilabel->boot_part = SGI_SSWAP16(0); 2415 sgilabel->boot_part = SGI_SSWAP16(0);
2385 sgilabel->swap_part = SGI_SSWAP16(1); 2416 sgilabel->swap_part = SGI_SSWAP16(1);
2386 2417
2387 /* sizeof(sgilabel->boot_file) = 16 > 6 */ 2418 /* sizeof(sgilabel->boot_file) = 16 > 6 */
2388 memset(sgilabel->boot_file, 0, 16); 2419 memset(sgilabel->boot_file, 0, 16);
2389 strcpy((char*)sgilabel->boot_file, "/unix"); 2420 strcpy((char*)sgilabel->boot_file, "/unix");
2390 2421
2391 sgilabel->devparam.skew = (0); 2422 sgilabel->devparam.skew = (0);
2392 sgilabel->devparam.gap1 = (0); 2423 sgilabel->devparam.gap1 = (0);
2393 sgilabel->devparam.gap2 = (0); 2424 sgilabel->devparam.gap2 = (0);
2394 sgilabel->devparam.sparecyl = (0); 2425 sgilabel->devparam.sparecyl = (0);
2395 sgilabel->devparam.pcylcount = SGI_SSWAP16(geometry.cylinders); 2426 sgilabel->devparam.pcylcount = SGI_SSWAP16(geometry.cylinders);
2396 sgilabel->devparam.head_vol0 = SGI_SSWAP16(0); 2427 sgilabel->devparam.head_vol0 = SGI_SSWAP16(0);
2397 sgilabel->devparam.ntrks = SGI_SSWAP16(geometry.heads); 2428 sgilabel->devparam.ntrks = SGI_SSWAP16(geometry.heads);
2398 /* tracks/cylinder (heads) */ 2429 /* tracks/cylinder (heads) */
2399 sgilabel->devparam.cmd_tag_queue_depth = (0); 2430 sgilabel->devparam.cmd_tag_queue_depth = (0);
2400 sgilabel->devparam.unused0 = (0); 2431 sgilabel->devparam.unused0 = (0);
2401 sgilabel->devparam.unused1 = SGI_SSWAP16(0); 2432 sgilabel->devparam.unused1 = SGI_SSWAP16(0);
2402 sgilabel->devparam.nsect = SGI_SSWAP16(geometry.sectors); 2433 sgilabel->devparam.nsect = SGI_SSWAP16(geometry.sectors);
2403 /* sectors/track */ 2434 /* sectors/track */
2404 sgilabel->devparam.bytes = SGI_SSWAP16(512); 2435 sgilabel->devparam.bytes = SGI_SSWAP16(512);
2405 sgilabel->devparam.ilfact = SGI_SSWAP16(1); 2436 sgilabel->devparam.ilfact = SGI_SSWAP16(1);
2406 sgilabel->devparam.flags = SGI_SSWAP32(TRACK_FWD| 2437 sgilabel->devparam.flags = SGI_SSWAP32(TRACK_FWD|
2407 IGNORE_ERRORS|RESEEK); 2438 IGNORE_ERRORS|RESEEK);
2408 sgilabel->devparam.datarate = SGI_SSWAP32(0); 2439 sgilabel->devparam.datarate = SGI_SSWAP32(0);
2409 sgilabel->devparam.retries_on_error = SGI_SSWAP32(1); 2440 sgilabel->devparam.retries_on_error = SGI_SSWAP32(1);
2410 sgilabel->devparam.ms_per_word = SGI_SSWAP32(0); 2441 sgilabel->devparam.ms_per_word = SGI_SSWAP32(0);
2411 sgilabel->devparam.xylogics_gap1 = SGI_SSWAP16(0); 2442 sgilabel->devparam.xylogics_gap1 = SGI_SSWAP16(0);
2412 sgilabel->devparam.xylogics_syncdelay = SGI_SSWAP16(0); 2443 sgilabel->devparam.xylogics_syncdelay = SGI_SSWAP16(0);
2413 sgilabel->devparam.xylogics_readdelay = SGI_SSWAP16(0); 2444 sgilabel->devparam.xylogics_readdelay = SGI_SSWAP16(0);
2414 sgilabel->devparam.xylogics_gap2 = SGI_SSWAP16(0); 2445 sgilabel->devparam.xylogics_gap2 = SGI_SSWAP16(0);
2415 sgilabel->devparam.xylogics_readgate = SGI_SSWAP16(0); 2446 sgilabel->devparam.xylogics_readgate = SGI_SSWAP16(0);
2416 sgilabel->devparam.xylogics_writecont = SGI_SSWAP16(0); 2447 sgilabel->devparam.xylogics_writecont = SGI_SSWAP16(0);
2417 memset( &(sgilabel->directory), 0, sizeof(struct volume_directory)*15 ); 2448 memset( &(sgilabel->directory), 0, sizeof(struct volume_directory)*15 );
2418 memset( &(sgilabel->partitions), 0, sizeof(struct sgi_partition)*16 ); 2449 memset( &(sgilabel->partitions), 0, sizeof(struct sgi_partition)*16 );
2419 sgi_label = 1; 2450 sgi_label = 1;
2420 partitions = 16; 2451 partitions = 16;
2421 sgi_volumes = 15; 2452 sgi_volumes = 15;
2422 sgi_set_entire(); 2453 sgi_set_entire();
2423 sgi_set_volhdr(); 2454 sgi_set_volhdr();
2424 for (i = 0; i < 4; i++) { 2455 for (i = 0; i < 4; i++) {
2425 if(old[i].sysid) { 2456 if(old[i].sysid) {
2426 sgi_set_partition(i, old[i].start, old[i].nsect, old[i].sysid); 2457 sgi_set_partition(i, old[i].start, old[i].nsect, old[i].sysid);
2427 } 2458 }
2428 } 2459 }
2429} 2460}
2430 2461
2431static void 2462static void
2432sgi_set_xcyl(void) 2463sgi_set_xcyl(void)
2433{ 2464{
2434 /* do nothing in the beginning */ 2465 /* do nothing in the beginning */
2435} 2466}
2436#endif /* CONFIG_FEATURE_FDISK_ADVANCED */ 2467#endif /* CONFIG_FEATURE_FDISK_ADVANCED */
2437 2468
@@ -2441,18 +2472,18 @@ sgi_set_xcyl(void)
2441static sgiinfo * 2472static sgiinfo *
2442fill_sgiinfo(void) 2473fill_sgiinfo(void)
2443{ 2474{
2444 sgiinfo *info = calloc(1, sizeof(sgiinfo)); 2475 sgiinfo *info = calloc(1, sizeof(sgiinfo));
2445 2476
2446 info->magic=SGI_SSWAP32(SGI_INFO_MAGIC); 2477 info->magic = SGI_SSWAP32(SGI_INFO_MAGIC);
2447 info->b1=SGI_SSWAP32(-1); 2478 info->b1 = SGI_SSWAP32(-1);
2448 info->b2=SGI_SSWAP16(-1); 2479 info->b2 = SGI_SSWAP16(-1);
2449 info->b3=SGI_SSWAP16(1); 2480 info->b3 = SGI_SSWAP16(1);
2450 /* You may want to replace this string !!!!!!! */ 2481 /* You may want to replace this string !!!!!!! */
2451 strcpy( (char*)info->scsi_string, "IBM OEM 0662S12 3 30" ); 2482 strcpy( (char*)info->scsi_string, "IBM OEM 0662S12 3 30" );
2452 strcpy( (char*)info->serial, "0000" ); 2483 strcpy( (char*)info->serial, "0000" );
2453 info->check1816 = SGI_SSWAP16(18*256 +16 ); 2484 info->check1816 = SGI_SSWAP16(18*256 +16 );
2454 strcpy( (char*)info->installer, "Sfx version 5.3, Oct 18, 1994" ); 2485 strcpy( (char*)info->installer, "Sfx version 5.3, Oct 18, 1994" );
2455 return info; 2486 return info;
2456} 2487}
2457#endif /* SGI_LABEL */ 2488#endif /* SGI_LABEL */
2458 2489
@@ -2471,9 +2502,9 @@ fill_sgiinfo(void)
2471 */ 2502 */
2472 2503
2473 2504
2474static int sun_other_endian; 2505static int sun_other_endian;
2475static int scsi_disk; 2506static int scsi_disk;
2476static int floppy; 2507static int floppy;
2477 2508
2478#ifndef IDE0_MAJOR 2509#ifndef IDE0_MAJOR
2479#define IDE0_MAJOR 3 2510#define IDE0_MAJOR 3
@@ -2482,19 +2513,21 @@ static int floppy;
2482#define IDE1_MAJOR 22 2513#define IDE1_MAJOR 22
2483#endif 2514#endif
2484 2515
2485static void guess_device_type(void) { 2516static void
2517guess_device_type(void)
2518{
2486 struct stat bootstat; 2519 struct stat bootstat;
2487 2520
2488 if (fstat (fd, &bootstat) < 0) { 2521 if (fstat(fd, &bootstat) < 0) {
2489 scsi_disk = 0; 2522 scsi_disk = 0;
2490 floppy = 0; 2523 floppy = 0;
2491 } else if (S_ISBLK(bootstat.st_mode) 2524 } else if (S_ISBLK(bootstat.st_mode)
2492 && (major(bootstat.st_rdev) == IDE0_MAJOR || 2525 && (major(bootstat.st_rdev) == IDE0_MAJOR ||
2493 major(bootstat.st_rdev) == IDE1_MAJOR)) { 2526 major(bootstat.st_rdev) == IDE1_MAJOR)) {
2494 scsi_disk = 0; 2527 scsi_disk = 0;
2495 floppy = 0; 2528 floppy = 0;
2496 } else if (S_ISBLK(bootstat.st_mode) 2529 } else if (S_ISBLK(bootstat.st_mode)
2497 && major(bootstat.st_rdev) == FLOPPY_MAJOR) { 2530 && major(bootstat.st_rdev) == FLOPPY_MAJOR) {
2498 scsi_disk = 0; 2531 scsi_disk = 0;
2499 floppy = 1; 2532 floppy = 1;
2500 } else { 2533 } else {
@@ -2504,26 +2537,27 @@ static void guess_device_type(void) {
2504} 2537}
2505 2538
2506static const struct systypes sun_sys_types[] = { 2539static const struct systypes sun_sys_types[] = {
2507/* 0 */ {"\x00" "Empty" }, 2540 { "\x00" "Empty" }, /* 0 */
2508/* 1 */ {"\x01" "Boot" }, 2541 { "\x01" "Boot" }, /* 1 */
2509/* 2 */ {"\x02" "SunOS root" }, 2542 { "\x02" "SunOS root" }, /* 2 */
2510/* SUNOS_SWAP */ {"\x03" "SunOS swap" }, 2543 { "\x03" "SunOS swap" }, /* SUNOS_SWAP */
2511/* 4 */ {"\x04" "SunOS usr" }, 2544 { "\x04" "SunOS usr" }, /* 4 */
2512/* WHOLE_DISK */ {"\x05" "Whole disk" }, 2545 { "\x05" "Whole disk" }, /* WHOLE_DISK */
2513/* 6 */ {"\x06" "SunOS stand" }, 2546 { "\x06" "SunOS stand" }, /* 6 */
2514/* 7 */ {"\x07" "SunOS var" }, 2547 { "\x07" "SunOS var" }, /* 7 */
2515/* 8 */ {"\x08" "SunOS home" }, 2548 { "\x08" "SunOS home" }, /* 8 */
2516/* LINUX_SWAP */ {"\x82" "Linux swap" }, 2549 { "\x82" "Linux swap" }, /* LINUX_SWAP */
2517/* LINUX_NATIVE */ {"\x83" "Linux native" }, 2550 { "\x83" "Linux native" }, /* LINUX_NATIVE */
2518/* 0x8e */ {"\x8e" "Linux LVM" }, 2551 { "\x8e" "Linux LVM" }, /* 0x8e */
2519/* New (2.2.x) raid partition with autodetect using persistent superblock */ 2552/* New (2.2.x) raid partition with autodetect using persistent superblock */
2520/* 0xfd */ {"\xfd" "Linux raid autodetect" }, 2553 { "\xfd" "Linux raid autodetect" }, /* 0xfd */
2521 { NULL } 2554 { NULL }
2522}; 2555};
2523 2556
2524 2557
2525static void 2558static void
2526set_sun_partition(int i, uint start, uint stop, int sysid) { 2559set_sun_partition(int i, uint start, uint stop, int sysid)
2560{
2527 sunlabel->infos[i].id = sysid; 2561 sunlabel->infos[i].id = sysid;
2528 sunlabel->partitions[i].start_cylinder = 2562 sunlabel->partitions[i].start_cylinder =
2529 SUN_SSWAP32(start / (heads * sectors)); 2563 SUN_SSWAP32(start / (heads * sectors));
@@ -2533,19 +2567,21 @@ set_sun_partition(int i, uint start, uint stop, int sysid) {
2533} 2567}
2534 2568
2535static void 2569static void
2536sun_nolabel(void) { 2570sun_nolabel(void)
2571{
2537 sun_label = 0; 2572 sun_label = 0;
2538 sunlabel->magic = 0; 2573 sunlabel->magic = 0;
2539 partitions = 4; 2574 partitions = 4;
2540} 2575}
2541 2576
2542static int 2577static int
2543check_sun_label(void) { 2578check_sun_label(void)
2579{
2544 unsigned short *ush; 2580 unsigned short *ush;
2545 int csum; 2581 int csum;
2546 2582
2547 if (sunlabel->magic != SUN_LABEL_MAGIC && 2583 if (sunlabel->magic != SUN_LABEL_MAGIC
2548 sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED) { 2584 && sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED) {
2549 sun_label = 0; 2585 sun_label = 0;
2550 sun_other_endian = 0; 2586 sun_other_endian = 0;
2551 return 0; 2587 return 0;
@@ -2580,98 +2616,101 @@ static const struct sun_predefined_drives {
2580 unsigned short nsect; 2616 unsigned short nsect;
2581 unsigned short rspeed; 2617 unsigned short rspeed;
2582} sun_drives[] = { 2618} sun_drives[] = {
2583{"Quantum","ProDrive 80S",1,832,2,834,6,34,3662}, 2619 { "Quantum","ProDrive 80S",1,832,2,834,6,34,3662},
2584{"Quantum","ProDrive 105S",1,974,2,1019,6,35,3662}, 2620 { "Quantum","ProDrive 105S",1,974,2,1019,6,35,3662},
2585{"CDC","Wren IV 94171-344",3,1545,2,1549,9,46,3600}, 2621 { "CDC","Wren IV 94171-344",3,1545,2,1549,9,46,3600},
2586{"IBM","DPES-31080",0,4901,2,4903,4,108,5400}, 2622 { "IBM","DPES-31080",0,4901,2,4903,4,108,5400},
2587{"IBM","DORS-32160",0,1015,2,1017,67,62,5400}, 2623 { "IBM","DORS-32160",0,1015,2,1017,67,62,5400},
2588{"IBM","DNES-318350",0,11199,2,11474,10,320,7200}, 2624 { "IBM","DNES-318350",0,11199,2,11474,10,320,7200},
2589{"SEAGATE","ST34371",0,3880,2,3882,16,135,7228}, 2625 { "SEAGATE","ST34371",0,3880,2,3882,16,135,7228},
2590{"","SUN0104",1,974,2,1019,6,35,3662}, 2626 { "","SUN0104",1,974,2,1019,6,35,3662},
2591{"","SUN0207",4,1254,2,1272,9,36,3600}, 2627 { "","SUN0207",4,1254,2,1272,9,36,3600},
2592{"","SUN0327",3,1545,2,1549,9,46,3600}, 2628 { "","SUN0327",3,1545,2,1549,9,46,3600},
2593{"","SUN0340",0,1538,2,1544,6,72,4200}, 2629 { "","SUN0340",0,1538,2,1544,6,72,4200},
2594{"","SUN0424",2,1151,2,2500,9,80,4400}, 2630 { "","SUN0424",2,1151,2,2500,9,80,4400},
2595{"","SUN0535",0,1866,2,2500,7,80,5400}, 2631 { "","SUN0535",0,1866,2,2500,7,80,5400},
2596{"","SUN0669",5,1614,2,1632,15,54,3600}, 2632 { "","SUN0669",5,1614,2,1632,15,54,3600},
2597{"","SUN1.0G",5,1703,2,1931,15,80,3597}, 2633 { "","SUN1.0G",5,1703,2,1931,15,80,3597},
2598{"","SUN1.05",0,2036,2,2038,14,72,5400}, 2634 { "","SUN1.05",0,2036,2,2038,14,72,5400},
2599{"","SUN1.3G",6,1965,2,3500,17,80,5400}, 2635 { "","SUN1.3G",6,1965,2,3500,17,80,5400},
2600{"","SUN2.1G",0,2733,2,3500,19,80,5400}, 2636 { "","SUN2.1G",0,2733,2,3500,19,80,5400},
2601{"IOMEGA","Jaz",0,1019,2,1021,64,32,5394}, 2637 { "IOMEGA","Jaz",0,1019,2,1021,64,32,5394},
2602}; 2638};
2603 2639
2604static const struct sun_predefined_drives * 2640static const struct sun_predefined_drives *
2605sun_autoconfigure_scsi(void) { 2641sun_autoconfigure_scsi(void)
2606 const struct sun_predefined_drives *p = NULL; 2642{
2643 const struct sun_predefined_drives *p = NULL;
2607 2644
2608#ifdef SCSI_IOCTL_GET_IDLUN 2645#ifdef SCSI_IOCTL_GET_IDLUN
2609 unsigned int id[2]; 2646 unsigned int id[2];
2610 char buffer[2048]; 2647 char buffer[2048];
2611 char buffer2[2048]; 2648 char buffer2[2048];
2612 FILE *pfd; 2649 FILE *pfd;
2613 char *vendor; 2650 char *vendor;
2614 char *model; 2651 char *model;
2615 char *q; 2652 char *q;
2616 int i; 2653 int i;
2617 2654
2618 if (!ioctl(fd, SCSI_IOCTL_GET_IDLUN, &id)) { 2655 if (!ioctl(fd, SCSI_IOCTL_GET_IDLUN, &id)) {
2619 sprintf(buffer, 2656 sprintf(buffer,
2620 "Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n", 2657 "Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n",
2621#if 0 2658#if 0
2622 ((id[0]>>24)&0xff)-/*PROC_SCSI_SCSI+PROC_SCSI_FILE*/33, 2659 ((id[0]>>24)&0xff)-/*PROC_SCSI_SCSI+PROC_SCSI_FILE*/33,
2623#else 2660#else
2624 /* This is very wrong (works only if you have one HBA), 2661 /* This is very wrong (works only if you have one HBA),
2625 but I haven't found a way how to get hostno 2662 but I haven't found a way how to get hostno
2626 from the current kernel */ 2663 from the current kernel */
2627 0, 2664 0,
2628#endif 2665#endif
2629 (id[0]>>16)&0xff, 2666 (id[0]>>16) & 0xff,
2630 id[0]&0xff, 2667 id[0] & 0xff,
2631 (id[0]>>8)&0xff); 2668 (id[0]>>8) & 0xff
2632 pfd = fopen("/proc/scsi/scsi","r"); 2669 );
2633 if (pfd) { 2670 pfd = fopen("/proc/scsi/scsi","r");
2634 while (fgets(buffer2,2048,pfd)) { 2671 if (pfd) {
2635 if (!strcmp(buffer, buffer2)) { 2672 while (fgets(buffer2, 2048, pfd)) {
2636 if (fgets(buffer2,2048,pfd)) { 2673 if (!strcmp(buffer, buffer2)) {
2637 q = strstr(buffer2,"Vendor: "); 2674 if (fgets(buffer2,2048,pfd)) {
2638 if (q) { 2675 q = strstr(buffer2,"Vendor: ");
2639 q += 8; 2676 if (q) {
2640 vendor = q; 2677 q += 8;
2641 q = strstr(q," "); 2678 vendor = q;
2642 *q++ = 0; /* truncate vendor name */ 2679 q = strstr(q," ");
2643 q = strstr(q,"Model: "); 2680 *q++ = 0; /* truncate vendor name */
2644 if (q) { 2681 q = strstr(q,"Model: ");
2645 *q = 0; 2682 if (q) {
2646 q += 7; 2683 *q = 0;
2647 model = q; 2684 q += 7;
2648 q = strstr(q," Rev: "); 2685 model = q;
2649 if (q) { 2686 q = strstr(q," Rev: ");
2650 *q = 0; 2687 if (q) {
2651 for (i = 0; i < SIZE(sun_drives); i++) { 2688 *q = 0;
2652 if (*sun_drives[i].vendor && strcasecmp(sun_drives[i].vendor, vendor)) 2689 for (i = 0; i < SIZE(sun_drives); i++) {
2653 continue; 2690 if (*sun_drives[i].vendor && strcasecmp(sun_drives[i].vendor, vendor))
2654 if (!strstr(model, sun_drives[i].model)) 2691 continue;
2655 continue; 2692 if (!strstr(model, sun_drives[i].model))
2656 printf(_("Autoconfigure found a %s%s%s\n"),sun_drives[i].vendor,(*sun_drives[i].vendor) ? " " : "",sun_drives[i].model); 2693 continue;
2657 p = sun_drives + i; 2694 printf(_("Autoconfigure found a %s%s%s\n"),sun_drives[i].vendor,(*sun_drives[i].vendor) ? " " : "",sun_drives[i].model);
2695 p = sun_drives + i;
2696 break;
2697 }
2698 }
2699 }
2700 }
2701 }
2658 break; 2702 break;
2659 }
2660 } 2703 }
2661 }
2662 } 2704 }
2663 } 2705 fclose(pfd);
2664 break;
2665 } 2706 }
2666 }
2667 fclose(pfd);
2668 } 2707 }
2669 }
2670#endif 2708#endif
2671 return p; 2709 return p;
2672} 2710}
2673 2711
2674static void create_sunlabel(void) 2712static void
2713create_sunlabel(void)
2675{ 2714{
2676 struct hd_geometry geometry; 2715 struct hd_geometry geometry;
2677 unsigned int ndiv; 2716 unsigned int ndiv;
@@ -2680,9 +2719,9 @@ static void create_sunlabel(void)
2680 const struct sun_predefined_drives *p = NULL; 2719 const struct sun_predefined_drives *p = NULL;
2681 2720
2682 fprintf(stderr, 2721 fprintf(stderr,
2683 _("Building a new sun disklabel. Changes will remain in memory only,\n" 2722 _("Building a new sun disklabel. Changes will remain in memory only,\n"
2684 "until you decide to write them. After that, of course, the previous\n" 2723 "until you decide to write them. After that, of course, the previous\n"
2685 "content won't be recoverable.\n\n")); 2724 "content won't be recoverable.\n\n"));
2686#if BYTE_ORDER == LITTLE_ENDIAN 2725#if BYTE_ORDER == LITTLE_ENDIAN
2687 sun_other_endian = 1; 2726 sun_other_endian = 1;
2688#else 2727#else
@@ -2691,113 +2730,103 @@ static void create_sunlabel(void)
2691 memset(MBRbuffer, 0, sizeof(MBRbuffer)); 2730 memset(MBRbuffer, 0, sizeof(MBRbuffer));
2692 sunlabel->magic = SUN_SSWAP16(SUN_LABEL_MAGIC); 2731 sunlabel->magic = SUN_SSWAP16(SUN_LABEL_MAGIC);
2693 if (!floppy) { 2732 if (!floppy) {
2694 puts(_("Drive type\n" 2733 puts(_("Drive type\n"
2695 " ? auto configure\n" 2734 " ? auto configure\n"
2696 " 0 custom (with hardware detected defaults)")); 2735 " 0 custom (with hardware detected defaults)"));
2697 for (i = 0; i < SIZE(sun_drives); i++) { 2736 for (i = 0; i < SIZE(sun_drives); i++) {
2698 printf(" %c %s%s%s\n", 2737 printf(" %c %s%s%s\n",
2699 i + 'a', sun_drives[i].vendor, 2738 i + 'a', sun_drives[i].vendor,
2700 (*sun_drives[i].vendor) ? " " : "", 2739 (*sun_drives[i].vendor) ? " " : "",
2701 sun_drives[i].model); 2740 sun_drives[i].model);
2702 } 2741 }
2703 for (;;) { 2742 while (1) {
2704 c = read_char(_("Select type (? for auto, 0 for custom): ")); 2743 c = read_char(_("Select type (? for auto, 0 for custom): "));
2705 if (c >= 'a' && c < 'a' + SIZE(sun_drives)) { 2744 if (c >= 'a' && c < 'a' + SIZE(sun_drives)) {
2706 p = sun_drives + c - 'a'; 2745 p = sun_drives + c - 'a';
2707 break; 2746 break;
2708 } else if (c >= 'A' && c < 'A' + SIZE(sun_drives)) { 2747 } else if (c >= 'A' && c < 'A' + SIZE(sun_drives)) {
2709 p = sun_drives + c - 'A'; 2748 p = sun_drives + c - 'A';
2710 break; 2749 break;
2711 } else if (c == '0') { 2750 } else if (c == '0') {
2712 break; 2751 break;
2713 } else if (c == '?' && scsi_disk) { 2752 } else if (c == '?' && scsi_disk) {
2714 p = sun_autoconfigure_scsi(); 2753 p = sun_autoconfigure_scsi();
2715 if (!p) 2754 if (!p)
2716 printf(_("Autoconfigure failed.\n")); 2755 printf(_("Autoconfigure failed.\n"));
2717 else 2756 else
2718 break; 2757 break;
2758 }
2719 } 2759 }
2720 }
2721 } 2760 }
2722 if (!p || floppy) { 2761 if (!p || floppy) {
2723 if (!ioctl(fd, HDIO_GETGEO, &geometry)) { 2762 if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
2724 heads = geometry.heads; 2763 heads = geometry.heads;
2725 sectors = geometry.sectors; 2764 sectors = geometry.sectors;
2726 cylinders = geometry.cylinders; 2765 cylinders = geometry.cylinders;
2727 } else { 2766 } else {
2728 heads = 0; 2767 heads = 0;
2729 sectors = 0; 2768 sectors = 0;
2730 cylinders = 0; 2769 cylinders = 0;
2731 } 2770 }
2732 if (floppy) { 2771 if (floppy) {
2733 sunlabel->nacyl = 0; 2772 sunlabel->nacyl = 0;
2734 sunlabel->pcylcount = SUN_SSWAP16(cylinders); 2773 sunlabel->pcylcount = SUN_SSWAP16(cylinders);
2735 sunlabel->rspeed = SUN_SSWAP16(300); 2774 sunlabel->rspeed = SUN_SSWAP16(300);
2736 sunlabel->ilfact = SUN_SSWAP16(1); 2775 sunlabel->ilfact = SUN_SSWAP16(1);
2737 sunlabel->sparecyl = 0; 2776 sunlabel->sparecyl = 0;
2738 } else { 2777 } else {
2739 heads = read_int(1,heads,1024,0,_("Heads")); 2778 heads = read_int(1,heads,1024,0,_("Heads"));
2740 sectors = read_int(1,sectors,1024,0,_("Sectors/track")); 2779 sectors = read_int(1,sectors,1024,0,_("Sectors/track"));
2741 if (cylinders) 2780 if (cylinders)
2742 cylinders = read_int(1,cylinders-2,65535,0,_("Cylinders")); 2781 cylinders = read_int(1,cylinders-2,65535,0,_("Cylinders"));
2743 else 2782 else
2744 cylinders = read_int(1,0,65535,0,_("Cylinders")); 2783 cylinders = read_int(1,0,65535,0,_("Cylinders"));
2745 sunlabel->nacyl = 2784 sunlabel->nacyl = SUN_SSWAP16(read_int(0,2,65535,0, _("Alternate cylinders")));
2746 SUN_SSWAP16(read_int(0,2,65535,0, 2785 sunlabel->pcylcount = SUN_SSWAP16(read_int(0,cylinders+SUN_SSWAP16(sunlabel->nacyl), 65535,0, _("Physical cylinders")));
2747 _("Alternate cylinders"))); 2786 sunlabel->rspeed = SUN_SSWAP16(read_int(1,5400,100000,0, _("Rotation speed (rpm)")));
2748 sunlabel->pcylcount = 2787 sunlabel->ilfact = SUN_SSWAP16(read_int(1,1,32,0, _("Interleave factor")));
2749 SUN_SSWAP16(read_int(0,cylinders+SUN_SSWAP16(sunlabel->nacyl), 2788 sunlabel->sparecyl = SUN_SSWAP16(read_int(0,0,sectors,0, _("Extra sectors per cylinder")));
2750 65535,0,_("Physical cylinders"))); 2789 }
2751 sunlabel->rspeed =
2752 SUN_SSWAP16(read_int(1,5400,100000,0,
2753 _("Rotation speed (rpm)")));
2754 sunlabel->ilfact =
2755 SUN_SSWAP16(read_int(1,1,32,0,_("Interleave factor")));
2756 sunlabel->sparecyl =
2757 SUN_SSWAP16(read_int(0,0,sectors,0,
2758 _("Extra sectors per cylinder")));
2759 }
2760 } else { 2790 } else {
2761 sunlabel->sparecyl = SUN_SSWAP16(p->sparecyl); 2791 sunlabel->sparecyl = SUN_SSWAP16(p->sparecyl);
2762 sunlabel->ncyl = SUN_SSWAP16(p->ncyl); 2792 sunlabel->ncyl = SUN_SSWAP16(p->ncyl);
2763 sunlabel->nacyl = SUN_SSWAP16(p->nacyl); 2793 sunlabel->nacyl = SUN_SSWAP16(p->nacyl);
2764 sunlabel->pcylcount = SUN_SSWAP16(p->pcylcount); 2794 sunlabel->pcylcount = SUN_SSWAP16(p->pcylcount);
2765 sunlabel->ntrks = SUN_SSWAP16(p->ntrks); 2795 sunlabel->ntrks = SUN_SSWAP16(p->ntrks);
2766 sunlabel->nsect = SUN_SSWAP16(p->nsect); 2796 sunlabel->nsect = SUN_SSWAP16(p->nsect);
2767 sunlabel->rspeed = SUN_SSWAP16(p->rspeed); 2797 sunlabel->rspeed = SUN_SSWAP16(p->rspeed);
2768 sunlabel->ilfact = SUN_SSWAP16(1); 2798 sunlabel->ilfact = SUN_SSWAP16(1);
2769 cylinders = p->ncyl; 2799 cylinders = p->ncyl;
2770 heads = p->ntrks; 2800 heads = p->ntrks;
2771 sectors = p->nsect; 2801 sectors = p->nsect;
2772 puts(_("You may change all the disk params from the x menu")); 2802 puts(_("You may change all the disk params from the x menu"));
2773 } 2803 }
2774 2804
2775 snprintf((char *)(sunlabel->info), sizeof(sunlabel->info), 2805 snprintf((char *)(sunlabel->info), sizeof(sunlabel->info),
2776 "%s%s%s cyl %d alt %d hd %d sec %d", 2806 "%s%s%s cyl %d alt %d hd %d sec %d",
2777 p ? p->vendor : "", (p && *p->vendor) ? " " : "", 2807 p ? p->vendor : "", (p && *p->vendor) ? " " : "",
2778 p ? p->model 2808 p ? p->model : (floppy ? _("3,5\" floppy") : _("Linux custom")),
2779 : (floppy ? _("3,5\" floppy") : _("Linux custom")),
2780 cylinders, SUN_SSWAP16(sunlabel->nacyl), heads, sectors); 2809 cylinders, SUN_SSWAP16(sunlabel->nacyl), heads, sectors);
2781 2810
2782 sunlabel->ntrks = SUN_SSWAP16(heads); 2811 sunlabel->ntrks = SUN_SSWAP16(heads);
2783 sunlabel->nsect = SUN_SSWAP16(sectors); 2812 sunlabel->nsect = SUN_SSWAP16(sectors);
2784 sunlabel->ncyl = SUN_SSWAP16(cylinders); 2813 sunlabel->ncyl = SUN_SSWAP16(cylinders);
2785 if (floppy) 2814 if (floppy)
2786 set_sun_partition(0, 0, cylinders * heads * sectors, LINUX_NATIVE); 2815 set_sun_partition(0, 0, cylinders * heads * sectors, LINUX_NATIVE);
2787 else { 2816 else {
2788 if (cylinders * heads * sectors >= 150 * 2048) { 2817 if (cylinders * heads * sectors >= 150 * 2048) {
2789 ndiv = cylinders - (50 * 2048 / (heads * sectors)); /* 50M swap */ 2818 ndiv = cylinders - (50 * 2048 / (heads * sectors)); /* 50M swap */
2790 } else 2819 } else
2791 ndiv = cylinders * 2 / 3; 2820 ndiv = cylinders * 2 / 3;
2792 set_sun_partition(0, 0, ndiv * heads * sectors, LINUX_NATIVE); 2821 set_sun_partition(0, 0, ndiv * heads * sectors, LINUX_NATIVE);
2793 set_sun_partition(1, ndiv * heads * sectors, cylinders * heads * sectors, LINUX_SWAP); 2822 set_sun_partition(1, ndiv * heads * sectors, cylinders * heads * sectors, LINUX_SWAP);
2794 sunlabel->infos[1].flags |= 0x01; /* Not mountable */ 2823 sunlabel->infos[1].flags |= 0x01; /* Not mountable */
2795 } 2824 }
2796 set_sun_partition(2, 0, cylinders * heads * sectors, WHOLE_DISK); 2825 set_sun_partition(2, 0, cylinders * heads * sectors, WHOLE_DISK);
2797 { 2826 {
2798 unsigned short *ush = (unsigned short *)sunlabel; 2827 unsigned short *ush = (unsigned short *)sunlabel;
2799 unsigned short csum = 0; 2828 unsigned short csum = 0;
2800 while(ush < (unsigned short *)(&sunlabel->csum)) 2829 while (ush < (unsigned short *)(&sunlabel->csum))
2801 csum ^= *ush++; 2830 csum ^= *ush++;
2802 sunlabel->csum = csum; 2831 sunlabel->csum = csum;
2803 } 2832 }
@@ -2808,21 +2837,26 @@ static void create_sunlabel(void)
2808} 2837}
2809 2838
2810static void 2839static void
2811toggle_sunflags(int i, unsigned char mask) { 2840toggle_sunflags(int i, unsigned char mask)
2841{
2812 if (sunlabel->infos[i].flags & mask) 2842 if (sunlabel->infos[i].flags & mask)
2813 sunlabel->infos[i].flags &= ~mask; 2843 sunlabel->infos[i].flags &= ~mask;
2814 else sunlabel->infos[i].flags |= mask; 2844 else
2845 sunlabel->infos[i].flags |= mask;
2815 set_changed(i); 2846 set_changed(i);
2816} 2847}
2817 2848
2818static void 2849static void
2819fetch_sun(uint *starts, uint *lens, uint *start, uint *stop) { 2850fetch_sun(uint *starts, uint *lens, uint *start, uint *stop)
2851{
2820 int i, continuous = 1; 2852 int i, continuous = 1;
2821 *start = 0; *stop = cylinders * heads * sectors; 2853
2854 *start = 0;
2855 *stop = cylinders * heads * sectors;
2822 for (i = 0; i < partitions; i++) { 2856 for (i = 0; i < partitions; i++) {
2823 if (sunlabel->partitions[i].num_sectors 2857 if (sunlabel->partitions[i].num_sectors
2824 && sunlabel->infos[i].id 2858 && sunlabel->infos[i].id
2825 && sunlabel->infos[i].id != WHOLE_DISK) { 2859 && sunlabel->infos[i].id != WHOLE_DISK) {
2826 starts[i] = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors; 2860 starts[i] = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors;
2827 lens[i] = SUN_SSWAP32(sunlabel->partitions[i].num_sectors); 2861 lens[i] = SUN_SSWAP32(sunlabel->partitions[i].num_sectors);
2828 if (continuous) { 2862 if (continuous) {
@@ -2845,77 +2879,80 @@ fetch_sun(uint *starts, uint *lens, uint *start, uint *stop) {
2845static uint *verify_sun_starts; 2879static uint *verify_sun_starts;
2846 2880
2847static int 2881static int
2848verify_sun_cmp(int *a, int *b) { 2882verify_sun_cmp(int *a, int *b)
2849 if (*a == -1) return 1; 2883{
2850 if (*b == -1) return -1; 2884 if (*a == -1) return 1;
2851 if (verify_sun_starts[*a] > verify_sun_starts[*b]) return 1; 2885 if (*b == -1) return -1;
2852 return -1; 2886 if (verify_sun_starts[*a] > verify_sun_starts[*b]) return 1;
2887 return -1;
2853} 2888}
2854 2889
2855static void 2890static void
2856verify_sun(void) { 2891verify_sun(void)
2857 uint starts[8], lens[8], start, stop; 2892{
2858 int i,j,k,starto,endo; 2893 uint starts[8], lens[8], start, stop;
2859 int array[8]; 2894 int i,j,k,starto,endo;
2860 2895 int array[8];
2861 verify_sun_starts = starts; 2896
2862 fetch_sun(starts,lens,&start,&stop); 2897 verify_sun_starts = starts;
2863 for (k = 0; k < 7; k++) { 2898 fetch_sun(starts,lens,&start,&stop);
2864 for (i = 0; i < 8; i++) { 2899 for (k = 0; k < 7; k++) {
2865 if (k && (lens[i] % (heads * sectors))) { 2900 for (i = 0; i < 8; i++) {
2866 printf(_("Partition %d doesn't end on cylinder boundary\n"), i+1); 2901 if (k && (lens[i] % (heads * sectors))) {
2867 } 2902 printf(_("Partition %d doesn't end on cylinder boundary\n"), i+1);
2868 if (lens[i]) {
2869 for (j = 0; j < i; j++)
2870 if (lens[j]) {
2871 if (starts[j] == starts[i]+lens[i]) {
2872 starts[j] = starts[i]; lens[j] += lens[i];
2873 lens[i] = 0;
2874 } else if (starts[i] == starts[j]+lens[j]){
2875 lens[j] += lens[i];
2876 lens[i] = 0;
2877 } else if (!k) {
2878 if (starts[i] < starts[j]+lens[j] &&
2879 starts[j] < starts[i]+lens[i]) {
2880 starto = starts[i];
2881 if (starts[j] > starto)
2882 starto = starts[j];
2883 endo = starts[i]+lens[i];
2884 if (starts[j]+lens[j] < endo)
2885 endo = starts[j]+lens[j];
2886 printf(_("Partition %d overlaps with others in "
2887 "sectors %d-%d\n"), i+1, starto, endo);
2888 }
2889 } 2903 }
2890 } 2904 if (lens[i]) {
2891 } 2905 for (j = 0; j < i; j++)
2906 if (lens[j]) {
2907 if (starts[j] == starts[i]+lens[i]) {
2908 starts[j] = starts[i]; lens[j] += lens[i];
2909 lens[i] = 0;
2910 } else if (starts[i] == starts[j]+lens[j]){
2911 lens[j] += lens[i];
2912 lens[i] = 0;
2913 } else if (!k) {
2914 if (starts[i] < starts[j]+lens[j]
2915 && starts[j] < starts[i]+lens[i]) {
2916 starto = starts[i];
2917 if (starts[j] > starto)
2918 starto = starts[j];
2919 endo = starts[i]+lens[i];
2920 if (starts[j]+lens[j] < endo)
2921 endo = starts[j]+lens[j];
2922 printf(_("Partition %d overlaps with others in "
2923 "sectors %d-%d\n"), i+1, starto, endo);
2924 }
2925 }
2926 }
2927 }
2928 }
2892 } 2929 }
2893 } 2930 for (i = 0; i < 8; i++) {
2894 for (i = 0; i < 8; i++) { 2931 if (lens[i])
2895 if (lens[i]) 2932 array[i] = i;
2896 array[i] = i; 2933 else
2897 else 2934 array[i] = -1;
2898 array[i] = -1; 2935 }
2899 } 2936 qsort(array,SIZE(array),sizeof(array[0]),
2900 qsort(array,SIZE(array),sizeof(array[0]), 2937 (int (*)(const void *,const void *)) verify_sun_cmp);
2901 (int (*)(const void *,const void *)) verify_sun_cmp); 2938 if (array[0] == -1) {
2902 if (array[0] == -1) { 2939 printf(_("No partitions defined\n"));
2903 printf(_("No partitions defined\n")); 2940 return;
2904 return; 2941 }
2905 } 2942 stop = cylinders * heads * sectors;
2906 stop = cylinders * heads * sectors; 2943 if (starts[array[0]])
2907 if (starts[array[0]]) 2944 printf(_("Unused gap - sectors 0-%d\n"),starts[array[0]]);
2908 printf(_("Unused gap - sectors 0-%d\n"),starts[array[0]]); 2945 for (i = 0; i < 7 && array[i+1] != -1; i++) {
2909 for (i = 0; i < 7 && array[i+1] != -1; i++) { 2946 printf(_("Unused gap - sectors %d-%d\n"),starts[array[i]]+lens[array[i]],starts[array[i+1]]);
2910 printf(_("Unused gap - sectors %d-%d\n"),starts[array[i]]+lens[array[i]],starts[array[i+1]]); 2947 }
2911 } 2948 start = starts[array[i]] + lens[array[i]];
2912 start = starts[array[i]]+lens[array[i]]; 2949 if (start < stop)
2913 if (start < stop) 2950 printf(_("Unused gap - sectors %d-%d\n"),start,stop);
2914 printf(_("Unused gap - sectors %d-%d\n"),start,stop);
2915} 2951}
2916 2952
2917static void 2953static void
2918add_sun_partition(int n, int sys) { 2954add_sun_partition(int n, int sys)
2955{
2919 uint start, stop, stop2; 2956 uint start, stop, stop2;
2920 uint starts[8], lens[8]; 2957 uint starts[8], lens[8];
2921 int whole_disk = 0; 2958 int whole_disk = 0;
@@ -2935,12 +2972,12 @@ add_sun_partition(int n, int sys) {
2935 whole_disk = 1; 2972 whole_disk = 1;
2936 else { 2973 else {
2937 printf(_("Other partitions already cover the whole disk.\nDelete " 2974 printf(_("Other partitions already cover the whole disk.\nDelete "
2938 "some/shrink them before retry.\n")); 2975 "some/shrink them before retry.\n"));
2939 return; 2976 return;
2940 } 2977 }
2941 } 2978 }
2942 snprintf(mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR)); 2979 snprintf(mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));
2943 for (;;) { 2980 while (1) {
2944 if (whole_disk) 2981 if (whole_disk)
2945 first = read_int(0, 0, 0, 0, mesg); 2982 first = read_int(0, 0, 0, 0, mesg);
2946 else 2983 else
@@ -2952,7 +2989,7 @@ add_sun_partition(int n, int sys) {
2952 /* Starting sector has to be properly aligned */ 2989 /* Starting sector has to be properly aligned */
2953 first = (first + heads * sectors - 1) / (heads * sectors); 2990 first = (first + heads * sectors - 1) / (heads * sectors);
2954 if (n == 2 && first != 0) 2991 if (n == 2 && first != 0)
2955 printf ("\ 2992 printf("\
2956It is highly recommended that the third partition covers the whole disk\n\ 2993It is highly recommended that the third partition covers the whole disk\n\
2957and is of type `Whole disk'\n"); 2994and is of type `Whole disk'\n");
2958 /* ewt asks to add: "don't start a partition at cyl 0" 2995 /* ewt asks to add: "don't start a partition at cyl 0"
@@ -2972,13 +3009,12 @@ and is of type `Whole disk'\n");
2972 starting at block 0 in an md, or the label will 3009 starting at block 0 in an md, or the label will
2973 be trashed. */ 3010 be trashed. */
2974 for (i = 0; i < partitions; i++) 3011 for (i = 0; i < partitions; i++)
2975 if (lens[i] && starts[i] <= first 3012 if (lens[i] && starts[i] <= first && starts[i] + lens[i] > first)
2976 && starts[i] + lens[i] > first)
2977 break; 3013 break;
2978 if (i < partitions && !whole_disk) { 3014 if (i < partitions && !whole_disk) {
2979 if (n == 2 && !first) { 3015 if (n == 2 && !first) {
2980 whole_disk = 1; 3016 whole_disk = 1;
2981 break; 3017 break;
2982 } 3018 }
2983 printf(_("Sector %d is already allocated\n"), first); 3019 printf(_("Sector %d is already allocated\n"), first);
2984 } else 3020 } else
@@ -2991,8 +3027,8 @@ and is of type `Whole disk'\n");
2991 stop = starts[i]; 3027 stop = starts[i];
2992 } 3028 }
2993 snprintf(mesg, sizeof(mesg), 3029 snprintf(mesg, sizeof(mesg),
2994 _("Last %s or +size or +sizeM or +sizeK"), 3030 _("Last %s or +size or +sizeM or +sizeK"),
2995 str_units(SINGULAR)); 3031 str_units(SINGULAR));
2996 if (whole_disk) 3032 if (whole_disk)
2997 last = read_int(scround(stop2), scround(stop2), scround(stop2), 3033 last = read_int(scround(stop2), scround(stop2), scround(stop2),
2998 0, mesg); 3034 0, mesg);
@@ -3006,51 +3042,55 @@ and is of type `Whole disk'\n");
3006 last *= units_per_sector; 3042 last *= units_per_sector;
3007 if (n == 2 && !first) { 3043 if (n == 2 && !first) {
3008 if (last >= stop2) { 3044 if (last >= stop2) {
3009 whole_disk = 1; 3045 whole_disk = 1;
3010 last = stop2; 3046 last = stop2;
3011 } else if (last > stop) { 3047 } else if (last > stop) {
3012 printf ( 3048 printf(_("You haven't covered the whole disk with "
3013 _("You haven't covered the whole disk with the 3rd partition, but your value\n" 3049 "the 3rd partition, but your value\n"
3014 "%d %s covers some other partition. Your entry has been changed\n" 3050 "%d %s covers some other partition. "
3015 "to %d %s\n"), 3051 "Your entry has been changed\n"
3016 scround(last), str_units(SINGULAR), 3052 "to %d %s\n"),
3017 scround(stop), str_units(SINGULAR)); 3053 scround(last), str_units(SINGULAR),
3018 last = stop; 3054 scround(stop), str_units(SINGULAR));
3055 last = stop;
3019 } 3056 }
3020 } else if (!whole_disk && last > stop) 3057 } else if (!whole_disk && last > stop)
3021 last = stop; 3058 last = stop;
3022 3059
3023 if (whole_disk) sys = WHOLE_DISK; 3060 if (whole_disk)
3061 sys = WHOLE_DISK;
3024 set_sun_partition(n, first, last, sys); 3062 set_sun_partition(n, first, last, sys);
3025} 3063}
3026 3064
3027static void 3065static void
3028sun_delete_partition(int i) { 3066sun_delete_partition(int i)
3067{
3029 unsigned int nsec; 3068 unsigned int nsec;
3030 3069
3031 if (i == 2 && sunlabel->infos[i].id == WHOLE_DISK && 3070 if (i == 2
3032 !sunlabel->partitions[i].start_cylinder && 3071 && sunlabel->infos[i].id == WHOLE_DISK
3033 (nsec = SUN_SSWAP32(sunlabel->partitions[i].num_sectors)) 3072 && !sunlabel->partitions[i].start_cylinder
3034 == heads * sectors * cylinders) 3073 && (nsec = SUN_SSWAP32(sunlabel->partitions[i].num_sectors)) == heads * sectors * cylinders)
3035 printf(_("If you want to maintain SunOS/Solaris compatibility, " 3074 printf(_("If you want to maintain SunOS/Solaris compatibility, "
3036 "consider leaving this\n" 3075 "consider leaving this\n"
3037 "partition as Whole disk (5), starting at 0, with %u " 3076 "partition as Whole disk (5), starting at 0, with %u "
3038 "sectors\n"), nsec); 3077 "sectors\n"), nsec);
3039 sunlabel->infos[i].id = 0; 3078 sunlabel->infos[i].id = 0;
3040 sunlabel->partitions[i].num_sectors = 0; 3079 sunlabel->partitions[i].num_sectors = 0;
3041} 3080}
3042 3081
3043static void 3082static void
3044sun_change_sysid(int i, int sys) { 3083sun_change_sysid(int i, int sys)
3084{
3045 if (sys == LINUX_SWAP && !sunlabel->partitions[i].start_cylinder) { 3085 if (sys == LINUX_SWAP && !sunlabel->partitions[i].start_cylinder) {
3046 read_chars( 3086 read_chars(
3047 _("It is highly recommended that the partition at offset 0\n" 3087 _("It is highly recommended that the partition at offset 0\n"
3048 "is UFS, EXT2FS filesystem or SunOS swap. Putting Linux swap\n" 3088 "is UFS, EXT2FS filesystem or SunOS swap. Putting Linux swap\n"
3049 "there may destroy your partition table and bootblock.\n" 3089 "there may destroy your partition table and bootblock.\n"
3050 "Type YES if you're very sure you would like that partition\n" 3090 "Type YES if you're very sure you would like that partition\n"
3051 "tagged with 82 (Linux swap): ")); 3091 "tagged with 82 (Linux swap): "));
3052 if (strcmp (line_ptr, _("YES\n"))) 3092 if (strcmp (line_ptr, _("YES\n")))
3053 return; 3093 return;
3054 } 3094 }
3055 switch (sys) { 3095 switch (sys) {
3056 case SUNOS_SWAP: 3096 case SUNOS_SWAP:
@@ -3068,7 +3108,8 @@ sun_change_sysid(int i, int sys) {
3068} 3108}
3069 3109
3070static void 3110static void
3071sun_list_table(int xtra) { 3111sun_list_table(int xtra)
3112{
3072 int i, w; 3113 int i, w;
3073 3114
3074 w = strlen(disk_device); 3115 w = strlen(disk_device);
@@ -3079,36 +3120,35 @@ sun_list_table(int xtra) {
3079 "%d extra sects/cyl, interleave %d:1\n" 3120 "%d extra sects/cyl, interleave %d:1\n"
3080 "%s\n" 3121 "%s\n"
3081 "Units = %s of %d * 512 bytes\n\n"), 3122 "Units = %s of %d * 512 bytes\n\n"),
3082 disk_device, heads, sectors, SUN_SSWAP16(sunlabel->rspeed), 3123 disk_device, heads, sectors, SUN_SSWAP16(sunlabel->rspeed),
3083 cylinders, SUN_SSWAP16(sunlabel->nacyl), 3124 cylinders, SUN_SSWAP16(sunlabel->nacyl),
3084 SUN_SSWAP16(sunlabel->pcylcount), 3125 SUN_SSWAP16(sunlabel->pcylcount),
3085 SUN_SSWAP16(sunlabel->sparecyl), 3126 SUN_SSWAP16(sunlabel->sparecyl),
3086 SUN_SSWAP16(sunlabel->ilfact), 3127 SUN_SSWAP16(sunlabel->ilfact),
3087 (char *)sunlabel, 3128 (char *)sunlabel,
3088 str_units(PLURAL), units_per_sector); 3129 str_units(PLURAL), units_per_sector);
3089 else 3130 else
3090 printf( 3131 printf(
3091 _("\nDisk %s (Sun disk label): %d heads, %d sectors, %d cylinders\n" 3132 _("\nDisk %s (Sun disk label): %d heads, %d sectors, %d cylinders\n"
3092 "Units = %s of %d * 512 bytes\n\n"), 3133 "Units = %s of %d * 512 bytes\n\n"),
3093 disk_device, heads, sectors, cylinders, 3134 disk_device, heads, sectors, cylinders,
3094 str_units(PLURAL), units_per_sector); 3135 str_units(PLURAL), units_per_sector);
3095 3136
3096 printf(_("%*s Flag Start End Blocks Id System\n"), 3137 printf(_("%*s Flag Start End Blocks Id System\n"),
3097 w + 1, _("Device")); 3138 w + 1, _("Device"));
3098 for (i = 0 ; i < partitions; i++) { 3139 for (i = 0 ; i < partitions; i++) {
3099 if (sunlabel->partitions[i].num_sectors) { 3140 if (sunlabel->partitions[i].num_sectors) {
3100 uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors; 3141 uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors;
3101 uint32_t len = SUN_SSWAP32(sunlabel->partitions[i].num_sectors); 3142 uint32_t len = SUN_SSWAP32(sunlabel->partitions[i].num_sectors);
3102 printf( 3143 printf("%s %c%c %9ld %9ld %9ld%c %2x %s\n",
3103 "%s %c%c %9ld %9ld %9ld%c %2x %s\n", 3144 partname(disk_device, i+1, w), /* device */
3104/* device */ partname(disk_device, i+1, w), 3145 (sunlabel->infos[i].flags & 0x01) ? 'u' : ' ', /* flags */
3105/* flags */ (sunlabel->infos[i].flags & 0x01) ? 'u' : ' ', 3146 (sunlabel->infos[i].flags & 0x10) ? 'r' : ' ',
3106 (sunlabel->infos[i].flags & 0x10) ? 'r' : ' ', 3147 (long) scround(start), /* start */
3107/* start */ (long) scround(start), 3148 (long) scround(start+len), /* end */
3108/* end */ (long) scround(start+len), 3149 (long) len / 2, len & 1 ? '+' : ' ', /* odd flag on end */
3109/* odd flag on end */ (long) len / 2, len & 1 ? '+' : ' ', 3150 sunlabel->infos[i].id, /* type id */
3110/* type id */ sunlabel->infos[i].id, 3151 partition_type(sunlabel->infos[i].id)); /* type name */
3111/* type name */ partition_type(sunlabel->infos[i].id));
3112 } 3152 }
3113 } 3153 }
3114} 3154}
@@ -3116,52 +3156,59 @@ sun_list_table(int xtra) {
3116#ifdef CONFIG_FEATURE_FDISK_ADVANCED 3156#ifdef CONFIG_FEATURE_FDISK_ADVANCED
3117 3157
3118static void 3158static void
3119sun_set_alt_cyl(void) { 3159sun_set_alt_cyl(void)
3160{
3120 sunlabel->nacyl = 3161 sunlabel->nacyl =
3121 SUN_SSWAP16(read_int(0,SUN_SSWAP16(sunlabel->nacyl), 65535, 0, 3162 SUN_SSWAP16(read_int(0,SUN_SSWAP16(sunlabel->nacyl), 65535, 0,
3122 _("Number of alternate cylinders"))); 3163 _("Number of alternate cylinders")));
3123} 3164}
3124 3165
3125static void 3166static void
3126sun_set_ncyl(int cyl) { 3167sun_set_ncyl(int cyl)
3168{
3127 sunlabel->ncyl = SUN_SSWAP16(cyl); 3169 sunlabel->ncyl = SUN_SSWAP16(cyl);
3128} 3170}
3129 3171
3130static void 3172static void
3131sun_set_xcyl(void) { 3173sun_set_xcyl(void)
3174{
3132 sunlabel->sparecyl = 3175 sunlabel->sparecyl =
3133 SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->sparecyl), sectors, 0, 3176 SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->sparecyl), sectors, 0,
3134 _("Extra sectors per cylinder"))); 3177 _("Extra sectors per cylinder")));
3135} 3178}
3136 3179
3137static void 3180static void
3138sun_set_ilfact(void) { 3181sun_set_ilfact(void)
3182{
3139 sunlabel->ilfact = 3183 sunlabel->ilfact =
3140 SUN_SSWAP16(read_int(1, SUN_SSWAP16(sunlabel->ilfact), 32, 0, 3184 SUN_SSWAP16(read_int(1, SUN_SSWAP16(sunlabel->ilfact), 32, 0,
3141 _("Interleave factor"))); 3185 _("Interleave factor")));
3142} 3186}
3143 3187
3144static void 3188static void
3145sun_set_rspeed(void) { 3189sun_set_rspeed(void)
3190{
3146 sunlabel->rspeed = 3191 sunlabel->rspeed =
3147 SUN_SSWAP16(read_int(1, SUN_SSWAP16(sunlabel->rspeed), 100000, 0, 3192 SUN_SSWAP16(read_int(1, SUN_SSWAP16(sunlabel->rspeed), 100000, 0,
3148 _("Rotation speed (rpm)"))); 3193 _("Rotation speed (rpm)")));
3149} 3194}
3150 3195
3151static void 3196static void
3152sun_set_pcylcount(void) { 3197sun_set_pcylcount(void)
3198{
3153 sunlabel->pcylcount = 3199 sunlabel->pcylcount =
3154 SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->pcylcount), 65535, 0, 3200 SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->pcylcount), 65535, 0,
3155 _("Number of physical cylinders"))); 3201 _("Number of physical cylinders")));
3156} 3202}
3157#endif /* CONFIG_FEATURE_FDISK_ADVANCED */ 3203#endif /* CONFIG_FEATURE_FDISK_ADVANCED */
3158 3204
3159static void 3205static void
3160sun_write_table(void) { 3206sun_write_table(void)
3207{
3161 unsigned short *ush = (unsigned short *)sunlabel; 3208 unsigned short *ush = (unsigned short *)sunlabel;
3162 unsigned short csum = 0; 3209 unsigned short csum = 0;
3163 3210
3164 while(ush < (unsigned short *)(&sunlabel->csum)) 3211 while (ush < (unsigned short *)(&sunlabel->csum))
3165 csum ^= *ush++; 3212 csum ^= *ush++;
3166 sunlabel->csum = csum; 3213 sunlabel->csum = csum;
3167 if (lseek(fd, 0, SEEK_SET) < 0) 3214 if (lseek(fd, 0, SEEK_SET) < 0)
@@ -3174,104 +3221,104 @@ sun_write_table(void) {
3174/* DOS partition types */ 3221/* DOS partition types */
3175 3222
3176static const struct systypes i386_sys_types[] = { 3223static const struct systypes i386_sys_types[] = {
3177 {"\x00" "Empty"}, 3224 { "\x00" "Empty" },
3178 {"\x01" "FAT12"}, 3225 { "\x01" "FAT12" },
3179 {"\x04" "FAT16 <32M"}, 3226 { "\x04" "FAT16 <32M" },
3180 {"\x05" "Extended"}, /* DOS 3.3+ extended partition */ 3227 { "\x05" "Extended" }, /* DOS 3.3+ extended partition */
3181 {"\x06" "FAT16"}, /* DOS 16-bit >=32M */ 3228 { "\x06" "FAT16" }, /* DOS 16-bit >=32M */
3182 {"\x07" "HPFS/NTFS"}, /* OS/2 IFS, eg, HPFS or NTFS or QNX */ 3229 { "\x07" "HPFS/NTFS" }, /* OS/2 IFS, eg, HPFS or NTFS or QNX */
3183 {"\x0a" "OS/2 Boot Manager"},/* OS/2 Boot Manager */ 3230 { "\x0a" "OS/2 Boot Manager" },/* OS/2 Boot Manager */
3184 {"\x0b" "Win95 FAT32"}, 3231 { "\x0b" "Win95 FAT32" },
3185 {"\x0c" "Win95 FAT32 (LBA)"},/* LBA really is `Extended Int 13h' */ 3232 { "\x0c" "Win95 FAT32 (LBA)" },/* LBA really is `Extended Int 13h' */
3186 {"\x0e" "Win95 FAT16 (LBA)"}, 3233 { "\x0e" "Win95 FAT16 (LBA)" },
3187 {"\x0f" "Win95 Ext'd (LBA)"}, 3234 { "\x0f" "Win95 Ext'd (LBA)" },
3188 {"\x11" "Hidden FAT12"}, 3235 { "\x11" "Hidden FAT12" },
3189 {"\x12" "Compaq diagnostics"}, 3236 { "\x12" "Compaq diagnostics" },
3190 {"\x14" "Hidden FAT16 <32M"}, 3237 { "\x14" "Hidden FAT16 <32M" },
3191 {"\x16" "Hidden FAT16"}, 3238 { "\x16" "Hidden FAT16" },
3192 {"\x17" "Hidden HPFS/NTFS"}, 3239 { "\x17" "Hidden HPFS/NTFS" },
3193 {"\x1b" "Hidden Win95 FAT32"}, 3240 { "\x1b" "Hidden Win95 FAT32" },
3194 {"\x1c" "Hidden Win95 FAT32 (LBA)"}, 3241 { "\x1c" "Hidden Win95 FAT32 (LBA)" },
3195 {"\x1e" "Hidden Win95 FAT16 (LBA)"}, 3242 { "\x1e" "Hidden Win95 FAT16 (LBA)" },
3196 {"\x3c" "PartitionMagic recovery"}, 3243 { "\x3c" "PartitionMagic recovery" },
3197 {"\x41" "PPC PReP Boot"}, 3244 { "\x41" "PPC PReP Boot" },
3198 {"\x42" "SFS"}, 3245 { "\x42" "SFS" },
3199 {"\x63" "GNU HURD or SysV"}, /* GNU HURD or Mach or Sys V/386 (such as ISC UNIX) */ 3246 { "\x63" "GNU HURD or SysV" }, /* GNU HURD or Mach or Sys V/386 (such as ISC UNIX) */
3200 {"\x80" "Old Minix"}, /* Minix 1.4a and earlier */ 3247 { "\x80" "Old Minix" }, /* Minix 1.4a and earlier */
3201 {"\x81" "Minix / old Linux"},/* Minix 1.4b and later */ 3248 { "\x81" "Minix / old Linux" },/* Minix 1.4b and later */
3202 {"\x82" "Linux swap"}, /* also Solaris */ 3249 { "\x82" "Linux swap" }, /* also Solaris */
3203 {"\x83" "Linux"}, 3250 { "\x83" "Linux" },
3204 {"\x84" "OS/2 hidden C: drive"}, 3251 { "\x84" "OS/2 hidden C: drive" },
3205 {"\x85" "Linux extended"}, 3252 { "\x85" "Linux extended" },
3206 {"\x86" "NTFS volume set"}, 3253 { "\x86" "NTFS volume set" },
3207 {"\x87" "NTFS volume set"}, 3254 { "\x87" "NTFS volume set" },
3208 {"\x8e" "Linux LVM"}, 3255 { "\x8e" "Linux LVM" },
3209 {"\x9f" "BSD/OS"}, /* BSDI */ 3256 { "\x9f" "BSD/OS" }, /* BSDI */
3210 {"\xa0" "IBM Thinkpad hibernation"}, 3257 { "\xa0" "IBM Thinkpad hibernation" },
3211 {"\xa5" "FreeBSD"}, /* various BSD flavours */ 3258 { "\xa5" "FreeBSD" }, /* various BSD flavours */
3212 {"\xa6" "OpenBSD"}, 3259 { "\xa6" "OpenBSD" },
3213 {"\xa8" "Darwin UFS"}, 3260 { "\xa8" "Darwin UFS" },
3214 {"\xa9" "NetBSD"}, 3261 { "\xa9" "NetBSD" },
3215 {"\xab" "Darwin boot"}, 3262 { "\xab" "Darwin boot" },
3216 {"\xb7" "BSDI fs"}, 3263 { "\xb7" "BSDI fs" },
3217 {"\xb8" "BSDI swap"}, 3264 { "\xb8" "BSDI swap" },
3218 {"\xbe" "Solaris boot"}, 3265 { "\xbe" "Solaris boot" },
3219 {"\xeb" "BeOS fs"}, 3266 { "\xeb" "BeOS fs" },
3220 {"\xee" "EFI GPT"}, /* Intel EFI GUID Partition Table */ 3267 { "\xee" "EFI GPT" }, /* Intel EFI GUID Partition Table */
3221 {"\xef" "EFI (FAT-12/16/32)"},/* Intel EFI System Partition */ 3268 { "\xef" "EFI (FAT-12/16/32)" },/* Intel EFI System Partition */
3222 {"\xf0" "Linux/PA-RISC boot"},/* Linux/PA-RISC boot loader */ 3269 { "\xf0" "Linux/PA-RISC boot" },/* Linux/PA-RISC boot loader */
3223 {"\xf2" "DOS secondary"}, /* DOS 3.3+ secondary */ 3270 { "\xf2" "DOS secondary" }, /* DOS 3.3+ secondary */
3224 {"\xfd" "Linux raid autodetect"},/* New (2.2.x) raid partition with 3271 { "\xfd" "Linux raid autodetect" },/* New (2.2.x) raid partition with
3225 autodetect using persistent 3272 autodetect using persistent
3226 superblock */ 3273 superblock */
3227#ifdef CONFIG_WEIRD_PARTITION_TYPES 3274#ifdef CONFIG_WEIRD_PARTITION_TYPES
3228 {"\x02" "XENIX root"}, 3275 { "\x02" "XENIX root" },
3229 {"\x03" "XENIX usr"}, 3276 { "\x03" "XENIX usr" },
3230 {"\x08" "AIX"}, /* AIX boot (AIX -- PS/2 port) or SplitDrive */ 3277 { "\x08" "AIX" }, /* AIX boot (AIX -- PS/2 port) or SplitDrive */
3231 {"\x09" "AIX bootable"}, /* AIX data or Coherent */ 3278 { "\x09" "AIX bootable" }, /* AIX data or Coherent */
3232 {"\x10" "OPUS"}, 3279 { "\x10" "OPUS" },
3233 {"\x18" "AST SmartSleep"}, 3280 { "\x18" "AST SmartSleep" },
3234 {"\x24" "NEC DOS"}, 3281 { "\x24" "NEC DOS" },
3235 {"\x39" "Plan 9"}, 3282 { "\x39" "Plan 9" },
3236 {"\x40" "Venix 80286"}, 3283 { "\x40" "Venix 80286" },
3237 {"\x4d" "QNX4.x"}, 3284 { "\x4d" "QNX4.x" },
3238 {"\x4e" "QNX4.x 2nd part"}, 3285 { "\x4e" "QNX4.x 2nd part" },
3239 {"\x4f" "QNX4.x 3rd part"}, 3286 { "\x4f" "QNX4.x 3rd part" },
3240 {"\x50" "OnTrack DM"}, 3287 { "\x50" "OnTrack DM" },
3241 {"\x51" "OnTrack DM6 Aux1"}, /* (or Novell) */ 3288 { "\x51" "OnTrack DM6 Aux1" }, /* (or Novell) */
3242 {"\x52" "CP/M"}, /* CP/M or Microport SysV/AT */ 3289 { "\x52" "CP/M" }, /* CP/M or Microport SysV/AT */
3243 {"\x53" "OnTrack DM6 Aux3"}, 3290 { "\x53" "OnTrack DM6 Aux3" },
3244 {"\x54" "OnTrackDM6"}, 3291 { "\x54" "OnTrackDM6" },
3245 {"\x55" "EZ-Drive"}, 3292 { "\x55" "EZ-Drive" },
3246 {"\x56" "Golden Bow"}, 3293 { "\x56" "Golden Bow" },
3247 {"\x5c" "Priam Edisk"}, 3294 { "\x5c" "Priam Edisk" },
3248 {"\x61" "SpeedStor"}, 3295 { "\x61" "SpeedStor" },
3249 {"\x64" "Novell Netware 286"}, 3296 { "\x64" "Novell Netware 286" },
3250 {"\x65" "Novell Netware 386"}, 3297 { "\x65" "Novell Netware 386" },
3251 {"\x70" "DiskSecure Multi-Boot"}, 3298 { "\x70" "DiskSecure Multi-Boot" },
3252 {"\x75" "PC/IX"}, 3299 { "\x75" "PC/IX" },
3253 {"\x93" "Amoeba"}, 3300 { "\x93" "Amoeba" },
3254 {"\x94" "Amoeba BBT"}, /* (bad block table) */ 3301 { "\x94" "Amoeba BBT" }, /* (bad block table) */
3255 {"\xa7" "NeXTSTEP"}, 3302 { "\xa7" "NeXTSTEP" },
3256 {"\xbb" "Boot Wizard hidden"}, 3303 { "\xbb" "Boot Wizard hidden" },
3257 {"\xc1" "DRDOS/sec (FAT-12)"}, 3304 { "\xc1" "DRDOS/sec (FAT-12)" },
3258 {"\xc4" "DRDOS/sec (FAT-16 < 32M)"}, 3305 { "\xc4" "DRDOS/sec (FAT-16 < 32M)" },
3259 {"\xc6" "DRDOS/sec (FAT-16)"}, 3306 { "\xc6" "DRDOS/sec (FAT-16)" },
3260 {"\xc7" "Syrinx"}, 3307 { "\xc7" "Syrinx" },
3261 {"\xda" "Non-FS data"}, 3308 { "\xda" "Non-FS data" },
3262 {"\xdb" "CP/M / CTOS / ..."},/* CP/M or Concurrent CP/M or 3309 { "\xdb" "CP/M / CTOS / ..." },/* CP/M or Concurrent CP/M or
3263 Concurrent DOS or CTOS */ 3310 Concurrent DOS or CTOS */
3264 {"\xde" "Dell Utility"}, /* Dell PowerEdge Server utilities */ 3311 { "\xde" "Dell Utility" }, /* Dell PowerEdge Server utilities */
3265 {"\xdf" "BootIt"}, /* BootIt EMBRM */ 3312 { "\xdf" "BootIt" }, /* BootIt EMBRM */
3266 {"\xe1" "DOS access"}, /* DOS access or SpeedStor 12-bit FAT 3313 { "\xe1" "DOS access" }, /* DOS access or SpeedStor 12-bit FAT
3267 extended partition */ 3314 extended partition */
3268 {"\xe3" "DOS R/O"}, /* DOS R/O or SpeedStor */ 3315 { "\xe3" "DOS R/O" }, /* DOS R/O or SpeedStor */
3269 {"\xe4" "SpeedStor"}, /* SpeedStor 16-bit FAT extended 3316 { "\xe4" "SpeedStor" }, /* SpeedStor 16-bit FAT extended
3270 partition < 1024 cyl. */ 3317 partition < 1024 cyl. */
3271 {"\xf1" "SpeedStor"}, 3318 { "\xf1" "SpeedStor" },
3272 {"\xf4" "SpeedStor"}, /* SpeedStor large partition */ 3319 { "\xf4" "SpeedStor" }, /* SpeedStor large partition */
3273 {"\xfe" "LANstep"}, /* SpeedStor >1024 cyl. or LANstep */ 3320 { "\xfe" "LANstep" }, /* SpeedStor >1024 cyl. or LANstep */
3274 {"\xff" "BBT"}, /* Xenix Bad Block Table */ 3321 { "\xff" "BBT" }, /* Xenix Bad Block Table */
3275#endif 3322#endif
3276 { 0 } 3323 { 0 }
3277}; 3324};
@@ -3280,14 +3327,16 @@ static const struct systypes i386_sys_types[] = {
3280 3327
3281/* A valid partition table sector ends in 0x55 0xaa */ 3328/* A valid partition table sector ends in 0x55 0xaa */
3282static unsigned int 3329static unsigned int
3283part_table_flag(const char *b) { 3330part_table_flag(const char *b)
3331{
3284 return ((uint) b[510]) + (((uint) b[511]) << 8); 3332 return ((uint) b[510]) + (((uint) b[511]) << 8);
3285} 3333}
3286 3334
3287 3335
3288#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3336#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3289static void 3337static void
3290write_part_table_flag(char *b) { 3338write_part_table_flag(char *b)
3339{
3291 b[510] = 0x55; 3340 b[510] = 0x55;
3292 b[511] = 0xaa; 3341 b[511] = 0xaa;
3293} 3342}
@@ -3295,7 +3344,8 @@ write_part_table_flag(char *b) {
3295/* start_sect and nr_sects are stored little endian on all machines */ 3344/* start_sect and nr_sects are stored little endian on all machines */
3296/* moreover, they are not aligned correctly */ 3345/* moreover, they are not aligned correctly */
3297static void 3346static void
3298store4_little_endian(unsigned char *cp, unsigned int val) { 3347store4_little_endian(unsigned char *cp, unsigned int val)
3348{
3299 cp[0] = (val & 0xff); 3349 cp[0] = (val & 0xff);
3300 cp[1] = ((val >> 8) & 0xff); 3350 cp[1] = ((val >> 8) & 0xff);
3301 cp[2] = ((val >> 16) & 0xff); 3351 cp[2] = ((val >> 16) & 0xff);
@@ -3304,32 +3354,37 @@ store4_little_endian(unsigned char *cp, unsigned int val) {
3304#endif /* CONFIG_FEATURE_FDISK_WRITABLE */ 3354#endif /* CONFIG_FEATURE_FDISK_WRITABLE */
3305 3355
3306static unsigned int 3356static unsigned int
3307read4_little_endian(const unsigned char *cp) { 3357read4_little_endian(const unsigned char *cp)
3358{
3308 return (uint)(cp[0]) + ((uint)(cp[1]) << 8) 3359 return (uint)(cp[0]) + ((uint)(cp[1]) << 8)
3309 + ((uint)(cp[2]) << 16) + ((uint)(cp[3]) << 24); 3360 + ((uint)(cp[2]) << 16) + ((uint)(cp[3]) << 24);
3310} 3361}
3311 3362
3312#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3363#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3313static void 3364static void
3314set_start_sect(struct partition *p, unsigned int start_sect) { 3365set_start_sect(struct partition *p, unsigned int start_sect)
3366{
3315 store4_little_endian(p->start4, start_sect); 3367 store4_little_endian(p->start4, start_sect);
3316} 3368}
3317#endif 3369#endif
3318 3370
3319static int32_t 3371static int32_t
3320get_start_sect(const struct partition *p) { 3372get_start_sect(const struct partition *p)
3373{
3321 return read4_little_endian(p->start4); 3374 return read4_little_endian(p->start4);
3322} 3375}
3323 3376
3324#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3377#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3325static void 3378static void
3326set_nr_sects(struct partition *p, int32_t nr_sects) { 3379set_nr_sects(struct partition *p, int32_t nr_sects)
3380{
3327 store4_little_endian(p->size4, nr_sects); 3381 store4_little_endian(p->size4, nr_sects);
3328} 3382}
3329#endif 3383#endif
3330 3384
3331static int32_t 3385static int32_t
3332get_nr_sects(const struct partition *p) { 3386get_nr_sects(const struct partition *p)
3387{
3333 return read4_little_endian(p->size4); 3388 return read4_little_endian(p->size4);
3334} 3389}
3335 3390
@@ -3337,9 +3392,9 @@ get_nr_sects(const struct partition *p) {
3337static int type_open = O_RDWR; 3392static int type_open = O_RDWR;
3338 3393
3339 3394
3340static int ext_index, /* the prime extended partition */ 3395static int ext_index; /* the prime extended partition */
3341 listing, /* no aborts for fdisk -l */ 3396static int listing; /* no aborts for fdisk -l */
3342 dos_compatible_flag = ~0; 3397static int dos_compatible_flag = ~0;
3343#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3398#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3344static int dos_changed; 3399static int dos_changed;
3345static int nowarn; /* no warnings for fdisk -l/-s */ 3400static int nowarn; /* no warnings for fdisk -l/-s */
@@ -3347,9 +3402,9 @@ static int nowarn; /* no warnings for fdisk -l/-s */
3347 3402
3348 3403
3349 3404
3350static uint user_cylinders, user_heads, user_sectors; 3405static uint user_cylinders, user_heads, user_sectors;
3351static uint pt_heads, pt_sectors; 3406static uint pt_heads, pt_sectors;
3352static uint kern_heads, kern_sectors; 3407static uint kern_heads, kern_sectors;
3353 3408
3354static off_t extended_offset; /* offset of link pointers */ 3409static off_t extended_offset; /* offset of link pointers */
3355 3410
@@ -3358,7 +3413,8 @@ static unsigned long long total_number_of_sectors;
3358 3413
3359static jmp_buf listingbuf; 3414static jmp_buf listingbuf;
3360 3415
3361static void fdisk_fatal(enum failure why) { 3416static void fdisk_fatal(enum failure why)
3417{
3362 const char *message; 3418 const char *message;
3363 3419
3364 if (listing) { 3420 if (listing) {
@@ -3367,23 +3423,23 @@ static void fdisk_fatal(enum failure why) {
3367 } 3423 }
3368 3424
3369 switch (why) { 3425 switch (why) {
3370 case unable_to_open: 3426 case unable_to_open:
3371 message = "Unable to open %s\n"; 3427 message = "Unable to open %s\n";
3372 break; 3428 break;
3373 case unable_to_read: 3429 case unable_to_read:
3374 message = "Unable to read %s\n"; 3430 message = "Unable to read %s\n";
3375 break; 3431 break;
3376 case unable_to_seek: 3432 case unable_to_seek:
3377 message = "Unable to seek on %s\n"; 3433 message = "Unable to seek on %s\n";
3378 break; 3434 break;
3379 case unable_to_write: 3435 case unable_to_write:
3380 message = "Unable to write %s\n"; 3436 message = "Unable to write %s\n";
3381 break; 3437 break;
3382 case ioctl_error: 3438 case ioctl_error:
3383 message = "BLKGETSIZE ioctl failed on %s\n"; 3439 message = "BLKGETSIZE ioctl failed on %s\n";
3384 break; 3440 break;
3385 default: 3441 default:
3386 message = "Fatal error\n"; 3442 message = "Fatal error\n";
3387 } 3443 }
3388 3444
3389 fputc('\n', stderr); 3445 fputc('\n', stderr);
@@ -3392,7 +3448,8 @@ static void fdisk_fatal(enum failure why) {
3392} 3448}
3393 3449
3394static void 3450static void
3395seek_sector(off_t secno) { 3451seek_sector(off_t secno)
3452{
3396 off_t offset = secno * sector_size; 3453 off_t offset = secno * sector_size;
3397 if (lseek(fd, offset, SEEK_SET) == (off_t) -1) 3454 if (lseek(fd, offset, SEEK_SET) == (off_t) -1)
3398 fdisk_fatal(unable_to_seek); 3455 fdisk_fatal(unable_to_seek);
@@ -3400,7 +3457,8 @@ seek_sector(off_t secno) {
3400 3457
3401#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3458#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3402static void 3459static void
3403write_sector(off_t secno, char *buf) { 3460write_sector(off_t secno, char *buf)
3461{
3404 seek_sector(secno); 3462 seek_sector(secno);
3405 if (write(fd, buf, sector_size) != sector_size) 3463 if (write(fd, buf, sector_size) != sector_size)
3406 fdisk_fatal(unable_to_write); 3464 fdisk_fatal(unable_to_write);
@@ -3409,8 +3467,8 @@ write_sector(off_t secno, char *buf) {
3409 3467
3410/* Allocate a buffer and read a partition table sector */ 3468/* Allocate a buffer and read a partition table sector */
3411static void 3469static void
3412read_pte(struct pte *pe, off_t offset) { 3470read_pte(struct pte *pe, off_t offset)
3413 3471{
3414 pe->offset = offset; 3472 pe->offset = offset;
3415 pe->sectorbuffer = (char *) xmalloc(sector_size); 3473 pe->sectorbuffer = (char *) xmalloc(sector_size);
3416 seek_sector(offset); 3474 seek_sector(offset);
@@ -3423,7 +3481,8 @@ read_pte(struct pte *pe, off_t offset) {
3423} 3481}
3424 3482
3425static unsigned int 3483static unsigned int
3426get_partition_start(const struct pte *pe) { 3484get_partition_start(const struct pte *pe)
3485{
3427 return pe->offset + get_start_sect(pe->part_table); 3486 return pe->offset + get_start_sect(pe->part_table);
3428} 3487}
3429 3488
@@ -3435,7 +3494,8 @@ get_partition_start(const struct pte *pe) {
3435 * for "is probably nondos partition". 3494 * for "is probably nondos partition".
3436 */ 3495 */
3437static int 3496static int
3438is_dos_partition(int t) { 3497is_dos_partition(int t)
3498{
3439 return (t == 1 || t == 4 || t == 6 || 3499 return (t == 1 || t == 4 || t == 6 ||
3440 t == 0x0b || t == 0x0c || t == 0x0e || 3500 t == 0x0b || t == 0x0c || t == 0x0e ||
3441 t == 0x11 || t == 0x12 || t == 0x14 || t == 0x16 || 3501 t == 0x11 || t == 0x12 || t == 0x14 || t == 0x16 ||
@@ -3444,78 +3504,79 @@ is_dos_partition(int t) {
3444} 3504}
3445 3505
3446static void 3506static void
3447menu(void) { 3507menu(void)
3508{
3448#ifdef CONFIG_FEATURE_SUN_LABEL 3509#ifdef CONFIG_FEATURE_SUN_LABEL
3449 if (sun_label) { 3510 if (sun_label) {
3450 puts(_("Command action")); 3511 puts(_("Command action"));
3451 puts(_("\ta\ttoggle a read only flag")); /* sun */ 3512 puts(_("\ta\ttoggle a read only flag")); /* sun */
3452 puts(_("\tb\tedit bsd disklabel")); 3513 puts(_("\tb\tedit bsd disklabel"));
3453 puts(_("\tc\ttoggle the mountable flag")); /* sun */ 3514 puts(_("\tc\ttoggle the mountable flag")); /* sun */
3454 puts(_("\td\tdelete a partition")); 3515 puts(_("\td\tdelete a partition"));
3455 puts(_("\tl\tlist known partition types")); 3516 puts(_("\tl\tlist known partition types"));
3456 puts(_("\tm\tprint this menu")); 3517 puts(_("\tm\tprint this menu"));
3457 puts(_("\tn\tadd a new partition")); 3518 puts(_("\tn\tadd a new partition"));
3458 puts(_("\to\tcreate a new empty DOS partition table")); 3519 puts(_("\to\tcreate a new empty DOS partition table"));
3459 puts(_("\tp\tprint the partition table")); 3520 puts(_("\tp\tprint the partition table"));
3460 puts(_("\tq\tquit without saving changes")); 3521 puts(_("\tq\tquit without saving changes"));
3461 puts(_("\ts\tcreate a new empty Sun disklabel")); /* sun */ 3522 puts(_("\ts\tcreate a new empty Sun disklabel")); /* sun */
3462 puts(_("\tt\tchange a partition's system id")); 3523 puts(_("\tt\tchange a partition's system id"));
3463 puts(_("\tu\tchange display/entry units")); 3524 puts(_("\tu\tchange display/entry units"));
3464 puts(_("\tv\tverify the partition table")); 3525 puts(_("\tv\tverify the partition table"));
3465 puts(_("\tw\twrite table to disk and exit")); 3526 puts(_("\tw\twrite table to disk and exit"));
3466#ifdef CONFIG_FEATURE_FDISK_ADVANCED 3527#ifdef CONFIG_FEATURE_FDISK_ADVANCED
3467 puts(_("\tx\textra functionality (experts only)")); 3528 puts(_("\tx\textra functionality (experts only)"));
3468#endif 3529#endif
3469 } else 3530 } else
3470#endif 3531#endif
3471#ifdef CONFIG_FEATURE_SGI_LABEL 3532#ifdef CONFIG_FEATURE_SGI_LABEL
3472 if (sgi_label) { 3533 if (sgi_label) {
3473 puts(_("Command action")); 3534 puts(_("Command action"));
3474 puts(_("\ta\tselect bootable partition")); /* sgi flavour */ 3535 puts(_("\ta\tselect bootable partition")); /* sgi flavour */
3475 puts(_("\tb\tedit bootfile entry")); /* sgi */ 3536 puts(_("\tb\tedit bootfile entry")); /* sgi */
3476 puts(_("\tc\tselect sgi swap partition")); /* sgi flavour */ 3537 puts(_("\tc\tselect sgi swap partition")); /* sgi flavour */
3477 puts(_("\td\tdelete a partition")); 3538 puts(_("\td\tdelete a partition"));
3478 puts(_("\tl\tlist known partition types")); 3539 puts(_("\tl\tlist known partition types"));
3479 puts(_("\tm\tprint this menu")); 3540 puts(_("\tm\tprint this menu"));
3480 puts(_("\tn\tadd a new partition")); 3541 puts(_("\tn\tadd a new partition"));
3481 puts(_("\to\tcreate a new empty DOS partition table")); 3542 puts(_("\to\tcreate a new empty DOS partition table"));
3482 puts(_("\tp\tprint the partition table")); 3543 puts(_("\tp\tprint the partition table"));
3483 puts(_("\tq\tquit without saving changes")); 3544 puts(_("\tq\tquit without saving changes"));
3484 puts(_("\ts\tcreate a new empty Sun disklabel")); /* sun */ 3545 puts(_("\ts\tcreate a new empty Sun disklabel")); /* sun */
3485 puts(_("\tt\tchange a partition's system id")); 3546 puts(_("\tt\tchange a partition's system id"));
3486 puts(_("\tu\tchange display/entry units")); 3547 puts(_("\tu\tchange display/entry units"));
3487 puts(_("\tv\tverify the partition table")); 3548 puts(_("\tv\tverify the partition table"));
3488 puts(_("\tw\twrite table to disk and exit")); 3549 puts(_("\tw\twrite table to disk and exit"));
3489 } else 3550 } else
3490#endif 3551#endif
3491#ifdef CONFIG_FEATURE_AIX_LABEL 3552#ifdef CONFIG_FEATURE_AIX_LABEL
3492 if (aix_label) { 3553 if (aix_label) {
3493 puts(_("Command action")); 3554 puts(_("Command action"));
3494 puts(_("\tm\tprint this menu")); 3555 puts(_("\tm\tprint this menu"));
3495 puts(_("\to\tcreate a new empty DOS partition table")); 3556 puts(_("\to\tcreate a new empty DOS partition table"));
3496 puts(_("\tq\tquit without saving changes")); 3557 puts(_("\tq\tquit without saving changes"));
3497 puts(_("\ts\tcreate a new empty Sun disklabel")); /* sun */ 3558 puts(_("\ts\tcreate a new empty Sun disklabel")); /* sun */
3498 } else 3559 } else
3499#endif 3560#endif
3500 { 3561 {
3501 puts(_("Command action")); 3562 puts(_("Command action"));
3502 puts(_("\ta\ttoggle a bootable flag")); 3563 puts(_("\ta\ttoggle a bootable flag"));
3503 puts(_("\tb\tedit bsd disklabel")); 3564 puts(_("\tb\tedit bsd disklabel"));
3504 puts(_("\tc\ttoggle the dos compatibility flag")); 3565 puts(_("\tc\ttoggle the dos compatibility flag"));
3505 puts(_("\td\tdelete a partition")); 3566 puts(_("\td\tdelete a partition"));
3506 puts(_("\tl\tlist known partition types")); 3567 puts(_("\tl\tlist known partition types"));
3507 puts(_("\tm\tprint this menu")); 3568 puts(_("\tm\tprint this menu"));
3508 puts(_("\tn\tadd a new partition")); 3569 puts(_("\tn\tadd a new partition"));
3509 puts(_("\to\tcreate a new empty DOS partition table")); 3570 puts(_("\to\tcreate a new empty DOS partition table"));
3510 puts(_("\tp\tprint the partition table")); 3571 puts(_("\tp\tprint the partition table"));
3511 puts(_("\tq\tquit without saving changes")); 3572 puts(_("\tq\tquit without saving changes"));
3512 puts(_("\ts\tcreate a new empty Sun disklabel")); /* sun */ 3573 puts(_("\ts\tcreate a new empty Sun disklabel")); /* sun */
3513 puts(_("\tt\tchange a partition's system id")); 3574 puts(_("\tt\tchange a partition's system id"));
3514 puts(_("\tu\tchange display/entry units")); 3575 puts(_("\tu\tchange display/entry units"));
3515 puts(_("\tv\tverify the partition table")); 3576 puts(_("\tv\tverify the partition table"));
3516 puts(_("\tw\twrite table to disk and exit")); 3577 puts(_("\tw\twrite table to disk and exit"));
3517#ifdef CONFIG_FEATURE_FDISK_ADVANCED 3578#ifdef CONFIG_FEATURE_FDISK_ADVANCED
3518 puts(_("\tx\textra functionality (experts only)")); 3579 puts(_("\tx\textra functionality (experts only)"));
3519#endif 3580#endif
3520 } 3581 }
3521} 3582}
@@ -3524,88 +3585,90 @@ menu(void) {
3524 3585
3525#ifdef CONFIG_FEATURE_FDISK_ADVANCED 3586#ifdef CONFIG_FEATURE_FDISK_ADVANCED
3526static void 3587static void
3527xmenu(void) { 3588xmenu(void)
3589{
3528#ifdef CONFIG_FEATURE_SUN_LABEL 3590#ifdef CONFIG_FEATURE_SUN_LABEL
3529 if (sun_label) { 3591 if (sun_label) {
3530 puts(_("Command action")); 3592 puts(_("Command action"));
3531 puts(_("\ta\tchange number of alternate cylinders")); /*sun*/ 3593 puts(_("\ta\tchange number of alternate cylinders")); /*sun*/
3532 puts(_("\tc\tchange number of cylinders")); 3594 puts(_("\tc\tchange number of cylinders"));
3533 puts(_("\td\tprint the raw data in the partition table")); 3595 puts(_("\td\tprint the raw data in the partition table"));
3534 puts(_("\te\tchange number of extra sectors per cylinder"));/*sun*/ 3596 puts(_("\te\tchange number of extra sectors per cylinder"));/*sun*/
3535 puts(_("\th\tchange number of heads")); 3597 puts(_("\th\tchange number of heads"));
3536 puts(_("\ti\tchange interleave factor")); /*sun*/ 3598 puts(_("\ti\tchange interleave factor")); /*sun*/
3537 puts(_("\to\tchange rotation speed (rpm)")); /*sun*/ 3599 puts(_("\to\tchange rotation speed (rpm)")); /*sun*/
3538 puts(_("\tm\tprint this menu")); 3600 puts(_("\tm\tprint this menu"));
3539 puts(_("\tp\tprint the partition table")); 3601 puts(_("\tp\tprint the partition table"));
3540 puts(_("\tq\tquit without saving changes")); 3602 puts(_("\tq\tquit without saving changes"));
3541 puts(_("\tr\treturn to main menu")); 3603 puts(_("\tr\treturn to main menu"));
3542 puts(_("\ts\tchange number of sectors/track")); 3604 puts(_("\ts\tchange number of sectors/track"));
3543 puts(_("\tv\tverify the partition table")); 3605 puts(_("\tv\tverify the partition table"));
3544 puts(_("\tw\twrite table to disk and exit")); 3606 puts(_("\tw\twrite table to disk and exit"));
3545 puts(_("\ty\tchange number of physical cylinders")); /*sun*/ 3607 puts(_("\ty\tchange number of physical cylinders")); /*sun*/
3546 } else 3608 } else
3547#endif 3609#endif
3548#ifdef CONFIG_FEATURE_SGI_LABEL 3610#ifdef CONFIG_FEATURE_SGI_LABEL
3549 if (sgi_label) { 3611 if (sgi_label) {
3550 puts(_("Command action")); 3612 puts(_("Command action"));
3551 puts(_("\tb\tmove beginning of data in a partition")); /* !sun */ 3613 puts(_("\tb\tmove beginning of data in a partition")); /* !sun */
3552 puts(_("\tc\tchange number of cylinders")); 3614 puts(_("\tc\tchange number of cylinders"));
3553 puts(_("\td\tprint the raw data in the partition table")); 3615 puts(_("\td\tprint the raw data in the partition table"));
3554 puts(_("\te\tlist extended partitions")); /* !sun */ 3616 puts(_("\te\tlist extended partitions")); /* !sun */
3555 puts(_("\tg\tcreate an IRIX (SGI) partition table"));/* sgi */ 3617 puts(_("\tg\tcreate an IRIX (SGI) partition table"));/* sgi */
3556 puts(_("\th\tchange number of heads")); 3618 puts(_("\th\tchange number of heads"));
3557 puts(_("\tm\tprint this menu")); 3619 puts(_("\tm\tprint this menu"));
3558 puts(_("\tp\tprint the partition table")); 3620 puts(_("\tp\tprint the partition table"));
3559 puts(_("\tq\tquit without saving changes")); 3621 puts(_("\tq\tquit without saving changes"));
3560 puts(_("\tr\treturn to main menu")); 3622 puts(_("\tr\treturn to main menu"));
3561 puts(_("\ts\tchange number of sectors/track")); 3623 puts(_("\ts\tchange number of sectors/track"));
3562 puts(_("\tv\tverify the partition table")); 3624 puts(_("\tv\tverify the partition table"));
3563 puts(_("\tw\twrite table to disk and exit")); 3625 puts(_("\tw\twrite table to disk and exit"));
3564 } else 3626 } else
3565#endif 3627#endif
3566#ifdef CONFIG_FEATURE_AIX_LABEL 3628#ifdef CONFIG_FEATURE_AIX_LABEL
3567 if (aix_label) { 3629 if (aix_label) {
3568 puts(_("Command action")); 3630 puts(_("Command action"));
3569 puts(_("\tb\tmove beginning of data in a partition")); /* !sun */ 3631 puts(_("\tb\tmove beginning of data in a partition")); /* !sun */
3570 puts(_("\tc\tchange number of cylinders")); 3632 puts(_("\tc\tchange number of cylinders"));
3571 puts(_("\td\tprint the raw data in the partition table")); 3633 puts(_("\td\tprint the raw data in the partition table"));
3572 puts(_("\te\tlist extended partitions")); /* !sun */ 3634 puts(_("\te\tlist extended partitions")); /* !sun */
3573 puts(_("\tg\tcreate an IRIX (SGI) partition table"));/* sgi */ 3635 puts(_("\tg\tcreate an IRIX (SGI) partition table"));/* sgi */
3574 puts(_("\th\tchange number of heads")); 3636 puts(_("\th\tchange number of heads"));
3575 puts(_("\tm\tprint this menu")); 3637 puts(_("\tm\tprint this menu"));
3576 puts(_("\tp\tprint the partition table")); 3638 puts(_("\tp\tprint the partition table"));
3577 puts(_("\tq\tquit without saving changes")); 3639 puts(_("\tq\tquit without saving changes"));
3578 puts(_("\tr\treturn to main menu")); 3640 puts(_("\tr\treturn to main menu"));
3579 puts(_("\ts\tchange number of sectors/track")); 3641 puts(_("\ts\tchange number of sectors/track"));
3580 puts(_("\tv\tverify the partition table")); 3642 puts(_("\tv\tverify the partition table"));
3581 puts(_("\tw\twrite table to disk and exit")); 3643 puts(_("\tw\twrite table to disk and exit"));
3582 } else 3644 } else
3583#endif 3645#endif
3584 { 3646 {
3585 puts(_("Command action")); 3647 puts(_("Command action"));
3586 puts(_("\tb\tmove beginning of data in a partition")); /* !sun */ 3648 puts(_("\tb\tmove beginning of data in a partition")); /* !sun */
3587 puts(_("\tc\tchange number of cylinders")); 3649 puts(_("\tc\tchange number of cylinders"));
3588 puts(_("\td\tprint the raw data in the partition table")); 3650 puts(_("\td\tprint the raw data in the partition table"));
3589 puts(_("\te\tlist extended partitions")); /* !sun */ 3651 puts(_("\te\tlist extended partitions")); /* !sun */
3590 puts(_("\tf\tfix partition order")); /* !sun, !aix, !sgi */ 3652 puts(_("\tf\tfix partition order")); /* !sun, !aix, !sgi */
3591#ifdef CONFIG_FEATURE_SGI_LABEL 3653#ifdef CONFIG_FEATURE_SGI_LABEL
3592 puts(_("\tg\tcreate an IRIX (SGI) partition table"));/* sgi */ 3654 puts(_("\tg\tcreate an IRIX (SGI) partition table"));/* sgi */
3593#endif 3655#endif
3594 puts(_("\th\tchange number of heads")); 3656 puts(_("\th\tchange number of heads"));
3595 puts(_("\tm\tprint this menu")); 3657 puts(_("\tm\tprint this menu"));
3596 puts(_("\tp\tprint the partition table")); 3658 puts(_("\tp\tprint the partition table"));
3597 puts(_("\tq\tquit without saving changes")); 3659 puts(_("\tq\tquit without saving changes"));
3598 puts(_("\tr\treturn to main menu")); 3660 puts(_("\tr\treturn to main menu"));
3599 puts(_("\ts\tchange number of sectors/track")); 3661 puts(_("\ts\tchange number of sectors/track"));
3600 puts(_("\tv\tverify the partition table")); 3662 puts(_("\tv\tverify the partition table"));
3601 puts(_("\tw\twrite table to disk and exit")); 3663 puts(_("\tw\twrite table to disk and exit"));
3602 } 3664 }
3603} 3665}
3604#endif /* ADVANCED mode */ 3666#endif /* ADVANCED mode */
3605 3667
3606#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3668#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3607static const struct systypes * 3669static const struct systypes *
3608get_sys_types(void) { 3670get_sys_types(void)
3671{
3609 return ( 3672 return (
3610#ifdef CONFIG_FEATURE_SUN_LABEL 3673#ifdef CONFIG_FEATURE_SUN_LABEL
3611 sun_label ? sun_sys_types : 3674 sun_label ? sun_sys_types :
@@ -3624,7 +3687,7 @@ static const char *partition_type(unsigned char type)
3624 int i; 3687 int i;
3625 const struct systypes *types = get_sys_types(); 3688 const struct systypes *types = get_sys_types();
3626 3689
3627 for (i=0; types[i].name; i++) 3690 for (i = 0; types[i].name; i++)
3628 if ((unsigned char )types[i].name[0] == type) 3691 if ((unsigned char )types[i].name[0] == type)
3629 return types[i].name + 1; 3692 return types[i].name + 1;
3630 3693
@@ -3634,7 +3697,8 @@ static const char *partition_type(unsigned char type)
3634 3697
3635#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3698#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3636static int 3699static int
3637get_sysid(int i) { 3700get_sysid(int i)
3701{
3638 return ( 3702 return (
3639#ifdef CONFIG_FEATURE_SUN_LABEL 3703#ifdef CONFIG_FEATURE_SUN_LABEL
3640 sun_label ? sunlabel->infos[i].id : 3704 sun_label ? sunlabel->infos[i].id :
@@ -3672,14 +3736,16 @@ void list_types(const struct systypes *sys)
3672#endif /* CONFIG_FEATURE_FDISK_WRITABLE */ 3736#endif /* CONFIG_FEATURE_FDISK_WRITABLE */
3673 3737
3674static int 3738static int
3675is_cleared_partition(const struct partition *p) { 3739is_cleared_partition(const struct partition *p)
3740{
3676 return !(!p || p->boot_ind || p->head || p->sector || p->cyl || 3741 return !(!p || p->boot_ind || p->head || p->sector || p->cyl ||
3677 p->sys_ind || p->end_head || p->end_sector || p->end_cyl || 3742 p->sys_ind || p->end_head || p->end_sector || p->end_cyl ||
3678 get_start_sect(p) || get_nr_sects(p)); 3743 get_start_sect(p) || get_nr_sects(p));
3679} 3744}
3680 3745
3681static void 3746static void
3682clear_partition(struct partition *p) { 3747clear_partition(struct partition *p)
3748{
3683 if (!p) 3749 if (!p)
3684 return; 3750 return;
3685 memset(p, 0, sizeof(struct partition)); 3751 memset(p, 0, sizeof(struct partition));
@@ -3687,7 +3753,8 @@ clear_partition(struct partition *p) {
3687 3753
3688#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3754#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3689static void 3755static void
3690set_partition(int i, int doext, off_t start, off_t stop, int sysid) { 3756set_partition(int i, int doext, off_t start, off_t stop, int sysid)
3757{
3691 struct partition *p; 3758 struct partition *p;
3692 off_t offset; 3759 off_t offset;
3693 3760
@@ -3713,7 +3780,8 @@ set_partition(int i, int doext, off_t start, off_t stop, int sysid) {
3713#endif 3780#endif
3714 3781
3715static int 3782static int
3716test_c(const char **m, const char *mesg) { 3783test_c(const char **m, const char *mesg)
3784{
3717 int val = 0; 3785 int val = 0;
3718 if (!*m) 3786 if (!*m)
3719 fprintf(stderr, _("You must set")); 3787 fprintf(stderr, _("You must set"));
@@ -3726,7 +3794,8 @@ test_c(const char **m, const char *mesg) {
3726} 3794}
3727 3795
3728static int 3796static int
3729warn_geometry(void) { 3797warn_geometry(void)
3798{
3730 const char *m = NULL; 3799 const char *m = NULL;
3731 int prev = 0; 3800 int prev = 0;
3732 3801
@@ -3760,7 +3829,8 @@ static void update_units(void)
3760 3829
3761#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3830#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3762static void 3831static void
3763warn_cylinders(void) { 3832warn_cylinders(void)
3833{
3764 if (dos_label && cylinders > 1024 && !nowarn) 3834 if (dos_label && cylinders > 1024 && !nowarn)
3765 fprintf(stderr, _("\n" 3835 fprintf(stderr, _("\n"
3766"The number of cylinders for this disk is set to %d.\n" 3836"The number of cylinders for this disk is set to %d.\n"
@@ -3774,7 +3844,8 @@ warn_cylinders(void) {
3774#endif 3844#endif
3775 3845
3776static void 3846static void
3777read_extended(int ext) { 3847read_extended(int ext)
3848{
3778 int i; 3849 int i;
3779 struct pte *pex; 3850 struct pte *pex;
3780 struct partition *p, *q; 3851 struct partition *p, *q;
@@ -3790,7 +3861,7 @@ read_extended(int ext) {
3790 return; 3861 return;
3791 } 3862 }
3792 3863
3793 while (IS_EXTENDED (p->sys_ind)) { 3864 while (IS_EXTENDED(p->sys_ind)) {
3794 struct pte *pe = &ptes[partitions]; 3865 struct pte *pe = &ptes[partitions];
3795 3866
3796 if (partitions >= MAXIMUM_PARTS) { 3867 if (partitions >= MAXIMUM_PARTS) {
@@ -3815,7 +3886,7 @@ read_extended(int ext) {
3815 3886
3816 q = p = pt_offset(pe->sectorbuffer, 0); 3887 q = p = pt_offset(pe->sectorbuffer, 0);
3817 for (i = 0; i < 4; i++, p++) if (get_nr_sects(p)) { 3888 for (i = 0; i < 4; i++, p++) if (get_nr_sects(p)) {
3818 if (IS_EXTENDED (p->sys_ind)) { 3889 if (IS_EXTENDED(p->sys_ind)) {
3819 if (pe->ext_pointer) 3890 if (pe->ext_pointer)
3820 fprintf(stderr, 3891 fprintf(stderr,
3821 _("Warning: extra link " 3892 _("Warning: extra link "
@@ -3859,7 +3930,7 @@ read_extended(int ext) {
3859 struct pte *pe = &ptes[i]; 3930 struct pte *pe = &ptes[i];
3860 3931
3861 if (!get_nr_sects(pe->part_table) && 3932 if (!get_nr_sects(pe->part_table) &&
3862 (partitions > 5 || ptes[4].part_table->sys_ind)) { 3933 (partitions > 5 || ptes[4].part_table->sys_ind)) {
3863 printf("omitting empty partition (%d)\n", i+1); 3934 printf("omitting empty partition (%d)\n", i+1);
3864 delete_partition(i); 3935 delete_partition(i);
3865 goto remove; /* numbering changed */ 3936 goto remove; /* numbering changed */
@@ -3870,7 +3941,8 @@ read_extended(int ext) {
3870 3941
3871#ifdef CONFIG_FEATURE_FDISK_WRITABLE 3942#ifdef CONFIG_FEATURE_FDISK_WRITABLE
3872static void 3943static void
3873create_doslabel(void) { 3944create_doslabel(void)
3945{
3874 int i; 3946 int i;
3875 3947
3876 fprintf(stderr, 3948 fprintf(stderr,
@@ -3903,20 +3975,22 @@ create_doslabel(void) {
3903#endif /* CONFIG_FEATURE_FDISK_WRITABLE */ 3975#endif /* CONFIG_FEATURE_FDISK_WRITABLE */
3904 3976
3905static void 3977static void
3906get_sectorsize(void) { 3978get_sectorsize(void)
3907 if (!user_set_sector_size && 3979{
3908 get_kernel_revision() >= MAKE_VERSION(2,3,3)) { 3980 if (!user_set_sector_size
3981 && get_kernel_revision() >= MAKE_VERSION(2,3,3)) {
3909 int arg; 3982 int arg;
3910 if (ioctl(fd, BLKSSZGET, &arg) == 0) 3983 if (ioctl(fd, BLKSSZGET, &arg) == 0)
3911 sector_size = arg; 3984 sector_size = arg;
3912 if (sector_size != DEFAULT_SECTOR_SIZE) 3985 if (sector_size != DEFAULT_SECTOR_SIZE)
3913 printf(_("Note: sector size is %d (not %d)\n"), 3986 printf(_("Note: sector size is %d (not %d)\n"),
3914 sector_size, DEFAULT_SECTOR_SIZE); 3987 sector_size, DEFAULT_SECTOR_SIZE);
3915 } 3988 }
3916} 3989}
3917 3990
3918static inline void 3991static inline void
3919get_kernel_geometry(void) { 3992get_kernel_geometry(void)
3993{
3920 struct hd_geometry geometry; 3994 struct hd_geometry geometry;
3921 3995
3922 if (!ioctl(fd, HDIO_GETGEO, &geometry)) { 3996 if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
@@ -3927,7 +4001,8 @@ get_kernel_geometry(void) {
3927} 4001}
3928 4002
3929static void 4003static void
3930get_partition_table_geometry(void) { 4004get_partition_table_geometry(void)
4005{
3931 const unsigned char *bufp = (const unsigned char *)MBRbuffer; 4006 const unsigned char *bufp = (const unsigned char *)MBRbuffer;
3932 struct partition *p; 4007 struct partition *p;
3933 int i, h, s, hh, ss; 4008 int i, h, s, hh, ss;
@@ -3938,7 +4013,7 @@ get_partition_table_geometry(void) {
3938 return; 4013 return;
3939 4014
3940 hh = ss = 0; 4015 hh = ss = 0;
3941 for (i=0; i<4; i++) { 4016 for (i = 0; i < 4; i++) {
3942 p = pt_offset(bufp, i); 4017 p = pt_offset(bufp, i);
3943 if (p->sys_ind != 0) { 4018 if (p->sys_ind != 0) {
3944 h = p->end_head + 1; 4019 h = p->end_head + 1;
@@ -3958,8 +4033,9 @@ get_partition_table_geometry(void) {
3958 } 4033 }
3959} 4034}
3960 4035
3961void 4036static void
3962get_geometry(void) { 4037get_geometry(void)
4038{
3963 int sec_fac; 4039 int sec_fac;
3964 unsigned long long bytes; /* really u64 */ 4040 unsigned long long bytes; /* really u64 */
3965 4041
@@ -4008,8 +4084,9 @@ get_geometry(void) {
4008 * 0: found or created label 4084 * 0: found or created label
4009 * 1: I/O error 4085 * 1: I/O error
4010 */ 4086 */
4011int 4087static int
4012get_boot(enum action what) { 4088get_boot(enum action what)
4089{
4013 int i; 4090 int i;
4014 4091
4015 partitions = 4; 4092 partitions = 4;
@@ -4038,13 +4115,13 @@ get_boot(enum action what) {
4038 goto got_dos_table; /* skip reading disk */ 4115 goto got_dos_table; /* skip reading disk */
4039 4116
4040 if ((fd = open(disk_device, type_open)) < 0) { 4117 if ((fd = open(disk_device, type_open)) < 0) {
4041 if ((fd = open(disk_device, O_RDONLY)) < 0) { 4118 if ((fd = open(disk_device, O_RDONLY)) < 0) {
4042 if (what == try_only) 4119 if (what == try_only)
4043 return 1; 4120 return 1;
4044 fdisk_fatal(unable_to_open); 4121 fdisk_fatal(unable_to_open);
4045 } else 4122 } else
4046 printf(_("You will not be able to write " 4123 printf(_("You will not be able to write "
4047 "the partition table.\n")); 4124 "the partition table.\n"));
4048 } 4125 }
4049 4126
4050 if (512 != read(fd, MBRbuffer, 512)) { 4127 if (512 != read(fd, MBRbuffer, 512)) {
@@ -4091,14 +4168,14 @@ get_boot(enum action what) {
4091#endif 4168#endif
4092 4169
4093#ifdef CONFIG_FEATURE_FDISK_WRITABLE 4170#ifdef CONFIG_FEATURE_FDISK_WRITABLE
4094got_dos_table: 4171 got_dos_table:
4095#endif 4172#endif
4096 4173
4097 if (!valid_part_table_flag(MBRbuffer)) { 4174 if (!valid_part_table_flag(MBRbuffer)) {
4098#ifndef CONFIG_FEATURE_FDISK_WRITABLE 4175#ifndef CONFIG_FEATURE_FDISK_WRITABLE
4099 return -1; 4176 return -1;
4100#else 4177#else
4101 switch(what) { 4178 switch (what) {
4102 case fdisk: 4179 case fdisk:
4103 fprintf(stderr, 4180 fprintf(stderr,
4104 _("Device contains neither a valid DOS " 4181 _("Device contains neither a valid DOS "
@@ -4134,7 +4211,7 @@ got_dos_table:
4134 for (i = 0; i < 4; i++) { 4211 for (i = 0; i < 4; i++) {
4135 struct pte *pe = &ptes[i]; 4212 struct pte *pe = &ptes[i];
4136 4213
4137 if (IS_EXTENDED (pe->part_table->sys_ind)) { 4214 if (IS_EXTENDED(pe->part_table->sys_ind)) {
4138 if (partitions != 4) 4215 if (partitions != 4)
4139 fprintf(stderr, _("Ignoring extra extended " 4216 fprintf(stderr, _("Ignoring extra extended "
4140 "partition %d\n"), i + 1); 4217 "partition %d\n"), i + 1);
@@ -4188,62 +4265,61 @@ read_int(uint low, uint dflt, uint high, uint base, char *mesg)
4188 snprintf(ms, mslen, _("%s (%u-%u, default %u): "), 4265 snprintf(ms, mslen, _("%s (%u-%u, default %u): "),
4189 mesg, low, high, dflt); 4266 mesg, low, high, dflt);
4190 else 4267 else
4191 snprintf(ms, mslen, "%s (%u-%u): ", 4268 snprintf(ms, mslen, "%s (%u-%u): ", mesg, low, high);
4192 mesg, low, high);
4193 4269
4194 while (1) { 4270 while (1) {
4195 int use_default = default_ok; 4271 int use_default = default_ok;
4196 4272
4197 /* ask question and read answer */ 4273 /* ask question and read answer */
4198 while (read_chars(ms) != '\n' && !isdigit(*line_ptr) 4274 while (read_chars(ms) != '\n' && !isdigit(*line_ptr)
4199 && *line_ptr != '-' && *line_ptr != '+') 4275 && *line_ptr != '-' && *line_ptr != '+')
4200 continue; 4276 continue;
4201 4277
4202 if (*line_ptr == '+' || *line_ptr == '-') { 4278 if (*line_ptr == '+' || *line_ptr == '-') {
4203 int minus = (*line_ptr == '-'); 4279 int minus = (*line_ptr == '-');
4204 int absolute = 0; 4280 int absolute = 0;
4205 4281
4206 i = atoi(line_ptr+1); 4282 i = atoi(line_ptr+1);
4207 4283
4208 while (isdigit(*++line_ptr)) 4284 while (isdigit(*++line_ptr))
4209 use_default = 0; 4285 use_default = 0;
4210 4286
4211 switch (*line_ptr) { 4287 switch (*line_ptr) {
4212 case 'c': 4288 case 'c':
4213 case 'C': 4289 case 'C':
4214 if (!display_in_cyl_units) 4290 if (!display_in_cyl_units)
4215 i *= heads * sectors; 4291 i *= heads * sectors;
4216 break; 4292 break;
4217 case 'K': 4293 case 'K':
4218 absolute = 1024; 4294 absolute = 1024;
4219 break; 4295 break;
4220 case 'k': 4296 case 'k':
4221 absolute = 1000; 4297 absolute = 1000;
4222 break; 4298 break;
4223 case 'm': 4299 case 'm':
4224 case 'M': 4300 case 'M':
4225 absolute = 1000000; 4301 absolute = 1000000;
4226 break; 4302 break;
4227 case 'g': 4303 case 'g':
4228 case 'G': 4304 case 'G':
4229 absolute = 1000000000; 4305 absolute = 1000000000;
4230 break; 4306 break;
4231 default: 4307 default:
4232 break; 4308 break;
4233 } 4309 }
4234 if (absolute) { 4310 if (absolute) {
4235 unsigned long long bytes; 4311 unsigned long long bytes;
4236 unsigned long unit; 4312 unsigned long unit;
4237 4313
4238 bytes = (unsigned long long) i * absolute; 4314 bytes = (unsigned long long) i * absolute;
4239 unit = sector_size * units_per_sector; 4315 unit = sector_size * units_per_sector;
4240 bytes += unit/2; /* round */ 4316 bytes += unit/2; /* round */
4241 bytes /= unit; 4317 bytes /= unit;
4242 i = bytes; 4318 i = bytes;
4243 } 4319 }
4244 if (minus) 4320 if (minus)
4245 i = -i; 4321 i = -i;
4246 i += base; 4322 i += base;
4247 } else { 4323 } else {
4248 i = atoi(line_ptr); 4324 i = atoi(line_ptr);
4249 while (isdigit(*line_ptr)) { 4325 while (isdigit(*line_ptr)) {
@@ -4261,8 +4337,9 @@ read_int(uint low, uint dflt, uint high, uint base, char *mesg)
4261 return i; 4337 return i;
4262} 4338}
4263 4339
4264int 4340static int
4265get_partition(int warn, int max) { 4341get_partition(int warn, int max)
4342{
4266 struct pte *pe; 4343 struct pte *pe;
4267 int i; 4344 int i;
4268 4345
@@ -4272,12 +4349,12 @@ get_partition(int warn, int max) {
4272 if (warn) { 4349 if (warn) {
4273 if ((!sun_label && !sgi_label && !pe->part_table->sys_ind) 4350 if ((!sun_label && !sgi_label && !pe->part_table->sys_ind)
4274#ifdef CONFIG_FEATURE_SUN_LABEL 4351#ifdef CONFIG_FEATURE_SUN_LABEL
4275 || (sun_label && 4352 || (sun_label &&
4276 (!sunlabel->partitions[i].num_sectors || 4353 (!sunlabel->partitions[i].num_sectors ||
4277 !sunlabel->infos[i].id)) 4354 !sunlabel->infos[i].id))
4278#endif 4355#endif
4279#ifdef CONFIG_FEATURE_SGI_LABEL 4356#ifdef CONFIG_FEATURE_SGI_LABEL
4280 || (sgi_label && (!sgi_get_num_sectors(i))) 4357 || (sgi_label && (!sgi_get_num_sectors(i)))
4281#endif 4358#endif
4282 ) 4359 )
4283 fprintf(stderr, 4360 fprintf(stderr,
@@ -4288,7 +4365,8 @@ get_partition(int warn, int max) {
4288} 4365}
4289 4366
4290static int 4367static int
4291get_existing_partition(int warn, int max) { 4368get_existing_partition(int warn, int max)
4369{
4292 int pno = -1; 4370 int pno = -1;
4293 int i; 4371 int i;
4294 4372
@@ -4314,7 +4392,8 @@ get_existing_partition(int warn, int max) {
4314} 4392}
4315 4393
4316static int 4394static int
4317get_nonexisting_partition(int warn, int max) { 4395get_nonexisting_partition(int warn, int max)
4396{
4318 int pno = -1; 4397 int pno = -1;
4319 int i; 4398 int i;
4320 4399
@@ -4349,11 +4428,12 @@ void change_units(void)
4349} 4428}
4350 4429
4351static void 4430static void
4352toggle_active(int i) { 4431toggle_active(int i)
4432{
4353 struct pte *pe = &ptes[i]; 4433 struct pte *pe = &ptes[i];
4354 struct partition *p = pe->part_table; 4434 struct partition *p = pe->part_table;
4355 4435
4356 if (IS_EXTENDED (p->sys_ind) && !p->boot_ind) 4436 if (IS_EXTENDED(p->sys_ind) && !p->boot_ind)
4357 fprintf(stderr, 4437 fprintf(stderr,
4358 _("WARNING: Partition %d is an extended partition\n"), 4438 _("WARNING: Partition %d is an extended partition\n"),
4359 i + 1); 4439 i + 1);
@@ -4362,7 +4442,8 @@ toggle_active(int i) {
4362} 4442}
4363 4443
4364static void 4444static void
4365toggle_dos_compatibility_flag(void) { 4445toggle_dos_compatibility_flag(void)
4446{
4366 dos_compatible_flag = ~dos_compatible_flag; 4447 dos_compatible_flag = ~dos_compatible_flag;
4367 if (dos_compatible_flag) { 4448 if (dos_compatible_flag) {
4368 sector_offset = sectors; 4449 sector_offset = sectors;
@@ -4375,7 +4456,8 @@ toggle_dos_compatibility_flag(void) {
4375} 4456}
4376 4457
4377static void 4458static void
4378delete_partition(int i) { 4459delete_partition(int i)
4460{
4379 struct pte *pe = &ptes[i]; 4461 struct pte *pe = &ptes[i];
4380 struct partition *p = pe->part_table; 4462 struct partition *p = pe->part_table;
4381 struct partition *q = pe->ext_pointer; 4463 struct partition *q = pe->ext_pointer;
@@ -4402,7 +4484,7 @@ delete_partition(int i) {
4402#endif 4484#endif
4403 4485
4404 if (i < 4) { 4486 if (i < 4) {
4405 if (IS_EXTENDED (p->sys_ind) && i == ext_index) { 4487 if (IS_EXTENDED(p->sys_ind) && i == ext_index) {
4406 partitions = 4; 4488 partitions = 4;
4407 ptes[ext_index].ext_pointer = NULL; 4489 ptes[ext_index].ext_pointer = NULL;
4408 extended_offset = 0; 4490 extended_offset = 0;
@@ -4432,8 +4514,8 @@ delete_partition(int i) {
4432 4514
4433 if (pe->part_table) /* prevent SEGFAULT */ 4515 if (pe->part_table) /* prevent SEGFAULT */
4434 set_start_sect(pe->part_table, 4516 set_start_sect(pe->part_table,
4435 get_partition_start(pe) - 4517 get_partition_start(pe) -
4436 extended_offset); 4518 extended_offset);
4437 pe->offset = extended_offset; 4519 pe->offset = extended_offset;
4438 pe->changed = 1; 4520 pe->changed = 1;
4439 } 4521 }
@@ -4451,7 +4533,8 @@ delete_partition(int i) {
4451} 4533}
4452 4534
4453static void 4535static void
4454change_sysid(void) { 4536change_sysid(void)
4537{
4455 int i, sys, origsys; 4538 int i, sys, origsys;
4456 struct partition *p; 4539 struct partition *p;
4457 4540
@@ -4460,7 +4543,7 @@ change_sysid(void) {
4460 let the user select a partition, since get_existing_partition() 4543 let the user select a partition, since get_existing_partition()
4461 only works for Linux like partition tables. */ 4544 only works for Linux like partition tables. */
4462 if (!sgi_label) { 4545 if (!sgi_label) {
4463 i = get_existing_partition(0, partitions); 4546 i = get_existing_partition(0, partitions);
4464 } else { 4547 } else {
4465 i = get_partition(0, partitions); 4548 i = get_partition(0, partitions);
4466 } 4549 }
@@ -4481,17 +4564,17 @@ change_sysid(void) {
4481 4564
4482 if (!sys && !sgi_label && !sun_label) { 4565 if (!sys && !sgi_label && !sun_label) {
4483 printf(_("Type 0 means free space to many systems\n" 4566 printf(_("Type 0 means free space to many systems\n"
4484 "(but not to Linux). Having partitions of\n" 4567 "(but not to Linux). Having partitions of\n"
4485 "type 0 is probably unwise. You can delete\n" 4568 "type 0 is probably unwise. You can delete\n"
4486 "a partition using the `d' command.\n")); 4569 "a partition using the `d' command.\n"));
4487 /* break; */ 4570 /* break; */
4488 } 4571 }
4489 4572
4490 if (!sun_label && !sgi_label) { 4573 if (!sun_label && !sgi_label) {
4491 if (IS_EXTENDED (sys) != IS_EXTENDED (p->sys_ind)) { 4574 if (IS_EXTENDED(sys) != IS_EXTENDED(p->sys_ind)) {
4492 printf(_("You cannot change a partition into" 4575 printf(_("You cannot change a partition into"
4493 " an extended one or vice versa\n" 4576 " an extended one or vice versa\n"
4494 "Delete it first.\n")); 4577 "Delete it first.\n"));
4495 break; 4578 break;
4496 } 4579 }
4497 } 4580 }
@@ -4500,17 +4583,17 @@ change_sysid(void) {
4500#ifdef CONFIG_FEATURE_SUN_LABEL 4583#ifdef CONFIG_FEATURE_SUN_LABEL
4501 if (sun_label && i == 2 && sys != WHOLE_DISK) 4584 if (sun_label && i == 2 && sys != WHOLE_DISK)
4502 printf(_("Consider leaving partition 3 " 4585 printf(_("Consider leaving partition 3 "
4503 "as Whole disk (5),\n" 4586 "as Whole disk (5),\n"
4504 "as SunOS/Solaris expects it and " 4587 "as SunOS/Solaris expects it and "
4505 "even Linux likes it.\n\n")); 4588 "even Linux likes it.\n\n"));
4506#endif 4589#endif
4507#ifdef CONFIG_FEATURE_SGI_LABEL 4590#ifdef CONFIG_FEATURE_SGI_LABEL
4508 if (sgi_label && ((i == 10 && sys != ENTIRE_DISK) 4591 if (sgi_label && ((i == 10 && sys != ENTIRE_DISK)
4509 || (i == 8 && sys != 0))) 4592 || (i == 8 && sys != 0)))
4510 printf(_("Consider leaving partition 9 " 4593 printf(_("Consider leaving partition 9 "
4511 "as volume header (0),\nand " 4594 "as volume header (0),\nand "
4512 "partition 11 as entire volume (6)" 4595 "partition 11 as entire volume (6)"
4513 "as IRIX expects it.\n\n")); 4596 "as IRIX expects it.\n\n"));
4514#endif 4597#endif
4515 if (sys == origsys) 4598 if (sys == origsys)
4516 break; 4599 break;
@@ -4525,12 +4608,12 @@ change_sysid(void) {
4525 } else 4608 } else
4526#endif 4609#endif
4527 p->sys_ind = sys; 4610 p->sys_ind = sys;
4528 printf (_("Changed system type of partition %d " 4611 printf(_("Changed system type of partition %d "
4529 "to %x (%s)\n"), i + 1, sys, 4612 "to %x (%s)\n"), i + 1, sys,
4530 partition_type(sys)); 4613 partition_type(sys));
4531 ptes[i].changed = 1; 4614 ptes[i].changed = 1;
4532 if (is_dos_partition(origsys) || 4615 if (is_dos_partition(origsys) ||
4533 is_dos_partition(sys)) 4616 is_dos_partition(sys))
4534 dos_changed = 1; 4617 dos_changed = 1;
4535 break; 4618 break;
4536 } 4619 }
@@ -4544,8 +4627,10 @@ change_sysid(void) {
4544 * Jan. 1990 (version 1.2.1 by Gordon W. Ross Aug. 1990; Modified by S. 4627 * Jan. 1990 (version 1.2.1 by Gordon W. Ross Aug. 1990; Modified by S.
4545 * Lubkin Oct. 1991). */ 4628 * Lubkin Oct. 1991). */
4546 4629
4547static void long2chs(ulong ls, uint *c, uint *h, uint *s) { 4630static void
4548 int spc = heads * sectors; 4631long2chs(ulong ls, uint *c, uint *h, uint *s)
4632{
4633 int spc = heads * sectors;
4549 4634
4550 *c = ls / spc; 4635 *c = ls / spc;
4551 ls = ls % spc; 4636 ls = ls % spc;
@@ -4553,11 +4638,13 @@ static void long2chs(ulong ls, uint *c, uint *h, uint *s) {
4553 *s = ls % sectors + 1; /* sectors count from 1 */ 4638 *s = ls % sectors + 1; /* sectors count from 1 */
4554} 4639}
4555 4640
4556static void check_consistency(const struct partition *p, int partition) { 4641static void
4557 uint pbc, pbh, pbs; /* physical beginning c, h, s */ 4642check_consistency(const struct partition *p, int partition)
4558 uint pec, peh, pes; /* physical ending c, h, s */ 4643{
4559 uint lbc, lbh, lbs; /* logical beginning c, h, s */ 4644 uint pbc, pbh, pbs; /* physical beginning c, h, s */
4560 uint lec, leh, les; /* logical ending c, h, s */ 4645 uint pec, peh, pes; /* physical ending c, h, s */
4646 uint lbc, lbh, lbs; /* logical beginning c, h, s */
4647 uint lec, leh, les; /* logical ending c, h, s */
4561 4648
4562 if (!heads || !sectors || (partition >= 4)) 4649 if (!heads || !sectors || (partition >= 4))
4563 return; /* do not check extended partitions */ 4650 return; /* do not check extended partitions */
@@ -4617,24 +4704,25 @@ static void check_consistency(const struct partition *p, int partition) {
4617} 4704}
4618 4705
4619static void 4706static void
4620list_disk_geometry(void) { 4707list_disk_geometry(void)
4708{
4621 long long bytes = (total_number_of_sectors << 9); 4709 long long bytes = (total_number_of_sectors << 9);
4622 long megabytes = bytes/1000000; 4710 long megabytes = bytes/1000000;
4623 4711
4624 if (megabytes < 10000) 4712 if (megabytes < 10000)
4625 printf(_("\nDisk %s: %ld MB, %lld bytes\n"), 4713 printf(_("\nDisk %s: %ld MB, %lld bytes\n"),
4626 disk_device, megabytes, bytes); 4714 disk_device, megabytes, bytes);
4627 else 4715 else
4628 printf(_("\nDisk %s: %ld.%ld GB, %lld bytes\n"), 4716 printf(_("\nDisk %s: %ld.%ld GB, %lld bytes\n"),
4629 disk_device, megabytes/1000, (megabytes/100)%10, bytes); 4717 disk_device, megabytes/1000, (megabytes/100)%10, bytes);
4630 printf(_("%d heads, %d sectors/track, %d cylinders"), 4718 printf(_("%d heads, %d sectors/track, %d cylinders"),
4631 heads, sectors, cylinders); 4719 heads, sectors, cylinders);
4632 if (units_per_sector == 1) 4720 if (units_per_sector == 1)
4633 printf(_(", total %llu sectors"), 4721 printf(_(", total %llu sectors"),
4634 total_number_of_sectors / (sector_size/512)); 4722 total_number_of_sectors / (sector_size/512));
4635 printf(_("\nUnits = %s of %d * %d = %d bytes\n\n"), 4723 printf(_("\nUnits = %s of %d * %d = %d bytes\n\n"),
4636 str_units(PLURAL), 4724 str_units(PLURAL),
4637 units_per_sector, sector_size, units_per_sector * sector_size); 4725 units_per_sector, sector_size, units_per_sector * sector_size);
4638} 4726}
4639 4727
4640/* 4728/*
@@ -4643,7 +4731,8 @@ list_disk_geometry(void) {
4643 * Two separate checks: primary and logical partitions. 4731 * Two separate checks: primary and logical partitions.
4644 */ 4732 */
4645static int 4733static int
4646wrong_p_order(int *prev) { 4734wrong_p_order(int *prev)
4735{
4647 const struct pte *pe; 4736 const struct pte *pe;
4648 const struct partition *p; 4737 const struct partition *p;
4649 off_t last_p_start_pos = 0, p_start_pos; 4738 off_t last_p_start_pos = 0, p_start_pos;
@@ -4686,7 +4775,8 @@ wrong_p_order(int *prev) {
4686 * may help. 4775 * may help.
4687 */ 4776 */
4688static void 4777static void
4689fix_chain_of_logicals(void) { 4778fix_chain_of_logicals(void)
4779{
4690 int j, oj, ojj, sj, sjj; 4780 int j, oj, ojj, sj, sjj;
4691 struct partition *pj,*pjj,tmp; 4781 struct partition *pj,*pjj,tmp;
4692 4782
@@ -4704,9 +4794,9 @@ fix_chain_of_logicals(void) {
4704 pjj = ptes[j+1].part_table; 4794 pjj = ptes[j+1].part_table;
4705 set_start_sect(pjj, get_start_sect(pjj)+ojj-oj); 4795 set_start_sect(pjj, get_start_sect(pjj)+ojj-oj);
4706 set_start_sect(ptes[j-1].ext_pointer, 4796 set_start_sect(ptes[j-1].ext_pointer,
4707 ojj-extended_offset); 4797 ojj-extended_offset);
4708 set_start_sect(ptes[j].ext_pointer, 4798 set_start_sect(ptes[j].ext_pointer,
4709 oj-extended_offset); 4799 oj-extended_offset);
4710 goto stage1; 4800 goto stage1;
4711 } 4801 }
4712 } 4802 }
@@ -4737,7 +4827,8 @@ fix_chain_of_logicals(void) {
4737 4827
4738 4828
4739static void 4829static void
4740fix_partition_table_order(void) { 4830fix_partition_table_order(void)
4831{
4741 struct pte *pei, *pek; 4832 struct pte *pei, *pek;
4742 int i,k; 4833 int i,k;
4743 4834
@@ -4776,7 +4867,8 @@ fix_partition_table_order(void) {
4776#endif 4867#endif
4777 4868
4778static void 4869static void
4779list_table(int xtra) { 4870list_table(int xtra)
4871{
4780 const struct partition *p; 4872 const struct partition *p;
4781 int i, w; 4873 int i, w;
4782 4874
@@ -4813,7 +4905,7 @@ list_table(int xtra) {
4813 w = 5; 4905 w = 5;
4814 4906
4815 printf(_("%*s Boot Start End Blocks Id System\n"), 4907 printf(_("%*s Boot Start End Blocks Id System\n"),
4816 w+1, _("Device")); 4908 w+1, _("Device"));
4817 4909
4818 for (i = 0; i < partitions; i++) { 4910 for (i = 0; i < partitions; i++) {
4819 const struct pte *pe = &ptes[i]; 4911 const struct pte *pe = &ptes[i];
@@ -4831,7 +4923,7 @@ list_table(int xtra) {
4831 if (sector_size > 1024) 4923 if (sector_size > 1024)
4832 pblocks *= (sector_size / 1024); 4924 pblocks *= (sector_size / 1024);
4833 printf( 4925 printf(
4834 "%s %c %11llu %11llu %11llu%c %2x %s\n", 4926 "%s %c %11llu %11llu %11llu%c %2x %s\n",
4835 partname(disk_device, i+1, w+2), 4927 partname(disk_device, i+1, w+2),
4836/* boot flag */ !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG 4928/* boot flag */ !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG
4837 ? '*' : '?', 4929 ? '*' : '?',
@@ -4855,7 +4947,8 @@ list_table(int xtra) {
4855 4947
4856#ifdef CONFIG_FEATURE_FDISK_ADVANCED 4948#ifdef CONFIG_FEATURE_FDISK_ADVANCED
4857static void 4949static void
4858x_list_table(int extend) { 4950x_list_table(int extend)
4951{
4859 const struct pte *pe; 4952 const struct pte *pe;
4860 const struct partition *p; 4953 const struct partition *p;
4861 int i; 4954 int i;
@@ -4883,14 +4976,15 @@ x_list_table(int extend) {
4883 4976
4884#ifdef CONFIG_FEATURE_FDISK_WRITABLE 4977#ifdef CONFIG_FEATURE_FDISK_WRITABLE
4885static void 4978static void
4886fill_bounds(off_t *first, off_t *last) { 4979fill_bounds(off_t *first, off_t *last)
4980{
4887 int i; 4981 int i;
4888 const struct pte *pe = &ptes[0]; 4982 const struct pte *pe = &ptes[0];
4889 const struct partition *p; 4983 const struct partition *p;
4890 4984
4891 for (i = 0; i < partitions; pe++,i++) { 4985 for (i = 0; i < partitions; pe++,i++) {
4892 p = pe->part_table; 4986 p = pe->part_table;
4893 if (!p->sys_ind || IS_EXTENDED (p->sys_ind)) { 4987 if (!p->sys_ind || IS_EXTENDED(p->sys_ind)) {
4894 first[i] = 0xffffffff; 4988 first[i] = 0xffffffff;
4895 last[i] = 0; 4989 last[i] = 0;
4896 } else { 4990 } else {
@@ -4901,7 +4995,8 @@ fill_bounds(off_t *first, off_t *last) {
4901} 4995}
4902 4996
4903static void 4997static void
4904check(int n, uint h, uint s, uint c, off_t start) { 4998check(int n, uint h, uint s, uint c, off_t start)
4999{
4905 off_t total, real_s, real_c; 5000 off_t total, real_s, real_c;
4906 5001
4907 real_s = sector(s) - 1; 5002 real_s = sector(s) - 1;
@@ -4926,7 +5021,8 @@ check(int n, uint h, uint s, uint c, off_t start) {
4926} 5021}
4927 5022
4928static void 5023static void
4929verify(void) { 5024verify(void)
5025{
4930 int i, j; 5026 int i, j;
4931 uint total = 1; 5027 uint total = 1;
4932 off_t first[partitions], last[partitions]; 5028 off_t first[partitions], last[partitions];
@@ -4953,7 +5049,7 @@ verify(void) {
4953 struct pte *pe = &ptes[i]; 5049 struct pte *pe = &ptes[i];
4954 5050
4955 p = pe->part_table; 5051 p = pe->part_table;
4956 if (p->sys_ind && !IS_EXTENDED (p->sys_ind)) { 5052 if (p->sys_ind && !IS_EXTENDED(p->sys_ind)) {
4957 check_consistency(p, i); 5053 check_consistency(p, i);
4958 if (get_partition_start(pe) < first[i]) 5054 if (get_partition_start(pe) < first[i])
4959 printf(_("Warning: bad start-of-data in " 5055 printf(_("Warning: bad start-of-data in "
@@ -5002,7 +5098,8 @@ verify(void) {
5002} 5098}
5003 5099
5004static void 5100static void
5005add_partition(int n, int sys) { 5101add_partition(int n, int sys)
5102{
5006 char mesg[256]; /* 48 does not suffice in Japanese */ 5103 char mesg[256]; /* 48 does not suffice in Japanese */
5007 int i, readed = 0; 5104 int i, readed = 0;
5008 struct partition *p = ptes[n].part_table; 5105 struct partition *p = ptes[n].part_table;
@@ -5047,7 +5144,7 @@ add_partition(int n, int sys) {
5047 5144
5048 if (start == ptes[i].offset) 5145 if (start == ptes[i].offset)
5049 start += sector_offset; 5146 start += sector_offset;
5050 lastplusoff = last[i] + ((n<4) ? 0 : sector_offset); 5147 lastplusoff = last[i] + ((n < 4) ? 0 : sector_offset);
5051 if (start >= first[i] && start <= lastplusoff) 5148 if (start >= first[i] && start <= lastplusoff)
5052 start = lastplusoff + 1; 5149 start = lastplusoff + 1;
5053 } 5150 }
@@ -5115,7 +5212,7 @@ add_partition(int n, int sys) {
5115 if (n > 4) 5212 if (n > 4)
5116 set_partition(n - 1, 1, ptes[n].offset, stop, EXTENDED); 5213 set_partition(n - 1, 1, ptes[n].offset, stop, EXTENDED);
5117 5214
5118 if (IS_EXTENDED (sys)) { 5215 if (IS_EXTENDED(sys)) {
5119 struct pte *pe4 = &ptes[4]; 5216 struct pte *pe4 = &ptes[4];
5120 struct pte *pen = &ptes[n]; 5217 struct pte *pen = &ptes[n];
5121 5218
@@ -5131,7 +5228,8 @@ add_partition(int n, int sys) {
5131} 5228}
5132 5229
5133static void 5230static void
5134add_logical(void) { 5231add_logical(void)
5232{
5135 if (partitions > 5 || ptes[4].part_table->sys_ind) { 5233 if (partitions > 5 || ptes[4].part_table->sys_ind) {
5136 struct pte *pe = &ptes[partitions]; 5234 struct pte *pe = &ptes[partitions];
5137 5235
@@ -5146,7 +5244,8 @@ add_logical(void) {
5146} 5244}
5147 5245
5148static void 5246static void
5149new_partition(void) { 5247new_partition(void)
5248{
5150 int i, free_primary = 0; 5249 int i, free_primary = 0;
5151 5250
5152 if (warn_geometry()) 5251 if (warn_geometry())
@@ -5178,10 +5277,10 @@ new_partition(void) {
5178 for (i = 0; i < 4; i++) 5277 for (i = 0; i < 4; i++)
5179 free_primary += !ptes[i].part_table->sys_ind; 5278 free_primary += !ptes[i].part_table->sys_ind;
5180 5279
5181 if (!free_primary && partitions >= MAXIMUM_PARTS) { 5280 if (!free_primary && partitions >= MAXIMUM_PARTS) {
5182 printf(_("The maximum number of partitions has been created\n")); 5281 printf(_("The maximum number of partitions has been created\n"));
5183 return; 5282 return;
5184 } 5283 }
5185 5284
5186 if (!free_primary) { 5285 if (!free_primary) {
5187 if (extended_offset) 5286 if (extended_offset)
@@ -5220,11 +5319,12 @@ new_partition(void) {
5220} 5319}
5221 5320
5222static void 5321static void
5223write_table(void) { 5322write_table(void)
5323{
5224 int i; 5324 int i;
5225 5325
5226 if (dos_label) { 5326 if (dos_label) {
5227 for (i=0; i<3; i++) 5327 for (i = 0; i < 3; i++)
5228 if (ptes[i].changed) 5328 if (ptes[i].changed)
5229 ptes[3].changed = 1; 5329 ptes[3].changed = 1;
5230 for (i = 3; i < partitions; i++) { 5330 for (i = 3; i < partitions; i++) {
@@ -5243,10 +5343,10 @@ write_table(void) {
5243 } 5343 }
5244#endif 5344#endif
5245#ifdef CONFIG_FEATURE_SUN_LABEL 5345#ifdef CONFIG_FEATURE_SUN_LABEL
5246 else if (sun_label) { 5346 else if (sun_label) {
5247 int needw = 0; 5347 int needw = 0;
5248 5348
5249 for (i=0; i<8; i++) 5349 for (i = 0; i < 8; i++)
5250 if (ptes[i].changed) 5350 if (ptes[i].changed)
5251 needw = 1; 5351 needw = 1;
5252 if (needw) 5352 if (needw)
@@ -5258,8 +5358,9 @@ write_table(void) {
5258 reread_partition_table(1); 5358 reread_partition_table(1);
5259} 5359}
5260 5360
5261void 5361static void
5262reread_partition_table(int leave) { 5362reread_partition_table(int leave)
5363{
5263 int error = 0; 5364 int error = 0;
5264 int i; 5365 int i;
5265 5366
@@ -5288,7 +5389,7 @@ reread_partition_table(int leave) {
5288 } 5389 }
5289 5390
5290 if (dos_changed) 5391 if (dos_changed)
5291 printf( 5392 printf(
5292 _("\nWARNING: If you have created or modified any DOS 6.x\n" 5393 _("\nWARNING: If you have created or modified any DOS 6.x\n"
5293 "partitions, please see the fdisk manual page for additional\n" 5394 "partitions, please see the fdisk manual page for additional\n"
5294 "information.\n")); 5395 "information.\n"));
@@ -5307,9 +5408,9 @@ reread_partition_table(int leave) {
5307#ifdef CONFIG_FEATURE_FDISK_ADVANCED 5408#ifdef CONFIG_FEATURE_FDISK_ADVANCED
5308#define MAX_PER_LINE 16 5409#define MAX_PER_LINE 16
5309static void 5410static void
5310print_buffer(char pbuffer[]) { 5411print_buffer(char *pbuffer)
5311 int i, 5412{
5312 l; 5413 int i,l;
5313 5414
5314 for (i = 0, l = 0; i < sector_size; i++, l++) { 5415 for (i = 0, l = 0; i < sector_size; i++, l++) {
5315 if (l == 0) 5416 if (l == 0)
@@ -5327,7 +5428,8 @@ print_buffer(char pbuffer[]) {
5327 5428
5328 5429
5329static void 5430static void
5330print_raw(void) { 5431print_raw(void)
5432{
5331 int i; 5433 int i;
5332 5434
5333 printf(_("Device: %s\n"), disk_device); 5435 printf(_("Device: %s\n"), disk_device);
@@ -5341,20 +5443,21 @@ print_raw(void) {
5341} 5443}
5342 5444
5343static void 5445static void
5344move_begin(int i) { 5446move_begin(int i)
5447{
5345 struct pte *pe = &ptes[i]; 5448 struct pte *pe = &ptes[i];
5346 struct partition *p = pe->part_table; 5449 struct partition *p = pe->part_table;
5347 off_t new, first; 5450 off_t new, first;
5348 5451
5349 if (warn_geometry()) 5452 if (warn_geometry())
5350 return; 5453 return;
5351 if (!p->sys_ind || !get_nr_sects(p) || IS_EXTENDED (p->sys_ind)) { 5454 if (!p->sys_ind || !get_nr_sects(p) || IS_EXTENDED(p->sys_ind)) {
5352 printf(_("Partition %d has no data area\n"), i + 1); 5455 printf(_("Partition %d has no data area\n"), i + 1);
5353 return; 5456 return;
5354 } 5457 }
5355 first = get_partition_start(pe); 5458 first = get_partition_start(pe);
5356 new = read_int(first, first, first + get_nr_sects(p) - 1, first, 5459 new = read_int(first, first, first + get_nr_sects(p) - 1, first,
5357 _("New beginning of data")) - pe->offset; 5460 _("New beginning of data")) - pe->offset;
5358 5461
5359 if (new != get_nr_sects(p)) { 5462 if (new != get_nr_sects(p)) {
5360 first = get_nr_sects(p) + get_start_sect(p) - new; 5463 first = get_nr_sects(p) + get_start_sect(p) - new;
@@ -5365,10 +5468,11 @@ move_begin(int i) {
5365} 5468}
5366 5469
5367static void 5470static void
5368xselect(void) { 5471xselect(void)
5472{
5369 char c; 5473 char c;
5370 5474
5371 while(1) { 5475 while (1) {
5372 putchar('\n'); 5476 putchar('\n');
5373 c = tolower(read_char(_("Expert command (m for help): "))); 5477 c = tolower(read_char(_("Expert command (m for help): ")));
5374 switch (c) { 5478 switch (c) {
@@ -5385,7 +5489,7 @@ xselect(void) {
5385 case 'c': 5489 case 'c':
5386 user_cylinders = cylinders = 5490 user_cylinders = cylinders =
5387 read_int(1, cylinders, 1048576, 0, 5491 read_int(1, cylinders, 1048576, 0,
5388 _("Number of cylinders")); 5492 _("Number of cylinders"));
5389#ifdef CONFIG_FEATURE_SUN_LABEL 5493#ifdef CONFIG_FEATURE_SUN_LABEL
5390 if (sun_label) 5494 if (sun_label)
5391 sun_set_ncyl(cylinders); 5495 sun_set_ncyl(cylinders);
@@ -5421,7 +5525,7 @@ xselect(void) {
5421 break; 5525 break;
5422 case 'h': 5526 case 'h':
5423 user_heads = heads = read_int(1, heads, 256, 0, 5527 user_heads = heads = read_int(1, heads, 256, 0,
5424 _("Number of heads")); 5528 _("Number of heads"));
5425 update_units(); 5529 update_units();
5426 break; 5530 break;
5427 case 'i': 5531 case 'i':
@@ -5481,7 +5585,8 @@ xselect(void) {
5481#endif /* ADVANCED mode */ 5585#endif /* ADVANCED mode */
5482 5586
5483static int 5587static int
5484is_ide_cdrom_or_tape(const char *device) { 5588is_ide_cdrom_or_tape(const char *device)
5589{
5485 FILE *procf; 5590 FILE *procf;
5486 char buf[100]; 5591 char buf[100];
5487 struct stat statbuf; 5592 struct stat statbuf;
@@ -5514,7 +5619,8 @@ is_ide_cdrom_or_tape(const char *device) {
5514} 5619}
5515 5620
5516static void 5621static void
5517try(const char *device, int user_specified) { 5622try(const char *device, int user_specified)
5623{
5518 int gb; 5624 int gb;
5519 5625
5520 disk_device = device; 5626 disk_device = device;
@@ -5536,7 +5642,7 @@ try(const char *device, int user_specified) {
5536#endif 5642#endif
5537 fprintf(stderr, 5643 fprintf(stderr,
5538 _("Disk %s doesn't contain a valid " 5644 _("Disk %s doesn't contain a valid "
5539 "partition table\n"), device); 5645 "partition table\n"), device);
5540 close(fd); 5646 close(fd);
5541 } else { 5647 } else {
5542 close(fd); 5648 close(fd);
@@ -5560,7 +5666,8 @@ try(const char *device, int user_specified) {
5560/* for fdisk -l: try all things in /proc/partitions 5666/* for fdisk -l: try all things in /proc/partitions
5561 that look like a partition name (do not end in a digit) */ 5667 that look like a partition name (do not end in a digit) */
5562static void 5668static void
5563tryprocpt(void) { 5669tryprocpt(void)
5670{
5564 FILE *procpt; 5671 FILE *procpt;
5565 char line[100], ptname[100], devname[120], *s; 5672 char line[100], ptname[100], devname[120], *s;
5566 int ma, mi, sz; 5673 int ma, mi, sz;
@@ -5568,8 +5675,8 @@ tryprocpt(void) {
5568 procpt = bb_wfopen(PROC_PARTITIONS, "r"); 5675 procpt = bb_wfopen(PROC_PARTITIONS, "r");
5569 5676
5570 while (fgets(line, sizeof(line), procpt)) { 5677 while (fgets(line, sizeof(line), procpt)) {
5571 if (sscanf (line, " %d %d %d %[^\n ]", 5678 if (sscanf(line, " %d %d %d %[^\n ]",
5572 &ma, &mi, &sz, ptname) != 4) 5679 &ma, &mi, &sz, ptname) != 4)
5573 continue; 5680 continue;
5574 for (s = ptname; *s; s++); 5681 for (s = ptname; *s; s++);
5575 if (isdigit(s[-1])) 5682 if (isdigit(s[-1]))
@@ -5584,12 +5691,14 @@ tryprocpt(void) {
5584 5691
5585#ifdef CONFIG_FEATURE_FDISK_WRITABLE 5692#ifdef CONFIG_FEATURE_FDISK_WRITABLE
5586static void 5693static void
5587unknown_command(int c) { 5694unknown_command(int c)
5695{
5588 printf(_("%c: unknown command\n"), c); 5696 printf(_("%c: unknown command\n"), c);
5589} 5697}
5590#endif 5698#endif
5591 5699
5592int fdisk_main(int argc, char **argv) { 5700int fdisk_main(int argc, char **argv)
5701{
5593 int c; 5702 int c;
5594#ifdef CONFIG_FEATURE_FDISK_WRITABLE 5703#ifdef CONFIG_FEATURE_FDISK_WRITABLE
5595 int optl = 0; 5704 int optl = 0;
@@ -5620,7 +5729,7 @@ int fdisk_main(int argc, char **argv) {
5620 */ 5729 */
5621 sector_size = atoi(optarg); 5730 sector_size = atoi(optarg);
5622 if (sector_size != 512 && sector_size != 1024 && 5731 if (sector_size != 512 && sector_size != 1024 &&
5623 sector_size != 2048) 5732 sector_size != 2048)
5624 bb_show_usage(); 5733 bb_show_usage();
5625 sector_offset = 2; 5734 sector_offset = 2;
5626 user_set_sector_size = 1; 5735 user_set_sector_size = 1;
@@ -5682,7 +5791,7 @@ int fdisk_main(int argc, char **argv) {
5682 (void)&k; 5791 (void)&k;
5683#endif 5792#endif
5684 listing = 1; 5793 listing = 1;
5685 for (k=optind; k<argc; k++) 5794 for (k = optind; k < argc; k++)
5686 try(argv[k], 1); 5795 try(argv[k], 1);
5687 } else { 5796 } else {
5688 /* we no longer have default device names */ 5797 /* we no longer have default device names */
@@ -5735,7 +5844,7 @@ int fdisk_main(int argc, char **argv) {
5735 /* OSF label, and no DOS label */ 5844 /* OSF label, and no DOS label */
5736 printf(_("Detected an OSF/1 disklabel on %s, entering " 5845 printf(_("Detected an OSF/1 disklabel on %s, entering "
5737 "disklabel mode.\n"), 5846 "disklabel mode.\n"),
5738 disk_device); 5847 disk_device);
5739 bselect(); 5848 bselect();
5740 osf_label = 0; 5849 osf_label = 0;
5741 /* If we return we may want to make an empty DOS label? */ 5850 /* If we return we may want to make an empty DOS label? */
@@ -5766,9 +5875,9 @@ int fdisk_main(int argc, char **argv) {
5766#ifdef CONFIG_FEATURE_SGI_LABEL 5875#ifdef CONFIG_FEATURE_SGI_LABEL
5767 if (sgi_label) { 5876 if (sgi_label) {
5768 printf(_("\nThe current boot file is: %s\n"), 5877 printf(_("\nThe current boot file is: %s\n"),
5769 sgi_get_bootfile()); 5878 sgi_get_bootfile());
5770 if (read_chars(_("Please enter the name of the " 5879 if (read_chars(_("Please enter the name of the "
5771 "new boot file: ")) == '\n') 5880 "new boot file: ")) == '\n')
5772 printf(_("Boot file unchanged\n")); 5881 printf(_("Boot file unchanged\n"));
5773 else 5882 else
5774 sgi_set_bootfile(line_ptr); 5883 sgi_set_bootfile(line_ptr);