summaryrefslogtreecommitdiff
path: root/util-linux/fdisk.c
diff options
context:
space:
mode:
authorDenis Vlasenko2008-06-29 05:10:47 +0000
committerDenis Vlasenko2008-06-29 05:10:47 +0000
commit6eaf0a98831960e3a4593e6630404634d747ab82 (patch)
tree433a90cad26f3c6ae9eff8572be94773523789e4 /util-linux/fdisk.c
parentce13b7600277478055de0b7c38b483a76145efd2 (diff)
downloadbusybox-6eaf0a98831960e3a4593e6630404634d747ab82.zip
busybox-6eaf0a98831960e3a4593e6630404634d747ab82.tar.gz
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 4034ca5..7f046ed 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -20,21 +20,22 @@
# define USE_FEATURE_FDISK_BLKSIZE(a)
#endif
-#define DEFAULT_SECTOR_SIZE 512
-#define MAX_SECTOR_SIZE 2048
-#define SECTOR_SIZE 512 /* still used in osf/sgi/sun code */
-#define MAXIMUM_PARTS 60
+#define DEFAULT_SECTOR_SIZE 512
+#define DEFAULT_SECTOR_SIZE_STR "512"
+#define MAX_SECTOR_SIZE 2048
+#define SECTOR_SIZE 512 /* still used in osf/sgi/sun code */
+#define MAXIMUM_PARTS 60
-#define ACTIVE_FLAG 0x80
+#define ACTIVE_FLAG 0x80
-#define EXTENDED 0x05
-#define WIN98_EXTENDED 0x0f
-#define LINUX_PARTITION 0x81
-#define LINUX_SWAP 0x82
-#define LINUX_NATIVE 0x83
-#define LINUX_EXTENDED 0x85
-#define LINUX_LVM 0x8e
-#define LINUX_RAID 0xfd
+#define EXTENDED 0x05
+#define WIN98_EXTENDED 0x0f
+#define LINUX_PARTITION 0x81
+#define LINUX_SWAP 0x82
+#define LINUX_NATIVE 0x83
+#define LINUX_EXTENDED 0x85
+#define LINUX_LVM 0x8e
+#define LINUX_RAID 0xfd
enum {
@@ -290,12 +291,25 @@ struct globals {
unsigned user_set_sector_size;
unsigned sector_offset; // = 1;
unsigned g_heads, g_sectors, g_cylinders;
- enum label_type current_label_type;
+ smallint /* enum label_type */ current_label_type;
smallint display_in_cyl_units; // = 1;
#if ENABLE_FEATURE_OSF_LABEL
smallint possibly_osf_label;
#endif
+ smallint listing; /* no aborts for fdisk -l */
+ smallint dos_compatible_flag; // = 1;
+#if ENABLE_FEATURE_FDISK_WRITABLE
+ //int dos_changed;
+ smallint nowarn; /* no warnings for fdisk -l/-s */
+#endif
+ int ext_index; /* the prime extended partition */
+ unsigned user_cylinders, user_heads, user_sectors;
+ unsigned pt_heads, pt_sectors;
+ unsigned kern_heads, kern_sectors;
+ ullong extended_offset; /* offset of link pointers */
+ ullong total_number_of_sectors;
+
jmp_buf listingbuf;
char line_buffer[80];
char partname_buffer[80];
@@ -319,6 +333,19 @@ struct globals {
#define current_label_type (G.current_label_type )
#define display_in_cyl_units (G.display_in_cyl_units)
#define possibly_osf_label (G.possibly_osf_label )
+#define listing (G.listing )
+#define dos_compatible_flag (G.dos_compatible_flag )
+#define nowarn (G.nowarn )
+#define ext_index (G.ext_index )
+#define user_cylinders (G.user_cylinders )
+#define user_heads (G.user_heads )
+#define user_sectors (G.user_sectors )
+#define pt_heads (G.pt_heads )
+#define pt_sectors (G.pt_sectors )
+#define kern_heads (G.kern_heads )
+#define kern_sectors (G.kern_sectors )
+#define extended_offset (G.extended_offset )
+#define total_number_of_sectors (G.total_number_of_sectors)
#define listingbuf (G.listingbuf)
#define line_buffer (G.line_buffer)
#define partname_buffer (G.partname_buffer)
@@ -331,6 +358,7 @@ struct globals {
g_partitions = 4; \
display_in_cyl_units = 1; \
units_per_sector = 1; \
+ dos_compatible_flag = 1; \
} while (0)
@@ -661,21 +689,6 @@ get_nr_sects(const struct partition *p)
return read4_little_endian(p->size4);
}
-static int ext_index; /* the prime extended partition */
-static smallint listing; /* no aborts for fdisk -l */
-static smallint dos_compatible_flag = 1;
-#if ENABLE_FEATURE_FDISK_WRITABLE
-//static int dos_changed;
-static smallint nowarn; /* no warnings for fdisk -l/-s */
-#endif
-
-static unsigned user_cylinders, user_heads, user_sectors;
-static unsigned pt_heads, pt_sectors;
-static unsigned kern_heads, kern_sectors;
-
-static ullong extended_offset; /* offset of link pointers */
-static ullong total_number_of_sectors;
-
static void fdisk_fatal(const char *why)
{
if (listing) {
@@ -706,8 +719,7 @@ static void
write_sector(ullong secno, char *buf)
{
seek_sector(secno);
- if (write(dev_fd, buf, sector_size) != sector_size)
- fdisk_fatal(unable_to_write);
+ xwrite(dev_fd, buf, sector_size);
}
#endif
@@ -716,9 +728,10 @@ static void
read_pte(struct pte *pe, ullong offset)
{
pe->offset = offset;
- pe->sectorbuffer = xmalloc(sector_size);
+ pe->sectorbuffer = xzalloc(sector_size);
seek_sector(offset);
- if (read(dev_fd, pe->sectorbuffer, sector_size) != sector_size)
+ /* xread would make us abort - bad for fdisk -l */
+ if (full_read(dev_fd, pe->sectorbuffer, sector_size) != sector_size)
fdisk_fatal(unable_to_read);
#if ENABLE_FEATURE_FDISK_WRITABLE
pe->changed = 0;
@@ -1167,8 +1180,9 @@ get_sectorsize(void)
if (ioctl(dev_fd, BLKSSZGET, &arg) == 0)
sector_size = arg;
if (sector_size != DEFAULT_SECTOR_SIZE)
- printf("Note: sector size is %d (not %d)\n",
- sector_size, DEFAULT_SECTOR_SIZE);
+ printf("Note: sector size is %d "
+ "(not " DEFAULT_SECTOR_SIZE_STR ")\n",
+ sector_size);
}
}
@@ -1302,7 +1316,7 @@ static int get_boot(void)
printf("'%s' is opened for read only\n", disk_device);
}
xmove_fd(fd, dev_fd);
- if (512 != read(dev_fd, MBRbuffer, 512)) {
+ if (512 != full_read(dev_fd, MBRbuffer, 512)) {
if (what == TRY_ONLY) {
close_dev_fd();
return 1;
@@ -1313,7 +1327,7 @@ static int get_boot(void)
fd = open(disk_device, O_RDONLY);
if (fd < 0)
return 1;
- if (512 != read(fd, MBRbuffer, 512)) {
+ if (512 != full_read(fd, MBRbuffer, 512)) {
close(fd);
return 1;
}