Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

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

    r1765 r2725  
    33 * mkfs.c - make a linux (minix) file-system.
    44 *
    5  * (C) 1991 Linus Torvalds. This file may be redistributed as per
    6  * the Linux copyright.
     5 * (C) 1991 Linus Torvalds.
     6 *
     7 * Licensed under GPLv2, see file LICENSE in this source tree.
    78 */
    89
     
    6869#include "minix.h"
    6970
    70 #define DEBUG 0
    71 
    72 /* If debugging, store the very same times/uids/gids for image consistency */
    73 #if DEBUG
     71/* Store the very same times/uids/gids for image consistency */
     72#if 1
    7473# define CUR_TIME 0
    7574# define GETUID 0
    7675# define GETGID 0
    7776#else
     77/* Was using this. Is it useful? NB: this will break testsuite */
    7878# define CUR_TIME time(NULL)
    7979# define GETUID getuid()
     
    9090#endif
    9191
     92enum { dev_fd = 3 };
     93
    9294struct globals {
    93     int dev_fd;
    94 
    9595#if ENABLE_FEATURE_MINIX2
    9696    smallint version2;
     
    110110    unsigned currently_testing;
    111111
    112 
    113112    char root_block[BLOCK_SIZE];
    114     char super_block_buffer[BLOCK_SIZE];
     113    char superblock_buffer[BLOCK_SIZE];
    115114    char boot_block_buffer[512];
    116115    unsigned short good_blocks_table[MAX_GOOD_BLOCKS];
    117116    /* check_blocks(): buffer[] was the biggest static in entire bbox */
    118117    char check_blocks_buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS];
     118
     119    unsigned short ind_block1[BLOCK_SIZE >> 1];
     120    unsigned short dind_block1[BLOCK_SIZE >> 1];
     121    unsigned long ind_block2[BLOCK_SIZE >> 2];
     122    unsigned long dind_block2[BLOCK_SIZE >> 2];
    119123};
    120 
    121124#define G (*ptr_to_globals)
     125#define INIT_G() do { \
     126    SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
     127} while (0)
    122128
    123129static ALWAYS_INLINE unsigned div_roundup(unsigned size, unsigned n)
     
    129135#define INODE_BUF2              (((struct minix2_inode*)G.inode_buffer) - 1)
    130136
    131 #define SB                      (*(struct minix_super_block*)G.super_block_buffer)
     137#define SB                      (*(struct minix_superblock*)G.superblock_buffer)
    132138
    133139#define SB_INODES               (SB.s_ninodes)
     
    145151# define SB_ZONES               (version2 ? SB.s_zones : SB.s_nzones)
    146152# define INODE_BLOCKS           div_roundup(SB_INODES, \
    147                                 version2 ? MINIX2_INODES_PER_BLOCK : MINIX1_INODES_PER_BLOCK)
     153                                (version2 ? MINIX2_INODES_PER_BLOCK : MINIX1_INODES_PER_BLOCK))
    148154#endif
    149155
     
    156162static int minix_bit(const char* a, unsigned i)
    157163{
    158       return a[i >> 3] & (1<<(i & 7));
     164    return a[i >> 3] & (1<<(i & 7));
    159165}
    160166
     
    231237static void write_tables(void)
    232238{
    233     /* Mark the super block valid. */
     239    /* Mark the superblock valid. */
    234240    SB.s_state |= MINIX_VALID_FS;
    235241    SB.s_state &= ~MINIX_ERROR_FS;
    236242
    237243    msg_eol = "seek to 0 failed";
    238     xlseek(G.dev_fd, 0, SEEK_SET);
    239 
    240     msg_eol = "cannot clear boot sector";
    241     xwrite(G.dev_fd, G.boot_block_buffer, 512);
     244    xlseek(dev_fd, 0, SEEK_SET);
     245
     246    msg_eol = "can't clear boot sector";
     247    xwrite(dev_fd, G.boot_block_buffer, 512);
    242248
    243249    msg_eol = "seek to BLOCK_SIZE failed";
    244     xlseek(G.dev_fd, BLOCK_SIZE, SEEK_SET);
    245 
    246     msg_eol = "cannot write superblock";
    247     xwrite(G.dev_fd, G.super_block_buffer, BLOCK_SIZE);
    248 
    249     msg_eol = "cannot write inode map";
    250     xwrite(G.dev_fd, G.inode_map, SB_IMAPS * BLOCK_SIZE);
    251 
    252     msg_eol = "cannot write zone map";
    253     xwrite(G.dev_fd, G.zone_map, SB_ZMAPS * BLOCK_SIZE);
    254 
    255     msg_eol = "cannot write inodes";
    256     xwrite(G.dev_fd, G.inode_buffer, INODE_BUFFER_SIZE);
     250    xlseek(dev_fd, BLOCK_SIZE, SEEK_SET);
     251
     252    msg_eol = "can't write superblock";
     253    xwrite(dev_fd, G.superblock_buffer, BLOCK_SIZE);
     254
     255    msg_eol = "can't write inode map";
     256    xwrite(dev_fd, G.inode_map, SB_IMAPS * BLOCK_SIZE);
     257
     258    msg_eol = "can't write zone map";
     259    xwrite(dev_fd, G.zone_map, SB_ZMAPS * BLOCK_SIZE);
     260
     261    msg_eol = "can't write inodes";
     262    xwrite(dev_fd, G.inode_buffer, INODE_BUFFER_SIZE);
    257263
    258264    msg_eol = "\n";
     
    261267static void write_block(int blk, char *buffer)
    262268{
    263     xlseek(G.dev_fd, blk * BLOCK_SIZE, SEEK_SET);
    264     xwrite(G.dev_fd, buffer, BLOCK_SIZE);
     269    xlseek(dev_fd, blk * BLOCK_SIZE, SEEK_SET);
     270    xwrite(dev_fd, buffer, BLOCK_SIZE);
    265271}
    266272
     
    307313    int i, j, zone;
    308314    int ind = 0, dind = 0;
     315    /* moved to globals to reduce stack usage
    309316    unsigned short ind_block[BLOCK_SIZE >> 1];
    310317    unsigned short dind_block[BLOCK_SIZE >> 1];
     318    */
     319#define ind_block (G.ind_block1)
     320#define dind_block (G.dind_block1)
    311321
    312322#define NEXT_BAD (zone = next(zone))
     
    352362    if (dind)
    353363        write_block(dind, (char *) dind_block);
     364#undef ind_block
     365#undef dind_block
    354366}
    355367
     
    360372    int i, j, zone;
    361373    int ind = 0, dind = 0;
     374    /* moved to globals to reduce stack usage
    362375    unsigned long ind_block[BLOCK_SIZE >> 2];
    363376    unsigned long dind_block[BLOCK_SIZE >> 2];
     377    */
     378#define ind_block (G.ind_block2)
     379#define dind_block (G.dind_block2)
    364380
    365381    if (!G.badblocks)
     
    402418    if (dind)
    403419        write_block(dind, (char *) dind_block);
     420#undef ind_block
     421#undef dind_block
    404422}
    405423#else
     
    465483    /* Seek to the correct loc. */
    466484    msg_eol = "seek failed during testing of blocks";
    467     xlseek(G.dev_fd, current_block * BLOCK_SIZE, SEEK_SET);
     485    xlseek(dev_fd, current_block * BLOCK_SIZE, SEEK_SET);
    468486    msg_eol = "\n";
    469487
    470488    /* Try the read */
    471     got = read(G.dev_fd, buffer, try * BLOCK_SIZE);
     489    got = read(dev_fd, buffer, try * BLOCK_SIZE);
    472490    if (got < 0)
    473491        got = 0;
     
    479497}
    480498
    481 static void alarm_intr(int alnum)
     499static void alarm_intr(int alnum UNUSED_PARAM)
    482500{
    483501    if (G.currently_testing >= SB_ZONES)
     
    488506        return;
    489507    printf("%d ...", G.currently_testing);
    490     fflush(stdout);
     508    fflush_all();
    491509}
    492510
     
    500518    while (G.currently_testing < SB_ZONES) {
    501519        msg_eol = "seek failed in check_blocks";
    502         xlseek(G.dev_fd, G.currently_testing * BLOCK_SIZE, SEEK_SET);
     520        xlseek(dev_fd, G.currently_testing * BLOCK_SIZE, SEEK_SET);
    503521        msg_eol = "\n";
    504522        try = TEST_BUFFER_BLOCKS;
     
    524542    unsigned long blockno;
    525543
    526     listfile = xfopen(filename, "r");
     544    listfile = xfopen_for_read(filename);
    527545    while (!feof(listfile)) {
    528546        fscanf(listfile, "%ld\n", &blockno);
     
    540558    unsigned i;
    541559
    542     /* memset(G.super_block_buffer, 0, BLOCK_SIZE); */
     560    /* memset(G.superblock_buffer, 0, BLOCK_SIZE); */
    543561    /* memset(G.boot_block_buffer, 0, 512); */
    544562    SB_MAGIC = G.magic;
     
    604622}
    605623
    606 int mkfs_minix_main(int argc, char **argv);
    607 int mkfs_minix_main(int argc, char **argv)
    608 {
    609     struct mntent *mp;
     624int mkfs_minix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     625int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
     626{
    610627    unsigned opt;
    611628    char *tmp;
    612629    struct stat statbuf;
    613     char *str_i, *str_n;
     630    char *str_i;
    614631    char *listfile = NULL;
    615632
    616     PTR_TO_GLOBALS = xzalloc(sizeof(G));
     633    INIT_G();
    617634/* default (changed to 30, per Linus's suggestion, Sun Nov 21 08:05:07 1993) */
    618635    G.namelen = 30;
     
    627644#endif
    628645
    629     opt = getopt32(argv, "ci:l:n:v", &str_i, &listfile, &str_n);
     646    opt_complementary = "n+"; /* -n N */
     647    opt = getopt32(argv, "ci:l:n:v", &str_i, &listfile, &G.namelen);
    630648    argv += optind;
    631649    //if (opt & 1) -c
     
    633651    //if (opt & 4) -l
    634652    if (opt & 8) { // -n
    635         G.namelen = xatoi_u(str_n);
    636653        if (G.namelen == 14) G.magic = MINIX1_SUPER_MAGIC;
    637654        else if (G.namelen == 30) G.magic = MINIX1_SUPER_MAGIC2;
     
    666683
    667684    /* Check if it is mounted */
    668     mp = find_mount_point(G.device_name, NULL);
    669     if (mp && strcmp(G.device_name, mp->mnt_fsname) == 0)
    670         bb_error_msg_and_die("%s is mounted on %s; "
    671                 "refusing to make a filesystem",
    672                 G.device_name, mp->mnt_dir);
    673 
    674     G.dev_fd = xopen(G.device_name, O_RDWR);
    675     if (fstat(G.dev_fd, &statbuf) < 0)
    676         bb_error_msg_and_die("cannot stat %s", G.device_name);
     685    if (find_mount_point(G.device_name, 0))
     686        bb_error_msg_and_die("can't format mounted filesystem");
     687
     688    xmove_fd(xopen(G.device_name, O_RDWR), dev_fd);
     689    xfstat(dev_fd, &statbuf, G.device_name);
    677690    if (!S_ISBLK(statbuf.st_mode))
    678691        opt &= ~1; // clear -c (check)
Note: See TracChangeset for help on using the changeset viewer.