Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/util-linux/fdisk.c

    r2725 r3232  
    77 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
     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"
    930
    1031#ifndef _LARGEFILE64_SOURCE
     
    549570    int sz;
    550571
    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);
    552573    if (sz <= 0)
    553574        exit(EXIT_SUCCESS); /* Ctrl-D or Ctrl-C */
     
    25232544
    25242545static 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 void
    25612546reread_partition_table(int leave)
    25622547{
     
    25652550    printf("Calling ioctl() to re-read partition table\n");
    25662551    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);
    25682556    i = ioctl_or_perror(dev_fd, BLKRRPART, NULL,
    25692557            "WARNING: rereading partition table "
     
    25822570        exit(i != 0);
    25832571    }
     2572}
     2573
     2574static void
     2575write_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);
    25842606}
    25852607#endif /* FEATURE_FDISK_WRITABLE */
     
    28252847}
    28262848
     2849/* Is it a whole disk? The digit check is still useful
     2850   for Xen devices for example. */
     2851static 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
    28272873/* for fdisk -l: try all things in /proc/partitions
    28282874   that look like a partition name (do not end in a digit) */
     
    28312877{
    28322878    FILE *procpt;
    2833     char line[100], ptname[100], devname[120], *s;
     2879    char line[100], ptname[100], devname[120];
    28342880    int ma, mi, sz;
    28352881
     
    28402886                &ma, &mi, &sz, ptname) != 4)
    28412887            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
    28472889        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);
    28492892    }
    28502893#if ENABLE_FEATURE_CLEAN_UP
     
    29813024                    sgi_get_bootfile());
    29823025                if (read_maybe_empty("Please enter the name of the "
    2983                            "new boot file: ") == '\n')
     3026                        "new boot file: ") == '\n')
    29843027                    printf("Boot file unchanged\n");
    29853028                else
     
    30593102            break;
    30603103        case 'w':
    3061             write_table();          /* does not return */
     3104            write_table();  /* does not return */
    30623105            break;
    30633106#if ENABLE_FEATURE_FDISK_ADVANCED
Note: See TracChangeset for help on using the changeset viewer.