xref: /minix3/sys/fs/v7fs/v7fs_inode.c (revision 9f988b79349f9b89ecc822458c30ec8897558560)
1*9f988b79SJean-Baptiste Boric /*	$NetBSD: v7fs_inode.c,v 1.2 2011/07/18 21:51:49 apb 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 __KERNEL_RCSID(0, "$NetBSD: v7fs_inode.c,v 1.2 2011/07/18 21:51:49 apb Exp $");
38*9f988b79SJean-Baptiste Boric #if defined _KERNEL_OPT
39*9f988b79SJean-Baptiste Boric #include "opt_v7fs.h"
40*9f988b79SJean-Baptiste Boric #endif
41*9f988b79SJean-Baptiste Boric 
42*9f988b79SJean-Baptiste Boric #ifdef _KERNEL
43*9f988b79SJean-Baptiste Boric #include <sys/systm.h>
44*9f988b79SJean-Baptiste Boric #include <sys/param.h>
45*9f988b79SJean-Baptiste Boric #else
46*9f988b79SJean-Baptiste Boric #include <stdio.h>
47*9f988b79SJean-Baptiste Boric #include <string.h>
48*9f988b79SJean-Baptiste Boric #include <errno.h>
49*9f988b79SJean-Baptiste Boric #include <time.h>
50*9f988b79SJean-Baptiste Boric #endif
51*9f988b79SJean-Baptiste Boric 
52*9f988b79SJean-Baptiste Boric #include "v7fs.h"
53*9f988b79SJean-Baptiste Boric #include "v7fs_impl.h"
54*9f988b79SJean-Baptiste Boric #include "v7fs_endian.h"
55*9f988b79SJean-Baptiste Boric #include "v7fs_inode.h"
56*9f988b79SJean-Baptiste Boric #include "v7fs_superblock.h"
57*9f988b79SJean-Baptiste Boric 
58*9f988b79SJean-Baptiste Boric #ifdef V7FS_INODE_DEBUG
59*9f988b79SJean-Baptiste Boric #define	DPRINTF(fmt, args...)	printf("%s: " fmt, __func__, ##args)
60*9f988b79SJean-Baptiste Boric #else
61*9f988b79SJean-Baptiste Boric #define	DPRINTF(fmt, args...)	((void)0)
62*9f988b79SJean-Baptiste Boric #endif
63*9f988b79SJean-Baptiste Boric 
64*9f988b79SJean-Baptiste Boric static void v7fs_inode_setup_disk_image(const struct v7fs_self *,
65*9f988b79SJean-Baptiste Boric     struct v7fs_inode *, struct v7fs_inode_diskimage *);
66*9f988b79SJean-Baptiste Boric static int v7fs_inode_inquire_disk_location(const struct v7fs_self *,
67*9f988b79SJean-Baptiste Boric     v7fs_ino_t, v7fs_daddr_t *, v7fs_daddr_t *);
68*9f988b79SJean-Baptiste Boric #ifdef V7FS_INODE_DEBUG
69*9f988b79SJean-Baptiste Boric static int v7fs_inode_block_sanity(const struct v7fs_superblock *,
70*9f988b79SJean-Baptiste Boric     v7fs_daddr_t);
71*9f988b79SJean-Baptiste Boric 
72*9f988b79SJean-Baptiste Boric static int
v7fs_inode_block_sanity(const struct v7fs_superblock * sb,v7fs_daddr_t blk)73*9f988b79SJean-Baptiste Boric v7fs_inode_block_sanity(const struct v7fs_superblock *sb, v7fs_daddr_t blk)
74*9f988b79SJean-Baptiste Boric {
75*9f988b79SJean-Baptiste Boric 
76*9f988b79SJean-Baptiste Boric 	if ((blk < V7FS_ILIST_SECTOR) || (blk >= sb->datablock_start_sector)) {
77*9f988b79SJean-Baptiste Boric 		DPRINTF("invalid inode block#%d (%d-%d)\n", blk,
78*9f988b79SJean-Baptiste Boric 		    V7FS_ILIST_SECTOR, sb->datablock_start_sector);
79*9f988b79SJean-Baptiste Boric 		return ENOSPC;
80*9f988b79SJean-Baptiste Boric 	}
81*9f988b79SJean-Baptiste Boric 
82*9f988b79SJean-Baptiste Boric 	return 0;
83*9f988b79SJean-Baptiste Boric }
84*9f988b79SJean-Baptiste Boric #endif /* V7FS_INODE_DEBUG */
85*9f988b79SJean-Baptiste Boric 
86*9f988b79SJean-Baptiste Boric int
v7fs_inode_number_sanity(const struct v7fs_superblock * sb,v7fs_ino_t ino)87*9f988b79SJean-Baptiste Boric v7fs_inode_number_sanity(const struct v7fs_superblock *sb, v7fs_ino_t ino)
88*9f988b79SJean-Baptiste Boric {
89*9f988b79SJean-Baptiste Boric 
90*9f988b79SJean-Baptiste Boric 	if (ino < V7FS_ROOT_INODE || ((size_t)ino >= V7FS_MAX_INODE(sb))) {
91*9f988b79SJean-Baptiste Boric 		DPRINTF("invalid inode#%d (%d-%zu)\n", ino,
92*9f988b79SJean-Baptiste Boric 		    V7FS_ROOT_INODE, V7FS_MAX_INODE(sb));
93*9f988b79SJean-Baptiste Boric 		return ENOSPC;
94*9f988b79SJean-Baptiste Boric 	}
95*9f988b79SJean-Baptiste Boric 
96*9f988b79SJean-Baptiste Boric 	return 0;
97*9f988b79SJean-Baptiste Boric }
98*9f988b79SJean-Baptiste Boric 
99*9f988b79SJean-Baptiste Boric int
v7fs_inode_allocate(struct v7fs_self * fs,v7fs_ino_t * ino)100*9f988b79SJean-Baptiste Boric v7fs_inode_allocate(struct v7fs_self *fs, v7fs_ino_t *ino)
101*9f988b79SJean-Baptiste Boric {
102*9f988b79SJean-Baptiste Boric 	struct v7fs_superblock *sb = &fs->superblock;
103*9f988b79SJean-Baptiste Boric 	v7fs_ino_t inode_number;
104*9f988b79SJean-Baptiste Boric 	int error = ENOSPC;
105*9f988b79SJean-Baptiste Boric 	*ino = 0;
106*9f988b79SJean-Baptiste Boric 
107*9f988b79SJean-Baptiste Boric 	SUPERB_LOCK(fs);
108*9f988b79SJean-Baptiste Boric 	if (sb->total_freeinode == 0) {
109*9f988b79SJean-Baptiste Boric 		DPRINTF("inode exhausted!(1)\n");
110*9f988b79SJean-Baptiste Boric 		goto errexit;
111*9f988b79SJean-Baptiste Boric 	}
112*9f988b79SJean-Baptiste Boric 
113*9f988b79SJean-Baptiste Boric 	/* If there is no free inode cache, update it. */
114*9f988b79SJean-Baptiste Boric 	if (sb->nfreeinode <= 0 && (error = v7fs_freeinode_update(fs))) {
115*9f988b79SJean-Baptiste Boric 		DPRINTF("inode exhausted!(2)\n");
116*9f988b79SJean-Baptiste Boric 		goto errexit;
117*9f988b79SJean-Baptiste Boric 	}
118*9f988b79SJean-Baptiste Boric 	/* Get inode from superblock cache. */
119*9f988b79SJean-Baptiste Boric 	KDASSERT(sb->nfreeinode <= V7FS_MAX_FREEINODE);
120*9f988b79SJean-Baptiste Boric 	inode_number = sb->freeinode[--sb->nfreeinode];
121*9f988b79SJean-Baptiste Boric 	sb->total_freeinode--;
122*9f988b79SJean-Baptiste Boric 	sb->modified = 1;
123*9f988b79SJean-Baptiste Boric 
124*9f988b79SJean-Baptiste Boric 	if ((error = v7fs_inode_number_sanity(sb, inode_number))) {
125*9f988b79SJean-Baptiste Boric 		DPRINTF("new inode#%d %d %d\n", inode_number, sb->nfreeinode,
126*9f988b79SJean-Baptiste Boric 		    sb->total_freeinode);
127*9f988b79SJean-Baptiste Boric 		DPRINTF("free inode list corupt\n");
128*9f988b79SJean-Baptiste Boric 		goto errexit;
129*9f988b79SJean-Baptiste Boric 	}
130*9f988b79SJean-Baptiste Boric 	*ino = inode_number;
131*9f988b79SJean-Baptiste Boric 
132*9f988b79SJean-Baptiste Boric errexit:
133*9f988b79SJean-Baptiste Boric 	SUPERB_UNLOCK(fs);
134*9f988b79SJean-Baptiste Boric 
135*9f988b79SJean-Baptiste Boric 	return error;
136*9f988b79SJean-Baptiste Boric }
137*9f988b79SJean-Baptiste Boric 
138*9f988b79SJean-Baptiste Boric void
v7fs_inode_deallocate(struct v7fs_self * fs,v7fs_ino_t ino)139*9f988b79SJean-Baptiste Boric v7fs_inode_deallocate(struct v7fs_self *fs, v7fs_ino_t ino)
140*9f988b79SJean-Baptiste Boric {
141*9f988b79SJean-Baptiste Boric 	struct v7fs_superblock *sb = &fs->superblock;
142*9f988b79SJean-Baptiste Boric 	struct v7fs_inode inode;
143*9f988b79SJean-Baptiste Boric 
144*9f988b79SJean-Baptiste Boric 	memset(&inode, 0, sizeof(inode));
145*9f988b79SJean-Baptiste Boric 	inode.inode_number = ino;
146*9f988b79SJean-Baptiste Boric 	v7fs_inode_writeback(fs, &inode);
147*9f988b79SJean-Baptiste Boric 
148*9f988b79SJean-Baptiste Boric 	SUPERB_LOCK(fs);
149*9f988b79SJean-Baptiste Boric 	if (sb->nfreeinode < V7FS_MAX_FREEINODE) {
150*9f988b79SJean-Baptiste Boric 		/* link to freeinode list. */
151*9f988b79SJean-Baptiste Boric 		sb->freeinode[sb->nfreeinode++] = ino;
152*9f988b79SJean-Baptiste Boric 	}
153*9f988b79SJean-Baptiste Boric 	/* If superblock inode cache is full, this inode charged by
154*9f988b79SJean-Baptiste Boric 	   v7fs_freeinode_update() later. */
155*9f988b79SJean-Baptiste Boric 	sb->total_freeinode++;
156*9f988b79SJean-Baptiste Boric 	sb->modified = true;
157*9f988b79SJean-Baptiste Boric 	SUPERB_UNLOCK(fs);
158*9f988b79SJean-Baptiste Boric }
159*9f988b79SJean-Baptiste Boric 
160*9f988b79SJean-Baptiste Boric void
v7fs_inode_setup_memory_image(const struct v7fs_self * fs __unused,struct v7fs_inode * mem,struct v7fs_inode_diskimage * disk)161*9f988b79SJean-Baptiste Boric v7fs_inode_setup_memory_image(const struct v7fs_self *fs __unused,
162*9f988b79SJean-Baptiste Boric     struct v7fs_inode *mem, struct v7fs_inode_diskimage *disk)
163*9f988b79SJean-Baptiste Boric {
164*9f988b79SJean-Baptiste Boric #define	conv16(m)	(mem->m = V7FS_VAL16(fs, (disk->m)))
165*9f988b79SJean-Baptiste Boric #define	conv32(m)	(mem->m = V7FS_VAL32(fs, (disk->m)))
166*9f988b79SJean-Baptiste Boric 	uint32_t addr;
167*9f988b79SJean-Baptiste Boric 	int i;
168*9f988b79SJean-Baptiste Boric 
169*9f988b79SJean-Baptiste Boric 	memset(mem, 0, sizeof(*mem));
170*9f988b79SJean-Baptiste Boric 	conv16(mode);
171*9f988b79SJean-Baptiste Boric 	conv16(nlink);
172*9f988b79SJean-Baptiste Boric 	conv16(uid);
173*9f988b79SJean-Baptiste Boric 	conv16(gid);
174*9f988b79SJean-Baptiste Boric 	conv32(filesize);
175*9f988b79SJean-Baptiste Boric 	conv32(atime);
176*9f988b79SJean-Baptiste Boric 	conv32(mtime);
177*9f988b79SJean-Baptiste Boric 	conv32(ctime);
178*9f988b79SJean-Baptiste Boric 
179*9f988b79SJean-Baptiste Boric 	for (i = 0; i < V7FS_NADDR; i++) {
180*9f988b79SJean-Baptiste Boric 		int j = i * 3; /* 3 byte each. (v7fs_daddr is 24bit) */
181*9f988b79SJean-Baptiste Boric 		/* expand to 4byte with endian conversion. */
182*9f988b79SJean-Baptiste Boric 		addr = V7FS_VAL24_READ(fs, &disk->addr[j]);
183*9f988b79SJean-Baptiste Boric 		mem->addr[i] = addr;
184*9f988b79SJean-Baptiste Boric 	}
185*9f988b79SJean-Baptiste Boric 	mem->device = 0;
186*9f988b79SJean-Baptiste Boric 	if (v7fs_inode_iscdev(mem) || v7fs_inode_isbdev(mem)) {
187*9f988b79SJean-Baptiste Boric 		mem->device = mem->addr[0];
188*9f988b79SJean-Baptiste Boric 	}
189*9f988b79SJean-Baptiste Boric 
190*9f988b79SJean-Baptiste Boric #undef conv16
191*9f988b79SJean-Baptiste Boric #undef conv32
192*9f988b79SJean-Baptiste Boric }
193*9f988b79SJean-Baptiste Boric 
194*9f988b79SJean-Baptiste Boric static void
v7fs_inode_setup_disk_image(const struct v7fs_self * fs __unused,struct v7fs_inode * mem,struct v7fs_inode_diskimage * disk)195*9f988b79SJean-Baptiste Boric v7fs_inode_setup_disk_image(const struct v7fs_self *fs __unused,
196*9f988b79SJean-Baptiste Boric     struct v7fs_inode *mem, struct v7fs_inode_diskimage *disk)
197*9f988b79SJean-Baptiste Boric {
198*9f988b79SJean-Baptiste Boric #define	conv16(m)	(disk->m = V7FS_VAL16(fs, (mem->m)))
199*9f988b79SJean-Baptiste Boric #define	conv32(m)	(disk->m = V7FS_VAL32(fs, (mem->m)))
200*9f988b79SJean-Baptiste Boric 
201*9f988b79SJean-Baptiste Boric 	conv16(mode);
202*9f988b79SJean-Baptiste Boric 	conv16(nlink);
203*9f988b79SJean-Baptiste Boric 	conv16(uid);
204*9f988b79SJean-Baptiste Boric 	conv16(gid);
205*9f988b79SJean-Baptiste Boric 	conv32(filesize);
206*9f988b79SJean-Baptiste Boric 	conv32(atime);
207*9f988b79SJean-Baptiste Boric 	conv32(mtime);
208*9f988b79SJean-Baptiste Boric 	conv32(ctime);
209*9f988b79SJean-Baptiste Boric 
210*9f988b79SJean-Baptiste Boric 	int i;
211*9f988b79SJean-Baptiste Boric 	for (i = 0; i < V7FS_NADDR; i++) {
212*9f988b79SJean-Baptiste Boric 		int j = i * 3; /* 3 byte each. */
213*9f988b79SJean-Baptiste Boric 		V7FS_VAL24_WRITE(fs, mem->addr[i], disk->addr + j);
214*9f988b79SJean-Baptiste Boric 	}
215*9f988b79SJean-Baptiste Boric #undef conv16
216*9f988b79SJean-Baptiste Boric #undef conv32
217*9f988b79SJean-Baptiste Boric }
218*9f988b79SJean-Baptiste Boric 
219*9f988b79SJean-Baptiste Boric /* Load inode from disk. */
220*9f988b79SJean-Baptiste Boric int
v7fs_inode_load(struct v7fs_self * fs,struct v7fs_inode * p,v7fs_ino_t n)221*9f988b79SJean-Baptiste Boric v7fs_inode_load(struct v7fs_self *fs, struct v7fs_inode *p, v7fs_ino_t n)
222*9f988b79SJean-Baptiste Boric {
223*9f988b79SJean-Baptiste Boric 	v7fs_daddr_t blk, ofs;
224*9f988b79SJean-Baptiste Boric 	struct v7fs_inode_diskimage *di;
225*9f988b79SJean-Baptiste Boric 	void *buf;
226*9f988b79SJean-Baptiste Boric 
227*9f988b79SJean-Baptiste Boric 	if (v7fs_inode_inquire_disk_location(fs, n, &blk, &ofs) != 0)
228*9f988b79SJean-Baptiste Boric 		return ENOENT;
229*9f988b79SJean-Baptiste Boric 
230*9f988b79SJean-Baptiste Boric 	ILIST_LOCK(fs);
231*9f988b79SJean-Baptiste Boric 	if (!(buf = scratch_read(fs, blk))) {
232*9f988b79SJean-Baptiste Boric 		ILIST_UNLOCK(fs);
233*9f988b79SJean-Baptiste Boric 		return EIO;
234*9f988b79SJean-Baptiste Boric 	}
235*9f988b79SJean-Baptiste Boric 	ILIST_UNLOCK(fs);
236*9f988b79SJean-Baptiste Boric 	di = (struct v7fs_inode_diskimage *)buf;
237*9f988b79SJean-Baptiste Boric 
238*9f988b79SJean-Baptiste Boric 	/* Decode disk address, convert endian. */
239*9f988b79SJean-Baptiste Boric 	v7fs_inode_setup_memory_image(fs, p, di + ofs);
240*9f988b79SJean-Baptiste Boric 	p->inode_number = n;
241*9f988b79SJean-Baptiste Boric 
242*9f988b79SJean-Baptiste Boric 	scratch_free(fs, buf);
243*9f988b79SJean-Baptiste Boric 
244*9f988b79SJean-Baptiste Boric 	return 0;
245*9f988b79SJean-Baptiste Boric }
246*9f988b79SJean-Baptiste Boric 
247*9f988b79SJean-Baptiste Boric /* Write back inode to disk. */
248*9f988b79SJean-Baptiste Boric int
v7fs_inode_writeback(struct v7fs_self * fs,struct v7fs_inode * mem)249*9f988b79SJean-Baptiste Boric v7fs_inode_writeback(struct v7fs_self *fs, struct v7fs_inode *mem)
250*9f988b79SJean-Baptiste Boric {
251*9f988b79SJean-Baptiste Boric 	struct v7fs_inode_diskimage disk;
252*9f988b79SJean-Baptiste Boric 	v7fs_ino_t ino = mem->inode_number;
253*9f988b79SJean-Baptiste Boric 	v7fs_daddr_t blk;
254*9f988b79SJean-Baptiste Boric 	v7fs_daddr_t ofs;
255*9f988b79SJean-Baptiste Boric 	void *buf;
256*9f988b79SJean-Baptiste Boric 	int error = 0;
257*9f988b79SJean-Baptiste Boric 
258*9f988b79SJean-Baptiste Boric 	if (v7fs_inode_inquire_disk_location(fs, ino, &blk, &ofs) != 0)
259*9f988b79SJean-Baptiste Boric 		return ENOENT;
260*9f988b79SJean-Baptiste Boric 
261*9f988b79SJean-Baptiste Boric 	v7fs_inode_setup_disk_image(fs, mem, &disk);
262*9f988b79SJean-Baptiste Boric 
263*9f988b79SJean-Baptiste Boric 	ILIST_LOCK(fs);
264*9f988b79SJean-Baptiste Boric 	if (!(buf = scratch_read(fs, blk))) {
265*9f988b79SJean-Baptiste Boric 		ILIST_UNLOCK(fs);
266*9f988b79SJean-Baptiste Boric 		return EIO;
267*9f988b79SJean-Baptiste Boric 	}
268*9f988b79SJean-Baptiste Boric 	struct v7fs_inode_diskimage *di = (struct v7fs_inode_diskimage *)buf;
269*9f988b79SJean-Baptiste Boric 	di[ofs] = disk; /* structure copy; */
270*9f988b79SJean-Baptiste Boric 	if (!fs->io.write(fs->io.cookie, buf, blk))
271*9f988b79SJean-Baptiste Boric 		error = EIO;
272*9f988b79SJean-Baptiste Boric 	ILIST_UNLOCK(fs);
273*9f988b79SJean-Baptiste Boric 
274*9f988b79SJean-Baptiste Boric 	scratch_free(fs, buf);
275*9f988b79SJean-Baptiste Boric 
276*9f988b79SJean-Baptiste Boric 	return error;
277*9f988b79SJean-Baptiste Boric }
278*9f988b79SJean-Baptiste Boric 
279*9f988b79SJean-Baptiste Boric static int
v7fs_inode_inquire_disk_location(const struct v7fs_self * fs __unused,v7fs_ino_t n,v7fs_daddr_t * block,v7fs_daddr_t * offset)280*9f988b79SJean-Baptiste Boric v7fs_inode_inquire_disk_location(const struct v7fs_self *fs
281*9f988b79SJean-Baptiste Boric     __unused, v7fs_ino_t n, v7fs_daddr_t *block,
282*9f988b79SJean-Baptiste Boric     v7fs_daddr_t *offset)
283*9f988b79SJean-Baptiste Boric {
284*9f988b79SJean-Baptiste Boric 	v7fs_daddr_t ofs, blk;
285*9f988b79SJean-Baptiste Boric #ifdef V7FS_INODE_DEBUG
286*9f988b79SJean-Baptiste Boric 	v7fs_inode_number_sanity(&fs->superblock, n);
287*9f988b79SJean-Baptiste Boric #endif
288*9f988b79SJean-Baptiste Boric 	ofs = (n - 1/*inode start from 1*/) *
289*9f988b79SJean-Baptiste Boric 	    sizeof(struct v7fs_inode_diskimage);
290*9f988b79SJean-Baptiste Boric 	blk = ofs >> V7FS_BSHIFT;
291*9f988b79SJean-Baptiste Boric 
292*9f988b79SJean-Baptiste Boric 	*block = blk + V7FS_ILIST_SECTOR;
293*9f988b79SJean-Baptiste Boric 	*offset = (ofs - blk * V7FS_BSIZE) /
294*9f988b79SJean-Baptiste Boric 	    sizeof(struct v7fs_inode_diskimage);
295*9f988b79SJean-Baptiste Boric #ifdef V7FS_INODE_DEBUG
296*9f988b79SJean-Baptiste Boric 	return v7fs_inode_block_sanity(&fs->superblock, *block);
297*9f988b79SJean-Baptiste Boric #else
298*9f988b79SJean-Baptiste Boric 	return 0;
299*9f988b79SJean-Baptiste Boric #endif
300*9f988b79SJean-Baptiste Boric }
301*9f988b79SJean-Baptiste Boric 
302