diff options
| author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-11-29 18:15:52 +0000 |
|---|---|---|
| committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-11-29 18:15:52 +0000 |
| commit | 9d8812e459a9e88f0fbc903180a48e2fae0e65af (patch) | |
| tree | fb5fd16229f7c9f34423c4f27ed47cc19e7434df /util-linux | |
| parent | d197ed14dc586ec6f9c816f7cef145924142fff5 (diff) | |
| download | busybox-w32-9d8812e459a9e88f0fbc903180a48e2fae0e65af.tar.gz busybox-w32-9d8812e459a9e88f0fbc903180a48e2fae0e65af.tar.bz2 busybox-w32-9d8812e459a9e88f0fbc903180a48e2fae0e65af.zip | |
cut 0.5k off mkfs.minix
assorted strtoul fixes (that's what brought me into minix)...
git-svn-id: svn://busybox.net/trunk/busybox@16722 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/fdisk.c | 9 | ||||
| -rw-r--r-- | util-linux/ipcrm.c | 25 | ||||
| -rw-r--r-- | util-linux/mkfs_minix.c | 284 |
3 files changed, 120 insertions, 198 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index c226d6a00..2f87f1c60 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
| @@ -330,13 +330,16 @@ read_maybe_empty(const char *mesg) | |||
| 330 | static int | 330 | static int |
| 331 | read_hex(const struct systypes *sys) | 331 | read_hex(const struct systypes *sys) |
| 332 | { | 332 | { |
| 333 | unsigned long v; | ||
| 333 | while (1) { | 334 | while (1) { |
| 334 | read_nonempty(_("Hex code (type L to list codes): ")); | 335 | read_nonempty(_("Hex code (type L to list codes): ")); |
| 335 | if (*line_ptr == 'l' || *line_ptr == 'L') | 336 | if (*line_ptr == 'l' || *line_ptr == 'L') { |
| 336 | list_types(sys); | 337 | list_types(sys); |
| 337 | else if (isxdigit(*line_ptr)) { | 338 | continue; |
| 338 | return strtoul(line_ptr, NULL, 16); | ||
| 339 | } | 339 | } |
| 340 | v = bb_strtoul(line_ptr, NULL, 16); | ||
| 341 | if (errno || v > 0xff) continue; | ||
| 342 | return v; | ||
| 340 | } | 343 | } |
| 341 | } | 344 | } |
| 342 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | 345 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ |
diff --git a/util-linux/ipcrm.c b/util-linux/ipcrm.c index 8ea9627c1..507e58fe3 100644 --- a/util-linux/ipcrm.c +++ b/util-linux/ipcrm.c | |||
| @@ -39,19 +39,16 @@ typedef enum type_id { | |||
| 39 | 39 | ||
| 40 | static int remove_ids(type_id type, int argc, char **argv) | 40 | static int remove_ids(type_id type, int argc, char **argv) |
| 41 | { | 41 | { |
| 42 | int id; | 42 | unsigned long id; |
| 43 | int ret = 0; /* silence gcc */ | 43 | int ret = 0; /* silence gcc */ |
| 44 | char *end; | ||
| 45 | int nb_errors = 0; | 44 | int nb_errors = 0; |
| 46 | union semun arg; | 45 | union semun arg; |
| 47 | 46 | ||
| 48 | arg.val = 0; | 47 | arg.val = 0; |
| 49 | 48 | ||
| 50 | while (argc) { | 49 | while (argc) { |
| 51 | 50 | id = bb_strtoul(argv[0], NULL, 10); | |
| 52 | id = strtoul(argv[0], &end, 10); | 51 | if (errno || id > INT_MAX) { |
| 53 | |||
| 54 | if (*end != 0) { | ||
| 55 | bb_error_msg("invalid id: %s", argv[0]); | 52 | bb_error_msg("invalid id: %s", argv[0]); |
| 56 | nb_errors++; | 53 | nb_errors++; |
| 57 | } else { | 54 | } else { |
| @@ -91,11 +88,13 @@ int ipcrm_main(int argc, char **argv) | |||
| 91 | type_id what = 0; /* silence gcc */ | 88 | type_id what = 0; /* silence gcc */ |
| 92 | char w; | 89 | char w; |
| 93 | 90 | ||
| 94 | if ((((w=argv[1][0]) == 'm' && argv[1][1] == 's' && argv[1][2] == 'g') | 91 | w=argv[1][0]; |
| 95 | || (argv[1][0] == 's' | 92 | if ( ((w == 'm' && argv[1][1] == 's' && argv[1][2] == 'g') |
| 96 | && ((w=argv[1][1]) == 'h' || w == 'e') | 93 | || (argv[1][0] == 's' |
| 97 | && argv[1][2] == 'm')) | 94 | && ((w=argv[1][1]) == 'h' || w == 'e') |
| 98 | && argv[1][3] == '\0') { | 95 | && argv[1][2] == 'm') |
| 96 | ) && argv[1][3] == '\0' | ||
| 97 | ) { | ||
| 99 | 98 | ||
| 100 | if (argc < 3) | 99 | if (argc < 3) |
| 101 | bb_show_usage(); | 100 | bb_show_usage(); |
| @@ -140,7 +139,7 @@ int ipcrm_main(int argc, char **argv) | |||
| 140 | 139 | ||
| 141 | if (iskey) { | 140 | if (iskey) { |
| 142 | /* keys are in hex or decimal */ | 141 | /* keys are in hex or decimal */ |
| 143 | key_t key = strtoul(optarg, NULL, 0); | 142 | key_t key = xstrtoul(optarg, 0); |
| 144 | 143 | ||
| 145 | if (key == IPC_PRIVATE) { | 144 | if (key == IPC_PRIVATE) { |
| 146 | error++; | 145 | error++; |
| @@ -176,7 +175,7 @@ int ipcrm_main(int argc, char **argv) | |||
| 176 | } | 175 | } |
| 177 | } else { | 176 | } else { |
| 178 | /* ids are in decimal */ | 177 | /* ids are in decimal */ |
| 179 | id = strtoul(optarg, NULL, 10); | 178 | id = xatoul(optarg); |
| 180 | } | 179 | } |
| 181 | 180 | ||
| 182 | result = ((c == 'q') ? msgctl(id, IPC_RMID, NULL) : | 181 | result = ((c == 'q') ? msgctl(id, IPC_RMID, NULL) : |
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c index 5cdbfead9..e9ba50046 100644 --- a/util-linux/mkfs_minix.c +++ b/util-linux/mkfs_minix.c | |||
| @@ -166,13 +166,15 @@ struct minix_dir_entry { | |||
| 166 | 166 | ||
| 167 | #define UPPER(size,n) (((size)+((n)-1))/(n)) | 167 | #define UPPER(size,n) (((size)+((n)-1))/(n)) |
| 168 | #define INODE_SIZE (sizeof(struct minix_inode)) | 168 | #define INODE_SIZE (sizeof(struct minix_inode)) |
| 169 | #ifdef CONFIG_FEATURE_MINIX2 | 169 | |
| 170 | #define INODE_SIZE2 (sizeof(struct minix2_inode)) | 170 | #if ENABLE_FEATURE_MINIX2 |
| 171 | #define INODE_BLOCKS UPPER(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \ | 171 | # define INODE_SIZE2 (sizeof(struct minix2_inode)) |
| 172 | # define INODE_BLOCKS UPPER(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \ | ||
| 172 | : MINIX_INODES_PER_BLOCK)) | 173 | : MINIX_INODES_PER_BLOCK)) |
| 173 | #else | 174 | #else |
| 174 | #define INODE_BLOCKS UPPER(INODES, (MINIX_INODES_PER_BLOCK)) | 175 | # define INODE_BLOCKS UPPER(INODES, (MINIX_INODES_PER_BLOCK)) |
| 175 | #endif | 176 | #endif |
| 177 | |||
| 176 | #define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE) | 178 | #define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE) |
| 177 | 179 | ||
| 178 | #define BITS_PER_BLOCK (BLOCK_SIZE<<3) | 180 | #define BITS_PER_BLOCK (BLOCK_SIZE<<3) |
| @@ -180,33 +182,37 @@ struct minix_dir_entry { | |||
| 180 | static char *device_name; | 182 | static char *device_name; |
| 181 | static int DEV = -1; | 183 | static int DEV = -1; |
| 182 | static uint32_t BLOCKS; | 184 | static uint32_t BLOCKS; |
| 183 | static int check; | ||
| 184 | static int badblocks; | 185 | static int badblocks; |
| 185 | static int namelen = 30; /* default (changed to 30, per Linus's | 186 | /* default (changed to 30, per Linus's suggestion, Sun Nov 21 08:05:07 1993) */ |
| 186 | 187 | static int namelen = 30; | |
| 187 | suggestion, Sun Nov 21 08:05:07 1993) */ | ||
| 188 | static int dirsize = 32; | 188 | static int dirsize = 32; |
| 189 | static int magic = MINIX_SUPER_MAGIC2; | 189 | static int magic = MINIX_SUPER_MAGIC2; |
| 190 | #if ENABLE_FEATURE_MINIX2 | ||
| 190 | static int version2; | 191 | static int version2; |
| 192 | #else | ||
| 193 | enum { version2 = 0 }; | ||
| 194 | #endif | ||
| 191 | 195 | ||
| 192 | static char root_block[BLOCK_SIZE]; | 196 | static char root_block[BLOCK_SIZE]; |
| 193 | 197 | ||
| 194 | static char *inode_buffer; | 198 | static char *inode_buffer; |
| 195 | 199 | ||
| 196 | #define Inode (((struct minix_inode *) inode_buffer)-1) | 200 | #define Inode (((struct minix_inode *) inode_buffer)-1) |
| 197 | #ifdef CONFIG_FEATURE_MINIX2 | 201 | #if ENABLE_FEATURE_MINIX2 |
| 198 | #define Inode2 (((struct minix2_inode *) inode_buffer)-1) | 202 | #define Inode2 (((struct minix2_inode *) inode_buffer)-1) |
| 199 | #endif | 203 | #endif |
| 200 | static char super_block_buffer[BLOCK_SIZE]; | 204 | static char super_block_buffer[BLOCK_SIZE]; |
| 201 | static char boot_block_buffer[512]; | 205 | static char boot_block_buffer[512]; |
| 202 | 206 | ||
| 203 | #define Super (*(struct minix_super_block *)super_block_buffer) | 207 | #define Super (*(struct minix_super_block *)super_block_buffer) |
| 208 | |||
| 204 | #define INODES (Super.s_ninodes) | 209 | #define INODES (Super.s_ninodes) |
| 205 | #ifdef CONFIG_FEATURE_MINIX2 | 210 | #if ENABLE_FEATURE_MINIX2 |
| 206 | #define ZONES (version2 ? Super.s_zones : Super.s_nzones) | 211 | # define ZONES (version2 ? Super.s_zones : Super.s_nzones) |
| 207 | #else | 212 | #else |
| 208 | #define ZONES (Super.s_nzones) | 213 | # define ZONES (Super.s_nzones) |
| 209 | #endif | 214 | #endif |
| 215 | |||
| 210 | #define IMAPS (Super.s_imap_blocks) | 216 | #define IMAPS (Super.s_imap_blocks) |
| 211 | #define ZMAPS (Super.s_zmap_blocks) | 217 | #define ZMAPS (Super.s_zmap_blocks) |
| 212 | #define FIRSTZONE (Super.s_firstdatazone) | 218 | #define FIRSTZONE (Super.s_firstdatazone) |
| @@ -222,7 +228,7 @@ static unsigned short good_blocks_table[MAX_GOOD_BLOCKS]; | |||
| 222 | static int used_good_blocks; | 228 | static int used_good_blocks; |
| 223 | static unsigned long req_nr_inodes; | 229 | static unsigned long req_nr_inodes; |
| 224 | 230 | ||
| 225 | static int bit(char * a,unsigned int i) | 231 | static int bit(char* a, unsigned i) |
| 226 | { | 232 | { |
| 227 | return (a[i >> 3] & (1<<(i & 7))) != 0; | 233 | return (a[i >> 3] & (1<<(i & 7))) != 0; |
| 228 | } | 234 | } |
| @@ -235,33 +241,11 @@ static int bit(char * a,unsigned int i) | |||
| 235 | #define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1)) | 241 | #define mark_zone(x) (setbit(zone_map,(x)-FIRSTZONE+1)) |
| 236 | #define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1)) | 242 | #define unmark_zone(x) (clrbit(zone_map,(x)-FIRSTZONE+1)) |
| 237 | 243 | ||
| 238 | /* | ||
| 239 | * Check to make certain that our new filesystem won't be created on | ||
| 240 | * an already mounted partition. Code adapted from mke2fs, Copyright | ||
| 241 | * (C) 1994 Theodore Ts'o. Also licensed under GPL. | ||
| 242 | */ | ||
| 243 | static void check_mount(void) | ||
| 244 | { | ||
| 245 | FILE *f; | ||
| 246 | struct mntent *mnt; | ||
| 247 | |||
| 248 | if ((f = setmntent(MOUNTED, "r")) == NULL) | ||
| 249 | return; | ||
| 250 | while ((mnt = getmntent(f)) != NULL) | ||
| 251 | if (strcmp(device_name, mnt->mnt_fsname) == 0) | ||
| 252 | break; | ||
| 253 | endmntent(f); | ||
| 254 | if (!mnt) | ||
| 255 | return; | ||
| 256 | |||
| 257 | bb_error_msg_and_die("%s is mounted; will not make a filesystem here!", device_name); | ||
| 258 | } | ||
| 259 | |||
| 260 | static long valid_offset(int fd, int offset) | 244 | static long valid_offset(int fd, int offset) |
| 261 | { | 245 | { |
| 262 | char ch; | 246 | char ch; |
| 263 | 247 | ||
| 264 | if (lseek(fd, offset, 0) < 0) | 248 | if (lseek(fd, offset, SEEK_SET) < 0) |
| 265 | return 0; | 249 | return 0; |
| 266 | if (read(fd, &ch, 1) < 1) | 250 | if (read(fd, &ch, 1) < 1) |
| 267 | return 0; | 251 | return 0; |
| @@ -275,6 +259,7 @@ static int count_blocks(int fd) | |||
| 275 | low = 0; | 259 | low = 0; |
| 276 | for (high = 1; valid_offset(fd, high); high *= 2) | 260 | for (high = 1; valid_offset(fd, high); high *= 2) |
| 277 | low = high; | 261 | low = high; |
| 262 | |||
| 278 | while (low < high - 1) { | 263 | while (low < high - 1) { |
| 279 | const int mid = (low + high) / 2; | 264 | const int mid = (low + high) / 2; |
| 280 | 265 | ||
| @@ -309,29 +294,34 @@ static void write_tables(void) | |||
| 309 | Super.s_state |= MINIX_VALID_FS; | 294 | Super.s_state |= MINIX_VALID_FS; |
| 310 | Super.s_state &= ~MINIX_ERROR_FS; | 295 | Super.s_state &= ~MINIX_ERROR_FS; |
| 311 | 296 | ||
| 312 | if (lseek(DEV, 0, SEEK_SET)) | 297 | msg_eol = "seek to 0 failed"; |
| 313 | bb_error_msg_and_die("seek to boot block failed in write_tables"); | 298 | xlseek(DEV, 0, SEEK_SET); |
| 314 | if (512 != write(DEV, boot_block_buffer, 512)) | 299 | |
| 315 | bb_error_msg_and_die("cannot clear boot sector"); | 300 | msg_eol = "cannot clear boot sector"; |
| 316 | if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET)) | 301 | xwrite(DEV, boot_block_buffer, 512); |
| 317 | bb_error_msg_and_die("seek failed in write_tables"); | ||
| 318 | if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE)) | ||
| 319 | bb_error_msg_and_die("cannot write super-block"); | ||
| 320 | if (IMAPS * BLOCK_SIZE != write(DEV, inode_map, IMAPS * BLOCK_SIZE)) | ||
| 321 | bb_error_msg_and_die("cannot write inode map"); | ||
| 322 | if (ZMAPS * BLOCK_SIZE != write(DEV, zone_map, ZMAPS * BLOCK_SIZE)) | ||
| 323 | bb_error_msg_and_die("cannot write zone map"); | ||
| 324 | if (INODE_BUFFER_SIZE != write(DEV, inode_buffer, INODE_BUFFER_SIZE)) | ||
| 325 | bb_error_msg_and_die("cannot write inodes"); | ||
| 326 | 302 | ||
| 303 | msg_eol = "seek to BLOCK_SIZE failed"; | ||
| 304 | xlseek(DEV, BLOCK_SIZE, SEEK_SET); | ||
| 305 | |||
| 306 | msg_eol = "cannot write superblock"; | ||
| 307 | xwrite(DEV, super_block_buffer, BLOCK_SIZE); | ||
| 308 | |||
| 309 | msg_eol = "cannot write inode map"; | ||
| 310 | xwrite(DEV, inode_map, IMAPS * BLOCK_SIZE); | ||
| 311 | |||
| 312 | msg_eol = "cannot write zone map"; | ||
| 313 | xwrite(DEV, zone_map, ZMAPS * BLOCK_SIZE); | ||
| 314 | |||
| 315 | msg_eol = "cannot write inodes"; | ||
| 316 | xwrite(DEV, inode_buffer, INODE_BUFFER_SIZE); | ||
| 317 | |||
| 318 | msg_eol = "\n"; | ||
| 327 | } | 319 | } |
| 328 | 320 | ||
| 329 | static void write_block(int blk, char *buffer) | 321 | static void write_block(int blk, char *buffer) |
| 330 | { | 322 | { |
| 331 | if (blk * BLOCK_SIZE != lseek(DEV, blk * BLOCK_SIZE, SEEK_SET)) | 323 | xlseek(DEV, blk * BLOCK_SIZE, SEEK_SET); |
| 332 | bb_error_msg_and_die("seek failed in write_block"); | 324 | xwrite(DEV, buffer, BLOCK_SIZE); |
| 333 | if (BLOCK_SIZE != write(DEV, buffer, BLOCK_SIZE)) | ||
| 334 | bb_error_msg_and_die("write failed in write_block"); | ||
| 335 | } | 325 | } |
| 336 | 326 | ||
| 337 | static int get_free_block(void) | 327 | static int get_free_block(void) |
| @@ -385,6 +375,8 @@ static void make_bad_inode(void) | |||
| 385 | return; | 375 | return; |
| 386 | mark_inode(MINIX_BAD_INO); | 376 | mark_inode(MINIX_BAD_INO); |
| 387 | inode->i_nlinks = 1; | 377 | inode->i_nlinks = 1; |
| 378 | /* BTW, setting this makes all images different */ | ||
| 379 | /* it's harder to check for bugs then - diff isn't helpful :(... */ | ||
| 388 | inode->i_time = time(NULL); | 380 | inode->i_time = time(NULL); |
| 389 | inode->i_mode = S_IFREG + 0000; | 381 | inode->i_mode = S_IFREG + 0000; |
| 390 | inode->i_size = badblocks * BLOCK_SIZE; | 382 | inode->i_size = badblocks * BLOCK_SIZE; |
| @@ -421,7 +413,7 @@ static void make_bad_inode(void) | |||
| 421 | write_block(dind, (char *) dind_block); | 413 | write_block(dind, (char *) dind_block); |
| 422 | } | 414 | } |
| 423 | 415 | ||
| 424 | #ifdef CONFIG_FEATURE_MINIX2 | 416 | #if ENABLE_FEATURE_MINIX2 |
| 425 | static void make_bad_inode2(void) | 417 | static void make_bad_inode2(void) |
| 426 | { | 418 | { |
| 427 | struct minix2_inode *inode = &Inode2[MINIX_BAD_INO]; | 419 | struct minix2_inode *inode = &Inode2[MINIX_BAD_INO]; |
| @@ -494,7 +486,7 @@ static void make_root_inode(void) | |||
| 494 | write_block(inode->i_zone[0], root_block); | 486 | write_block(inode->i_zone[0], root_block); |
| 495 | } | 487 | } |
| 496 | 488 | ||
| 497 | #ifdef CONFIG_FEATURE_MINIX2 | 489 | #if ENABLE_FEATURE_MINIX2 |
| 498 | static void make_root_inode2(void) | 490 | static void make_root_inode2(void) |
| 499 | { | 491 | { |
| 500 | struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO]; | 492 | struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO]; |
| @@ -528,11 +520,9 @@ static void setup_tables(void) | |||
| 528 | MAGIC = magic; | 520 | MAGIC = magic; |
| 529 | ZONESIZE = 0; | 521 | ZONESIZE = 0; |
| 530 | MAXSIZE = version2 ? 0x7fffffff : (7 + 512 + 512 * 512) * 1024; | 522 | MAXSIZE = version2 ? 0x7fffffff : (7 + 512 + 512 * 512) * 1024; |
| 531 | #ifdef CONFIG_FEATURE_MINIX2 | ||
| 532 | if (version2) { | 523 | if (version2) { |
| 533 | Super.s_zones = BLOCKS; | 524 | Super.s_zones = BLOCKS; |
| 534 | } else | 525 | } else |
| 535 | #endif | ||
| 536 | Super.s_nzones = BLOCKS; | 526 | Super.s_nzones = BLOCKS; |
| 537 | 527 | ||
| 538 | /* some magic nrs: 1 inode / 3 blocks */ | 528 | /* some magic nrs: 1 inode / 3 blocks */ |
| @@ -541,12 +531,10 @@ static void setup_tables(void) | |||
| 541 | else | 531 | else |
| 542 | inodes = req_nr_inodes; | 532 | inodes = req_nr_inodes; |
| 543 | /* Round up inode count to fill block size */ | 533 | /* Round up inode count to fill block size */ |
| 544 | #ifdef CONFIG_FEATURE_MINIX2 | ||
| 545 | if (version2) | 534 | if (version2) |
| 546 | inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) & | 535 | inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) & |
| 547 | ~(MINIX2_INODES_PER_BLOCK - 1)); | 536 | ~(MINIX2_INODES_PER_BLOCK - 1)); |
| 548 | else | 537 | else |
| 549 | #endif | ||
| 550 | inodes = ((inodes + MINIX_INODES_PER_BLOCK - 1) & | 538 | inodes = ((inodes + MINIX_INODES_PER_BLOCK - 1) & |
| 551 | ~(MINIX_INODES_PER_BLOCK - 1)); | 539 | ~(MINIX_INODES_PER_BLOCK - 1)); |
| 552 | if (inodes > 65535) | 540 | if (inodes > 65535) |
| @@ -594,16 +582,14 @@ static void setup_tables(void) | |||
| 594 | * Perform a test of a block; return the number of | 582 | * Perform a test of a block; return the number of |
| 595 | * blocks readable/writable. | 583 | * blocks readable/writable. |
| 596 | */ | 584 | */ |
| 597 | static long do_check(char *buffer, int try, unsigned int current_block) | 585 | static long do_check(char *buffer, int try, unsigned current_block) |
| 598 | { | 586 | { |
| 599 | long got; | 587 | long got; |
| 600 | 588 | ||
| 601 | /* Seek to the correct loc. */ | 589 | /* Seek to the correct loc. */ |
| 602 | if (lseek(DEV, current_block * BLOCK_SIZE, SEEK_SET) != | 590 | msg_eol = "seek failed during testing of blocks"; |
| 603 | current_block * BLOCK_SIZE) { | 591 | xlseek(DEV, current_block * BLOCK_SIZE, SEEK_SET); |
| 604 | bb_error_msg_and_die("seek failed during testing of blocks"); | 592 | msg_eol = "\n"; |
| 605 | } | ||
| 606 | |||
| 607 | 593 | ||
| 608 | /* Try the read */ | 594 | /* Try the read */ |
| 609 | got = read(DEV, buffer, try * BLOCK_SIZE); | 595 | got = read(DEV, buffer, try * BLOCK_SIZE); |
| @@ -616,7 +602,7 @@ static long do_check(char *buffer, int try, unsigned int current_block) | |||
| 616 | return got; | 602 | return got; |
| 617 | } | 603 | } |
| 618 | 604 | ||
| 619 | static unsigned int currently_testing; | 605 | static unsigned currently_testing; |
| 620 | 606 | ||
| 621 | static void alarm_intr(int alnum) | 607 | static void alarm_intr(int alnum) |
| 622 | { | 608 | { |
| @@ -639,9 +625,9 @@ static void check_blocks(void) | |||
| 639 | signal(SIGALRM, alarm_intr); | 625 | signal(SIGALRM, alarm_intr); |
| 640 | alarm(5); | 626 | alarm(5); |
| 641 | while (currently_testing < ZONES) { | 627 | while (currently_testing < ZONES) { |
| 642 | if (lseek(DEV, currently_testing * BLOCK_SIZE, SEEK_SET) != | 628 | msg_eol = "seek failed in check_blocks"; |
| 643 | currently_testing * BLOCK_SIZE) | 629 | xlseek(DEV, currently_testing * BLOCK_SIZE, SEEK_SET); |
| 644 | bb_error_msg_and_die("seek failed in check_blocks"); | 630 | msg_eol = "\n"; |
| 645 | try = TEST_BUFFER_BLOCKS; | 631 | try = TEST_BUFFER_BLOCKS; |
| 646 | if (currently_testing + try > ZONES) | 632 | if (currently_testing + try > ZONES) |
| 647 | try = ZONES - currently_testing; | 633 | try = ZONES - currently_testing; |
| @@ -655,10 +641,7 @@ static void check_blocks(void) | |||
| 655 | badblocks++; | 641 | badblocks++; |
| 656 | currently_testing++; | 642 | currently_testing++; |
| 657 | } | 643 | } |
| 658 | if (badblocks > 1) | 644 | printf("%d bad block(s)\n", badblocks); |
| 659 | printf("%d bad blocks\n", badblocks); | ||
| 660 | else if (badblocks == 1) | ||
| 661 | printf("one bad block\n"); | ||
| 662 | } | 645 | } |
| 663 | 646 | ||
| 664 | static void get_list_blocks(char *filename) | 647 | static void get_list_blocks(char *filename) |
| @@ -672,130 +655,66 @@ static void get_list_blocks(char *filename) | |||
| 672 | mark_zone(blockno); | 655 | mark_zone(blockno); |
| 673 | badblocks++; | 656 | badblocks++; |
| 674 | } | 657 | } |
| 675 | if (badblocks > 1) | 658 | printf("%d bad block(s)\n", badblocks); |
| 676 | printf("%d bad blocks\n", badblocks); | ||
| 677 | else if (badblocks == 1) | ||
| 678 | printf("one bad block\n"); | ||
| 679 | } | 659 | } |
| 680 | 660 | ||
| 681 | int mkfs_minix_main(int argc, char **argv) | 661 | int mkfs_minix_main(int argc, char **argv) |
| 682 | { | 662 | { |
| 683 | int i=1; | 663 | unsigned opt; |
| 684 | char *tmp; | 664 | char *tmp; |
| 685 | struct stat statbuf; | 665 | struct stat statbuf; |
| 666 | char *str_i, *str_n; | ||
| 686 | char *listfile = NULL; | 667 | char *listfile = NULL; |
| 687 | int stopIt=FALSE; | ||
| 688 | 668 | ||
| 689 | if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) | 669 | if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) |
| 690 | bb_error_msg_and_die("bad inode size"); | 670 | bb_error_msg_and_die("bad inode size"); |
| 691 | #ifdef CONFIG_FEATURE_MINIX2 | 671 | #if ENABLE_FEATURE_MINIX2 |
| 692 | if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) | 672 | if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) |
| 693 | bb_error_msg_and_die("bad inode size"); | 673 | bb_error_msg_and_die("bad inode size"); |
| 694 | #endif | 674 | #endif |
| 695 | 675 | ||
| 696 | /* Parse options */ | 676 | opt = getopt32(argc, argv, "ci:l:n:v", &str_i, &listfile, &str_n); |
| 697 | argv++; | 677 | argv += optind; |
| 698 | while (--argc >= 0 && *argv && **argv) { | 678 | //if (opt & 1) -c |
| 699 | if (**argv == '-') { | 679 | if (opt & 2) req_nr_inodes = xatoul(str_i); // -i |
| 700 | stopIt=FALSE; | 680 | //if (opt & 4) -l |
| 701 | while (i > 0 && *++(*argv) && stopIt==FALSE) { | 681 | if (opt & 8) { // -n |
| 702 | switch (**argv) { | 682 | namelen = xatoi_u(str_n); |
| 703 | case 'c': | 683 | if (namelen == 14) magic = MINIX_SUPER_MAGIC; |
| 704 | check = 1; | 684 | else if (namelen == 30) magic = MINIX_SUPER_MAGIC2; |
| 705 | break; | 685 | else bb_show_usage(); |
| 706 | case 'i': | 686 | dirsize = namelen + 2; |
| 707 | { | 687 | } |
| 708 | char *cp=NULL; | 688 | if (opt & 0x10) { // -v |
| 709 | if (*(*argv+1) != 0) { | 689 | #if ENABLE_FEATURE_MINIX2 |
| 710 | cp = ++(*argv); | 690 | version2 = 1; |
| 711 | } else { | ||
| 712 | if (--argc == 0) { | ||
| 713 | goto goodbye; | ||
| 714 | } | ||
| 715 | cp = *(++argv); | ||
| 716 | } | ||
| 717 | req_nr_inodes = strtoul(cp, &tmp, 0); | ||
| 718 | if (*tmp) | ||
| 719 | bb_show_usage(); | ||
| 720 | stopIt=TRUE; | ||
| 721 | break; | ||
| 722 | } | ||
| 723 | case 'l': | ||
| 724 | if (--argc == 0) { | ||
| 725 | goto goodbye; | ||
| 726 | } | ||
| 727 | listfile = *(++argv); | ||
| 728 | break; | ||
| 729 | case 'n': | ||
| 730 | { | ||
| 731 | char *cp=NULL; | ||
| 732 | |||
| 733 | if (*(*argv+1) != 0) { | ||
| 734 | cp = ++(*argv); | ||
| 735 | } else { | ||
| 736 | if (--argc == 0) { | ||
| 737 | goto goodbye; | ||
| 738 | } | ||
| 739 | cp = *(++argv); | ||
| 740 | } | ||
| 741 | i = strtoul(cp, &tmp, 0); | ||
| 742 | if (*tmp) | ||
| 743 | bb_show_usage(); | ||
| 744 | if (i == 14) | ||
| 745 | magic = MINIX_SUPER_MAGIC; | ||
| 746 | else if (i == 30) | ||
| 747 | magic = MINIX_SUPER_MAGIC2; | ||
| 748 | else | ||
| 749 | bb_show_usage(); | ||
| 750 | namelen = i; | ||
| 751 | dirsize = i + 2; | ||
| 752 | stopIt=TRUE; | ||
| 753 | break; | ||
| 754 | } | ||
| 755 | case 'v': | ||
| 756 | #ifdef CONFIG_FEATURE_MINIX2 | ||
| 757 | version2 = 1; | ||
| 758 | #else | 691 | #else |
| 759 | bb_error_msg("%s: not compiled with minix v2 support", | 692 | bb_error_msg_and_die("%s: not compiled with minix v2 support", |
| 760 | device_name); | 693 | device_name); |
| 761 | exit(-1); | ||
| 762 | #endif | 694 | #endif |
| 763 | break; | ||
| 764 | case '-': | ||
| 765 | case 'h': | ||
| 766 | default: | ||
| 767 | goodbye: | ||
| 768 | bb_show_usage(); | ||
| 769 | } | ||
| 770 | } | ||
| 771 | } else { | ||
| 772 | if (device_name == NULL) | ||
| 773 | device_name = *argv; | ||
| 774 | else if (BLOCKS == 0) | ||
| 775 | BLOCKS = strtol(*argv, &tmp, 0); | ||
| 776 | else { | ||
| 777 | goto goodbye; | ||
| 778 | } | ||
| 779 | } | ||
| 780 | argv++; | ||
| 781 | } | 695 | } |
| 782 | 696 | ||
| 783 | if (device_name && !BLOCKS) | 697 | device_name = *argv++; |
| 784 | BLOCKS = get_size(device_name) / 1024; | 698 | if (!device_name) |
| 785 | if (!device_name || BLOCKS < 10) { | ||
| 786 | bb_show_usage(); | 699 | bb_show_usage(); |
| 787 | } | 700 | if (*argv) { |
| 788 | #ifdef CONFIG_FEATURE_MINIX2 | 701 | BLOCKS = xatou32(*argv); |
| 702 | if (BLOCKS < 10) | ||
| 703 | bb_show_usage(); | ||
| 704 | } else | ||
| 705 | BLOCKS = get_size(device_name) / 1024; | ||
| 706 | |||
| 789 | if (version2) { | 707 | if (version2) { |
| 708 | magic = MINIX2_SUPER_MAGIC2; | ||
| 790 | if (namelen == 14) | 709 | if (namelen == 14) |
| 791 | magic = MINIX2_SUPER_MAGIC; | 710 | magic = MINIX2_SUPER_MAGIC; |
| 792 | else | 711 | } else if (BLOCKS > 65535) |
| 793 | magic = MINIX2_SUPER_MAGIC2; | ||
| 794 | } else | ||
| 795 | #endif | ||
| 796 | if (BLOCKS > 65535) | ||
| 797 | BLOCKS = 65535; | 712 | BLOCKS = 65535; |
| 798 | check_mount(); /* is it already mounted? */ | 713 | |
| 714 | if (find_mount_point(device_name, NULL)) | ||
| 715 | bb_error_msg_and_die("%s is mounted; refusing to make " | ||
| 716 | "a filesystem", device_name); | ||
| 717 | |||
| 799 | tmp = root_block; | 718 | tmp = root_block; |
| 800 | *(short *) tmp = 1; | 719 | *(short *) tmp = 1; |
| 801 | strcpy(tmp + 2, "."); | 720 | strcpy(tmp + 2, "."); |
| @@ -805,30 +724,31 @@ goodbye: | |||
| 805 | tmp += dirsize; | 724 | tmp += dirsize; |
| 806 | *(short *) tmp = 2; | 725 | *(short *) tmp = 2; |
| 807 | strcpy(tmp + 2, ".badblocks"); | 726 | strcpy(tmp + 2, ".badblocks"); |
| 727 | |||
| 808 | DEV = xopen(device_name, O_RDWR); | 728 | DEV = xopen(device_name, O_RDWR); |
| 809 | if (fstat(DEV, &statbuf) < 0) | 729 | if (fstat(DEV, &statbuf) < 0) |
| 810 | bb_error_msg_and_die("cannot stat %s", device_name); | 730 | bb_error_msg_and_die("cannot stat %s", device_name); |
| 811 | if (!S_ISBLK(statbuf.st_mode)) | 731 | if (!S_ISBLK(statbuf.st_mode)) |
| 812 | check = 0; | 732 | opt &= ~1; // clear -c (check) |
| 813 | else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) | 733 | else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) |
| 814 | bb_error_msg_and_die("will not try to make filesystem on '%s'", device_name); | 734 | bb_error_msg_and_die("will not try to make filesystem on '%s'", device_name); |
| 735 | |||
| 815 | setup_tables(); | 736 | setup_tables(); |
| 816 | if (check) | 737 | |
| 738 | if (opt & 1) // -c ? | ||
| 817 | check_blocks(); | 739 | check_blocks(); |
| 818 | else if (listfile) | 740 | else if (listfile) |
| 819 | get_list_blocks(listfile); | 741 | get_list_blocks(listfile); |
| 820 | #ifdef CONFIG_FEATURE_MINIX2 | 742 | |
| 821 | if (version2) { | 743 | if (version2) { |
| 822 | make_root_inode2(); | 744 | make_root_inode2(); |
| 823 | make_bad_inode2(); | 745 | make_bad_inode2(); |
| 824 | } else | 746 | } else { |
| 825 | #endif | ||
| 826 | { | ||
| 827 | make_root_inode(); | 747 | make_root_inode(); |
| 828 | make_bad_inode(); | 748 | make_bad_inode(); |
| 829 | } | 749 | } |
| 750 | |||
| 830 | mark_good_blocks(); | 751 | mark_good_blocks(); |
| 831 | write_tables(); | 752 | write_tables(); |
| 832 | return 0; | 753 | return 0; |
| 833 | |||
| 834 | } | 754 | } |
