Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/util-linux/mkfs_minix.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/util-linux/mkfs_minix.c
r1765 r2725 3 3 * mkfs.c - make a linux (minix) file-system. 4 4 * 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. 7 8 */ 8 9 … … 68 69 #include "minix.h" 69 70 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 74 73 # define CUR_TIME 0 75 74 # define GETUID 0 76 75 # define GETGID 0 77 76 #else 77 /* Was using this. Is it useful? NB: this will break testsuite */ 78 78 # define CUR_TIME time(NULL) 79 79 # define GETUID getuid() … … 90 90 #endif 91 91 92 enum { dev_fd = 3 }; 93 92 94 struct globals { 93 int dev_fd;94 95 95 #if ENABLE_FEATURE_MINIX2 96 96 smallint version2; … … 110 110 unsigned currently_testing; 111 111 112 113 112 char root_block[BLOCK_SIZE]; 114 char super _block_buffer[BLOCK_SIZE];113 char superblock_buffer[BLOCK_SIZE]; 115 114 char boot_block_buffer[512]; 116 115 unsigned short good_blocks_table[MAX_GOOD_BLOCKS]; 117 116 /* check_blocks(): buffer[] was the biggest static in entire bbox */ 118 117 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]; 119 123 }; 120 121 124 #define G (*ptr_to_globals) 125 #define INIT_G() do { \ 126 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 127 } while (0) 122 128 123 129 static ALWAYS_INLINE unsigned div_roundup(unsigned size, unsigned n) … … 129 135 #define INODE_BUF2 (((struct minix2_inode*)G.inode_buffer) - 1) 130 136 131 #define SB (*(struct minix_super _block*)G.super_block_buffer)137 #define SB (*(struct minix_superblock*)G.superblock_buffer) 132 138 133 139 #define SB_INODES (SB.s_ninodes) … … 145 151 # define SB_ZONES (version2 ? SB.s_zones : SB.s_nzones) 146 152 # 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)) 148 154 #endif 149 155 … … 156 162 static int minix_bit(const char* a, unsigned i) 157 163 { 158 164 return a[i >> 3] & (1<<(i & 7)); 159 165 } 160 166 … … 231 237 static void write_tables(void) 232 238 { 233 /* Mark the super 239 /* Mark the superblock valid. */ 234 240 SB.s_state |= MINIX_VALID_FS; 235 241 SB.s_state &= ~MINIX_ERROR_FS; 236 242 237 243 msg_eol = "seek to 0 failed"; 238 xlseek( G.dev_fd, 0, SEEK_SET);239 240 msg_eol = "can not 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); 242 248 243 249 msg_eol = "seek to BLOCK_SIZE failed"; 244 xlseek( G.dev_fd, BLOCK_SIZE, SEEK_SET);245 246 msg_eol = "can not write superblock";247 xwrite( G.dev_fd, G.super_block_buffer, BLOCK_SIZE);248 249 msg_eol = "can not write inode map";250 xwrite( G.dev_fd, G.inode_map, SB_IMAPS * BLOCK_SIZE);251 252 msg_eol = "can not write zone map";253 xwrite( G.dev_fd, G.zone_map, SB_ZMAPS * BLOCK_SIZE);254 255 msg_eol = "can not 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); 257 263 258 264 msg_eol = "\n"; … … 261 267 static void write_block(int blk, char *buffer) 262 268 { 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); 265 271 } 266 272 … … 307 313 int i, j, zone; 308 314 int ind = 0, dind = 0; 315 /* moved to globals to reduce stack usage 309 316 unsigned short ind_block[BLOCK_SIZE >> 1]; 310 317 unsigned short dind_block[BLOCK_SIZE >> 1]; 318 */ 319 #define ind_block (G.ind_block1) 320 #define dind_block (G.dind_block1) 311 321 312 322 #define NEXT_BAD (zone = next(zone)) … … 352 362 if (dind) 353 363 write_block(dind, (char *) dind_block); 364 #undef ind_block 365 #undef dind_block 354 366 } 355 367 … … 360 372 int i, j, zone; 361 373 int ind = 0, dind = 0; 374 /* moved to globals to reduce stack usage 362 375 unsigned long ind_block[BLOCK_SIZE >> 2]; 363 376 unsigned long dind_block[BLOCK_SIZE >> 2]; 377 */ 378 #define ind_block (G.ind_block2) 379 #define dind_block (G.dind_block2) 364 380 365 381 if (!G.badblocks) … … 402 418 if (dind) 403 419 write_block(dind, (char *) dind_block); 420 #undef ind_block 421 #undef dind_block 404 422 } 405 423 #else … … 465 483 /* Seek to the correct loc. */ 466 484 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); 468 486 msg_eol = "\n"; 469 487 470 488 /* Try the read */ 471 got = read( G.dev_fd, buffer, try * BLOCK_SIZE);489 got = read(dev_fd, buffer, try * BLOCK_SIZE); 472 490 if (got < 0) 473 491 got = 0; … … 479 497 } 480 498 481 static void alarm_intr(int alnum )499 static void alarm_intr(int alnum UNUSED_PARAM) 482 500 { 483 501 if (G.currently_testing >= SB_ZONES) … … 488 506 return; 489 507 printf("%d ...", G.currently_testing); 490 fflush (stdout);508 fflush_all(); 491 509 } 492 510 … … 500 518 while (G.currently_testing < SB_ZONES) { 501 519 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); 503 521 msg_eol = "\n"; 504 522 try = TEST_BUFFER_BLOCKS; … … 524 542 unsigned long blockno; 525 543 526 listfile = xfopen (filename, "r");544 listfile = xfopen_for_read(filename); 527 545 while (!feof(listfile)) { 528 546 fscanf(listfile, "%ld\n", &blockno); … … 540 558 unsigned i; 541 559 542 /* memset(G.super _block_buffer, 0, BLOCK_SIZE); */560 /* memset(G.superblock_buffer, 0, BLOCK_SIZE); */ 543 561 /* memset(G.boot_block_buffer, 0, 512); */ 544 562 SB_MAGIC = G.magic; … … 604 622 } 605 623 606 int mkfs_minix_main(int argc, char **argv); 607 int mkfs_minix_main(int argc, char **argv) 608 { 609 struct mntent *mp; 624 int mkfs_minix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 625 int mkfs_minix_main(int argc UNUSED_PARAM, char **argv) 626 { 610 627 unsigned opt; 611 628 char *tmp; 612 629 struct stat statbuf; 613 char *str_i , *str_n;630 char *str_i; 614 631 char *listfile = NULL; 615 632 616 PTR_TO_GLOBALS = xzalloc(sizeof(G));633 INIT_G(); 617 634 /* default (changed to 30, per Linus's suggestion, Sun Nov 21 08:05:07 1993) */ 618 635 G.namelen = 30; … … 627 644 #endif 628 645 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); 630 648 argv += optind; 631 649 //if (opt & 1) -c … … 633 651 //if (opt & 4) -l 634 652 if (opt & 8) { // -n 635 G.namelen = xatoi_u(str_n);636 653 if (G.namelen == 14) G.magic = MINIX1_SUPER_MAGIC; 637 654 else if (G.namelen == 30) G.magic = MINIX1_SUPER_MAGIC2; … … 666 683 667 684 /* 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); 677 690 if (!S_ISBLK(statbuf.st_mode)) 678 691 opt &= ~1; // clear -c (check)
Note:
See TracChangeset
for help on using the changeset viewer.