diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-07-13 09:06:32 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-07-13 09:06:32 +0200 |
commit | 80856b37e888612c054158b9fa8a0021dbf8dadf (patch) | |
tree | f01a23fb58e9afb1a0276907d0f358ba82cd0f7c | |
parent | a669eca3a230e35e4a6894a30168a047000f3b75 (diff) | |
download | busybox-w32-80856b37e888612c054158b9fa8a0021dbf8dadf.tar.gz busybox-w32-80856b37e888612c054158b9fa8a0021dbf8dadf.tar.bz2 busybox-w32-80856b37e888612c054158b9fa8a0021dbf8dadf.zip |
fdisk: reinstate a short sleep between sync() and ioctl(BLKRRPART)
While at it, simplify code a bit.
function old new delta
write_table 201 198 -3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/fdisk.c | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index b86b13bdc..976558693 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -201,7 +201,6 @@ enum action { OPEN_MAIN, TRY_ONLY, CREATE_EMPTY_DOS, CREATE_EMPTY_SUN }; | |||
201 | static void update_units(void); | 201 | static void update_units(void); |
202 | #if ENABLE_FEATURE_FDISK_WRITABLE | 202 | #if ENABLE_FEATURE_FDISK_WRITABLE |
203 | static void change_units(void); | 203 | static void change_units(void); |
204 | static void reread_partition_table(int leave); | ||
205 | static void delete_partition(int i); | 204 | static void delete_partition(int i); |
206 | static unsigned get_partition(int warn, unsigned max); | 205 | static unsigned get_partition(int warn, unsigned max); |
207 | static void list_types(const char *const *sys); | 206 | static void list_types(const char *const *sys); |
@@ -2553,7 +2552,6 @@ write_table(void) | |||
2553 | ptes[3].changed = 1; | 2552 | ptes[3].changed = 1; |
2554 | for (i = 3; i < g_partitions; i++) { | 2553 | for (i = 3; i < g_partitions; i++) { |
2555 | struct pte *pe = &ptes[i]; | 2554 | struct pte *pe = &ptes[i]; |
2556 | |||
2557 | if (pe->changed) { | 2555 | if (pe->changed) { |
2558 | write_part_table_flag(pe->sectorbuffer); | 2556 | write_part_table_flag(pe->sectorbuffer); |
2559 | write_sector(pe->offset_from_dev_start, pe->sectorbuffer); | 2557 | write_sector(pe->offset_from_dev_start, pe->sectorbuffer); |
@@ -2565,27 +2563,24 @@ write_table(void) | |||
2565 | sgi_write_table(); | 2563 | sgi_write_table(); |
2566 | } | 2564 | } |
2567 | else if (LABEL_IS_SUN) { | 2565 | else if (LABEL_IS_SUN) { |
2568 | int needw = 0; | 2566 | for (i = 0; i < 8; i++) { |
2569 | 2567 | if (ptes[i].changed) { | |
2570 | for (i = 0; i < 8; i++) | 2568 | sun_write_table(); |
2571 | if (ptes[i].changed) | 2569 | break; |
2572 | needw = 1; | 2570 | } |
2573 | if (needw) | 2571 | } |
2574 | sun_write_table(); | ||
2575 | } | 2572 | } |
2576 | 2573 | ||
2577 | printf("The partition table has been altered!\n\n"); | 2574 | printf( |
2578 | reread_partition_table(1); | 2575 | "The partition table has been altered.\n" |
2579 | } | 2576 | "Calling ioctl(BLKRRPART) to re-read partition table.\n" |
2580 | 2577 | ); | |
2581 | static void | ||
2582 | reread_partition_table(int leave) | ||
2583 | { | ||
2584 | int i; | ||
2585 | 2578 | ||
2586 | printf("Calling ioctl() to re-read partition table\n"); | ||
2587 | sync(); | 2579 | sync(); |
2588 | /* sleep(2); Huh? */ | 2580 | /* Users with slow external USB disks on a 320MHz ARM system (year 2011) |
2581 | * report that sleep is needed, otherwise BLKRRPART may fail with -EIO: | ||
2582 | */ | ||
2583 | sleep(1); | ||
2589 | i = ioctl_or_perror(dev_fd, BLKRRPART, NULL, | 2584 | i = ioctl_or_perror(dev_fd, BLKRRPART, NULL, |
2590 | "WARNING: rereading partition table " | 2585 | "WARNING: rereading partition table " |
2591 | "failed, kernel still uses old table"); | 2586 | "failed, kernel still uses old table"); |
@@ -2597,11 +2592,9 @@ reread_partition_table(int leave) | |||
2597 | "information\n"); | 2592 | "information\n"); |
2598 | #endif | 2593 | #endif |
2599 | 2594 | ||
2600 | if (leave) { | 2595 | if (ENABLE_FEATURE_CLEAN_UP) |
2601 | if (ENABLE_FEATURE_CLEAN_UP) | 2596 | close_dev_fd(); |
2602 | close_dev_fd(); | 2597 | exit(i != 0); |
2603 | exit(i != 0); | ||
2604 | } | ||
2605 | } | 2598 | } |
2606 | #endif /* FEATURE_FDISK_WRITABLE */ | 2599 | #endif /* FEATURE_FDISK_WRITABLE */ |
2607 | 2600 | ||
@@ -3100,7 +3093,7 @@ int fdisk_main(int argc UNUSED_PARAM, char **argv) | |||
3100 | verify(); | 3093 | verify(); |
3101 | break; | 3094 | break; |
3102 | case 'w': | 3095 | case 'w': |
3103 | write_table(); /* does not return */ | 3096 | write_table(); /* does not return */ |
3104 | break; | 3097 | break; |
3105 | #if ENABLE_FEATURE_FDISK_ADVANCED | 3098 | #if ENABLE_FEATURE_FDISK_ADVANCED |
3106 | case 'x': | 3099 | case 'x': |