Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/util-linux/fdisk.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/util-linux/fdisk.c
r2725 r3232 7 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 10 /* Looks like someone forgot to add this to config system */ 11 //usage:#ifndef ENABLE_FEATURE_FDISK_BLKSIZE 12 //usage:# define ENABLE_FEATURE_FDISK_BLKSIZE 0 13 //usage:# define IF_FEATURE_FDISK_BLKSIZE(a) 14 //usage:#endif 15 //usage: 16 //usage:#define fdisk_trivial_usage 17 //usage: "[-ul" IF_FEATURE_FDISK_BLKSIZE("s") "] " 18 //usage: "[-C CYLINDERS] [-H HEADS] [-S SECTORS] [-b SSZ] DISK" 19 //usage:#define fdisk_full_usage "\n\n" 20 //usage: "Change partition table\n" 21 //usage: "\n -u Start and End are in sectors (instead of cylinders)" 22 //usage: "\n -l Show partition table for each DISK, then exit" 23 //usage: IF_FEATURE_FDISK_BLKSIZE( 24 //usage: "\n -s Show partition sizes in kb for each DISK, then exit" 25 //usage: ) 26 //usage: "\n -b 2048 (for certain MO disks) use 2048-byte sectors" 27 //usage: "\n -C CYLINDERS Set number of cylinders/heads/sectors" 28 //usage: "\n -H HEADS" 29 //usage: "\n -S SECTORS" 9 30 10 31 #ifndef _LARGEFILE64_SOURCE … … 549 570 int sz; 550 571 551 sz = read_line_input( prompt, line_buffer, sizeof(line_buffer), NULL);572 sz = read_line_input(NULL, prompt, line_buffer, sizeof(line_buffer), /*timeout*/ -1); 552 573 if (sz <= 0) 553 574 exit(EXIT_SUCCESS); /* Ctrl-D or Ctrl-C */ … … 2523 2544 2524 2545 static void 2525 write_table(void)2526 {2527 int i;2528 2529 if (LABEL_IS_DOS) {2530 for (i = 0; i < 3; i++)2531 if (ptes[i].changed)2532 ptes[3].changed = 1;2533 for (i = 3; i < g_partitions; i++) {2534 struct pte *pe = &ptes[i];2535 2536 if (pe->changed) {2537 write_part_table_flag(pe->sectorbuffer);2538 write_sector(pe->offset_from_dev_start, pe->sectorbuffer);2539 }2540 }2541 }2542 else if (LABEL_IS_SGI) {2543 /* no test on change? the printf below might be mistaken */2544 sgi_write_table();2545 }2546 else if (LABEL_IS_SUN) {2547 int needw = 0;2548 2549 for (i = 0; i < 8; i++)2550 if (ptes[i].changed)2551 needw = 1;2552 if (needw)2553 sun_write_table();2554 }2555 2556 printf("The partition table has been altered!\n\n");2557 reread_partition_table(1);2558 }2559 2560 static void2561 2546 reread_partition_table(int leave) 2562 2547 { … … 2565 2550 printf("Calling ioctl() to re-read partition table\n"); 2566 2551 sync(); 2567 /* sleep(2); Huh? */ 2552 /* Users with slow external USB disks on a 320MHz ARM system (year 2011) 2553 * report that sleep is needed, otherwise BLKRRPART may fail with -EIO: 2554 */ 2555 sleep(1); 2568 2556 i = ioctl_or_perror(dev_fd, BLKRRPART, NULL, 2569 2557 "WARNING: rereading partition table " … … 2582 2570 exit(i != 0); 2583 2571 } 2572 } 2573 2574 static void 2575 write_table(void) 2576 { 2577 int i; 2578 2579 if (LABEL_IS_DOS) { 2580 for (i = 0; i < 3; i++) 2581 if (ptes[i].changed) 2582 ptes[3].changed = 1; 2583 for (i = 3; i < g_partitions; i++) { 2584 struct pte *pe = &ptes[i]; 2585 if (pe->changed) { 2586 write_part_table_flag(pe->sectorbuffer); 2587 write_sector(pe->offset_from_dev_start, pe->sectorbuffer); 2588 } 2589 } 2590 } 2591 else if (LABEL_IS_SGI) { 2592 /* no test on change? the printf below might be mistaken */ 2593 sgi_write_table(); 2594 } 2595 else if (LABEL_IS_SUN) { 2596 for (i = 0; i < 8; i++) { 2597 if (ptes[i].changed) { 2598 sun_write_table(); 2599 break; 2600 } 2601 } 2602 } 2603 2604 printf("The partition table has been altered.\n"); 2605 reread_partition_table(1); 2584 2606 } 2585 2607 #endif /* FEATURE_FDISK_WRITABLE */ … … 2825 2847 } 2826 2848 2849 /* Is it a whole disk? The digit check is still useful 2850 for Xen devices for example. */ 2851 static int is_whole_disk(const char *disk) 2852 { 2853 unsigned len; 2854 int fd = open(disk, O_RDONLY); 2855 2856 if (fd != -1) { 2857 struct hd_geometry geometry; 2858 int err = ioctl(fd, HDIO_GETGEO, &geometry); 2859 close(fd); 2860 if (!err) 2861 return (geometry.start == 0); 2862 } 2863 2864 /* Treat "nameN" as a partition name, not whole disk */ 2865 /* note: mmcblk0 should work from the geometry check above */ 2866 len = strlen(disk); 2867 if (len != 0 && isdigit(disk[len - 1])) 2868 return 0; 2869 2870 return 1; 2871 } 2872 2827 2873 /* for fdisk -l: try all things in /proc/partitions 2828 2874 that look like a partition name (do not end in a digit) */ … … 2831 2877 { 2832 2878 FILE *procpt; 2833 char line[100], ptname[100], devname[120] , *s;2879 char line[100], ptname[100], devname[120]; 2834 2880 int ma, mi, sz; 2835 2881 … … 2840 2886 &ma, &mi, &sz, ptname) != 4) 2841 2887 continue; 2842 for (s = ptname; *s; s++) 2843 continue; 2844 /* note: excluding '0': e.g. mmcblk0 is not a partition name! */ 2845 if (s[-1] >= '1' && s[-1] <= '9') 2846 continue; 2888 2847 2889 sprintf(devname, "/dev/%s", ptname); 2848 open_list_and_close(devname, 0); 2890 if (is_whole_disk(devname)) 2891 open_list_and_close(devname, 0); 2849 2892 } 2850 2893 #if ENABLE_FEATURE_CLEAN_UP … … 2981 3024 sgi_get_bootfile()); 2982 3025 if (read_maybe_empty("Please enter the name of the " 2983 3026 "new boot file: ") == '\n') 2984 3027 printf("Boot file unchanged\n"); 2985 3028 else … … 3059 3102 break; 3060 3103 case 'w': 3061 write_table(); 3104 write_table(); /* does not return */ 3062 3105 break; 3063 3106 #if ENABLE_FEATURE_FDISK_ADVANCED
Note:
See TracChangeset
for help on using the changeset viewer.