cut 0.5k off mkfs.minix

assorted strtoul fixes (that's what brought me into minix)...
This commit is contained in:
Denis Vlasenko 2006-11-29 18:15:52 +00:00
parent a35c9e91ba
commit c6ce8733dd
5 changed files with 131 additions and 207 deletions

View File

@ -7,12 +7,9 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/ */
#include <stdio.h>
#include <string.h>
#include "libbb.h" #include "libbb.h"
#include <mntent.h> #include <mntent.h>
/* /*
* Given a block device, find the mount table entry if that block device * Given a block device, find the mount table entry if that block device
* is mounted. * is mounted.
@ -36,14 +33,16 @@ struct mntent *find_mount_point(const char *name, const char *table)
mountDevice = s.st_dev; mountDevice = s.st_dev;
if ((mountTable = setmntent(table ? table : bb_path_mtab_file, "r")) == 0) mountTable = setmntent(table ? table : bb_path_mtab_file, "r");
if (!mountTable)
return 0; return 0;
while ((mountEntry = getmntent(mountTable)) != 0) { while ((mountEntry = getmntent(mountTable)) != 0) {
if (strcmp(name, mountEntry->mnt_dir) == 0
if(strcmp(name, mountEntry->mnt_dir) == 0 || strcmp(name, mountEntry->mnt_fsname) == 0
|| strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */ ) { /* String match. */
break; break;
}
if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */ if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */
break; break;
if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */ if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */

View File

@ -147,8 +147,11 @@ void xwrite(int fd, const void *buf, size_t count)
off_t xlseek(int fd, off_t offset, int whence) off_t xlseek(int fd, off_t offset, int whence)
{ {
off_t off = lseek(fd, offset, whence); off_t off = lseek(fd, offset, whence);
if (off == (off_t)-1) if (off == (off_t)-1) {
if (whence == SEEK_SET)
bb_perror_msg_and_die("lseek(%"OFF_FMT"u)", offset);
bb_perror_msg_and_die("lseek"); bb_perror_msg_and_die("lseek");
}
return off; return off;
} }

View File

@ -330,13 +330,16 @@ read_maybe_empty(const char *mesg)
static int static int
read_hex(const struct systypes *sys) read_hex(const struct systypes *sys)
{ {
unsigned long v;
while (1) { while (1) {
read_nonempty(_("Hex code (type L to list codes): ")); read_nonempty(_("Hex code (type L to list codes): "));
if (*line_ptr == 'l' || *line_ptr == 'L') if (*line_ptr == 'l' || *line_ptr == 'L') {
list_types(sys); list_types(sys);
else if (isxdigit(*line_ptr)) { continue;
return strtoul(line_ptr, NULL, 16);
} }
v = bb_strtoul(line_ptr, NULL, 16);
if (errno || v > 0xff) continue;
return v;
} }
} }
#endif /* CONFIG_FEATURE_FDISK_WRITABLE */ #endif /* CONFIG_FEATURE_FDISK_WRITABLE */

View File

@ -39,19 +39,16 @@ typedef enum type_id {
static int remove_ids(type_id type, int argc, char **argv) static int remove_ids(type_id type, int argc, char **argv)
{ {
int id; unsigned long id;
int ret = 0; /* silence gcc */ int ret = 0; /* silence gcc */
char *end;
int nb_errors = 0; int nb_errors = 0;
union semun arg; union semun arg;
arg.val = 0; arg.val = 0;
while (argc) { while (argc) {
id = bb_strtoul(argv[0], NULL, 10);
id = strtoul(argv[0], &end, 10); if (errno || id > INT_MAX) {
if (*end != 0) {
bb_error_msg("invalid id: %s", argv[0]); bb_error_msg("invalid id: %s", argv[0]);
nb_errors++; nb_errors++;
} else { } else {
@ -91,11 +88,13 @@ int ipcrm_main(int argc, char **argv)
type_id what = 0; /* silence gcc */ type_id what = 0; /* silence gcc */
char w; char w;
if ((((w=argv[1][0]) == 'm' && argv[1][1] == 's' && argv[1][2] == 'g') w=argv[1][0];
|| (argv[1][0] == 's' if ( ((w == 'm' && argv[1][1] == 's' && argv[1][2] == 'g')
&& ((w=argv[1][1]) == 'h' || w == 'e') || (argv[1][0] == 's'
&& argv[1][2] == 'm')) && ((w=argv[1][1]) == 'h' || w == 'e')
&& argv[1][3] == '\0') { && argv[1][2] == 'm')
) && argv[1][3] == '\0'
) {
if (argc < 3) if (argc < 3)
bb_show_usage(); bb_show_usage();
@ -140,7 +139,7 @@ int ipcrm_main(int argc, char **argv)
if (iskey) { if (iskey) {
/* keys are in hex or decimal */ /* keys are in hex or decimal */
key_t key = strtoul(optarg, NULL, 0); key_t key = xstrtoul(optarg, 0);
if (key == IPC_PRIVATE) { if (key == IPC_PRIVATE) {
error++; error++;
@ -176,7 +175,7 @@ int ipcrm_main(int argc, char **argv)
} }
} else { } else {
/* ids are in decimal */ /* ids are in decimal */
id = strtoul(optarg, NULL, 10); id = xatoul(optarg);
} }
result = ((c == 'q') ? msgctl(id, IPC_RMID, NULL) : result = ((c == 'q') ? msgctl(id, IPC_RMID, NULL) :

View File

@ -166,13 +166,15 @@ struct minix_dir_entry {
#define UPPER(size,n) (((size)+((n)-1))/(n)) #define UPPER(size,n) (((size)+((n)-1))/(n))
#define INODE_SIZE (sizeof(struct minix_inode)) #define INODE_SIZE (sizeof(struct minix_inode))
#ifdef CONFIG_FEATURE_MINIX2
#define INODE_SIZE2 (sizeof(struct minix2_inode)) #if ENABLE_FEATURE_MINIX2
#define INODE_BLOCKS UPPER(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \ # define INODE_SIZE2 (sizeof(struct minix2_inode))
# define INODE_BLOCKS UPPER(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \
: MINIX_INODES_PER_BLOCK)) : MINIX_INODES_PER_BLOCK))
#else #else
#define INODE_BLOCKS UPPER(INODES, (MINIX_INODES_PER_BLOCK)) # define INODE_BLOCKS UPPER(INODES, (MINIX_INODES_PER_BLOCK))
#endif #endif
#define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE) #define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE)
#define BITS_PER_BLOCK (BLOCK_SIZE<<3) #define BITS_PER_BLOCK (BLOCK_SIZE<<3)
@ -180,33 +182,37 @@ struct minix_dir_entry {
static char *device_name; static char *device_name;
static int DEV = -1; static int DEV = -1;
static uint32_t BLOCKS; static uint32_t BLOCKS;
static int check;
static int badblocks; static int badblocks;
static int namelen = 30; /* default (changed to 30, per Linus's /* default (changed to 30, per Linus's suggestion, Sun Nov 21 08:05:07 1993) */
static int namelen = 30;
suggestion, Sun Nov 21 08:05:07 1993) */
static int dirsize = 32; static int dirsize = 32;
static int magic = MINIX_SUPER_MAGIC2; static int magic = MINIX_SUPER_MAGIC2;
#if ENABLE_FEATURE_MINIX2
static int version2; static int version2;
#else
enum { version2 = 0 };
#endif
static char root_block[BLOCK_SIZE]; static char root_block[BLOCK_SIZE];
static char *inode_buffer; static char *inode_buffer;
#define Inode (((struct minix_inode *) inode_buffer)-1) #define Inode (((struct minix_inode *) inode_buffer)-1)
#ifdef CONFIG_FEATURE_MINIX2 #if ENABLE_FEATURE_MINIX2
#define Inode2 (((struct minix2_inode *) inode_buffer)-1) #define Inode2 (((struct minix2_inode *) inode_buffer)-1)
#endif #endif
static char super_block_buffer[BLOCK_SIZE]; static char super_block_buffer[BLOCK_SIZE];
static char boot_block_buffer[512]; static char boot_block_buffer[512];
#define Super (*(struct minix_super_block *)super_block_buffer) #define Super (*(struct minix_super_block *)super_block_buffer)
#define INODES (Super.s_ninodes) #define INODES (Super.s_ninodes)
#ifdef CONFIG_FEATURE_MINIX2 #if ENABLE_FEATURE_MINIX2
#define ZONES (version2 ? Super.s_zones : Super.s_nzones) # define ZONES (version2 ? Super.s_zones : Super.s_nzones)
#else #else
#define ZONES (Super.s_nzones) # define ZONES (Super.s_nzones)
#endif #endif
#define IMAPS (Super.s_imap_blocks) #define IMAPS (Super.s_imap_blocks)
#define ZMAPS (Super.s_zmap_blocks) #define ZMAPS (Super.s_zmap_blocks)
#define FIRSTZONE (Super.s_firstdatazone) #define FIRSTZONE (Super.s_firstdatazone)
@ -222,7 +228,7 @@ static unsigned short good_blocks_table[MAX_GOOD_BLOCKS];
static int used_good_blocks; static int used_good_blocks;
static unsigned long req_nr_inodes; static unsigned long req_nr_inodes;
static int bit(char * a,unsigned int i) static int bit(char* a, unsigned i)
{ {
return (a[i >> 3] & (1<<(i & 7))) != 0; return (a[i >> 3] & (1<<(i & 7))) != 0;
} }
@ -235,33 +241,11 @@ static int bit(char * a,unsigned int i)
#define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1)) #define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1))
#define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1)) #define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1))
/*
* Check to make certain that our new filesystem won't be created on
* an already mounted partition. Code adapted from mke2fs, Copyright
* (C) 1994 Theodore Ts'o. Also licensed under GPL.
*/
static void check_mount(void)
{
FILE *f;
struct mntent *mnt;
if ((f = setmntent(MOUNTED, "r")) == NULL)
return;
while ((mnt = getmntent(f)) != NULL)
if (strcmp(device_name, mnt->mnt_fsname) == 0)
break;
endmntent(f);
if (!mnt)
return;
bb_error_msg_and_die("%s is mounted; will not make a filesystem here!", device_name);
}
static long valid_offset(int fd, int offset) static long valid_offset(int fd, int offset)
{ {
char ch; char ch;
if (lseek(fd, offset, 0) < 0) if (lseek(fd, offset, SEEK_SET) < 0)
return 0; return 0;
if (read(fd, &ch, 1) < 1) if (read(fd, &ch, 1) < 1)
return 0; return 0;
@ -275,6 +259,7 @@ static int count_blocks(int fd)
low = 0; low = 0;
for (high = 1; valid_offset(fd, high); high *= 2) for (high = 1; valid_offset(fd, high); high *= 2)
low = high; low = high;
while (low < high - 1) { while (low < high - 1) {
const int mid = (low + high) / 2; const int mid = (low + high) / 2;
@ -309,29 +294,34 @@ static void write_tables(void)
Super.s_state |= MINIX_VALID_FS; Super.s_state |= MINIX_VALID_FS;
Super.s_state &= ~MINIX_ERROR_FS; Super.s_state &= ~MINIX_ERROR_FS;
if (lseek(DEV, 0, SEEK_SET)) msg_eol = "seek to 0 failed";
bb_error_msg_and_die("seek to boot block failed in write_tables"); xlseek(DEV, 0, SEEK_SET);
if (512 != write(DEV, boot_block_buffer, 512))
bb_error_msg_and_die("cannot clear boot sector");
if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET))
bb_error_msg_and_die("seek failed in write_tables");
if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE))
bb_error_msg_and_die("cannot write super-block");
if (IMAPS * BLOCK_SIZE != write(DEV, inode_map, IMAPS * BLOCK_SIZE))
bb_error_msg_and_die("cannot write inode map");
if (ZMAPS * BLOCK_SIZE != write(DEV, zone_map, ZMAPS * BLOCK_SIZE))
bb_error_msg_and_die("cannot write zone map");
if (INODE_BUFFER_SIZE != write(DEV, inode_buffer, INODE_BUFFER_SIZE))
bb_error_msg_and_die("cannot write inodes");
msg_eol = "cannot clear boot sector";
xwrite(DEV, boot_block_buffer, 512);
msg_eol = "seek to BLOCK_SIZE failed";
xlseek(DEV, BLOCK_SIZE, SEEK_SET);
msg_eol = "cannot write superblock";
xwrite(DEV, super_block_buffer, BLOCK_SIZE);
msg_eol = "cannot write inode map";
xwrite(DEV, inode_map, IMAPS * BLOCK_SIZE);
msg_eol = "cannot write zone map";
xwrite(DEV, zone_map, ZMAPS * BLOCK_SIZE);
msg_eol = "cannot write inodes";
xwrite(DEV, inode_buffer, INODE_BUFFER_SIZE);
msg_eol = "\n";
} }
static void write_block(int blk, char *buffer) static void write_block(int blk, char *buffer)
{ {
if (blk * BLOCK_SIZE != lseek(DEV, blk * BLOCK_SIZE, SEEK_SET)) xlseek(DEV, blk * BLOCK_SIZE, SEEK_SET);
bb_error_msg_and_die("seek failed in write_block"); xwrite(DEV, buffer, BLOCK_SIZE);
if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE))
bb_error_msg_and_die("write failed in write_block");
} }
static int get_free_block(void) static int get_free_block(void)
@ -385,6 +375,8 @@ static void make_bad_inode(void)
return; return;
mark_inode(MINIX_BAD_INO); mark_inode(MINIX_BAD_INO);
inode->i_nlinks = 1; inode->i_nlinks = 1;
/* BTW, setting this makes all images different */
/* it's harder to check for bugs then - diff isn't helpful :(... */
inode->i_time = time(NULL); inode->i_time = time(NULL);
inode->i_mode = S_IFREG + 0000; inode->i_mode = S_IFREG + 0000;
inode->i_size = badblocks * BLOCK_SIZE; inode->i_size = badblocks * BLOCK_SIZE;
@ -421,7 +413,7 @@ static void make_bad_inode(void)
write_block(dind, (char *) dind_block); write_block(dind, (char *) dind_block);
} }
#ifdef CONFIG_FEATURE_MINIX2 #if ENABLE_FEATURE_MINIX2
static void make_bad_inode2(void) static void make_bad_inode2(void)
{ {
struct minix2_inode *inode = &Inode2[MINIX_BAD_INO]; struct minix2_inode *inode = &Inode2[MINIX_BAD_INO];
@ -494,7 +486,7 @@ static void make_root_inode(void)
write_block(inode->i_zone[0], root_block); write_block(inode->i_zone[0], root_block);
} }
#ifdef CONFIG_FEATURE_MINIX2 #if ENABLE_FEATURE_MINIX2
static void make_root_inode2(void) static void make_root_inode2(void)
{ {
struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO]; struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO];
@ -528,11 +520,9 @@ static void setup_tables(void)
MAGIC = magic; MAGIC = magic;
ZONESIZE = 0; ZONESIZE = 0;
MAXSIZE = version2 ? 0x7fffffff : (7 + 512 + 512 * 512) * 1024; MAXSIZE = version2 ? 0x7fffffff : (7 + 512 + 512 * 512) * 1024;
#ifdef CONFIG_FEATURE_MINIX2
if (version2) { if (version2) {
Super.s_zones = BLOCKS; Super.s_zones = BLOCKS;
} else } else
#endif
Super.s_nzones = BLOCKS; Super.s_nzones = BLOCKS;
/* some magic nrs: 1 inode / 3 blocks */ /* some magic nrs: 1 inode / 3 blocks */
@ -541,12 +531,10 @@ static void setup_tables(void)
else else
inodes = req_nr_inodes; inodes = req_nr_inodes;
/* Round up inode count to fill block size */ /* Round up inode count to fill block size */
#ifdef CONFIG_FEATURE_MINIX2
if (version2) if (version2)
inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) & inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) &
~(MINIX2_INODES_PER_BLOCK - 1)); ~(MINIX2_INODES_PER_BLOCK - 1));
else else
#endif
inodes = ((inodes + MINIX_INODES_PER_BLOCK - 1) & inodes = ((inodes + MINIX_INODES_PER_BLOCK - 1) &
~(MINIX_INODES_PER_BLOCK - 1)); ~(MINIX_INODES_PER_BLOCK - 1));
if (inodes > 65535) if (inodes > 65535)
@ -594,16 +582,14 @@ static void setup_tables(void)
* Perform a test of a block; return the number of * Perform a test of a block; return the number of
* blocks readable/writable. * blocks readable/writable.
*/ */
static long do_check(char *buffer, int try, unsigned int current_block) static long do_check(char *buffer, int try, unsigned current_block)
{ {
long got; long got;
/* Seek to the correct loc. */ /* Seek to the correct loc. */
if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) != msg_eol = "seek failed during testing of blocks";
current_block * BLOCK_SIZE) { xlseek(DEV, current_block * BLOCK_SIZE, SEEK_SET);
bb_error_msg_and_die("seek failed during testing of blocks"); msg_eol = "\n";
}
/* Try the read */ /* Try the read */
got = read(DEV, buffer, try * BLOCK_SIZE); got = read(DEV, buffer, try * BLOCK_SIZE);
@ -616,7 +602,7 @@ static long do_check(char *buffer, int try, unsigned int current_block)
return got; return got;
} }
static unsigned int currently_testing; static unsigned currently_testing;
static void alarm_intr(int alnum) static void alarm_intr(int alnum)
{ {
@ -639,9 +625,9 @@ static void check_blocks(void)
signal(SIGALRM, alarm_intr); signal(SIGALRM, alarm_intr);
alarm(5); alarm(5);
while (currently_testing < ZONES) { while (currently_testing < ZONES) {
if (lseek(DEV, currently_testing * BLOCK_SIZE, SEEK_SET) != msg_eol = "seek failed in check_blocks";
currently_testing * BLOCK_SIZE) xlseek(DEV, currently_testing * BLOCK_SIZE, SEEK_SET);
bb_error_msg_and_die("seek failed in check_blocks"); msg_eol = "\n";
try = TEST_BUFFER_BLOCKS; try = TEST_BUFFER_BLOCKS;
if (currently_testing + try > ZONES) if (currently_testing + try > ZONES)
try = ZONES - currently_testing; try = ZONES - currently_testing;
@ -655,10 +641,7 @@ static void check_blocks(void)
badblocks++; badblocks++;
currently_testing++; currently_testing++;
} }
if (badblocks > 1) printf("%d bad block(s)\n", badblocks);
printf("%d bad blocks\n", badblocks);
else if (badblocks == 1)
printf("one bad block\n");
} }
static void get_list_blocks(char *filename) static void get_list_blocks(char *filename)
@ -672,130 +655,66 @@ static void get_list_blocks(char *filename)
mark_zone(blockno); mark_zone(blockno);
badblocks++; badblocks++;
} }
if (badblocks > 1) printf("%d bad block(s)\n", badblocks);
printf("%d bad blocks\n", badblocks);
else if (badblocks == 1)
printf("one bad block\n");
} }
int mkfs_minix_main(int argc, char **argv) int mkfs_minix_main(int argc, char **argv)
{ {
int i=1; unsigned opt;
char *tmp; char *tmp;
struct stat statbuf; struct stat statbuf;
char *str_i, *str_n;
char *listfile = NULL; char *listfile = NULL;
int stopIt=FALSE;
if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE)
bb_error_msg_and_die("bad inode size"); bb_error_msg_and_die("bad inode size");
#ifdef CONFIG_FEATURE_MINIX2 #if ENABLE_FEATURE_MINIX2
if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
bb_error_msg_and_die("bad inode size"); bb_error_msg_and_die("bad inode size");
#endif #endif
/* Parse options */ opt = getopt32(argc, argv, "ci:l:n:v", &str_i, &listfile, &str_n);
argv++; argv += optind;
while (--argc >= 0 && *argv && **argv) { //if (opt & 1) -c
if (**argv == '-') { if (opt & 2) req_nr_inodes = xatoul(str_i); // -i
stopIt=FALSE; //if (opt & 4) -l
while (i > 0 && *++(*argv) && stopIt==FALSE) { if (opt & 8) { // -n
switch (**argv) { namelen = xatoi_u(str_n);
case 'c': if (namelen == 14) magic = MINIX_SUPER_MAGIC;
check = 1; else if (namelen == 30) magic = MINIX_SUPER_MAGIC2;
break; else bb_show_usage();
case 'i': dirsize = namelen + 2;
{ }
char *cp=NULL; if (opt & 0x10) { // -v
if (*(*argv+1) != 0) { #if ENABLE_FEATURE_MINIX2
cp = ++(*argv); version2 = 1;
} else {
if (--argc == 0) {
goto goodbye;
}
cp = *(++argv);
}
req_nr_inodes = strtoul(cp, &tmp, 0);
if (*tmp)
bb_show_usage();
stopIt=TRUE;
break;
}
case 'l':
if (--argc == 0) {
goto goodbye;
}
listfile = *(++argv);
break;
case 'n':
{
char *cp=NULL;
if (*(*argv+1) != 0) {
cp = ++(*argv);
} else {
if (--argc == 0) {
goto goodbye;
}
cp = *(++argv);
}
i = strtoul(cp, &tmp, 0);
if (*tmp)
bb_show_usage();
if (i == 14)
magic = MINIX_SUPER_MAGIC;
else if (i == 30)
magic = MINIX_SUPER_MAGIC2;
else
bb_show_usage();
namelen = i;
dirsize = i + 2;
stopIt=TRUE;
break;
}
case 'v':
#ifdef CONFIG_FEATURE_MINIX2
version2 = 1;
#else #else
bb_error_msg("%s: not compiled with minix v2 support", bb_error_msg_and_die("%s: not compiled with minix v2 support",
device_name); device_name);
exit(-1);
#endif #endif
break;
case '-':
case 'h':
default:
goodbye:
bb_show_usage();
}
}
} else {
if (device_name == NULL)
device_name = *argv;
else if (BLOCKS == 0)
BLOCKS = strtol(*argv, &tmp, 0);
else {
goto goodbye;
}
}
argv++;
} }
if (device_name && !BLOCKS) device_name = *argv++;
BLOCKS = get_size(device_name) / 1024; if (!device_name)
if (!device_name || BLOCKS < 10) {
bb_show_usage(); bb_show_usage();
} if (*argv) {
#ifdef CONFIG_FEATURE_MINIX2 BLOCKS = xatou32(*argv);
if (BLOCKS < 10)
bb_show_usage();
} else
BLOCKS = get_size(device_name) / 1024;
if (version2) { if (version2) {
magic = MINIX2_SUPER_MAGIC2;
if (namelen == 14) if (namelen == 14)
magic = MINIX2_SUPER_MAGIC; magic = MINIX2_SUPER_MAGIC;
else } else if (BLOCKS > 65535)
magic = MINIX2_SUPER_MAGIC2;
} else
#endif
if (BLOCKS > 65535)
BLOCKS = 65535; BLOCKS = 65535;
check_mount(); /* is it already mounted? */
if (find_mount_point(device_name, NULL))
bb_error_msg_and_die("%s is mounted; refusing to make "
"a filesystem", device_name);
tmp = root_block; tmp = root_block;
*(short *) tmp = 1; *(short *) tmp = 1;
strcpy(tmp + 2, "."); strcpy(tmp + 2, ".");
@ -805,30 +724,31 @@ goodbye:
tmp += dirsize; tmp += dirsize;
*(short *) tmp = 2; *(short *) tmp = 2;
strcpy(tmp + 2, ".badblocks"); strcpy(tmp + 2, ".badblocks");
DEV = xopen(device_name, O_RDWR); DEV = xopen(device_name, O_RDWR);
if (fstat(DEV, &statbuf) < 0) if (fstat(DEV, &statbuf) < 0)
bb_error_msg_and_die("cannot stat %s", device_name); bb_error_msg_and_die("cannot stat %s", device_name);
if (!S_ISBLK(statbuf.st_mode)) if (!S_ISBLK(statbuf.st_mode))
check = 0; opt &= ~1; // clear -c (check)
else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
bb_error_msg_and_die("will not try to make filesystem on '%s'", device_name); bb_error_msg_and_die("will not try to make filesystem on '%s'", device_name);
setup_tables(); setup_tables();
if (check)
if (opt & 1) // -c ?
check_blocks(); check_blocks();
else if (listfile) else if (listfile)
get_list_blocks(listfile); get_list_blocks(listfile);
#ifdef CONFIG_FEATURE_MINIX2
if (version2) { if (version2) {
make_root_inode2(); make_root_inode2();
make_bad_inode2(); make_bad_inode2();
} else } else {
#endif
{
make_root_inode(); make_root_inode();
make_bad_inode(); make_bad_inode();
} }
mark_good_blocks(); mark_good_blocks();
write_tables(); write_tables();
return 0; return 0;
} }