aboutsummaryrefslogtreecommitdiff
path: root/util-linux/fdisk.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 08:42:43 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 08:42:43 +0000
commitcdf62770af9e8bf7d5bb2344ddef8acb3216cfe2 (patch)
treef3c72eba4318ead484dfb36c6e21d55f443c5f6b /util-linux/fdisk.c
parent107fe7c081c2e0ab96628b431d9d812cdf9c82b2 (diff)
downloadbusybox-w32-cdf62770af9e8bf7d5bb2344ddef8acb3216cfe2.tar.gz
busybox-w32-cdf62770af9e8bf7d5bb2344ddef8acb3216cfe2.tar.bz2
busybox-w32-cdf62770af9e8bf7d5bb2344ddef8acb3216cfe2.zip
dos2unix: tiny shrink
login,su: fix setup_environment() so that it works as intended (parameter names were a bit misleading) fdisk: shrink help text: shrink function old new delta login_main 1658 1701 +43 setup_environment 206 203 -3 dos_compatible_flag 4 1 -3 dos2unix_main 383 375 -8 get_boot 1724 1702 -22 fdisk_main 2949 2889 -60 packed_usage 24250 23948 -302 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/6 up/down: 43/-398) Total: -355 bytes text data bss dec hex filename 798768 661 7428 806857 c4fc9 busybox_old 798327 658 7428 806413 c4e0d busybox_unstripped
Diffstat (limited to 'util-linux/fdisk.c')
-rw-r--r--util-linux/fdisk.c79
1 files changed, 36 insertions, 43 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 827ea21f3..a75b4f817 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -318,6 +318,23 @@ struct globals {
318} while (0) 318} while (0)
319 319
320 320
321/* TODO: move to libbb? */
322static ullong bb_BLKGETSIZE_sectors(void)
323{
324 uint64_t v64;
325 unsigned long longsectors;
326
327 if (ioctl(fd, BLKGETSIZE64, &v64) == 0) {
328 /* got bytes, convert to 512 byte sectors */
329 return (v64 >> 9);
330 }
331 /* Needs temp of type long */
332 if (ioctl(fd, BLKGETSIZE, &longsectors))
333 longsectors = 0;
334 return longsectors;
335}
336
337
321#define IS_EXTENDED(i) \ 338#define IS_EXTENDED(i) \
322 ((i) == EXTENDED || (i) == WIN98_EXTENDED || (i) == LINUX_EXTENDED) 339 ((i) == EXTENDED || (i) == WIN98_EXTENDED || (i) == LINUX_EXTENDED)
323 340
@@ -624,12 +641,12 @@ get_nr_sects(const struct partition *p)
624/* normally O_RDWR, -l option gives O_RDONLY */ 641/* normally O_RDWR, -l option gives O_RDONLY */
625static int type_open = O_RDWR; 642static int type_open = O_RDWR;
626 643
627static int ext_index; /* the prime extended partition */ 644static int ext_index; /* the prime extended partition */
628static smallint listing; /* no aborts for fdisk -l */ 645static smallint listing; /* no aborts for fdisk -l */
629static int dos_compatible_flag = ~0; 646static smallint dos_compatible_flag = 1;
630#if ENABLE_FEATURE_FDISK_WRITABLE 647#if ENABLE_FEATURE_FDISK_WRITABLE
631//static int dos_changed; 648//static int dos_changed;
632static smallint nowarn; /* no warnings for fdisk -l/-s */ 649static smallint nowarn; /* no warnings for fdisk -l/-s */
633#endif 650#endif
634 651
635static unsigned user_cylinders, user_heads, user_sectors; 652static unsigned user_cylinders, user_heads, user_sectors;
@@ -1184,7 +1201,6 @@ static void
1184get_geometry(void) 1201get_geometry(void)
1185{ 1202{
1186 int sec_fac; 1203 int sec_fac;
1187 uint64_t v64;
1188 1204
1189 get_sectorsize(); 1205 get_sectorsize();
1190 sec_fac = sector_size / 512; 1206 sec_fac = sector_size / 512;
@@ -1204,15 +1220,7 @@ get_geometry(void)
1204 g_sectors = user_sectors ? user_sectors : 1220 g_sectors = user_sectors ? user_sectors :
1205 pt_sectors ? pt_sectors : 1221 pt_sectors ? pt_sectors :
1206 kern_sectors ? kern_sectors : 63; 1222 kern_sectors ? kern_sectors : 63;
1207 if (ioctl(fd, BLKGETSIZE64, &v64) == 0) { 1223 total_number_of_sectors = bb_BLKGETSIZE_sectors();
1208 /* got bytes, convert to 512 byte sectors */
1209 total_number_of_sectors = (v64 >> 9);
1210 } else {
1211 unsigned long longsectors; /* need temp of type long */
1212 if (ioctl(fd, BLKGETSIZE, &longsectors))
1213 longsectors = 0;
1214 total_number_of_sectors = longsectors;
1215 }
1216 1224
1217 sector_offset = 1; 1225 sector_offset = 1;
1218 if (dos_compatible_flag) 1226 if (dos_compatible_flag)
@@ -1576,7 +1584,7 @@ toggle_active(int i)
1576static void 1584static void
1577toggle_dos_compatibility_flag(void) 1585toggle_dos_compatibility_flag(void)
1578{ 1586{
1579 dos_compatible_flag = ~dos_compatible_flag; 1587 dos_compatible_flag = 1 - dos_compatible_flag;
1580 if (dos_compatible_flag) { 1588 if (dos_compatible_flag) {
1581 sector_offset = g_sectors; 1589 sector_offset = g_sectors;
1582 printf("DOS Compatibility flag is set\n"); 1590 printf("DOS Compatibility flag is set\n");
@@ -2732,7 +2740,8 @@ tryprocpt(void)
2732 if (sscanf(line, " %d %d %d %[^\n ]", 2740 if (sscanf(line, " %d %d %d %[^\n ]",
2733 &ma, &mi, &sz, ptname) != 4) 2741 &ma, &mi, &sz, ptname) != 4)
2734 continue; 2742 continue;
2735 for (s = ptname; *s; s++); 2743 for (s = ptname; *s; s++)
2744 continue;
2736 if (isdigit(s[-1])) 2745 if (isdigit(s[-1]))
2737 continue; 2746 continue;
2738 sprintf(devname, "/dev/%s", ptname); 2747 sprintf(devname, "/dev/%s", ptname);
@@ -2798,28 +2807,19 @@ int fdisk_main(int argc, char **argv)
2798 if (opt & OPT_u) 2807 if (opt & OPT_u)
2799 display_in_cyl_units = 0; // -u 2808 display_in_cyl_units = 0; // -u
2800 2809
2801 if (user_set_sector_size && argc != 1)
2802 printf("Warning: the -b (set sector size) option should"
2803 " be used with one specified device\n");
2804
2805#if ENABLE_FEATURE_FDISK_WRITABLE 2810#if ENABLE_FEATURE_FDISK_WRITABLE
2806 if (opt & OPT_l) { 2811 if (opt & OPT_l) {
2807 nowarn = 1; 2812 nowarn = 1;
2808#endif 2813#endif
2809 type_open = O_RDONLY; 2814 type_open = O_RDONLY;
2810 if (argc > 0) { 2815 if (*argv) {
2811 int k;
2812#if defined(__GNUC__)
2813 /* avoid gcc warning:
2814 variable `k' might be clobbered by `longjmp' */
2815 (void)&k;
2816#endif
2817 listing = 1; 2816 listing = 1;
2818 for (k = 0; k < argc; k++) 2817 do {
2819 trydev(argv[k], 1); 2818 trydev(*argv, 1);
2819 } while (*++argv);
2820 } else { 2820 } else {
2821 /* we no longer have default device names */ 2821 /* we don't have device names, */
2822 /* but, we can use /proc/partitions instead */ 2822 /* use /proc/partitions instead */
2823 tryprocpt(); 2823 tryprocpt();
2824 } 2824 }
2825 return 0; 2825 return 0;
@@ -2829,27 +2829,20 @@ int fdisk_main(int argc, char **argv)
2829 2829
2830#if ENABLE_FEATURE_FDISK_BLKSIZE 2830#if ENABLE_FEATURE_FDISK_BLKSIZE
2831 if (opt & OPT_s) { 2831 if (opt & OPT_s) {
2832 long size;
2833 int j; 2832 int j;
2834 2833
2835 nowarn = 1; 2834 nowarn = 1;
2836 type_open = O_RDONLY;
2837
2838 if (argc <= 0) 2835 if (argc <= 0)
2839 bb_show_usage(); 2836 bb_show_usage();
2840
2841 for (j = 0; j < argc; j++) { 2837 for (j = 0; j < argc; j++) {
2842 disk_device = argv[j]; 2838 unsigned long long size;
2843 fd = open(disk_device, type_open); 2839 fd = xopen(argv[j], O_RDONLY);
2844 if (fd < 0) 2840 size = bb_BLKGETSIZE_sectors() / 2;
2845 fdisk_fatal(unable_to_open);
2846 if (ioctl(fd, BLKGETSIZE, &size))
2847 fdisk_fatal(ioctl_error);
2848 close(fd); 2841 close(fd);
2849 if (argc == 1) 2842 if (argc == 1)
2850 printf("%ld\n", size/2); 2843 printf("%lld\n", size);
2851 else 2844 else
2852 printf("%s: %ld\n", argv[j], size/2); 2845 printf("%s: %lld\n", argv[j], size);
2853 } 2846 }
2854 return 0; 2847 return 0;
2855 } 2848 }