aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util-linux/fdisk.c88
-rw-r--r--util-linux/fdisk_osf.c31
-rw-r--r--util-linux/fdisk_sgi.c10
-rw-r--r--util-linux/fdisk_sun.c5
4 files changed, 66 insertions, 68 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 4034ca555..7f046edfb 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -20,21 +20,22 @@
20# define USE_FEATURE_FDISK_BLKSIZE(a) 20# define USE_FEATURE_FDISK_BLKSIZE(a)
21#endif 21#endif
22 22
23#define DEFAULT_SECTOR_SIZE 512 23#define DEFAULT_SECTOR_SIZE 512
24#define MAX_SECTOR_SIZE 2048 24#define DEFAULT_SECTOR_SIZE_STR "512"
25#define SECTOR_SIZE 512 /* still used in osf/sgi/sun code */ 25#define MAX_SECTOR_SIZE 2048
26#define MAXIMUM_PARTS 60 26#define SECTOR_SIZE 512 /* still used in osf/sgi/sun code */
27#define MAXIMUM_PARTS 60
27 28
28#define ACTIVE_FLAG 0x80 29#define ACTIVE_FLAG 0x80
29 30
30#define EXTENDED 0x05 31#define EXTENDED 0x05
31#define WIN98_EXTENDED 0x0f 32#define WIN98_EXTENDED 0x0f
32#define LINUX_PARTITION 0x81 33#define LINUX_PARTITION 0x81
33#define LINUX_SWAP 0x82 34#define LINUX_SWAP 0x82
34#define LINUX_NATIVE 0x83 35#define LINUX_NATIVE 0x83
35#define LINUX_EXTENDED 0x85 36#define LINUX_EXTENDED 0x85
36#define LINUX_LVM 0x8e 37#define LINUX_LVM 0x8e
37#define LINUX_RAID 0xfd 38#define LINUX_RAID 0xfd
38 39
39 40
40enum { 41enum {
@@ -290,12 +291,25 @@ struct globals {
290 unsigned user_set_sector_size; 291 unsigned user_set_sector_size;
291 unsigned sector_offset; // = 1; 292 unsigned sector_offset; // = 1;
292 unsigned g_heads, g_sectors, g_cylinders; 293 unsigned g_heads, g_sectors, g_cylinders;
293 enum label_type current_label_type; 294 smallint /* enum label_type */ current_label_type;
294 smallint display_in_cyl_units; // = 1; 295 smallint display_in_cyl_units; // = 1;
295#if ENABLE_FEATURE_OSF_LABEL 296#if ENABLE_FEATURE_OSF_LABEL
296 smallint possibly_osf_label; 297 smallint possibly_osf_label;
297#endif 298#endif
298 299
300 smallint listing; /* no aborts for fdisk -l */
301 smallint dos_compatible_flag; // = 1;
302#if ENABLE_FEATURE_FDISK_WRITABLE
303 //int dos_changed;
304 smallint nowarn; /* no warnings for fdisk -l/-s */
305#endif
306 int ext_index; /* the prime extended partition */
307 unsigned user_cylinders, user_heads, user_sectors;
308 unsigned pt_heads, pt_sectors;
309 unsigned kern_heads, kern_sectors;
310 ullong extended_offset; /* offset of link pointers */
311 ullong total_number_of_sectors;
312
299 jmp_buf listingbuf; 313 jmp_buf listingbuf;
300 char line_buffer[80]; 314 char line_buffer[80];
301 char partname_buffer[80]; 315 char partname_buffer[80];
@@ -319,6 +333,19 @@ struct globals {
319#define current_label_type (G.current_label_type ) 333#define current_label_type (G.current_label_type )
320#define display_in_cyl_units (G.display_in_cyl_units) 334#define display_in_cyl_units (G.display_in_cyl_units)
321#define possibly_osf_label (G.possibly_osf_label ) 335#define possibly_osf_label (G.possibly_osf_label )
336#define listing (G.listing )
337#define dos_compatible_flag (G.dos_compatible_flag )
338#define nowarn (G.nowarn )
339#define ext_index (G.ext_index )
340#define user_cylinders (G.user_cylinders )
341#define user_heads (G.user_heads )
342#define user_sectors (G.user_sectors )
343#define pt_heads (G.pt_heads )
344#define pt_sectors (G.pt_sectors )
345#define kern_heads (G.kern_heads )
346#define kern_sectors (G.kern_sectors )
347#define extended_offset (G.extended_offset )
348#define total_number_of_sectors (G.total_number_of_sectors)
322#define listingbuf (G.listingbuf) 349#define listingbuf (G.listingbuf)
323#define line_buffer (G.line_buffer) 350#define line_buffer (G.line_buffer)
324#define partname_buffer (G.partname_buffer) 351#define partname_buffer (G.partname_buffer)
@@ -331,6 +358,7 @@ struct globals {
331 g_partitions = 4; \ 358 g_partitions = 4; \
332 display_in_cyl_units = 1; \ 359 display_in_cyl_units = 1; \
333 units_per_sector = 1; \ 360 units_per_sector = 1; \
361 dos_compatible_flag = 1; \
334} while (0) 362} while (0)
335 363
336 364
@@ -661,21 +689,6 @@ get_nr_sects(const struct partition *p)
661 return read4_little_endian(p->size4); 689 return read4_little_endian(p->size4);
662} 690}
663 691
664static int ext_index; /* the prime extended partition */
665static smallint listing; /* no aborts for fdisk -l */
666static smallint dos_compatible_flag = 1;
667#if ENABLE_FEATURE_FDISK_WRITABLE
668//static int dos_changed;
669static smallint nowarn; /* no warnings for fdisk -l/-s */
670#endif
671
672static unsigned user_cylinders, user_heads, user_sectors;
673static unsigned pt_heads, pt_sectors;
674static unsigned kern_heads, kern_sectors;
675
676static ullong extended_offset; /* offset of link pointers */
677static ullong total_number_of_sectors;
678
679static void fdisk_fatal(const char *why) 692static void fdisk_fatal(const char *why)
680{ 693{
681 if (listing) { 694 if (listing) {
@@ -706,8 +719,7 @@ static void
706write_sector(ullong secno, char *buf) 719write_sector(ullong secno, char *buf)
707{ 720{
708 seek_sector(secno); 721 seek_sector(secno);
709 if (write(dev_fd, buf, sector_size) != sector_size) 722 xwrite(dev_fd, buf, sector_size);
710 fdisk_fatal(unable_to_write);
711} 723}
712#endif 724#endif
713 725
@@ -716,9 +728,10 @@ static void
716read_pte(struct pte *pe, ullong offset) 728read_pte(struct pte *pe, ullong offset)
717{ 729{
718 pe->offset = offset; 730 pe->offset = offset;
719 pe->sectorbuffer = xmalloc(sector_size); 731 pe->sectorbuffer = xzalloc(sector_size);
720 seek_sector(offset); 732 seek_sector(offset);
721 if (read(dev_fd, pe->sectorbuffer, sector_size) != sector_size) 733 /* xread would make us abort - bad for fdisk -l */
734 if (full_read(dev_fd, pe->sectorbuffer, sector_size) != sector_size)
722 fdisk_fatal(unable_to_read); 735 fdisk_fatal(unable_to_read);
723#if ENABLE_FEATURE_FDISK_WRITABLE 736#if ENABLE_FEATURE_FDISK_WRITABLE
724 pe->changed = 0; 737 pe->changed = 0;
@@ -1167,8 +1180,9 @@ get_sectorsize(void)
1167 if (ioctl(dev_fd, BLKSSZGET, &arg) == 0) 1180 if (ioctl(dev_fd, BLKSSZGET, &arg) == 0)
1168 sector_size = arg; 1181 sector_size = arg;
1169 if (sector_size != DEFAULT_SECTOR_SIZE) 1182 if (sector_size != DEFAULT_SECTOR_SIZE)
1170 printf("Note: sector size is %d (not %d)\n", 1183 printf("Note: sector size is %d "
1171 sector_size, DEFAULT_SECTOR_SIZE); 1184 "(not " DEFAULT_SECTOR_SIZE_STR ")\n",
1185 sector_size);
1172 } 1186 }
1173} 1187}
1174 1188
@@ -1302,7 +1316,7 @@ static int get_boot(void)
1302 printf("'%s' is opened for read only\n", disk_device); 1316 printf("'%s' is opened for read only\n", disk_device);
1303 } 1317 }
1304 xmove_fd(fd, dev_fd); 1318 xmove_fd(fd, dev_fd);
1305 if (512 != read(dev_fd, MBRbuffer, 512)) { 1319 if (512 != full_read(dev_fd, MBRbuffer, 512)) {
1306 if (what == TRY_ONLY) { 1320 if (what == TRY_ONLY) {
1307 close_dev_fd(); 1321 close_dev_fd();
1308 return 1; 1322 return 1;
@@ -1313,7 +1327,7 @@ static int get_boot(void)
1313 fd = open(disk_device, O_RDONLY); 1327 fd = open(disk_device, O_RDONLY);
1314 if (fd < 0) 1328 if (fd < 0)
1315 return 1; 1329 return 1;
1316 if (512 != read(fd, MBRbuffer, 512)) { 1330 if (512 != full_read(fd, MBRbuffer, 512)) {
1317 close(fd); 1331 close(fd);
1318 return 1; 1332 return 1;
1319 } 1333 }
diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c
index 24f240af3..c50ee9b16 100644
--- a/util-linux/fdisk_osf.c
+++ b/util-linux/fdisk_osf.c
@@ -688,13 +688,12 @@ xbsd_get_bootstrap(char *path, void *ptr, int size)
688{ 688{
689 int fdb; 689 int fdb;
690 690
691 fdb = open(path, O_RDONLY); 691 fdb = open_or_warn(path, O_RDONLY);
692 if (fdb < 0) { 692 if (fdb < 0) {
693 perror(path);
694 return 0; 693 return 0;
695 } 694 }
696 if (read(fdb, ptr, size) < 0) { 695 if (full_read(fdb, ptr, size) < 0) {
697 perror(path); 696 bb_simple_perror_msg(path);
698 close(fdb); 697 close(fdb);
699 return 0; 698 return 0;
700 } 699 }
@@ -765,10 +764,8 @@ xbsd_write_bootstrap(void)
765 sector = get_start_sect(xbsd_part); 764 sector = get_start_sect(xbsd_part);
766#endif 765#endif
767 766
768 if (lseek(dev_fd, sector * SECTOR_SIZE, SEEK_SET) == -1) 767 seek_sector(sector);
769 fdisk_fatal(unable_to_seek); 768 xwrite(dev_fd, disklabelbuffer, BSD_BBSIZE);
770 if (BSD_BBSIZE != write(dev_fd, disklabelbuffer, BSD_BBSIZE))
771 fdisk_fatal(unable_to_write);
772 769
773#if defined(__alpha__) 770#if defined(__alpha__)
774 printf("Bootstrap installed on %s\n", disk_device); 771 printf("Bootstrap installed on %s\n", disk_device);
@@ -938,9 +935,8 @@ xbsd_readlabel(struct partition *p)
938 sector = 0; 935 sector = 0;
939#endif 936#endif
940 937
941 if (lseek(dev_fd, sector * SECTOR_SIZE, SEEK_SET) == -1) 938 seek_sector(sector);
942 fdisk_fatal(unable_to_seek); 939 if (BSD_BBSIZE != full_read(dev_fd, disklabelbuffer, BSD_BBSIZE))
943 if (BSD_BBSIZE != read(dev_fd, disklabelbuffer, BSD_BBSIZE))
944 fdisk_fatal(unable_to_read); 940 fdisk_fatal(unable_to_read);
945 941
946 memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], 942 memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
@@ -984,15 +980,12 @@ xbsd_writelabel(struct partition *p)
984 980
985#if defined(__alpha__) && BSD_LABELSECTOR == 0 981#if defined(__alpha__) && BSD_LABELSECTOR == 0
986 alpha_bootblock_checksum(disklabelbuffer); 982 alpha_bootblock_checksum(disklabelbuffer);
987 if (lseek(dev_fd, 0, SEEK_SET) == -1) 983 seek_sector(0);
988 fdisk_fatal(unable_to_seek); 984 xwrite(dev_fd, disklabelbuffer, BSD_BBSIZE);
989 if (BSD_BBSIZE != write(dev_fd, disklabelbuffer, BSD_BBSIZE))
990 fdisk_fatal(unable_to_write);
991#else 985#else
992 if (lseek(dev_fd, sector * SECTOR_SIZE + BSD_LABELOFFSET, SEEK_SET) == -1) 986 seek_sector(sector);
993 fdisk_fatal(unable_to_seek); 987 lseek(dev_fd, BSD_LABELOFFSET, SEEK_CUR);
994 if (sizeof(struct xbsd_disklabel) != write(dev_fd, d, sizeof(struct xbsd_disklabel))) 988 xwrite(dev_fd, d, sizeof(*d));
995 fdisk_fatal(unable_to_write);
996#endif 989#endif
997 sync_disks(); 990 sync_disks();
998 return 1; 991 return 1;
diff --git a/util-linux/fdisk_sgi.c b/util-linux/fdisk_sgi.c
index 55e77d58c..5a86a6848 100644
--- a/util-linux/fdisk_sgi.c
+++ b/util-linux/fdisk_sgi.c
@@ -439,10 +439,7 @@ sgi_write_table(void)
439 assert(two_s_complement_32bit_sum( 439 assert(two_s_complement_32bit_sum(
440 (unsigned int*)sgilabel, sizeof(*sgilabel)) == 0); 440 (unsigned int*)sgilabel, sizeof(*sgilabel)) == 0);
441 441
442 if (lseek(dev_fd, 0, SEEK_SET) < 0) 442 write_sector(0, sgilabel);
443 fdisk_fatal(unable_to_seek);
444 if (write(dev_fd, sgilabel, SECTOR_SIZE) != SECTOR_SIZE)
445 fdisk_fatal(unable_to_write);
446 if (!strncmp((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8)) { 443 if (!strncmp((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8)) {
447 /* 444 /*
448 * keep this habit of first writing the "sgilabel". 445 * keep this habit of first writing the "sgilabel".
@@ -450,10 +447,7 @@ sgi_write_table(void)
450 */ 447 */
451 sgiinfo *info = fill_sgiinfo(); 448 sgiinfo *info = fill_sgiinfo();
452 int infostartblock = SGI_SSWAP32(sgilabel->directory[0].vol_file_start); 449 int infostartblock = SGI_SSWAP32(sgilabel->directory[0].vol_file_start);
453 if (lseek(dev_fd, infostartblock*SECTOR_SIZE, SEEK_SET) < 0) 450 write_sector(infostartblock, info);
454 fdisk_fatal(unable_to_seek);
455 if (write(dev_fd, info, SECTOR_SIZE) != SECTOR_SIZE)
456 fdisk_fatal(unable_to_write);
457 free(info); 451 free(info);
458 } 452 }
459} 453}
diff --git a/util-linux/fdisk_sun.c b/util-linux/fdisk_sun.c
index eec319c6e..427efbee3 100644
--- a/util-linux/fdisk_sun.c
+++ b/util-linux/fdisk_sun.c
@@ -722,9 +722,6 @@ sun_write_table(void)
722 while (ush < (unsigned short *)(&sunlabel->csum)) 722 while (ush < (unsigned short *)(&sunlabel->csum))
723 csum ^= *ush++; 723 csum ^= *ush++;
724 sunlabel->csum = csum; 724 sunlabel->csum = csum;
725 if (lseek(dev_fd, 0, SEEK_SET) < 0) 725 write_sector(0, sunlabel);
726 fdisk_fatal(unable_to_seek);
727 if (write(dev_fd, sunlabel, SECTOR_SIZE) != SECTOR_SIZE)
728 fdisk_fatal(unable_to_write);
729} 726}
730#endif /* SUN_LABEL */ 727#endif /* SUN_LABEL */