summaryrefslogtreecommitdiff
path: root/util-linux/fdisk.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-29 05:10:47 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-29 05:10:47 +0000
commit6eaf0a98831960e3a4593e6630404634d747ab82 (patch)
tree433a90cad26f3c6ae9eff8572be94773523789e4 /util-linux/fdisk.c
parentce13b7600277478055de0b7c38b483a76145efd2 (diff)
downloadbusybox-w32-6eaf0a98831960e3a4593e6630404634d747ab82.tar.gz
busybox-w32-6eaf0a98831960e3a4593e6630404634d747ab82.tar.bz2
busybox-w32-6eaf0a98831960e3a4593e6630404634d747ab82.zip
fdisk: move more data to struct globals; shrink code
function old new delta nowarn 1 - -1 listing 1 - -1 dos_compatible_flag 1 - -1 warn_cylinders 44 42 -2 open_list_and_close 364 362 -2 fdisk_fatal 41 38 -3 verify 1053 1049 -4 user_sectors 4 - -4 user_heads 4 - -4 user_cylinders 4 - -4 pt_sectors 4 - -4 pt_heads 4 - -4 kern_sectors 4 - -4 kern_heads 4 - -4 ext_index 4 - -4 total_number_of_sectors 8 - -8 extended_offset 8 - -8 create_doslabel 129 120 -9 write_table 225 211 -14 delete_partition 445 431 -14 set_partition 476 459 -17 list_disk_geometry 247 229 -18 unable_to_write 19 - -19 add_partition 2515 2486 -29 get_boot 1709 1636 -73 fdisk_main 2812 2679 -133 ------------------------------------------------------------------------------ (add/remove: 0/14 grow/shrink: 0/12 up/down: 0/-388) Total: -388 bytes text data bss dec hex filename 804634 611 6852 812097 c6441 busybox_old 804298 610 6804 811712 c62c0 busybox_unstripped
Diffstat (limited to 'util-linux/fdisk.c')
-rw-r--r--util-linux/fdisk.c88
1 files changed, 51 insertions, 37 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 }