xref: /minix3/sbin/newfs_v7fs/main.c (revision 9f988b79349f9b89ecc822458c30ec8897558560)
1*9f988b79SJean-Baptiste Boric /*	$NetBSD: main.c,v 1.10 2011/08/10 11:31:49 uch Exp $	*/
2*9f988b79SJean-Baptiste Boric 
3*9f988b79SJean-Baptiste Boric /*-
4*9f988b79SJean-Baptiste Boric  * Copyright (c) 2011 The NetBSD Foundation, Inc.
5*9f988b79SJean-Baptiste Boric  * All rights reserved.
6*9f988b79SJean-Baptiste Boric  *
7*9f988b79SJean-Baptiste Boric  * This code is derived from software contributed to The NetBSD Foundation
8*9f988b79SJean-Baptiste Boric  * by UCHIYAMA Yasushi.
9*9f988b79SJean-Baptiste Boric  *
10*9f988b79SJean-Baptiste Boric  * Redistribution and use in source and binary forms, with or without
11*9f988b79SJean-Baptiste Boric  * modification, are permitted provided that the following conditions
12*9f988b79SJean-Baptiste Boric  * are met:
13*9f988b79SJean-Baptiste Boric  * 1. Redistributions of source code must retain the above copyright
14*9f988b79SJean-Baptiste Boric  *    notice, this list of conditions and the following disclaimer.
15*9f988b79SJean-Baptiste Boric  * 2. Redistributions in binary form must reproduce the above copyright
16*9f988b79SJean-Baptiste Boric  *    notice, this list of conditions and the following disclaimer in the
17*9f988b79SJean-Baptiste Boric  *    documentation and/or other materials provided with the distribution.
18*9f988b79SJean-Baptiste Boric  *
19*9f988b79SJean-Baptiste Boric  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*9f988b79SJean-Baptiste Boric  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*9f988b79SJean-Baptiste Boric  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*9f988b79SJean-Baptiste Boric  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*9f988b79SJean-Baptiste Boric  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*9f988b79SJean-Baptiste Boric  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*9f988b79SJean-Baptiste Boric  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*9f988b79SJean-Baptiste Boric  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*9f988b79SJean-Baptiste Boric  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*9f988b79SJean-Baptiste Boric  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*9f988b79SJean-Baptiste Boric  * POSSIBILITY OF SUCH DAMAGE.
30*9f988b79SJean-Baptiste Boric  */
31*9f988b79SJean-Baptiste Boric 
32*9f988b79SJean-Baptiste Boric #if HAVE_NBTOOL_CONFIG_H
33*9f988b79SJean-Baptiste Boric #include "nbtool_config.h"
34*9f988b79SJean-Baptiste Boric #endif
35*9f988b79SJean-Baptiste Boric 
36*9f988b79SJean-Baptiste Boric #include <sys/cdefs.h>
37*9f988b79SJean-Baptiste Boric #ifndef lint
38*9f988b79SJean-Baptiste Boric __RCSID("$NetBSD: main.c,v 1.10 2011/08/10 11:31:49 uch Exp $");
39*9f988b79SJean-Baptiste Boric #endif /* not lint */
40*9f988b79SJean-Baptiste Boric 
41*9f988b79SJean-Baptiste Boric #include <sys/param.h>
42*9f988b79SJean-Baptiste Boric #include <stdio.h>
43*9f988b79SJean-Baptiste Boric #include <string.h>
44*9f988b79SJean-Baptiste Boric #include <errno.h>
45*9f988b79SJean-Baptiste Boric #include <time.h>
46*9f988b79SJean-Baptiste Boric #include <err.h>
47*9f988b79SJean-Baptiste Boric 
48*9f988b79SJean-Baptiste Boric #include "v7fs.h"
49*9f988b79SJean-Baptiste Boric #include "v7fs_impl.h"
50*9f988b79SJean-Baptiste Boric #include "v7fs_endian.h"
51*9f988b79SJean-Baptiste Boric #include "v7fs_superblock.h"
52*9f988b79SJean-Baptiste Boric #include "v7fs_inode.h"
53*9f988b79SJean-Baptiste Boric #include "v7fs_datablock.h" /*v7fs_datablock_expand/last */
54*9f988b79SJean-Baptiste Boric #include "newfs_v7fs.h"
55*9f988b79SJean-Baptiste Boric #include "progress.h" /*../sbin/fsck */
56*9f988b79SJean-Baptiste Boric 
57*9f988b79SJean-Baptiste Boric #define	VPRINTF(lv, fmt, args...)	{ if (v7fs_newfs_verbose >= lv)	\
58*9f988b79SJean-Baptiste Boric 	printf(fmt, ##args); }
59*9f988b79SJean-Baptiste Boric 
60*9f988b79SJean-Baptiste Boric static v7fs_daddr_t
determine_ilist_size(v7fs_daddr_t volume_size,int32_t files)61*9f988b79SJean-Baptiste Boric determine_ilist_size(v7fs_daddr_t volume_size, int32_t files)
62*9f988b79SJean-Baptiste Boric {
63*9f988b79SJean-Baptiste Boric 	v7fs_daddr_t ilist_size;
64*9f988b79SJean-Baptiste Boric 
65*9f988b79SJean-Baptiste Boric 	if (files)
66*9f988b79SJean-Baptiste Boric 		ilist_size =  howmany(files, V7FS_INODE_PER_BLOCK);
67*9f988b79SJean-Baptiste Boric 	else
68*9f988b79SJean-Baptiste Boric 		ilist_size = volume_size / 25; /* 4% */
69*9f988b79SJean-Baptiste Boric 	if (ilist_size > (v7fs_daddr_t)V7FS_ILISTBLK_MAX)
70*9f988b79SJean-Baptiste Boric 		ilist_size = V7FS_ILISTBLK_MAX;
71*9f988b79SJean-Baptiste Boric 
72*9f988b79SJean-Baptiste Boric 	return ilist_size;
73*9f988b79SJean-Baptiste Boric }
74*9f988b79SJean-Baptiste Boric 
75*9f988b79SJean-Baptiste Boric static int
partition_check(struct v7fs_self * fs)76*9f988b79SJean-Baptiste Boric partition_check(struct v7fs_self *fs)
77*9f988b79SJean-Baptiste Boric {
78*9f988b79SJean-Baptiste Boric 	struct v7fs_superblock *sb = &fs->superblock;
79*9f988b79SJean-Baptiste Boric 	int error;
80*9f988b79SJean-Baptiste Boric 
81*9f988b79SJean-Baptiste Boric 	if ((error = v7fs_superblock_load(fs))) {
82*9f988b79SJean-Baptiste Boric 		if (error != EINVAL) {
83*9f988b79SJean-Baptiste Boric 			/* Invalid superblock information is OK. */
84*9f988b79SJean-Baptiste Boric 			warnx("Can't read superblock sector.");
85*9f988b79SJean-Baptiste Boric 		}
86*9f988b79SJean-Baptiste Boric 	}
87*9f988b79SJean-Baptiste Boric 	sb->modified = 1;
88*9f988b79SJean-Baptiste Boric 	if ((error = v7fs_superblock_writeback(fs))) {
89*9f988b79SJean-Baptiste Boric 		if (errno == EROFS) {
90*9f988b79SJean-Baptiste Boric 			warnx("Overwriting disk label? ");
91*9f988b79SJean-Baptiste Boric 		}
92*9f988b79SJean-Baptiste Boric 		warnx("Can't write superblock sector.");
93*9f988b79SJean-Baptiste Boric 	}
94*9f988b79SJean-Baptiste Boric 
95*9f988b79SJean-Baptiste Boric 	return error;
96*9f988b79SJean-Baptiste Boric }
97*9f988b79SJean-Baptiste Boric 
98*9f988b79SJean-Baptiste Boric static int
make_root(struct v7fs_self * fs)99*9f988b79SJean-Baptiste Boric make_root(struct v7fs_self *fs)
100*9f988b79SJean-Baptiste Boric {
101*9f988b79SJean-Baptiste Boric 	struct v7fs_inode inode;
102*9f988b79SJean-Baptiste Boric 	struct v7fs_dirent *dir;
103*9f988b79SJean-Baptiste Boric 	int error;
104*9f988b79SJean-Baptiste Boric 
105*9f988b79SJean-Baptiste Boric 	/* INO 1 badblk (don't used) */
106*9f988b79SJean-Baptiste Boric 	memset(&inode, 0, sizeof(inode));
107*9f988b79SJean-Baptiste Boric 	inode.inode_number = 1;
108*9f988b79SJean-Baptiste Boric 	inode.mode = V7FS_IFREG;	/* V7 manner */
109*9f988b79SJean-Baptiste Boric 	v7fs_inode_writeback(fs, &inode);
110*9f988b79SJean-Baptiste Boric 
111*9f988b79SJean-Baptiste Boric 	/* INO 2 root */
112*9f988b79SJean-Baptiste Boric 	v7fs_ino_t ino;
113*9f988b79SJean-Baptiste Boric 	if ((error = v7fs_inode_allocate(fs, &ino))) {
114*9f988b79SJean-Baptiste Boric 		errno = error;
115*9f988b79SJean-Baptiste Boric 		warn("Can't allocate / inode");
116*9f988b79SJean-Baptiste Boric 		return error;
117*9f988b79SJean-Baptiste Boric 	}
118*9f988b79SJean-Baptiste Boric 
119*9f988b79SJean-Baptiste Boric 	memset(&inode, 0, sizeof(inode));
120*9f988b79SJean-Baptiste Boric 	inode.inode_number = ino;
121*9f988b79SJean-Baptiste Boric 	inode.mode = 0777 | V7FS_IFDIR;
122*9f988b79SJean-Baptiste Boric 	inode.uid = 0;
123*9f988b79SJean-Baptiste Boric 	inode.gid = 0;
124*9f988b79SJean-Baptiste Boric 	inode.nlink = 2;	/* . + .. */
125*9f988b79SJean-Baptiste Boric 	inode.atime = inode.mtime = inode.ctime = time(0);
126*9f988b79SJean-Baptiste Boric 
127*9f988b79SJean-Baptiste Boric 	/* root dirent. */
128*9f988b79SJean-Baptiste Boric 	v7fs_datablock_expand(fs, &inode, sizeof(*dir) * 2);
129*9f988b79SJean-Baptiste Boric 	v7fs_daddr_t blk = inode.addr[0];
130*9f988b79SJean-Baptiste Boric 	void *buf;
131*9f988b79SJean-Baptiste Boric 	if (!(buf = scratch_read(fs, blk))) {
132*9f988b79SJean-Baptiste Boric 		v7fs_inode_deallocate(fs, ino);
133*9f988b79SJean-Baptiste Boric 		errno = error = EIO;
134*9f988b79SJean-Baptiste Boric 		warn("Can't read / dirent.");
135*9f988b79SJean-Baptiste Boric 		return error;
136*9f988b79SJean-Baptiste Boric 	}
137*9f988b79SJean-Baptiste Boric 	dir = (struct v7fs_dirent *)buf; /*disk endian */
138*9f988b79SJean-Baptiste Boric 
139*9f988b79SJean-Baptiste Boric 	strcpy(dir[0].name, ".");
140*9f988b79SJean-Baptiste Boric 	dir[0].inode_number = V7FS_VAL16(fs, ino);
141*9f988b79SJean-Baptiste Boric 	strcpy(dir[1].name, "..");
142*9f988b79SJean-Baptiste Boric 	dir[1].inode_number = V7FS_VAL16(fs, ino);
143*9f988b79SJean-Baptiste Boric 	if (!fs->io.write(fs->io.cookie, buf, blk)) {/*writeback */
144*9f988b79SJean-Baptiste Boric 		scratch_free(fs, buf);
145*9f988b79SJean-Baptiste Boric 		errno = error = EIO;
146*9f988b79SJean-Baptiste Boric 		warn("Can't write / dirent.");
147*9f988b79SJean-Baptiste Boric 		return error;
148*9f988b79SJean-Baptiste Boric 	}
149*9f988b79SJean-Baptiste Boric 	scratch_free(fs, buf);
150*9f988b79SJean-Baptiste Boric 	v7fs_inode_writeback(fs, &inode);
151*9f988b79SJean-Baptiste Boric 	if ((error = v7fs_superblock_writeback(fs))) {
152*9f988b79SJean-Baptiste Boric 		errno = error;
153*9f988b79SJean-Baptiste Boric 		warnx("Can't write superblock.");
154*9f988b79SJean-Baptiste Boric 	}
155*9f988b79SJean-Baptiste Boric 
156*9f988b79SJean-Baptiste Boric 	return error;
157*9f988b79SJean-Baptiste Boric }
158*9f988b79SJean-Baptiste Boric 
159*9f988b79SJean-Baptiste Boric static v7fs_daddr_t
make_freeblocklist(struct v7fs_self * fs,v7fs_daddr_t listblk,uint8_t * buf)160*9f988b79SJean-Baptiste Boric make_freeblocklist(struct v7fs_self *fs, v7fs_daddr_t listblk, uint8_t *buf)
161*9f988b79SJean-Baptiste Boric {
162*9f988b79SJean-Baptiste Boric 	uint32_t (*val32)(uint32_t) = fs->val.conv32;
163*9f988b79SJean-Baptiste Boric 	uint16_t (*val16)(uint16_t) = fs->val.conv16;
164*9f988b79SJean-Baptiste Boric 	struct v7fs_freeblock *fb = (struct v7fs_freeblock *)buf;
165*9f988b79SJean-Baptiste Boric 	int i, j, k;
166*9f988b79SJean-Baptiste Boric 
167*9f988b79SJean-Baptiste Boric 	memset(buf, 0, V7FS_BSIZE);
168*9f988b79SJean-Baptiste Boric 
169*9f988b79SJean-Baptiste Boric 	for (i = V7FS_MAX_FREEBLOCK - 1, j = listblk + 1, k = 0; i >= 0;
170*9f988b79SJean-Baptiste Boric 	    i--, j++, k++) {
171*9f988b79SJean-Baptiste Boric 		progress(0);
172*9f988b79SJean-Baptiste Boric 		if (j == (int32_t)fs->superblock.volume_size)
173*9f988b79SJean-Baptiste Boric 		{
174*9f988b79SJean-Baptiste Boric 			VPRINTF(4, "\nlast freeblock #%d\n",
175*9f988b79SJean-Baptiste Boric 			    (*val32)(fb->freeblock[i + 1]));
176*9f988b79SJean-Baptiste Boric 
177*9f988b79SJean-Baptiste Boric 			memmove(fb->freeblock + 1, fb->freeblock + i + 1, k *
178*9f988b79SJean-Baptiste Boric 			    sizeof(v7fs_daddr_t));
179*9f988b79SJean-Baptiste Boric 			fb->freeblock[0] = 0; /* Terminate link; */
180*9f988b79SJean-Baptiste Boric 			fb->nfreeblock = (*val16)(k + 1);
181*9f988b79SJean-Baptiste Boric 			VPRINTF(4, "last freeblock contains #%d\n",
182*9f988b79SJean-Baptiste Boric 			    (*val16)(fb->nfreeblock));
183*9f988b79SJean-Baptiste Boric 			fs->io.write(fs->io.cookie, buf, listblk);
184*9f988b79SJean-Baptiste Boric 			return 0;
185*9f988b79SJean-Baptiste Boric 		}
186*9f988b79SJean-Baptiste Boric 		fb->freeblock[i] = (*val32)(j);
187*9f988b79SJean-Baptiste Boric 	}
188*9f988b79SJean-Baptiste Boric 	fb->nfreeblock = (*val16)(k);
189*9f988b79SJean-Baptiste Boric 
190*9f988b79SJean-Baptiste Boric 	if (!fs->io.write(fs->io.cookie, buf, listblk)) {
191*9f988b79SJean-Baptiste Boric 		errno = EIO;
192*9f988b79SJean-Baptiste Boric 		warn("blk=%ld", (long)listblk);
193*9f988b79SJean-Baptiste Boric 		return 0;
194*9f988b79SJean-Baptiste Boric 	}
195*9f988b79SJean-Baptiste Boric 
196*9f988b79SJean-Baptiste Boric 	/* Return next link block */
197*9f988b79SJean-Baptiste Boric 	return (*val32)(fb->freeblock[0]);
198*9f988b79SJean-Baptiste Boric }
199*9f988b79SJean-Baptiste Boric 
200*9f988b79SJean-Baptiste Boric static int
make_filesystem(struct v7fs_self * fs,v7fs_daddr_t volume_size,v7fs_daddr_t ilist_size)201*9f988b79SJean-Baptiste Boric make_filesystem(struct v7fs_self *fs, v7fs_daddr_t volume_size,
202*9f988b79SJean-Baptiste Boric     v7fs_daddr_t ilist_size)
203*9f988b79SJean-Baptiste Boric {
204*9f988b79SJean-Baptiste Boric 	struct v7fs_superblock *sb;
205*9f988b79SJean-Baptiste Boric 	v7fs_daddr_t blk;
206*9f988b79SJean-Baptiste Boric 	uint8_t buf[V7FS_BSIZE];
207*9f988b79SJean-Baptiste Boric 	int error = 0;
208*9f988b79SJean-Baptiste Boric 	int32_t i, j;
209*9f988b79SJean-Baptiste Boric 
210*9f988b79SJean-Baptiste Boric 	/* Setup ilist. (ilist must be zero filled. becuase of they are free) */
211*9f988b79SJean-Baptiste Boric 	VPRINTF(4, "Zero clear ilist.\n");
212*9f988b79SJean-Baptiste Boric 	progress(&(struct progress_arg){ .label = "zero ilist", .tick =
213*9f988b79SJean-Baptiste Boric 	    ilist_size / PROGRESS_BAR_GRANULE });
214*9f988b79SJean-Baptiste Boric 	memset(buf, 0, sizeof buf);
215*9f988b79SJean-Baptiste Boric 	for (i = V7FS_ILIST_SECTOR; i < (int32_t)ilist_size; i++) {
216*9f988b79SJean-Baptiste Boric 		fs->io.write(fs->io.cookie, buf, i);
217*9f988b79SJean-Baptiste Boric 		progress(0);
218*9f988b79SJean-Baptiste Boric 	}
219*9f988b79SJean-Baptiste Boric #ifndef HAVE_NBTOOL_CONFIG_H
220*9f988b79SJean-Baptiste Boric 	progress_done();
221*9f988b79SJean-Baptiste Boric #endif
222*9f988b79SJean-Baptiste Boric 	VPRINTF(4, "\n");
223*9f988b79SJean-Baptiste Boric 
224*9f988b79SJean-Baptiste Boric 	/* Construct superblock */
225*9f988b79SJean-Baptiste Boric 	sb = &fs->superblock;
226*9f988b79SJean-Baptiste Boric 	sb->volume_size = volume_size;
227*9f988b79SJean-Baptiste Boric 	sb->datablock_start_sector = ilist_size + V7FS_ILIST_SECTOR;
228*9f988b79SJean-Baptiste Boric 	sb->update_time = time(NULL);
229*9f988b79SJean-Baptiste Boric 
230*9f988b79SJean-Baptiste Boric 	/* fill free inode cache. */
231*9f988b79SJean-Baptiste Boric 	VPRINTF(4, "Setup inode cache.\n");
232*9f988b79SJean-Baptiste Boric 	sb->nfreeinode = V7FS_MAX_FREEINODE;
233*9f988b79SJean-Baptiste Boric 	for (i = V7FS_MAX_FREEINODE - 1, j = V7FS_ROOT_INODE; i >= 0; i--, j++)
234*9f988b79SJean-Baptiste Boric 		sb->freeinode[i] = j;
235*9f988b79SJean-Baptiste Boric 	sb->total_freeinode = ilist_size * V7FS_INODE_PER_BLOCK - 1;
236*9f988b79SJean-Baptiste Boric 
237*9f988b79SJean-Baptiste Boric 	/* fill free block cache. */
238*9f988b79SJean-Baptiste Boric 	VPRINTF(4, "Setup free block cache.\n");
239*9f988b79SJean-Baptiste Boric 	sb->nfreeblock = V7FS_MAX_FREEBLOCK;
240*9f988b79SJean-Baptiste Boric 	for (i = V7FS_MAX_FREEBLOCK - 1, j = sb->datablock_start_sector; i >= 0;
241*9f988b79SJean-Baptiste Boric 	    i--, j++)
242*9f988b79SJean-Baptiste Boric 		sb->freeblock[i] = j;
243*9f988b79SJean-Baptiste Boric 
244*9f988b79SJean-Baptiste Boric 	sb->total_freeblock = volume_size - sb->datablock_start_sector;
245*9f988b79SJean-Baptiste Boric 
246*9f988b79SJean-Baptiste Boric 	/* Write superblock. */
247*9f988b79SJean-Baptiste Boric 	sb->modified = 1;
248*9f988b79SJean-Baptiste Boric 	if ((error = v7fs_superblock_writeback(fs))) {
249*9f988b79SJean-Baptiste Boric 		errno = error;
250*9f988b79SJean-Baptiste Boric 		warn("Can't write back superblock.");
251*9f988b79SJean-Baptiste Boric 		return error;
252*9f988b79SJean-Baptiste Boric 	}
253*9f988b79SJean-Baptiste Boric 
254*9f988b79SJean-Baptiste Boric 	/* Construct freeblock list */
255*9f988b79SJean-Baptiste Boric 	VPRINTF(4, "Setup whole freeblock list.\n");
256*9f988b79SJean-Baptiste Boric 	progress(&(struct progress_arg){ .label = "freeblock list", .tick =
257*9f988b79SJean-Baptiste Boric 	    (volume_size - sb->datablock_start_sector) / PROGRESS_BAR_GRANULE});
258*9f988b79SJean-Baptiste Boric 	blk = sb->freeblock[0];
259*9f988b79SJean-Baptiste Boric 	while ((blk = make_freeblocklist(fs, blk, buf)))
260*9f988b79SJean-Baptiste Boric 		continue;
261*9f988b79SJean-Baptiste Boric #ifndef HAVE_NBTOOL_CONFIG_H
262*9f988b79SJean-Baptiste Boric 	progress_done();
263*9f988b79SJean-Baptiste Boric #endif
264*9f988b79SJean-Baptiste Boric 
265*9f988b79SJean-Baptiste Boric 	VPRINTF(4, "done.\n");
266*9f988b79SJean-Baptiste Boric 
267*9f988b79SJean-Baptiste Boric 	return 0;
268*9f988b79SJean-Baptiste Boric }
269*9f988b79SJean-Baptiste Boric 
270*9f988b79SJean-Baptiste Boric int
v7fs_newfs(const struct v7fs_mount_device * mount,int32_t maxfile)271*9f988b79SJean-Baptiste Boric v7fs_newfs(const struct v7fs_mount_device *mount, int32_t maxfile)
272*9f988b79SJean-Baptiste Boric {
273*9f988b79SJean-Baptiste Boric 	struct v7fs_self *fs;
274*9f988b79SJean-Baptiste Boric 	v7fs_daddr_t ilist_size;
275*9f988b79SJean-Baptiste Boric 	int error;
276*9f988b79SJean-Baptiste Boric 	v7fs_daddr_t volume_size = mount->sectors;
277*9f988b79SJean-Baptiste Boric 
278*9f988b79SJean-Baptiste Boric 	/* Check and determine ilistblock, datablock size. */
279*9f988b79SJean-Baptiste Boric 	if (volume_size > V7FS_DADDR_MAX + 1) {
280*9f988b79SJean-Baptiste Boric 		warnx("volume size %d over v7fs limit %d. truncated.",
281*9f988b79SJean-Baptiste Boric 		    volume_size, V7FS_DADDR_MAX + 1);
282*9f988b79SJean-Baptiste Boric 		volume_size = V7FS_DADDR_MAX + 1;
283*9f988b79SJean-Baptiste Boric 	}
284*9f988b79SJean-Baptiste Boric 
285*9f988b79SJean-Baptiste Boric 	ilist_size = determine_ilist_size(volume_size, maxfile);
286*9f988b79SJean-Baptiste Boric 
287*9f988b79SJean-Baptiste Boric 	VPRINTF(1, "volume size=%d, ilist size=%d, endian=%d, NAME_MAX=%d\n",
288*9f988b79SJean-Baptiste Boric 	    volume_size, ilist_size, mount->endian, V7FS_NAME_MAX);
289*9f988b79SJean-Baptiste Boric 
290*9f988b79SJean-Baptiste Boric 	/* Setup I/O ops. */
291*9f988b79SJean-Baptiste Boric 	if ((error = v7fs_io_init(&fs, mount, V7FS_BSIZE))) {
292*9f988b79SJean-Baptiste Boric 		errno = error;
293*9f988b79SJean-Baptiste Boric 		warn("I/O setup failed.");
294*9f988b79SJean-Baptiste Boric 		return error;
295*9f988b79SJean-Baptiste Boric 	}
296*9f988b79SJean-Baptiste Boric 	fs->endian = mount->endian;
297*9f988b79SJean-Baptiste Boric 	v7fs_endian_init(fs);
298*9f988b79SJean-Baptiste Boric 
299*9f988b79SJean-Baptiste Boric 	if ((error = partition_check(fs))) {
300*9f988b79SJean-Baptiste Boric 		return error;
301*9f988b79SJean-Baptiste Boric 	}
302*9f988b79SJean-Baptiste Boric 
303*9f988b79SJean-Baptiste Boric 	/* Construct filesystem. */
304*9f988b79SJean-Baptiste Boric 	if ((error = make_filesystem(fs, volume_size, ilist_size))) {
305*9f988b79SJean-Baptiste Boric 		return error;
306*9f988b79SJean-Baptiste Boric 	}
307*9f988b79SJean-Baptiste Boric 
308*9f988b79SJean-Baptiste Boric 	/* Setup root. */
309*9f988b79SJean-Baptiste Boric 	if ((error = make_root(fs))) {
310*9f988b79SJean-Baptiste Boric 		return error;
311*9f988b79SJean-Baptiste Boric 	}
312*9f988b79SJean-Baptiste Boric 
313*9f988b79SJean-Baptiste Boric 	v7fs_io_fini(fs);
314*9f988b79SJean-Baptiste Boric 
315*9f988b79SJean-Baptiste Boric 	return 0;
316*9f988b79SJean-Baptiste Boric }
317