blob: aaabf8453e40b7fd093cf63ce515e4823d74a07b [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersene494fdd1999-10-19 20:23:03 +00002/*
3 * mkfs.c - make a linux (minix) file-system.
4 *
Denis Vlasenkodb12d1d2008-12-07 00:52:58 +00005 * (C) 1991 Linus Torvalds.
6 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2, see file LICENSE in this source tree.
Eric Andersene494fdd1999-10-19 20:23:03 +00008 */
9
10/*
11 * DD.MM.YY
12 *
13 * 24.11.91 - Time began. Used the fsck sources to get started.
14 *
15 * 25.11.91 - Corrected some bugs. Added support for ".badblocks"
16 * The algorithm for ".badblocks" is a bit weird, but
17 * it should work. Oh, well.
18 *
19 * 25.01.92 - Added the -l option for getting the list of bad blocks
20 * out of a named file. (Dave Rivers, rivers@ponds.uucp)
21 *
22 * 28.02.92 - Added %-information when using -c.
23 *
24 * 28.02.93 - Added support for other namelengths than the original
25 * 14 characters so that I can test the new kernel routines..
26 *
27 * 09.10.93 - Make exit status conform to that required by fsutil
28 * (Rik Faith, faith@cs.unc.edu)
29 *
30 * 31.10.93 - Added inode request feature, for backup floppies: use
31 * 32 inodes, for a news partition use more.
32 * (Scott Heavner, sdh@po.cwru.edu)
33 *
34 * 03.01.94 - Added support for file system valid flag.
35 * (Dr. Wettstein, greg%wind.uucp@plains.nodak.edu)
36 *
Denis Vlasenko66b86c62006-11-29 22:33:47 +000037 * 30.10.94 - added support for v2 filesystem
38 * (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de)
Eric Andersenc7bda1c2004-03-15 08:29:22 +000039 *
Eric Andersene494fdd1999-10-19 20:23:03 +000040 * 09.11.94 - Added test to prevent overwrite of mounted fs adapted
41 * from Theodore Ts'o's (tytso@athena.mit.edu) mke2fs
42 * program. (Daniel Quinlan, quinlan@yggdrasil.com)
43 *
44 * 03.20.95 - Clear first 512 bytes of filesystem to make certain that
45 * the filesystem is not misidentified as a MS-DOS FAT filesystem.
46 * (Daniel Quinlan, quinlan@yggdrasil.com)
47 *
48 * 02.07.96 - Added small patch from Russell King to make the program a
49 * good deal more portable (janl@math.uio.no)
50 *
51 * Usage: mkfs [-c | -l filename ] [-v] [-nXX] [-iXX] device [size-in-blocks]
52 *
Eric Andersenaff114c2004-04-14 17:51:38 +000053 * -c for readability checking (SLOW!)
Eric Andersene494fdd1999-10-19 20:23:03 +000054 * -l for getting a list of bad blocks from a file.
55 * -n for namelength (currently the kernel only uses 14 or 30)
56 * -i for number of inodes
57 * -v for v2 filesystem
58 *
59 * The device may be a block device or a image of one, but this isn't
Eric Andersenc7bda1c2004-03-15 08:29:22 +000060 * enforced (but it's not much fun on a character device :-).
Erik Andersen330fd2b2000-05-19 05:35:19 +000061 *
62 * Modified for BusyBox by Erik Andersen <andersen@debian.org> --
63 * removed getopt based parser and added a hand rolled one.
Eric Andersene494fdd1999-10-19 20:23:03 +000064 */
65
Pere Orga5bc8c002011-04-11 03:29:49 +020066//usage:#define mkfs_minix_trivial_usage
67//usage: "[-c | -l FILE] [-nXX] [-iXX] BLOCKDEV [KBYTES]"
68//usage:#define mkfs_minix_full_usage "\n\n"
69//usage: "Make a MINIX filesystem\n"
Pere Orga5bc8c002011-04-11 03:29:49 +020070//usage: "\n -c Check device for bad blocks"
71//usage: "\n -n [14|30] Maximum length of filenames"
72//usage: "\n -i INODES Number of inodes for the filesystem"
73//usage: "\n -l FILE Read bad blocks list from FILE"
74//usage: "\n -v Make version 2 filesystem"
75
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000076#include "libbb.h"
Rob Landleyd921b2e2006-08-03 15:41:12 +000077#include <mntent.h>
Eric Andersene494fdd1999-10-19 20:23:03 +000078
Denis Vlasenkoaa959592007-01-03 00:43:19 +000079#include "minix.h"
80
Denis Vlasenko7ab36992007-12-02 08:55:34 +000081/* Store the very same times/uids/gids for image consistency */
82#if 1
Denis Vlasenko66b86c62006-11-29 22:33:47 +000083# define CUR_TIME 0
84# define GETUID 0
85# define GETGID 0
86#else
Denis Vlasenko7ab36992007-12-02 08:55:34 +000087/* Was using this. Is it useful? NB: this will break testsuite */
Denis Vlasenko66b86c62006-11-29 22:33:47 +000088# define CUR_TIME time(NULL)
89# define GETUID getuid()
90# define GETGID getgid()
91#endif
Eric Andersen85c55202000-07-10 22:46:55 +000092
Denis Vlasenko66b86c62006-11-29 22:33:47 +000093enum {
Denis Vlasenko66b86c62006-11-29 22:33:47 +000094 MAX_GOOD_BLOCKS = 512,
Denis Vlasenko66b86c62006-11-29 22:33:47 +000095 TEST_BUFFER_BLOCKS = 16,
96};
Eric Andersen85c55202000-07-10 22:46:55 +000097
Denis Vlasenko4efeaee2007-03-15 19:52:42 +000098#if !ENABLE_FEATURE_MINIX2
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +000099enum { version2 = 0 };
100#endif
Eric Andersene494fdd1999-10-19 20:23:03 +0000101
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000102enum { dev_fd = 3 };
Eric Andersene494fdd1999-10-19 20:23:03 +0000103
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000104struct globals {
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000105#if ENABLE_FEATURE_MINIX2
Denis Vlasenkoca525b42007-06-13 12:27:17 +0000106 smallint version2;
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000107#define version2 G.version2
108#endif
109 char *device_name;
110 uint32_t total_blocks;
111 int badblocks;
112 int namelen;
113 int dirsize;
114 int magic;
115 char *inode_buffer;
116 char *inode_map;
117 char *zone_map;
118 int used_good_blocks;
119 unsigned long req_nr_inodes;
120 unsigned currently_testing;
Eric Andersene494fdd1999-10-19 20:23:03 +0000121
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000122 char root_block[BLOCK_SIZE];
Bernhard Reutner-Fischere1e51742008-07-21 13:33:22 +0000123 char superblock_buffer[BLOCK_SIZE];
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000124 char boot_block_buffer[512];
125 unsigned short good_blocks_table[MAX_GOOD_BLOCKS];
Denis Vlasenko83bb98f2007-03-18 14:43:21 +0000126 /* check_blocks(): buffer[] was the biggest static in entire bbox */
127 char check_blocks_buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS];
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000128
Denis Vlasenkoab801872007-12-02 08:35:37 +0000129 unsigned short ind_block1[BLOCK_SIZE >> 1];
130 unsigned short dind_block1[BLOCK_SIZE >> 1];
131 unsigned long ind_block2[BLOCK_SIZE >> 2];
132 unsigned long dind_block2[BLOCK_SIZE >> 2];
133};
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000134#define G (*ptr_to_globals)
Denis Vlasenkoab801872007-12-02 08:35:37 +0000135#define INIT_G() do { \
Denis Vlasenko574f2f42008-02-27 18:41:59 +0000136 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
Denis Vlasenkoab801872007-12-02 08:35:37 +0000137} while (0)
Eric Andersene494fdd1999-10-19 20:23:03 +0000138
Denis Vlasenko3ad5d0c2007-06-12 20:54:54 +0000139static ALWAYS_INLINE unsigned div_roundup(unsigned size, unsigned n)
Eric Andersen56f3e352000-09-19 21:13:55 +0000140{
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000141 return (size + n-1) / n;
Eric Andersen56f3e352000-09-19 21:13:55 +0000142}
Eric Andersene494fdd1999-10-19 20:23:03 +0000143
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000144#define INODE_BUF1 (((struct minix1_inode*)G.inode_buffer) - 1)
145#define INODE_BUF2 (((struct minix2_inode*)G.inode_buffer) - 1)
Eric Andersene494fdd1999-10-19 20:23:03 +0000146
Bernhard Reutner-Fischere1e51742008-07-21 13:33:22 +0000147#define SB (*(struct minix_superblock*)G.superblock_buffer)
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000148
149#define SB_INODES (SB.s_ninodes)
150#define SB_IMAPS (SB.s_imap_blocks)
151#define SB_ZMAPS (SB.s_zmap_blocks)
152#define SB_FIRSTZONE (SB.s_firstdatazone)
153#define SB_ZONE_SIZE (SB.s_log_zone_size)
154#define SB_MAXSIZE (SB.s_max_size)
155#define SB_MAGIC (SB.s_magic)
156
157#if !ENABLE_FEATURE_MINIX2
158# define SB_ZONES (SB.s_nzones)
159# define INODE_BLOCKS div_roundup(SB_INODES, MINIX1_INODES_PER_BLOCK)
160#else
161# define SB_ZONES (version2 ? SB.s_zones : SB.s_nzones)
162# define INODE_BLOCKS div_roundup(SB_INODES, \
Denis Vlasenko7049ff82008-06-25 09:53:17 +0000163 (version2 ? MINIX2_INODES_PER_BLOCK : MINIX1_INODES_PER_BLOCK))
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000164#endif
165
166#define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE)
167#define NORM_FIRSTZONE (2 + SB_IMAPS + SB_ZMAPS + INODE_BLOCKS)
168
Denis Vlasenkocc244192007-02-06 00:37:40 +0000169/* Before you ask "where they come from?": */
170/* setbit/clrbit are supplied by sys/param.h */
171
172static int minix_bit(const char* a, unsigned i)
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000173{
Denis Vlasenko12ff9dc2008-11-22 18:58:11 +0000174 return a[i >> 3] & (1<<(i & 7));
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000175}
176
Denis Vlasenkocc244192007-02-06 00:37:40 +0000177static void minix_setbit(char *a, unsigned i)
178{
179 setbit(a, i);
180}
181static void minix_clrbit(char *a, unsigned i)
182{
183 clrbit(a, i);
184}
Denis Vlasenkodc485c92007-02-06 00:36:53 +0000185
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000186/* Note: do not assume 0/1, it is 0/nonzero */
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000187#define zone_in_use(x) minix_bit(G.zone_map,(x)-SB_FIRSTZONE+1)
188/*#define inode_in_use(x) minix_bit(G.inode_map,(x))*/
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000189
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000190#define mark_inode(x) minix_setbit(G.inode_map,(x))
191#define unmark_inode(x) minix_clrbit(G.inode_map,(x))
192#define mark_zone(x) minix_setbit(G.zone_map,(x)-SB_FIRSTZONE+1)
193#define unmark_zone(x) minix_clrbit(G.zone_map,(x)-SB_FIRSTZONE+1)
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000194
195#ifndef BLKGETSIZE
196# define BLKGETSIZE _IO(0x12,96) /* return device size */
197#endif
198
Rob Landley88621d72006-08-29 19:41:06 +0000199static void write_tables(void)
Eric Andersene494fdd1999-10-19 20:23:03 +0000200{
Bernhard Reutner-Fischere1e51742008-07-21 13:33:22 +0000201 /* Mark the superblock valid. */
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000202 SB.s_state |= MINIX_VALID_FS;
203 SB.s_state &= ~MINIX_ERROR_FS;
Eric Andersene494fdd1999-10-19 20:23:03 +0000204
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000205 msg_eol = "seek to 0 failed";
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000206 xlseek(dev_fd, 0, SEEK_SET);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000207
Denys Vlasenko6331cf02009-11-13 09:08:27 +0100208 msg_eol = "can't clear boot sector";
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000209 xwrite(dev_fd, G.boot_block_buffer, 512);
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000210
211 msg_eol = "seek to BLOCK_SIZE failed";
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000212 xlseek(dev_fd, BLOCK_SIZE, SEEK_SET);
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000213
Denys Vlasenko6331cf02009-11-13 09:08:27 +0100214 msg_eol = "can't write superblock";
Bernhard Reutner-Fischere1e51742008-07-21 13:33:22 +0000215 xwrite(dev_fd, G.superblock_buffer, BLOCK_SIZE);
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000216
Denys Vlasenko6331cf02009-11-13 09:08:27 +0100217 msg_eol = "can't write inode map";
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000218 xwrite(dev_fd, G.inode_map, SB_IMAPS * BLOCK_SIZE);
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000219
Denys Vlasenko6331cf02009-11-13 09:08:27 +0100220 msg_eol = "can't write zone map";
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000221 xwrite(dev_fd, G.zone_map, SB_ZMAPS * BLOCK_SIZE);
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000222
Denys Vlasenko6331cf02009-11-13 09:08:27 +0100223 msg_eol = "can't write inodes";
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000224 xwrite(dev_fd, G.inode_buffer, INODE_BUFFER_SIZE);
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000225
226 msg_eol = "\n";
Eric Andersene494fdd1999-10-19 20:23:03 +0000227}
228
Erik Andersene49d5ec2000-02-08 19:58:47 +0000229static void write_block(int blk, char *buffer)
Eric Andersene494fdd1999-10-19 20:23:03 +0000230{
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000231 xlseek(dev_fd, blk * BLOCK_SIZE, SEEK_SET);
232 xwrite(dev_fd, buffer, BLOCK_SIZE);
Eric Andersene494fdd1999-10-19 20:23:03 +0000233}
234
Eric Andersene674eb71999-10-19 20:52:57 +0000235static int get_free_block(void)
Eric Andersene494fdd1999-10-19 20:23:03 +0000236{
237 int blk;
238
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000239 if (G.used_good_blocks + 1 >= MAX_GOOD_BLOCKS)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000240 bb_error_msg_and_die("too many bad blocks");
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000241 if (G.used_good_blocks)
242 blk = G.good_blocks_table[G.used_good_blocks - 1] + 1;
Eric Andersene494fdd1999-10-19 20:23:03 +0000243 else
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000244 blk = SB_FIRSTZONE;
245 while (blk < SB_ZONES && zone_in_use(blk))
Eric Andersene494fdd1999-10-19 20:23:03 +0000246 blk++;
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000247 if (blk >= SB_ZONES)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000248 bb_error_msg_and_die("not enough good blocks");
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000249 G.good_blocks_table[G.used_good_blocks] = blk;
250 G.used_good_blocks++;
Eric Andersene494fdd1999-10-19 20:23:03 +0000251 return blk;
252}
253
Rob Landley88621d72006-08-29 19:41:06 +0000254static void mark_good_blocks(void)
Eric Andersene494fdd1999-10-19 20:23:03 +0000255{
256 int blk;
257
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000258 for (blk = 0; blk < G.used_good_blocks; blk++)
259 mark_zone(G.good_blocks_table[blk]);
Eric Andersene494fdd1999-10-19 20:23:03 +0000260}
261
Eric Andersen92d23242001-03-19 23:49:41 +0000262static int next(int zone)
Eric Andersene494fdd1999-10-19 20:23:03 +0000263{
264 if (!zone)
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000265 zone = SB_FIRSTZONE - 1;
266 while (++zone < SB_ZONES)
Eric Andersene494fdd1999-10-19 20:23:03 +0000267 if (zone_in_use(zone))
268 return zone;
269 return 0;
270}
271
Rob Landley88621d72006-08-29 19:41:06 +0000272static void make_bad_inode(void)
Eric Andersene494fdd1999-10-19 20:23:03 +0000273{
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000274 struct minix1_inode *inode = &INODE_BUF1[MINIX_BAD_INO];
Erik Andersene49d5ec2000-02-08 19:58:47 +0000275 int i, j, zone;
276 int ind = 0, dind = 0;
Denis Vlasenkoab801872007-12-02 08:35:37 +0000277 /* moved to globals to reduce stack usage
Erik Andersene49d5ec2000-02-08 19:58:47 +0000278 unsigned short ind_block[BLOCK_SIZE >> 1];
279 unsigned short dind_block[BLOCK_SIZE >> 1];
Denis Vlasenkoab801872007-12-02 08:35:37 +0000280 */
281#define ind_block (G.ind_block1)
282#define dind_block (G.dind_block1)
Eric Andersene494fdd1999-10-19 20:23:03 +0000283
284#define NEXT_BAD (zone = next(zone))
285
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000286 if (!G.badblocks)
Eric Andersene494fdd1999-10-19 20:23:03 +0000287 return;
288 mark_inode(MINIX_BAD_INO);
289 inode->i_nlinks = 1;
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000290 /* BTW, setting this makes all images different */
291 /* it's harder to check for bugs then - diff isn't helpful :(... */
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000292 inode->i_time = CUR_TIME;
Eric Andersene494fdd1999-10-19 20:23:03 +0000293 inode->i_mode = S_IFREG + 0000;
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000294 inode->i_size = G.badblocks * BLOCK_SIZE;
Eric Andersene494fdd1999-10-19 20:23:03 +0000295 zone = next(0);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000296 for (i = 0; i < 7; i++) {
Eric Andersene494fdd1999-10-19 20:23:03 +0000297 inode->i_zone[i] = zone;
298 if (!NEXT_BAD)
299 goto end_bad;
300 }
301 inode->i_zone[7] = ind = get_free_block();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000302 memset(ind_block, 0, BLOCK_SIZE);
303 for (i = 0; i < 512; i++) {
Eric Andersene494fdd1999-10-19 20:23:03 +0000304 ind_block[i] = zone;
305 if (!NEXT_BAD)
306 goto end_bad;
307 }
308 inode->i_zone[8] = dind = get_free_block();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000309 memset(dind_block, 0, BLOCK_SIZE);
310 for (i = 0; i < 512; i++) {
311 write_block(ind, (char *) ind_block);
Eric Andersene494fdd1999-10-19 20:23:03 +0000312 dind_block[i] = ind = get_free_block();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000313 memset(ind_block, 0, BLOCK_SIZE);
314 for (j = 0; j < 512; j++) {
Eric Andersene494fdd1999-10-19 20:23:03 +0000315 ind_block[j] = zone;
316 if (!NEXT_BAD)
317 goto end_bad;
318 }
319 }
Manuel Novoa III cad53642003-03-19 09:13:01 +0000320 bb_error_msg_and_die("too many bad blocks");
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000321 end_bad:
Eric Andersene494fdd1999-10-19 20:23:03 +0000322 if (ind)
323 write_block(ind, (char *) ind_block);
324 if (dind)
325 write_block(dind, (char *) dind_block);
Denis Vlasenkoab801872007-12-02 08:35:37 +0000326#undef ind_block
327#undef dind_block
Eric Andersene494fdd1999-10-19 20:23:03 +0000328}
329
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000330#if ENABLE_FEATURE_MINIX2
Rob Landley88621d72006-08-29 19:41:06 +0000331static void make_bad_inode2(void)
Eric Andersene494fdd1999-10-19 20:23:03 +0000332{
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000333 struct minix2_inode *inode = &INODE_BUF2[MINIX_BAD_INO];
Eric Andersene494fdd1999-10-19 20:23:03 +0000334 int i, j, zone;
335 int ind = 0, dind = 0;
Denis Vlasenkoab801872007-12-02 08:35:37 +0000336 /* moved to globals to reduce stack usage
Eric Andersene494fdd1999-10-19 20:23:03 +0000337 unsigned long ind_block[BLOCK_SIZE >> 2];
338 unsigned long dind_block[BLOCK_SIZE >> 2];
Denis Vlasenkoab801872007-12-02 08:35:37 +0000339 */
340#define ind_block (G.ind_block2)
341#define dind_block (G.dind_block2)
Eric Andersene494fdd1999-10-19 20:23:03 +0000342
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000343 if (!G.badblocks)
Eric Andersene494fdd1999-10-19 20:23:03 +0000344 return;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000345 mark_inode(MINIX_BAD_INO);
Eric Andersene494fdd1999-10-19 20:23:03 +0000346 inode->i_nlinks = 1;
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000347 inode->i_atime = inode->i_mtime = inode->i_ctime = CUR_TIME;
Eric Andersene494fdd1999-10-19 20:23:03 +0000348 inode->i_mode = S_IFREG + 0000;
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000349 inode->i_size = G.badblocks * BLOCK_SIZE;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000350 zone = next(0);
Eric Andersene494fdd1999-10-19 20:23:03 +0000351 for (i = 0; i < 7; i++) {
352 inode->i_zone[i] = zone;
353 if (!NEXT_BAD)
354 goto end_bad;
355 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000356 inode->i_zone[7] = ind = get_free_block();
357 memset(ind_block, 0, BLOCK_SIZE);
Eric Andersene494fdd1999-10-19 20:23:03 +0000358 for (i = 0; i < 256; i++) {
359 ind_block[i] = zone;
360 if (!NEXT_BAD)
361 goto end_bad;
362 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000363 inode->i_zone[8] = dind = get_free_block();
364 memset(dind_block, 0, BLOCK_SIZE);
Eric Andersene494fdd1999-10-19 20:23:03 +0000365 for (i = 0; i < 256; i++) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000366 write_block(ind, (char *) ind_block);
367 dind_block[i] = ind = get_free_block();
368 memset(ind_block, 0, BLOCK_SIZE);
Eric Andersene494fdd1999-10-19 20:23:03 +0000369 for (j = 0; j < 256; j++) {
370 ind_block[j] = zone;
371 if (!NEXT_BAD)
372 goto end_bad;
373 }
374 }
375 /* Could make triple indirect block here */
Manuel Novoa III cad53642003-03-19 09:13:01 +0000376 bb_error_msg_and_die("too many bad blocks");
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000377 end_bad:
Eric Andersene494fdd1999-10-19 20:23:03 +0000378 if (ind)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000379 write_block(ind, (char *) ind_block);
Eric Andersene494fdd1999-10-19 20:23:03 +0000380 if (dind)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000381 write_block(dind, (char *) dind_block);
Denis Vlasenkoab801872007-12-02 08:35:37 +0000382#undef ind_block
383#undef dind_block
Eric Andersene494fdd1999-10-19 20:23:03 +0000384}
Denis Vlasenko3bba5452006-12-30 17:57:03 +0000385#else
386void make_bad_inode2(void);
Eric Andersene494fdd1999-10-19 20:23:03 +0000387#endif
388
Rob Landley88621d72006-08-29 19:41:06 +0000389static void make_root_inode(void)
Eric Andersene494fdd1999-10-19 20:23:03 +0000390{
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000391 struct minix1_inode *inode = &INODE_BUF1[MINIX_ROOT_INO];
Eric Andersene494fdd1999-10-19 20:23:03 +0000392
393 mark_inode(MINIX_ROOT_INO);
394 inode->i_zone[0] = get_free_block();
395 inode->i_nlinks = 2;
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000396 inode->i_time = CUR_TIME;
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000397 if (G.badblocks)
398 inode->i_size = 3 * G.dirsize;
Eric Andersene494fdd1999-10-19 20:23:03 +0000399 else {
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000400 G.root_block[2 * G.dirsize] = '\0';
401 G.root_block[2 * G.dirsize + 1] = '\0';
402 inode->i_size = 2 * G.dirsize;
Eric Andersene494fdd1999-10-19 20:23:03 +0000403 }
404 inode->i_mode = S_IFDIR + 0755;
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000405 inode->i_uid = GETUID;
Eric Andersene494fdd1999-10-19 20:23:03 +0000406 if (inode->i_uid)
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000407 inode->i_gid = GETGID;
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000408 write_block(inode->i_zone[0], G.root_block);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000409}
410
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000411#if ENABLE_FEATURE_MINIX2
Rob Landley88621d72006-08-29 19:41:06 +0000412static void make_root_inode2(void)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000413{
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000414 struct minix2_inode *inode = &INODE_BUF2[MINIX_ROOT_INO];
Erik Andersene49d5ec2000-02-08 19:58:47 +0000415
416 mark_inode(MINIX_ROOT_INO);
417 inode->i_zone[0] = get_free_block();
418 inode->i_nlinks = 2;
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000419 inode->i_atime = inode->i_mtime = inode->i_ctime = CUR_TIME;
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000420 if (G.badblocks)
421 inode->i_size = 3 * G.dirsize;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000422 else {
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000423 G.root_block[2 * G.dirsize] = '\0';
424 G.root_block[2 * G.dirsize + 1] = '\0';
425 inode->i_size = 2 * G.dirsize;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000426 }
427 inode->i_mode = S_IFDIR + 0755;
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000428 inode->i_uid = GETUID;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000429 if (inode->i_uid)
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000430 inode->i_gid = GETGID;
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000431 write_block(inode->i_zone[0], G.root_block);
Eric Andersene494fdd1999-10-19 20:23:03 +0000432}
Denis Vlasenko3bba5452006-12-30 17:57:03 +0000433#else
434void make_root_inode2(void);
Eric Andersene494fdd1999-10-19 20:23:03 +0000435#endif
436
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000437/*
438 * Perform a test of a block; return the number of
439 * blocks readable.
440 */
441static size_t do_check(char *buffer, size_t try, unsigned current_block)
442{
443 ssize_t got;
444
445 /* Seek to the correct loc. */
446 msg_eol = "seek failed during testing of blocks";
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000447 xlseek(dev_fd, current_block * BLOCK_SIZE, SEEK_SET);
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000448 msg_eol = "\n";
449
450 /* Try the read */
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000451 got = read(dev_fd, buffer, try * BLOCK_SIZE);
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000452 if (got < 0)
453 got = 0;
454 try = ((size_t)got) / BLOCK_SIZE;
455
456 if (got & (BLOCK_SIZE - 1))
457 fprintf(stderr, "Short read at block %u\n", (unsigned)(current_block + try));
458 return try;
459}
460
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000461static void alarm_intr(int alnum UNUSED_PARAM)
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000462{
463 if (G.currently_testing >= SB_ZONES)
464 return;
465 signal(SIGALRM, alarm_intr);
466 alarm(5);
467 if (!G.currently_testing)
468 return;
469 printf("%d ...", G.currently_testing);
Denys Vlasenko8131eea2009-11-02 14:19:51 +0100470 fflush_all();
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000471}
472
473static void check_blocks(void)
474{
475 size_t try, got;
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000476
477 G.currently_testing = 0;
478 signal(SIGALRM, alarm_intr);
479 alarm(5);
480 while (G.currently_testing < SB_ZONES) {
481 msg_eol = "seek failed in check_blocks";
Denis Vlasenkoe06f61d2008-06-25 10:00:58 +0000482 xlseek(dev_fd, G.currently_testing * BLOCK_SIZE, SEEK_SET);
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000483 msg_eol = "\n";
484 try = TEST_BUFFER_BLOCKS;
485 if (G.currently_testing + try > SB_ZONES)
486 try = SB_ZONES - G.currently_testing;
Denis Vlasenko83bb98f2007-03-18 14:43:21 +0000487 got = do_check(G.check_blocks_buffer, try, G.currently_testing);
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000488 G.currently_testing += got;
489 if (got == try)
490 continue;
491 if (G.currently_testing < SB_FIRSTZONE)
492 bb_error_msg_and_die("bad blocks before data-area: cannot make fs");
493 mark_zone(G.currently_testing);
494 G.badblocks++;
495 G.currently_testing++;
496 }
497 alarm(0);
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000498 printf("%d bad block(s)\n", G.badblocks);
499}
500
501static void get_list_blocks(char *filename)
502{
503 FILE *listfile;
504 unsigned long blockno;
505
Denis Vlasenko5415c852008-07-21 23:05:26 +0000506 listfile = xfopen_for_read(filename);
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000507 while (!feof(listfile)) {
Denys Vlasenko327f5502013-11-29 16:45:45 +0100508 fscanf(listfile, "%lu\n", &blockno);
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000509 mark_zone(blockno);
510 G.badblocks++;
511 }
512 printf("%d bad block(s)\n", G.badblocks);
513}
514
Rob Landley88621d72006-08-29 19:41:06 +0000515static void setup_tables(void)
Eric Andersene494fdd1999-10-19 20:23:03 +0000516{
Eric Andersene494fdd1999-10-19 20:23:03 +0000517 unsigned long inodes;
Denis Vlasenko016a82e2006-11-29 22:47:42 +0000518 unsigned norm_firstzone;
Denis Vlasenko28bb84b2006-11-29 23:15:04 +0000519 unsigned sb_zmaps;
520 unsigned i;
Eric Andersene494fdd1999-10-19 20:23:03 +0000521
Bernhard Reutner-Fischere1e51742008-07-21 13:33:22 +0000522 /* memset(G.superblock_buffer, 0, BLOCK_SIZE); */
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000523 /* memset(G.boot_block_buffer, 0, 512); */
524 SB_MAGIC = G.magic;
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000525 SB_ZONE_SIZE = 0;
526 SB_MAXSIZE = version2 ? 0x7fffffff : (7 + 512 + 512 * 512) * 1024;
527 if (version2)
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000528 SB.s_zones = G.total_blocks;
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000529 else
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000530 SB.s_nzones = G.total_blocks;
Eric Andersenb225e2a2004-08-28 00:43:07 +0000531
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000532 /* some magic nrs: 1 inode / 3 blocks */
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000533 if (G.req_nr_inodes == 0)
534 inodes = G.total_blocks / 3;
Eric Andersene494fdd1999-10-19 20:23:03 +0000535 else
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000536 inodes = G.req_nr_inodes;
Eric Andersene494fdd1999-10-19 20:23:03 +0000537 /* Round up inode count to fill block size */
Eric Andersene494fdd1999-10-19 20:23:03 +0000538 if (version2)
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000539 inodes = (inodes + MINIX2_INODES_PER_BLOCK - 1) &
540 ~(MINIX2_INODES_PER_BLOCK - 1);
Eric Andersene494fdd1999-10-19 20:23:03 +0000541 else
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000542 inodes = (inodes + MINIX1_INODES_PER_BLOCK - 1) &
543 ~(MINIX1_INODES_PER_BLOCK - 1);
Eric Andersene494fdd1999-10-19 20:23:03 +0000544 if (inodes > 65535)
545 inodes = 65535;
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000546 SB_INODES = inodes;
547 SB_IMAPS = div_roundup(SB_INODES + 1, BITS_PER_BLOCK);
548
Eric Andersene494fdd1999-10-19 20:23:03 +0000549 /* Real bad hack but overwise mkfs.minix can be thrown
550 * in infinite loop...
551 * try:
552 * dd if=/dev/zero of=test.fs count=10 bs=1024
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000553 * mkfs.minix -i 200 test.fs
554 */
Denis Vlasenko016a82e2006-11-29 22:47:42 +0000555 /* This code is not insane: NORM_FIRSTZONE is not a constant,
556 * it is calculated from SB_INODES, SB_IMAPS and SB_ZMAPS */
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000557 i = 999;
558 SB_ZMAPS = 0;
559 do {
Denis Vlasenko016a82e2006-11-29 22:47:42 +0000560 norm_firstzone = NORM_FIRSTZONE;
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000561 sb_zmaps = div_roundup(G.total_blocks - norm_firstzone + 1, BITS_PER_BLOCK);
Denis Vlasenko016a82e2006-11-29 22:47:42 +0000562 if (SB_ZMAPS == sb_zmaps) goto got_it;
563 SB_ZMAPS = sb_zmaps;
564 /* new SB_ZMAPS, need to recalc NORM_FIRSTZONE */
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000565 } while (--i);
566 bb_error_msg_and_die("incompatible size/inode count, try different -i N");
567 got_it:
568
Denis Vlasenko016a82e2006-11-29 22:47:42 +0000569 SB_FIRSTZONE = norm_firstzone;
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000570 G.inode_map = xmalloc(SB_IMAPS * BLOCK_SIZE);
571 G.zone_map = xmalloc(SB_ZMAPS * BLOCK_SIZE);
572 memset(G.inode_map, 0xff, SB_IMAPS * BLOCK_SIZE);
573 memset(G.zone_map, 0xff, SB_ZMAPS * BLOCK_SIZE);
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000574 for (i = SB_FIRSTZONE; i < SB_ZONES; i++)
Eric Andersene494fdd1999-10-19 20:23:03 +0000575 unmark_zone(i);
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000576 for (i = MINIX_ROOT_INO; i <= SB_INODES; i++)
Eric Andersene494fdd1999-10-19 20:23:03 +0000577 unmark_inode(i);
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000578 G.inode_buffer = xzalloc(INODE_BUFFER_SIZE);
Denys Vlasenko7f3a2a22015-10-08 11:24:44 +0200579 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);
Eric Andersene494fdd1999-10-19 20:23:03 +0000584}
585
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000586int mkfs_minix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000587int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
Eric Andersene494fdd1999-10-19 20:23:03 +0000588{
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000589 unsigned opt;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000590 char *tmp;
Denis Vlasenko1d426652008-03-17 09:09:09 +0000591 char *str_i;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000592 char *listfile = NULL;
Eric Andersene494fdd1999-10-19 20:23:03 +0000593
Denis Vlasenkoab801872007-12-02 08:35:37 +0000594 INIT_G();
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000595/* default (changed to 30, per Linus's suggestion, Sun Nov 21 08:05:07 1993) */
596 G.namelen = 30;
597 G.dirsize = 32;
598 G.magic = MINIX1_SUPER_MAGIC2;
599
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000600 if (INODE_SIZE1 * MINIX1_INODES_PER_BLOCK != BLOCK_SIZE)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000601 bb_error_msg_and_die("bad inode size");
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000602#if ENABLE_FEATURE_MINIX2
Erik Andersene49d5ec2000-02-08 19:58:47 +0000603 if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000604 bb_error_msg_and_die("bad inode size");
Eric Andersene494fdd1999-10-19 20:23:03 +0000605#endif
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000606
Denys Vlasenko237bedd2016-07-06 21:58:02 +0200607 opt = getopt32(argv, "ci:l:n:+v", &str_i, &listfile, &G.namelen);
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000608 argv += optind;
609 //if (opt & 1) -c
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000610 if (opt & 2) G.req_nr_inodes = xatoul(str_i); // -i
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000611 //if (opt & 4) -l
612 if (opt & 8) { // -n
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000613 if (G.namelen == 14) G.magic = MINIX1_SUPER_MAGIC;
614 else if (G.namelen == 30) G.magic = MINIX1_SUPER_MAGIC2;
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000615 else bb_show_usage();
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000616 G.dirsize = G.namelen + 2;
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000617 }
618 if (opt & 0x10) { // -v
619#if ENABLE_FEATURE_MINIX2
620 version2 = 1;
Eric Andersene494fdd1999-10-19 20:23:03 +0000621#else
Denis Vlasenkodc485c92007-02-06 00:36:53 +0000622 bb_error_msg_and_die("not compiled with minix v2 support");
Eric Andersene494fdd1999-10-19 20:23:03 +0000623#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000624 }
Eric Andersene494fdd1999-10-19 20:23:03 +0000625
Denys Vlasenko7c6f2d42013-03-18 02:26:58 +0100626 G.device_name = argv[0];
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000627 if (!G.device_name)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000628 bb_show_usage();
Denys Vlasenko7c6f2d42013-03-18 02:26:58 +0100629
630 /* Check if it is mounted */
631 if (find_mount_point(G.device_name, 0))
632 bb_error_msg_and_die("can't format mounted filesystem");
633
634 xmove_fd(xopen(G.device_name, O_RDWR), dev_fd);
635
636 G.total_blocks = get_volume_size_in_bytes(dev_fd, argv[1], 1024, /*extend:*/ 1) / 1024;
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000637
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000638 if (G.total_blocks < 10)
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000639 bb_error_msg_and_die("must have at least 10 blocks");
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000640
Erik Andersene49d5ec2000-02-08 19:58:47 +0000641 if (version2) {
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000642 G.magic = MINIX2_SUPER_MAGIC2;
643 if (G.namelen == 14)
644 G.magic = MINIX2_SUPER_MAGIC;
645 } else if (G.total_blocks > 65535)
646 G.total_blocks = 65535;
Denys Vlasenko7c6f2d42013-03-18 02:26:58 +0100647#if 0
648 struct stat statbuf;
Denys Vlasenko8d3e2252010-08-31 12:42:06 +0200649 xfstat(dev_fd, &statbuf, G.device_name);
Denys Vlasenko7c6f2d42013-03-18 02:26:58 +0100650/* why? */
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000651 if (!S_ISBLK(statbuf.st_mode))
652 opt &= ~1; // clear -c (check)
Denys Vlasenko7c6f2d42013-03-18 02:26:58 +0100653#if 0
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000654/* I don't know why someone has special code to prevent mkfs.minix
655 * on IDE devices. Why IDE but not SCSI, etc?... */
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000656 else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
657 /* what is this? */
658 bb_error_msg_and_die("will not try "
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000659 "to make filesystem on '%s'", G.device_name);
Denis Vlasenko66b86c62006-11-29 22:33:47 +0000660#endif
Denys Vlasenko7c6f2d42013-03-18 02:26:58 +0100661#endif
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000662 tmp = G.root_block;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000663 *(short *) tmp = 1;
664 strcpy(tmp + 2, ".");
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000665 tmp += G.dirsize;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000666 *(short *) tmp = 1;
667 strcpy(tmp + 2, "..");
Denis Vlasenko4efeaee2007-03-15 19:52:42 +0000668 tmp += G.dirsize;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000669 *(short *) tmp = 2;
670 strcpy(tmp + 2, ".badblocks");
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000671
Erik Andersene49d5ec2000-02-08 19:58:47 +0000672 setup_tables();
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000673
674 if (opt & 1) // -c ?
Erik Andersene49d5ec2000-02-08 19:58:47 +0000675 check_blocks();
676 else if (listfile)
677 get_list_blocks(listfile);
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000678
Erik Andersene49d5ec2000-02-08 19:58:47 +0000679 if (version2) {
680 make_root_inode2();
681 make_bad_inode2();
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000682 } else {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000683 make_root_inode();
684 make_bad_inode();
685 }
Denis Vlasenkoc6ce8732006-11-29 18:15:52 +0000686
Erik Andersene49d5ec2000-02-08 19:58:47 +0000687 mark_good_blocks();
688 write_tables();
"Vladimir N. Oleynik"1f2dc402005-10-15 13:56:17 +0000689 return 0;
Eric Andersene494fdd1999-10-19 20:23:03 +0000690}