aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-03-18 02:26:58 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-03-18 02:26:58 +0100
commit7c6f2d4207e11ca60964132deb3bd1c4cb583aba (patch)
treea9fe1b448e0454f7e3c0faa6d8a79b4370cca8e4
parent4424dfd69bc4edfe514b17b7006f8855892a338b (diff)
downloadbusybox-w32-7c6f2d4207e11ca60964132deb3bd1c4cb583aba.tar.gz
busybox-w32-7c6f2d4207e11ca60964132deb3bd1c4cb583aba.tar.bz2
busybox-w32-7c6f2d4207e11ca60964132deb3bd1c4cb583aba.zip
mkfs_minix: use get_volume_size_in_bytes instead of local version
Hopefully this also closes 4730 function old new delta valid_offset 55 - -55 mkfs_minix_main 2925 2674 -251 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-306) Total: -306 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/mkfs_minix.c77
1 files changed, 14 insertions, 63 deletions
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c
index 59d7d23d4..49afd1176 100644
--- a/util-linux/mkfs_minix.c
+++ b/util-linux/mkfs_minix.c
@@ -196,54 +196,6 @@ static void minix_clrbit(char *a, unsigned i)
196# define BLKGETSIZE _IO(0x12,96) /* return device size */ 196# define BLKGETSIZE _IO(0x12,96) /* return device size */
197#endif 197#endif
198 198
199
200static 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
211static 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 else
225 high = mid;
226 }
227 valid_offset(fd, 0);
228 return (low + 1);
229}
230
231static 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
247static void write_tables(void) 199static void write_tables(void)
248{ 200{
249 /* Mark the superblock valid. */ 201 /* Mark the superblock valid. */
@@ -636,7 +588,6 @@ int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
636{ 588{
637 unsigned opt; 589 unsigned opt;
638 char *tmp; 590 char *tmp;
639 struct stat statbuf;
640 char *str_i; 591 char *str_i;
641 char *listfile = NULL; 592 char *listfile = NULL;
642 593
@@ -673,13 +624,17 @@ int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
673#endif 624#endif
674 } 625 }
675 626
676 G.device_name = *argv++; 627 G.device_name = argv[0];
677 if (!G.device_name) 628 if (!G.device_name)
678 bb_show_usage(); 629 bb_show_usage();
679 if (*argv) 630
680 G.total_blocks = xatou32(*argv); 631 /* Check if it is mounted */
681 else 632 if (find_mount_point(G.device_name, 0))
682 G.total_blocks = get_size(G.device_name) / 1024; 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 if (G.total_blocks < 10) 639 if (G.total_blocks < 10)
685 bb_error_msg_and_die("must have at least 10 blocks"); 640 bb_error_msg_and_die("must have at least 10 blocks");
@@ -690,25 +645,21 @@ int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
690 G.magic = MINIX2_SUPER_MAGIC; 645 G.magic = MINIX2_SUPER_MAGIC;
691 } else if (G.total_blocks > 65535) 646 } else if (G.total_blocks > 65535)
692 G.total_blocks = 65535; 647 G.total_blocks = 65535;
693 648#if 0
694 /* Check if it is mounted */ 649 struct stat statbuf;
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);
699 xfstat(dev_fd, &statbuf, G.device_name); 650 xfstat(dev_fd, &statbuf, G.device_name);
651/* why? */
700 if (!S_ISBLK(statbuf.st_mode)) 652 if (!S_ISBLK(statbuf.st_mode))
701 opt &= ~1; // clear -c (check) 653 opt &= ~1; // clear -c (check)
702 654#if 0
703/* I don't know why someone has special code to prevent mkfs.minix 655/* I don't know why someone has special code to prevent mkfs.minix
704 * on IDE devices. Why IDE but not SCSI, etc?... */ 656 * on IDE devices. Why IDE but not SCSI, etc?... */
705#if 0
706 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) 657 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
707 /* what is this? */ 658 /* what is this? */
708 bb_error_msg_and_die("will not try " 659 bb_error_msg_and_die("will not try "
709 "to make filesystem on '%s'", G.device_name); 660 "to make filesystem on '%s'", G.device_name);
710#endif 661#endif
711 662#endif
712 tmp = G.root_block; 663 tmp = G.root_block;
713 *(short *) tmp = 1; 664 *(short *) tmp = 1;
714 strcpy(tmp + 2, "."); 665 strcpy(tmp + 2, ".");