Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/util-linux/mkfs_minix.c

    r3232 r3621  
    196196# define BLKGETSIZE     _IO(0x12,96)    /* return device size */
    197197#endif
    198 
    199 
    200 static long valid_offset(int fd, int offset)
    201 {
    202     char ch;
    203 
    204     if (lseek(fd, offset, SEEK_SET) < 0)
    205         return 0;
    206     if (read(fd, &ch, 1) < 1)
    207         return 0;
    208     return 1;
    209 }
    210 
    211 static int count_blocks(int fd)
    212 {
    213     int high, low;
    214 
    215     low = 0;
    216     for (high = 1; valid_offset(fd, high); high *= 2)
    217         low = high;
    218 
    219     while (low < high - 1) {
    220         const int mid = (low + high) / 2;
    221 
    222         if (valid_offset(fd, mid))
    223             low = mid;
    224         else
    225             high = mid;
    226     }
    227     valid_offset(fd, 0);
    228     return (low + 1);
    229 }
    230 
    231 static int get_size(const char *file)
    232 {
    233     int fd;
    234     long size;
    235 
    236     fd = xopen(file, O_RDWR);
    237     if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
    238         close(fd);
    239         return (size * 512);
    240     }
    241 
    242     size = count_blocks(fd);
    243     close(fd);
    244     return size;
    245 }
    246198
    247199static void write_tables(void)
     
    554506    listfile = xfopen_for_read(filename);
    555507    while (!feof(listfile)) {
    556         fscanf(listfile, "%ld\n", &blockno);
     508        fscanf(listfile, "%lu\n", &blockno);
    557509        mark_zone(blockno);
    558510        G.badblocks++;
     
    625577        unmark_inode(i);
    626578    G.inode_buffer = xzalloc(INODE_BUFFER_SIZE);
    627     printf("%ld inodes\n", (long)SB_INODES);
    628     printf("%ld blocks\n", (long)SB_ZONES);
    629     printf("Firstdatazone=%ld (%ld)\n", (long)SB_FIRSTZONE, (long)norm_firstzone);
    630     printf("Zonesize=%d\n", BLOCK_SIZE << SB_ZONE_SIZE);
    631     printf("Maxsize=%ld\n", (long)SB_MAXSIZE);
     579    printf("%lu inodes\n", (unsigned long)SB_INODES);
     580    printf("%lu blocks\n", (unsigned long)SB_ZONES);
     581    printf("Firstdatazone=%lu (%lu)\n", (unsigned long)SB_FIRSTZONE, (unsigned long)norm_firstzone);
     582    printf("Zonesize=%u\n", BLOCK_SIZE << SB_ZONE_SIZE);
     583    printf("Maxsize=%lu\n", (unsigned long)SB_MAXSIZE);
    632584}
    633585
     
    637589    unsigned opt;
    638590    char *tmp;
    639     struct stat statbuf;
    640591    char *str_i;
    641592    char *listfile = NULL;
     
    674625    }
    675626
    676     G.device_name = *argv++;
     627    G.device_name = argv[0];
    677628    if (!G.device_name)
    678629        bb_show_usage();
    679     if (*argv)
    680         G.total_blocks = xatou32(*argv);
    681     else
    682         G.total_blocks = get_size(G.device_name) / 1024;
     630
     631    /* Check if it is mounted */
     632    if (find_mount_point(G.device_name, 0))
     633        bb_error_msg_and_die("can't format mounted filesystem");
     634
     635    xmove_fd(xopen(G.device_name, O_RDWR), dev_fd);
     636
     637    G.total_blocks = get_volume_size_in_bytes(dev_fd, argv[1], 1024, /*extend:*/ 1) / 1024;
    683638
    684639    if (G.total_blocks < 10)
     
    691646    } else if (G.total_blocks > 65535)
    692647        G.total_blocks = 65535;
    693 
    694     /* Check if it is mounted */
    695     if (find_mount_point(G.device_name, 0))
    696         bb_error_msg_and_die("can't format mounted filesystem");
    697 
    698     xmove_fd(xopen(G.device_name, O_RDWR), dev_fd);
     648#if 0
     649    struct stat statbuf;
    699650    xfstat(dev_fd, &statbuf, G.device_name);
     651/* why? */
    700652    if (!S_ISBLK(statbuf.st_mode))
    701653        opt &= ~1; // clear -c (check)
    702 
     654#if 0
    703655/* I don't know why someone has special code to prevent mkfs.minix
    704656 * on IDE devices. Why IDE but not SCSI, etc?... */
    705 #if 0
    706657    else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
    707658        /* what is this? */
     
    709660            "to make filesystem on '%s'", G.device_name);
    710661#endif
    711 
     662#endif
    712663    tmp = G.root_block;
    713664    *(short *) tmp = 1;
Note: See TracChangeset for help on using the changeset viewer.