Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/util-linux/mkfs_minix.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- 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 196 196 # define BLKGETSIZE _IO(0x12,96) /* return device size */ 197 197 #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 else225 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 }246 198 247 199 static void write_tables(void) … … 554 506 listfile = xfopen_for_read(filename); 555 507 while (!feof(listfile)) { 556 fscanf(listfile, "%l d\n", &blockno);508 fscanf(listfile, "%lu\n", &blockno); 557 509 mark_zone(blockno); 558 510 G.badblocks++; … … 625 577 unmark_inode(i); 626 578 G.inode_buffer = xzalloc(INODE_BUFFER_SIZE); 627 printf("%l d inodes\n", (long)SB_INODES);628 printf("%l d blocks\n", (long)SB_ZONES);629 printf("Firstdatazone=%l d (%ld)\n", (long)SB_FIRSTZONE, (long)norm_firstzone);630 printf("Zonesize=% d\n", BLOCK_SIZE << SB_ZONE_SIZE);631 printf("Maxsize=%l d\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); 632 584 } 633 585 … … 637 589 unsigned opt; 638 590 char *tmp; 639 struct stat statbuf;640 591 char *str_i; 641 592 char *listfile = NULL; … … 674 625 } 675 626 676 G.device_name = *argv++;627 G.device_name = argv[0]; 677 628 if (!G.device_name) 678 629 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; 683 638 684 639 if (G.total_blocks < 10) … … 691 646 } else if (G.total_blocks > 65535) 692 647 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; 699 650 xfstat(dev_fd, &statbuf, G.device_name); 651 /* why? */ 700 652 if (!S_ISBLK(statbuf.st_mode)) 701 653 opt &= ~1; // clear -c (check) 702 654 #if 0 703 655 /* I don't know why someone has special code to prevent mkfs.minix 704 656 * on IDE devices. Why IDE but not SCSI, etc?... */ 705 #if 0706 657 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) 707 658 /* what is this? */ … … 709 660 "to make filesystem on '%s'", G.device_name); 710 661 #endif 711 662 #endif 712 663 tmp = G.root_block; 713 664 *(short *) tmp = 1;
Note:
See TracChangeset
for help on using the changeset viewer.