xref: /freebsd-src/sys/fs/ext2fs/ext2_inode.c (revision 29363fb446372cb3f10bc98664e9767c53fbb457)
1e09c00caSUlf Lilleengen /*-
2e09c00caSUlf Lilleengen  *  modified for Lites 1.1
3e09c00caSUlf Lilleengen  *
4e09c00caSUlf Lilleengen  *  Aug 1995, Godmar Back (gback@cs.utah.edu)
5e09c00caSUlf Lilleengen  *  University of Utah, Department of Computer Science
6e09c00caSUlf Lilleengen  */
7e09c00caSUlf Lilleengen /*-
851369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
951369649SPedro F. Giffuni  *
10e09c00caSUlf Lilleengen  * Copyright (c) 1982, 1986, 1989, 1993
11e09c00caSUlf Lilleengen  *	The Regents of the University of California.  All rights reserved.
12e09c00caSUlf Lilleengen  *
13e09c00caSUlf Lilleengen  * Redistribution and use in source and binary forms, with or without
14e09c00caSUlf Lilleengen  * modification, are permitted provided that the following conditions
15e09c00caSUlf Lilleengen  * are met:
16e09c00caSUlf Lilleengen  * 1. Redistributions of source code must retain the above copyright
17e09c00caSUlf Lilleengen  *    notice, this list of conditions and the following disclaimer.
18e09c00caSUlf Lilleengen  * 2. Redistributions in binary form must reproduce the above copyright
19e09c00caSUlf Lilleengen  *    notice, this list of conditions and the following disclaimer in the
20e09c00caSUlf Lilleengen  *    documentation and/or other materials provided with the distribution.
21fca15474SPedro F. Giffuni  * 3. Neither the name of the University nor the names of its contributors
22e09c00caSUlf Lilleengen  *    may be used to endorse or promote products derived from this software
23e09c00caSUlf Lilleengen  *    without specific prior written permission.
24e09c00caSUlf Lilleengen  *
25e09c00caSUlf Lilleengen  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26e09c00caSUlf Lilleengen  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27e09c00caSUlf Lilleengen  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28e09c00caSUlf Lilleengen  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29e09c00caSUlf Lilleengen  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30e09c00caSUlf Lilleengen  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31e09c00caSUlf Lilleengen  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32e09c00caSUlf Lilleengen  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33e09c00caSUlf Lilleengen  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34e09c00caSUlf Lilleengen  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35e09c00caSUlf Lilleengen  * SUCH DAMAGE.
36e09c00caSUlf Lilleengen  */
37e09c00caSUlf Lilleengen 
38e09c00caSUlf Lilleengen #include <sys/param.h>
39e09c00caSUlf Lilleengen #include <sys/systm.h>
40e09c00caSUlf Lilleengen #include <sys/mount.h>
41e09c00caSUlf Lilleengen #include <sys/bio.h>
42e09c00caSUlf Lilleengen #include <sys/buf.h>
43cd3acfe7SFedor Uporov #include <sys/endian.h>
44e09c00caSUlf Lilleengen #include <sys/vnode.h>
45e09c00caSUlf Lilleengen #include <sys/malloc.h>
4622a72260SJeff Roberson #include <sys/rwlock.h>
47ebc94b66SFedor Uporov #include <sys/sdt.h>
48e09c00caSUlf Lilleengen 
49e09c00caSUlf Lilleengen #include <vm/vm.h>
50e09c00caSUlf Lilleengen #include <vm/vm_extern.h>
51e09c00caSUlf Lilleengen 
52e06e5241SFedor Uporov #include <fs/ext2fs/fs.h>
53e09c00caSUlf Lilleengen #include <fs/ext2fs/inode.h>
54e09c00caSUlf Lilleengen #include <fs/ext2fs/ext2_mount.h>
55e09c00caSUlf Lilleengen #include <fs/ext2fs/ext2fs.h>
56e09c00caSUlf Lilleengen #include <fs/ext2fs/fs.h>
57e09c00caSUlf Lilleengen #include <fs/ext2fs/ext2_extern.h>
5834f43888SPedro F. Giffuni #include <fs/ext2fs/ext2_extattr.h>
59e09c00caSUlf Lilleengen 
60e09c00caSUlf Lilleengen /*
61e09c00caSUlf Lilleengen  * Update the access, modified, and inode change times as specified by the
62e09c00caSUlf Lilleengen  * IN_ACCESS, IN_UPDATE, and IN_CHANGE flags respectively.  Write the inode
63e09c00caSUlf Lilleengen  * to disk if the IN_MODIFIED flag is set (it may be set initially, or by
64e09c00caSUlf Lilleengen  * the timestamp update).  The IN_LAZYMOD flag is set to force a write
65e09c00caSUlf Lilleengen  * later if not now.  If we write now, then clear both IN_MODIFIED and
66e09c00caSUlf Lilleengen  * IN_LAZYMOD to reflect the presumably successful write, and if waitfor is
67e09c00caSUlf Lilleengen  * set, then wait for the write to complete.
68e09c00caSUlf Lilleengen  */
69e09c00caSUlf Lilleengen int
ext2_update(struct vnode * vp,int waitfor)70a9d1b299SPedro F. Giffuni ext2_update(struct vnode *vp, int waitfor)
71e09c00caSUlf Lilleengen {
72e09c00caSUlf Lilleengen 	struct m_ext2fs *fs;
73e09c00caSUlf Lilleengen 	struct buf *bp;
74e09c00caSUlf Lilleengen 	struct inode *ip;
75e09c00caSUlf Lilleengen 	int error;
76e09c00caSUlf Lilleengen 
77e09c00caSUlf Lilleengen 	ASSERT_VOP_ELOCKED(vp, "ext2_update");
78e09c00caSUlf Lilleengen 	ext2_itimes(vp);
79e09c00caSUlf Lilleengen 	ip = VTOI(vp);
80e09c00caSUlf Lilleengen 	if ((ip->i_flag & IN_MODIFIED) == 0 && waitfor == 0)
81e09c00caSUlf Lilleengen 		return (0);
82e09c00caSUlf Lilleengen 	ip->i_flag &= ~(IN_LAZYACCESS | IN_LAZYMOD | IN_MODIFIED);
83e09c00caSUlf Lilleengen 	fs = ip->i_e2fs;
84e09c00caSUlf Lilleengen 	if (fs->e2fs_ronly)
85e09c00caSUlf Lilleengen 		return (0);
86e09c00caSUlf Lilleengen 	if ((error = bread(ip->i_devvp,
87e09c00caSUlf Lilleengen 	    fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
88e09c00caSUlf Lilleengen 	    (int)fs->e2fs_bsize, NOCRED, &bp)) != 0) {
89e09c00caSUlf Lilleengen 		brelse(bp);
90e09c00caSUlf Lilleengen 		return (error);
91e09c00caSUlf Lilleengen 	}
9272530f91SFedor Uporov 	error = ext2_i2ei(ip, (struct ext2fs_dinode *)((char *)bp->b_data +
93e09c00caSUlf Lilleengen 	    EXT2_INODE_SIZE(fs) * ino_to_fsbo(fs, ip->i_number)));
9472530f91SFedor Uporov 	if (error) {
9572530f91SFedor Uporov 		brelse(bp);
9672530f91SFedor Uporov 		return (error);
9772530f91SFedor Uporov 	}
989e880b87SJohn Baldwin 	if (waitfor && !DOINGASYNC(vp))
99e09c00caSUlf Lilleengen 		return (bwrite(bp));
100e09c00caSUlf Lilleengen 	else {
101e09c00caSUlf Lilleengen 		bdwrite(bp);
102e09c00caSUlf Lilleengen 		return (0);
103e09c00caSUlf Lilleengen 	}
104e09c00caSUlf Lilleengen }
105e09c00caSUlf Lilleengen 
106e09c00caSUlf Lilleengen #define	SINGLE	0	/* index of single indirect block */
107e09c00caSUlf Lilleengen #define	DOUBLE	1	/* index of double indirect block */
108e09c00caSUlf Lilleengen #define	TRIPLE	2	/* index of triple indirect block */
109b394cd1eSFedor Uporov 
110b394cd1eSFedor Uporov /*
111b394cd1eSFedor Uporov  * Release blocks associated with the inode ip and stored in the indirect
112b394cd1eSFedor Uporov  * block bn.  Blocks are free'd in LIFO order up to (but not including)
113b394cd1eSFedor Uporov  * lastbn.  If level is greater than SINGLE, the block is an indirect block
114b394cd1eSFedor Uporov  * and recursive calls to indirtrunc must be used to cleanse other indirect
115b394cd1eSFedor Uporov  * blocks.
116b394cd1eSFedor Uporov  *
117b394cd1eSFedor Uporov  * NB: triple indirect blocks are untested.
118b394cd1eSFedor Uporov  */
119b394cd1eSFedor Uporov static int
ext2_indirtrunc(struct inode * ip,daddr_t lbn,daddr_t dbn,daddr_t lastbn,int level,e4fs_daddr_t * countp)120b394cd1eSFedor Uporov ext2_indirtrunc(struct inode *ip, daddr_t lbn, daddr_t dbn,
121b394cd1eSFedor Uporov     daddr_t lastbn, int level, e4fs_daddr_t *countp)
122b394cd1eSFedor Uporov {
123b394cd1eSFedor Uporov 	struct buf *bp;
124b394cd1eSFedor Uporov 	struct m_ext2fs *fs = ip->i_e2fs;
125b394cd1eSFedor Uporov 	struct vnode *vp;
126b394cd1eSFedor Uporov 	e2fs_daddr_t *bap, *copy;
127b394cd1eSFedor Uporov 	int i, nblocks, error = 0, allerror = 0;
128b394cd1eSFedor Uporov 	e2fs_lbn_t nb, nlbn, last;
129b394cd1eSFedor Uporov 	e4fs_daddr_t blkcount, factor, blocksreleased = 0;
130b394cd1eSFedor Uporov 
131b394cd1eSFedor Uporov 	/*
132b394cd1eSFedor Uporov 	 * Calculate index in current block of last
133b394cd1eSFedor Uporov 	 * block to be kept.  -1 indicates the entire
134b394cd1eSFedor Uporov 	 * block so we need not calculate the index.
135b394cd1eSFedor Uporov 	 */
136b394cd1eSFedor Uporov 	factor = 1;
137b394cd1eSFedor Uporov 	for (i = SINGLE; i < level; i++)
138b394cd1eSFedor Uporov 		factor *= NINDIR(fs);
139b394cd1eSFedor Uporov 	last = lastbn;
140b394cd1eSFedor Uporov 	if (lastbn > 0)
141b394cd1eSFedor Uporov 		last /= factor;
142b394cd1eSFedor Uporov 	nblocks = btodb(fs->e2fs_bsize);
143b394cd1eSFedor Uporov 	/*
144b394cd1eSFedor Uporov 	 * Get buffer of block pointers, zero those entries corresponding
145b394cd1eSFedor Uporov 	 * to blocks to be free'd, and update on disk copy first.  Since
146b394cd1eSFedor Uporov 	 * double(triple) indirect before single(double) indirect, calls
147b394cd1eSFedor Uporov 	 * to bmap on these blocks will fail.  However, we already have
148b394cd1eSFedor Uporov 	 * the on disk address, so we have to set the b_blkno field
149b394cd1eSFedor Uporov 	 * explicitly instead of letting bread do everything for us.
150b394cd1eSFedor Uporov 	 */
151b394cd1eSFedor Uporov 	vp = ITOV(ip);
152b394cd1eSFedor Uporov 	bp = getblk(vp, lbn, (int)fs->e2fs_bsize, 0, 0, 0);
153b394cd1eSFedor Uporov 	if ((bp->b_flags & (B_DONE | B_DELWRI)) == 0) {
154b394cd1eSFedor Uporov 		bp->b_iocmd = BIO_READ;
155b394cd1eSFedor Uporov 		if (bp->b_bcount > bp->b_bufsize)
156b394cd1eSFedor Uporov 			panic("ext2_indirtrunc: bad buffer size");
157b394cd1eSFedor Uporov 		bp->b_blkno = dbn;
158b394cd1eSFedor Uporov 		vfs_busy_pages(bp, 0);
159b394cd1eSFedor Uporov 		bp->b_iooffset = dbtob(bp->b_blkno);
160b394cd1eSFedor Uporov 		bstrategy(bp);
161b394cd1eSFedor Uporov 		error = bufwait(bp);
162b394cd1eSFedor Uporov 	}
163b394cd1eSFedor Uporov 	if (error) {
164b394cd1eSFedor Uporov 		brelse(bp);
165b394cd1eSFedor Uporov 		*countp = 0;
166b394cd1eSFedor Uporov 		return (error);
167b394cd1eSFedor Uporov 	}
168b394cd1eSFedor Uporov 	bap = (e2fs_daddr_t *)bp->b_data;
169b394cd1eSFedor Uporov 	copy = malloc(fs->e2fs_bsize, M_TEMP, M_WAITOK);
170b394cd1eSFedor Uporov 	bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->e2fs_bsize);
171b394cd1eSFedor Uporov 	bzero((caddr_t)&bap[last + 1],
172b394cd1eSFedor Uporov 	    (NINDIR(fs) - (last + 1)) * sizeof(e2fs_daddr_t));
173b394cd1eSFedor Uporov 	if (last == -1)
174b394cd1eSFedor Uporov 		bp->b_flags |= B_INVAL;
175b394cd1eSFedor Uporov 	if (DOINGASYNC(vp)) {
176b394cd1eSFedor Uporov 		bdwrite(bp);
177b394cd1eSFedor Uporov 	} else {
178b394cd1eSFedor Uporov 		error = bwrite(bp);
179b394cd1eSFedor Uporov 		if (error)
180b394cd1eSFedor Uporov 			allerror = error;
181b394cd1eSFedor Uporov 	}
182b394cd1eSFedor Uporov 	bap = copy;
183b394cd1eSFedor Uporov 
184b394cd1eSFedor Uporov 	/*
185b394cd1eSFedor Uporov 	 * Recursively free totally unused blocks.
186b394cd1eSFedor Uporov 	 */
187b394cd1eSFedor Uporov 	for (i = NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last;
188b394cd1eSFedor Uporov 	    i--, nlbn += factor) {
189cd3acfe7SFedor Uporov 		nb = le32toh(bap[i]);
190b394cd1eSFedor Uporov 		if (nb == 0)
191b394cd1eSFedor Uporov 			continue;
192b394cd1eSFedor Uporov 		if (level > SINGLE) {
193b394cd1eSFedor Uporov 			if ((error = ext2_indirtrunc(ip, nlbn,
194b394cd1eSFedor Uporov 			    fsbtodb(fs, nb), (int32_t)-1, level - 1, &blkcount)) != 0)
195b394cd1eSFedor Uporov 				allerror = error;
196b394cd1eSFedor Uporov 			blocksreleased += blkcount;
197b394cd1eSFedor Uporov 		}
198b394cd1eSFedor Uporov 		ext2_blkfree(ip, nb, fs->e2fs_bsize);
199b394cd1eSFedor Uporov 		blocksreleased += nblocks;
200b394cd1eSFedor Uporov 	}
201b394cd1eSFedor Uporov 
202b394cd1eSFedor Uporov 	/*
203b394cd1eSFedor Uporov 	 * Recursively free last partial block.
204b394cd1eSFedor Uporov 	 */
205b394cd1eSFedor Uporov 	if (level > SINGLE && lastbn >= 0) {
206b394cd1eSFedor Uporov 		last = lastbn % factor;
207cd3acfe7SFedor Uporov 		nb = le32toh(bap[i]);
208b394cd1eSFedor Uporov 		if (nb != 0) {
209b394cd1eSFedor Uporov 			if ((error = ext2_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
210b394cd1eSFedor Uporov 			    last, level - 1, &blkcount)) != 0)
211b394cd1eSFedor Uporov 				allerror = error;
212b394cd1eSFedor Uporov 			blocksreleased += blkcount;
213b394cd1eSFedor Uporov 		}
214b394cd1eSFedor Uporov 	}
215b394cd1eSFedor Uporov 	free(copy, M_TEMP);
216b394cd1eSFedor Uporov 	*countp = blocksreleased;
217b394cd1eSFedor Uporov 	return (allerror);
218b394cd1eSFedor Uporov }
219b394cd1eSFedor Uporov 
220e09c00caSUlf Lilleengen /*
221e09c00caSUlf Lilleengen  * Truncate the inode oip to at most length size, freeing the
222e09c00caSUlf Lilleengen  * disk blocks.
223e09c00caSUlf Lilleengen  */
224b394cd1eSFedor Uporov static int
ext2_ind_truncate(struct vnode * vp,off_t length,int flags,struct ucred * cred,struct thread * td)225b394cd1eSFedor Uporov ext2_ind_truncate(struct vnode *vp, off_t length, int flags, struct ucred *cred,
226a9d1b299SPedro F. Giffuni     struct thread *td)
227e09c00caSUlf Lilleengen {
228e09c00caSUlf Lilleengen 	struct vnode *ovp = vp;
229ffbde5eaSFedor Uporov 	e4fs_daddr_t lastblock;
230e09c00caSUlf Lilleengen 	struct inode *oip;
231ffbde5eaSFedor Uporov 	e4fs_daddr_t bn, lbn, lastiblock[EXT2_NIADDR], indir_lbn[EXT2_NIADDR];
2321dc349abSEd Maste 	uint32_t oldblks[EXT2_NDADDR + EXT2_NIADDR];
233*c656f5c1SNavdeep Parhar #ifdef INVARIANTS
2341dc349abSEd Maste 	uint32_t newblks[EXT2_NDADDR + EXT2_NIADDR];
235*c656f5c1SNavdeep Parhar #endif
236e09c00caSUlf Lilleengen 	struct m_ext2fs *fs;
237e09c00caSUlf Lilleengen 	struct buf *bp;
238e09c00caSUlf Lilleengen 	int offset, size, level;
23970097aacSPedro F. Giffuni 	e4fs_daddr_t count, nblocks, blocksreleased = 0;
2409e880b87SJohn Baldwin 	int error, i, allerror;
241e09c00caSUlf Lilleengen 	off_t osize;
242ae266f89SEnji Cooper #ifdef INVARIANTS
243ae266f89SEnji Cooper 	struct bufobj *bo;
244ae266f89SEnji Cooper #endif
245e09c00caSUlf Lilleengen 
246e09c00caSUlf Lilleengen 	oip = VTOI(ovp);
247ae266f89SEnji Cooper #ifdef INVARIANTS
248ae266f89SEnji Cooper 	bo = &ovp->v_bufobj;
249ae266f89SEnji Cooper #endif
250e09c00caSUlf Lilleengen 
251e09c00caSUlf Lilleengen 	fs = oip->i_e2fs;
252e09c00caSUlf Lilleengen 	osize = oip->i_size;
253e09c00caSUlf Lilleengen 	/*
254e09c00caSUlf Lilleengen 	 * Lengthen the size of the file. We must ensure that the
255e09c00caSUlf Lilleengen 	 * last byte of the file is allocated. Since the smallest
256e09c00caSUlf Lilleengen 	 * value of osize is 0, length will be at least 1.
257e09c00caSUlf Lilleengen 	 */
258e09c00caSUlf Lilleengen 	if (osize < length) {
259e09c00caSUlf Lilleengen 		if (length > oip->i_e2fs->e2fs_maxfilesize)
260e09c00caSUlf Lilleengen 			return (EFBIG);
261e09c00caSUlf Lilleengen 		vnode_pager_setsize(ovp, length);
262e09c00caSUlf Lilleengen 		offset = blkoff(fs, length - 1);
263e09c00caSUlf Lilleengen 		lbn = lblkno(fs, length - 1);
2649e880b87SJohn Baldwin 		flags |= BA_CLRBUF;
2659e880b87SJohn Baldwin 		error = ext2_balloc(oip, lbn, offset + 1, cred, &bp, flags);
266e09c00caSUlf Lilleengen 		if (error) {
267e09c00caSUlf Lilleengen 			vnode_pager_setsize(vp, osize);
268e09c00caSUlf Lilleengen 			return (error);
269e09c00caSUlf Lilleengen 		}
270e09c00caSUlf Lilleengen 		oip->i_size = length;
271e09c00caSUlf Lilleengen 		if (bp->b_bufsize == fs->e2fs_bsize)
272e09c00caSUlf Lilleengen 			bp->b_flags |= B_CLUSTEROK;
2739e880b87SJohn Baldwin 		if (flags & IO_SYNC)
274e09c00caSUlf Lilleengen 			bwrite(bp);
2759e880b87SJohn Baldwin 		else if (DOINGASYNC(ovp))
276e09c00caSUlf Lilleengen 			bdwrite(bp);
277e09c00caSUlf Lilleengen 		else
278e09c00caSUlf Lilleengen 			bawrite(bp);
279e09c00caSUlf Lilleengen 		oip->i_flag |= IN_CHANGE | IN_UPDATE;
280b187108fSPedro F. Giffuni 		return (ext2_update(ovp, !DOINGASYNC(ovp)));
281e09c00caSUlf Lilleengen 	}
282e09c00caSUlf Lilleengen 	/*
283e09c00caSUlf Lilleengen 	 * Shorten the size of the file. If the file is not being
28491a25a7dSPedro F. Giffuni 	 * truncated to a block boundary, the contents of the
285e09c00caSUlf Lilleengen 	 * partial block following the end of the file must be
286e09c00caSUlf Lilleengen 	 * zero'ed in case it ever become accessible again because
287e09c00caSUlf Lilleengen 	 * of subsequent file growth.
288e09c00caSUlf Lilleengen 	 */
289e09c00caSUlf Lilleengen 	/* I don't understand the comment above */
290e09c00caSUlf Lilleengen 	offset = blkoff(fs, length);
291e09c00caSUlf Lilleengen 	if (offset == 0) {
292e09c00caSUlf Lilleengen 		oip->i_size = length;
293e09c00caSUlf Lilleengen 	} else {
294e09c00caSUlf Lilleengen 		lbn = lblkno(fs, length);
2959e880b87SJohn Baldwin 		flags |= BA_CLRBUF;
2969e880b87SJohn Baldwin 		error = ext2_balloc(oip, lbn, offset, cred, &bp, flags);
297e09c00caSUlf Lilleengen 		if (error)
298e09c00caSUlf Lilleengen 			return (error);
299e09c00caSUlf Lilleengen 		oip->i_size = length;
300e09c00caSUlf Lilleengen 		size = blksize(fs, oip, lbn);
301e09c00caSUlf Lilleengen 		bzero((char *)bp->b_data + offset, (u_int)(size - offset));
302e09c00caSUlf Lilleengen 		allocbuf(bp, size);
303e09c00caSUlf Lilleengen 		if (bp->b_bufsize == fs->e2fs_bsize)
304e09c00caSUlf Lilleengen 			bp->b_flags |= B_CLUSTEROK;
3059e880b87SJohn Baldwin 		if (flags & IO_SYNC)
306e09c00caSUlf Lilleengen 			bwrite(bp);
3079e880b87SJohn Baldwin 		else if (DOINGASYNC(ovp))
308e09c00caSUlf Lilleengen 			bdwrite(bp);
309e09c00caSUlf Lilleengen 		else
310e09c00caSUlf Lilleengen 			bawrite(bp);
311e09c00caSUlf Lilleengen 	}
312e09c00caSUlf Lilleengen 	/*
313e09c00caSUlf Lilleengen 	 * Calculate index into inode's block list of
314e09c00caSUlf Lilleengen 	 * last direct and indirect blocks (if any)
315e09c00caSUlf Lilleengen 	 * which we want to keep.  Lastblock is -1 when
316e09c00caSUlf Lilleengen 	 * the file is truncated to 0.
317e09c00caSUlf Lilleengen 	 */
318e09c00caSUlf Lilleengen 	lastblock = lblkno(fs, length + fs->e2fs_bsize - 1) - 1;
3191dc349abSEd Maste 	lastiblock[SINGLE] = lastblock - EXT2_NDADDR;
320e09c00caSUlf Lilleengen 	lastiblock[DOUBLE] = lastiblock[SINGLE] - NINDIR(fs);
321e09c00caSUlf Lilleengen 	lastiblock[TRIPLE] = lastiblock[DOUBLE] - NINDIR(fs) * NINDIR(fs);
322e09c00caSUlf Lilleengen 	nblocks = btodb(fs->e2fs_bsize);
323e09c00caSUlf Lilleengen 	/*
324e09c00caSUlf Lilleengen 	 * Update file and block pointers on disk before we start freeing
325e09c00caSUlf Lilleengen 	 * blocks.  If we crash before free'ing blocks below, the blocks
326e09c00caSUlf Lilleengen 	 * will be returned to the free list.  lastiblock values are also
327e09c00caSUlf Lilleengen 	 * normalized to -1 for calls to ext2_indirtrunc below.
328e09c00caSUlf Lilleengen 	 */
3298f87059bSPedro F. Giffuni 	for (level = TRIPLE; level >= SINGLE; level--) {
3301dc349abSEd Maste 		oldblks[EXT2_NDADDR + level] = oip->i_ib[level];
331e09c00caSUlf Lilleengen 		if (lastiblock[level] < 0) {
332e09c00caSUlf Lilleengen 			oip->i_ib[level] = 0;
333e09c00caSUlf Lilleengen 			lastiblock[level] = -1;
334e09c00caSUlf Lilleengen 		}
3358f87059bSPedro F. Giffuni 	}
3361dc349abSEd Maste 	for (i = 0; i < EXT2_NDADDR; i++) {
3378f87059bSPedro F. Giffuni 		oldblks[i] = oip->i_db[i];
3388f87059bSPedro F. Giffuni 		if (i > lastblock)
339e09c00caSUlf Lilleengen 			oip->i_db[i] = 0;
3408f87059bSPedro F. Giffuni 	}
341e09c00caSUlf Lilleengen 	oip->i_flag |= IN_CHANGE | IN_UPDATE;
342b187108fSPedro F. Giffuni 	allerror = ext2_update(ovp, !DOINGASYNC(ovp));
343e09c00caSUlf Lilleengen 
344e09c00caSUlf Lilleengen 	/*
345e09c00caSUlf Lilleengen 	 * Having written the new inode to disk, save its new configuration
346e09c00caSUlf Lilleengen 	 * and put back the old block pointers long enough to process them.
347e09c00caSUlf Lilleengen 	 * Note that we save the new block configuration so we can check it
348e09c00caSUlf Lilleengen 	 * when we are done.
349e09c00caSUlf Lilleengen 	 */
3501dc349abSEd Maste 	for (i = 0; i < EXT2_NDADDR; i++) {
351*c656f5c1SNavdeep Parhar #ifdef INVARIANTS
3528f87059bSPedro F. Giffuni 		newblks[i] = oip->i_db[i];
353*c656f5c1SNavdeep Parhar #endif
3548f87059bSPedro F. Giffuni 		oip->i_db[i] = oldblks[i];
3558f87059bSPedro F. Giffuni 	}
3561dc349abSEd Maste 	for (i = 0; i < EXT2_NIADDR; i++) {
357*c656f5c1SNavdeep Parhar #ifdef INVARIANTS
3581dc349abSEd Maste 		newblks[EXT2_NDADDR + i] = oip->i_ib[i];
359*c656f5c1SNavdeep Parhar #endif
3601dc349abSEd Maste 		oip->i_ib[i] = oldblks[EXT2_NDADDR + i];
3618f87059bSPedro F. Giffuni 	}
362e09c00caSUlf Lilleengen 	oip->i_size = osize;
36365417f5eSAlan Somers 	error = vtruncbuf(ovp, length, (int)fs->e2fs_bsize);
364e09c00caSUlf Lilleengen 	if (error && (allerror == 0))
365e09c00caSUlf Lilleengen 		allerror = error;
366e09c00caSUlf Lilleengen 	vnode_pager_setsize(ovp, length);
367e09c00caSUlf Lilleengen 
368e09c00caSUlf Lilleengen 	/*
369e09c00caSUlf Lilleengen 	 * Indirect blocks first.
370e09c00caSUlf Lilleengen 	 */
3711dc349abSEd Maste 	indir_lbn[SINGLE] = -EXT2_NDADDR;
372e09c00caSUlf Lilleengen 	indir_lbn[DOUBLE] = indir_lbn[SINGLE] - NINDIR(fs) - 1;
373e09c00caSUlf Lilleengen 	indir_lbn[TRIPLE] = indir_lbn[DOUBLE] - NINDIR(fs) * NINDIR(fs) - 1;
374e09c00caSUlf Lilleengen 	for (level = TRIPLE; level >= SINGLE; level--) {
375e09c00caSUlf Lilleengen 		bn = oip->i_ib[level];
376e09c00caSUlf Lilleengen 		if (bn != 0) {
377e09c00caSUlf Lilleengen 			error = ext2_indirtrunc(oip, indir_lbn[level],
378e09c00caSUlf Lilleengen 			    fsbtodb(fs, bn), lastiblock[level], level, &count);
379e09c00caSUlf Lilleengen 			if (error)
380e09c00caSUlf Lilleengen 				allerror = error;
381e09c00caSUlf Lilleengen 			blocksreleased += count;
382e09c00caSUlf Lilleengen 			if (lastiblock[level] < 0) {
383e09c00caSUlf Lilleengen 				oip->i_ib[level] = 0;
384e09c00caSUlf Lilleengen 				ext2_blkfree(oip, bn, fs->e2fs_fsize);
385e09c00caSUlf Lilleengen 				blocksreleased += nblocks;
386e09c00caSUlf Lilleengen 			}
387e09c00caSUlf Lilleengen 		}
388e09c00caSUlf Lilleengen 		if (lastiblock[level] >= 0)
389e09c00caSUlf Lilleengen 			goto done;
390e09c00caSUlf Lilleengen 	}
391e09c00caSUlf Lilleengen 
392e09c00caSUlf Lilleengen 	/*
393e09c00caSUlf Lilleengen 	 * All whole direct blocks or frags.
394e09c00caSUlf Lilleengen 	 */
3951dc349abSEd Maste 	for (i = EXT2_NDADDR - 1; i > lastblock; i--) {
396e09c00caSUlf Lilleengen 		long bsize;
397e09c00caSUlf Lilleengen 
398e09c00caSUlf Lilleengen 		bn = oip->i_db[i];
399e09c00caSUlf Lilleengen 		if (bn == 0)
400e09c00caSUlf Lilleengen 			continue;
401e09c00caSUlf Lilleengen 		oip->i_db[i] = 0;
402e09c00caSUlf Lilleengen 		bsize = blksize(fs, oip, i);
403e09c00caSUlf Lilleengen 		ext2_blkfree(oip, bn, bsize);
404e09c00caSUlf Lilleengen 		blocksreleased += btodb(bsize);
405e09c00caSUlf Lilleengen 	}
406e09c00caSUlf Lilleengen 	if (lastblock < 0)
407e09c00caSUlf Lilleengen 		goto done;
408e09c00caSUlf Lilleengen 
409e09c00caSUlf Lilleengen 	/*
410e09c00caSUlf Lilleengen 	 * Finally, look for a change in size of the
411e09c00caSUlf Lilleengen 	 * last direct block; release any frags.
412e09c00caSUlf Lilleengen 	 */
413e09c00caSUlf Lilleengen 	bn = oip->i_db[lastblock];
414e09c00caSUlf Lilleengen 	if (bn != 0) {
415e09c00caSUlf Lilleengen 		long oldspace, newspace;
416e09c00caSUlf Lilleengen 
417e09c00caSUlf Lilleengen 		/*
418e09c00caSUlf Lilleengen 		 * Calculate amount of space we're giving
419e09c00caSUlf Lilleengen 		 * back as old block size minus new block size.
420e09c00caSUlf Lilleengen 		 */
421e09c00caSUlf Lilleengen 		oldspace = blksize(fs, oip, lastblock);
422e09c00caSUlf Lilleengen 		oip->i_size = length;
423e09c00caSUlf Lilleengen 		newspace = blksize(fs, oip, lastblock);
424e09c00caSUlf Lilleengen 		if (newspace == 0)
425757224cbSPedro F. Giffuni 			panic("ext2_truncate: newspace");
426e09c00caSUlf Lilleengen 		if (oldspace - newspace > 0) {
427e09c00caSUlf Lilleengen 			/*
428e09c00caSUlf Lilleengen 			 * Block number of space to be free'd is
429e09c00caSUlf Lilleengen 			 * the old block # plus the number of frags
430e09c00caSUlf Lilleengen 			 * required for the storage we're keeping.
431e09c00caSUlf Lilleengen 			 */
432e09c00caSUlf Lilleengen 			bn += numfrags(fs, newspace);
433e09c00caSUlf Lilleengen 			ext2_blkfree(oip, bn, oldspace - newspace);
434e09c00caSUlf Lilleengen 			blocksreleased += btodb(oldspace - newspace);
435e09c00caSUlf Lilleengen 		}
436e09c00caSUlf Lilleengen 	}
437e09c00caSUlf Lilleengen done:
43877b193c2SPedro F. Giffuni #ifdef INVARIANTS
439e09c00caSUlf Lilleengen 	for (level = SINGLE; level <= TRIPLE; level++)
4401dc349abSEd Maste 		if (newblks[EXT2_NDADDR + level] != oip->i_ib[level])
441e09c00caSUlf Lilleengen 			panic("itrunc1");
4421dc349abSEd Maste 	for (i = 0; i < EXT2_NDADDR; i++)
443e09c00caSUlf Lilleengen 		if (newblks[i] != oip->i_db[i])
444e09c00caSUlf Lilleengen 			panic("itrunc2");
445e09c00caSUlf Lilleengen 	BO_LOCK(bo);
446e09c00caSUlf Lilleengen 	if (length == 0 && (bo->bo_dirty.bv_cnt != 0 ||
447e09c00caSUlf Lilleengen 	    bo->bo_clean.bv_cnt != 0))
448e09c00caSUlf Lilleengen 		panic("itrunc3");
449e09c00caSUlf Lilleengen 	BO_UNLOCK(bo);
45077b193c2SPedro F. Giffuni #endif	/* INVARIANTS */
451e09c00caSUlf Lilleengen 	/*
452e09c00caSUlf Lilleengen 	 * Put back the real size.
453e09c00caSUlf Lilleengen 	 */
454e09c00caSUlf Lilleengen 	oip->i_size = length;
455879aeda7SPedro F. Giffuni 	if (oip->i_blocks >= blocksreleased)
4561d04725aSPedro F. Giffuni 		oip->i_blocks -= blocksreleased;
4571d04725aSPedro F. Giffuni 	else				/* sanity */
458e09c00caSUlf Lilleengen 		oip->i_blocks = 0;
459e09c00caSUlf Lilleengen 	oip->i_flag |= IN_CHANGE;
460e09c00caSUlf Lilleengen 	vnode_pager_setsize(ovp, length);
461e09c00caSUlf Lilleengen 	return (allerror);
462e09c00caSUlf Lilleengen }
463e09c00caSUlf Lilleengen 
464e09c00caSUlf Lilleengen static int
ext2_ext_truncate(struct vnode * vp,off_t length,int flags,struct ucred * cred,struct thread * td)465b394cd1eSFedor Uporov ext2_ext_truncate(struct vnode *vp, off_t length, int flags,
466b394cd1eSFedor Uporov     struct ucred *cred, struct thread *td)
467e09c00caSUlf Lilleengen {
468b394cd1eSFedor Uporov 	struct vnode *ovp = vp;
469b394cd1eSFedor Uporov 	int32_t lastblock;
470b394cd1eSFedor Uporov 	struct m_ext2fs *fs;
471b394cd1eSFedor Uporov 	struct inode *oip;
472e09c00caSUlf Lilleengen 	struct buf *bp;
473b394cd1eSFedor Uporov 	uint32_t lbn, offset;
474b394cd1eSFedor Uporov 	int error, size;
475b394cd1eSFedor Uporov 	off_t osize;
476e09c00caSUlf Lilleengen 
477b394cd1eSFedor Uporov 	oip = VTOI(ovp);
478b394cd1eSFedor Uporov 	fs = oip->i_e2fs;
479b394cd1eSFedor Uporov 	osize = oip->i_size;
480b394cd1eSFedor Uporov 
481b394cd1eSFedor Uporov 	if (osize < length) {
482b394cd1eSFedor Uporov 		if (length > oip->i_e2fs->e2fs_maxfilesize) {
483b394cd1eSFedor Uporov 			return (EFBIG);
484e09c00caSUlf Lilleengen 		}
485b394cd1eSFedor Uporov 		vnode_pager_setsize(ovp, length);
486b394cd1eSFedor Uporov 		offset = blkoff(fs, length - 1);
487b394cd1eSFedor Uporov 		lbn = lblkno(fs, length - 1);
488b394cd1eSFedor Uporov 		flags |= BA_CLRBUF;
489b394cd1eSFedor Uporov 		error = ext2_balloc(oip, lbn, offset + 1, cred, &bp, flags);
490e09c00caSUlf Lilleengen 		if (error) {
491b394cd1eSFedor Uporov 			vnode_pager_setsize(vp, osize);
492e09c00caSUlf Lilleengen 			return (error);
493e09c00caSUlf Lilleengen 		}
494b394cd1eSFedor Uporov 		oip->i_size = length;
495b394cd1eSFedor Uporov 		if (bp->b_bufsize == fs->e2fs_bsize)
496b394cd1eSFedor Uporov 			bp->b_flags |= B_CLUSTEROK;
497b394cd1eSFedor Uporov 		if (flags & IO_SYNC)
498b394cd1eSFedor Uporov 			bwrite(bp);
499b394cd1eSFedor Uporov 		else if (DOINGASYNC(ovp))
500b187108fSPedro F. Giffuni 			bdwrite(bp);
501b394cd1eSFedor Uporov 		else
502b394cd1eSFedor Uporov 			bawrite(bp);
503b394cd1eSFedor Uporov 		oip->i_flag |= IN_CHANGE | IN_UPDATE;
504b394cd1eSFedor Uporov 		return (ext2_update(ovp, !DOINGASYNC(ovp)));
505b394cd1eSFedor Uporov 	}
506b394cd1eSFedor Uporov 
507b394cd1eSFedor Uporov 	lastblock = (length + fs->e2fs_bsize - 1) / fs->e2fs_bsize;
508b394cd1eSFedor Uporov 	error = ext4_ext_remove_space(oip, lastblock, flags, cred, td);
509e09c00caSUlf Lilleengen 	if (error)
510b394cd1eSFedor Uporov 		return (error);
511e09c00caSUlf Lilleengen 
512b394cd1eSFedor Uporov 	offset = blkoff(fs, length);
513b394cd1eSFedor Uporov 	if (offset == 0) {
514b394cd1eSFedor Uporov 		oip->i_size = length;
515b394cd1eSFedor Uporov 	} else {
516b394cd1eSFedor Uporov 		lbn = lblkno(fs, length);
517b394cd1eSFedor Uporov 		flags |= BA_CLRBUF;
518b394cd1eSFedor Uporov 		error = ext2_balloc(oip, lbn, offset, cred, &bp, flags);
519b394cd1eSFedor Uporov 		if (error) {
520b394cd1eSFedor Uporov 			return (error);
521e09c00caSUlf Lilleengen 		}
522b394cd1eSFedor Uporov 		oip->i_size = length;
523b394cd1eSFedor Uporov 		size = blksize(fs, oip, lbn);
524b394cd1eSFedor Uporov 		bzero((char *)bp->b_data + offset, (u_int)(size - offset));
525b394cd1eSFedor Uporov 		allocbuf(bp, size);
526b394cd1eSFedor Uporov 		if (bp->b_bufsize == fs->e2fs_bsize)
527b394cd1eSFedor Uporov 			bp->b_flags |= B_CLUSTEROK;
528b394cd1eSFedor Uporov 		if (flags & IO_SYNC)
529b394cd1eSFedor Uporov 			bwrite(bp);
530b394cd1eSFedor Uporov 		else if (DOINGASYNC(ovp))
531b394cd1eSFedor Uporov 			bdwrite(bp);
532b394cd1eSFedor Uporov 		else
533b394cd1eSFedor Uporov 			bawrite(bp);
534b394cd1eSFedor Uporov 	}
535b394cd1eSFedor Uporov 
536b394cd1eSFedor Uporov 	oip->i_size = osize;
53765417f5eSAlan Somers 	error = vtruncbuf(ovp, length, (int)fs->e2fs_bsize);
538b394cd1eSFedor Uporov 	if (error)
539b394cd1eSFedor Uporov 		return (error);
540b394cd1eSFedor Uporov 
541b394cd1eSFedor Uporov 	vnode_pager_setsize(ovp, length);
542b394cd1eSFedor Uporov 
543b394cd1eSFedor Uporov 	oip->i_size = length;
544b394cd1eSFedor Uporov 	oip->i_flag |= IN_CHANGE | IN_UPDATE;
545b394cd1eSFedor Uporov 	error = ext2_update(ovp, !DOINGASYNC(ovp));
546b394cd1eSFedor Uporov 
547b394cd1eSFedor Uporov 	return (error);
548e09c00caSUlf Lilleengen }
549e09c00caSUlf Lilleengen 
550e09c00caSUlf Lilleengen /*
551b394cd1eSFedor Uporov  * Truncate the inode ip to at most length size, freeing the
552b394cd1eSFedor Uporov  * disk blocks.
553e09c00caSUlf Lilleengen  */
554b394cd1eSFedor Uporov int
ext2_truncate(struct vnode * vp,off_t length,int flags,struct ucred * cred,struct thread * td)555b394cd1eSFedor Uporov ext2_truncate(struct vnode *vp, off_t length, int flags, struct ucred *cred,
556b394cd1eSFedor Uporov     struct thread *td)
557b394cd1eSFedor Uporov {
558b394cd1eSFedor Uporov 	struct inode *ip;
559b394cd1eSFedor Uporov 	int error;
560b394cd1eSFedor Uporov 
561b394cd1eSFedor Uporov 	ASSERT_VOP_LOCKED(vp, "ext2_truncate");
562b394cd1eSFedor Uporov 
563b394cd1eSFedor Uporov 	if (length < 0)
564b394cd1eSFedor Uporov 		return (EINVAL);
565b394cd1eSFedor Uporov 
566b394cd1eSFedor Uporov 	ip = VTOI(vp);
567b394cd1eSFedor Uporov 	if (vp->v_type == VLNK &&
568f784da88SKonstantin Belousov 	    ip->i_size < VFSTOEXT2(vp->v_mount)->um_e2fs->e2fs_maxsymlinklen) {
569b394cd1eSFedor Uporov #ifdef INVARIANTS
570b394cd1eSFedor Uporov 		if (length != 0)
571b394cd1eSFedor Uporov 			panic("ext2_truncate: partial truncate of symlink");
572b394cd1eSFedor Uporov #endif
573b394cd1eSFedor Uporov 		bzero((char *)&ip->i_shortlink, (u_int)ip->i_size);
574b394cd1eSFedor Uporov 		ip->i_size = 0;
575b394cd1eSFedor Uporov 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
576b394cd1eSFedor Uporov 		return (ext2_update(vp, 1));
577e09c00caSUlf Lilleengen 	}
578b394cd1eSFedor Uporov 	if (ip->i_size == length) {
579b394cd1eSFedor Uporov 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
580b394cd1eSFedor Uporov 		return (ext2_update(vp, 0));
581e09c00caSUlf Lilleengen 	}
582b394cd1eSFedor Uporov 
583b394cd1eSFedor Uporov 	if (ip->i_flag & IN_E4EXTENTS)
584b394cd1eSFedor Uporov 		error = ext2_ext_truncate(vp, length, flags, cred, td);
585b394cd1eSFedor Uporov 	else
586b394cd1eSFedor Uporov 		error = ext2_ind_truncate(vp, length, flags, cred, td);
5878b723968SKonstantin Belousov 	cluster_init_vn(&ip->i_clusterw);
588b394cd1eSFedor Uporov 
589b394cd1eSFedor Uporov 	return (error);
590e09c00caSUlf Lilleengen }
591e09c00caSUlf Lilleengen 
592e09c00caSUlf Lilleengen /*
593e09c00caSUlf Lilleengen  *	discard preallocated blocks
594e09c00caSUlf Lilleengen  */
595e09c00caSUlf Lilleengen int
ext2_inactive(struct vop_inactive_args * ap)596a9d1b299SPedro F. Giffuni ext2_inactive(struct vop_inactive_args *ap)
597e09c00caSUlf Lilleengen {
598e09c00caSUlf Lilleengen 	struct vnode *vp = ap->a_vp;
599e09c00caSUlf Lilleengen 	struct inode *ip = VTOI(vp);
600ab21ed17SMateusz Guzik 	struct thread *td = curthread;
601e09c00caSUlf Lilleengen 	int mode, error = 0;
602e09c00caSUlf Lilleengen 
603e09c00caSUlf Lilleengen 	/*
604e09c00caSUlf Lilleengen 	 * Ignore inodes related to stale file handles.
605e09c00caSUlf Lilleengen 	 */
606e09c00caSUlf Lilleengen 	if (ip->i_mode == 0)
607e09c00caSUlf Lilleengen 		goto out;
608e09c00caSUlf Lilleengen 	if (ip->i_nlink <= 0) {
60934f43888SPedro F. Giffuni 		ext2_extattr_free(ip);
610e09c00caSUlf Lilleengen 		error = ext2_truncate(vp, (off_t)0, 0, NOCRED, td);
611e09c00caSUlf Lilleengen 		ip->i_rdev = 0;
612e09c00caSUlf Lilleengen 		mode = ip->i_mode;
613e09c00caSUlf Lilleengen 		ip->i_mode = 0;
614e09c00caSUlf Lilleengen 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
615e09c00caSUlf Lilleengen 		ext2_vfree(vp, ip->i_number, mode);
616e09c00caSUlf Lilleengen 	}
617e09c00caSUlf Lilleengen 	if (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE))
618e09c00caSUlf Lilleengen 		ext2_update(vp, 0);
619e09c00caSUlf Lilleengen out:
620e09c00caSUlf Lilleengen 	/*
621e09c00caSUlf Lilleengen 	 * If we are done with the inode, reclaim it
622e09c00caSUlf Lilleengen 	 * so that it can be reused immediately.
623e09c00caSUlf Lilleengen 	 */
624e09c00caSUlf Lilleengen 	if (ip->i_mode == 0)
625af6e6b87SEdward Tomasz Napierala 		vrecycle(vp);
626e09c00caSUlf Lilleengen 	return (error);
627e09c00caSUlf Lilleengen }
628e09c00caSUlf Lilleengen 
629e09c00caSUlf Lilleengen /*
630e09c00caSUlf Lilleengen  * Reclaim an inode so that it can be used for other purposes.
631e09c00caSUlf Lilleengen  */
632e09c00caSUlf Lilleengen int
ext2_reclaim(struct vop_reclaim_args * ap)633a9d1b299SPedro F. Giffuni ext2_reclaim(struct vop_reclaim_args *ap)
634e09c00caSUlf Lilleengen {
635e09c00caSUlf Lilleengen 	struct inode *ip;
636e09c00caSUlf Lilleengen 	struct vnode *vp = ap->a_vp;
637e09c00caSUlf Lilleengen 
638e09c00caSUlf Lilleengen 	ip = VTOI(vp);
639e09c00caSUlf Lilleengen 	if (ip->i_flag & IN_LAZYMOD) {
640e09c00caSUlf Lilleengen 		ip->i_flag |= IN_MODIFIED;
641e09c00caSUlf Lilleengen 		ext2_update(vp, 0);
642e09c00caSUlf Lilleengen 	}
643e09c00caSUlf Lilleengen 	vfs_hash_remove(vp);
644e09c00caSUlf Lilleengen 	free(vp->v_data, M_EXT2NODE);
645e09c00caSUlf Lilleengen 	vp->v_data = 0;
646e09c00caSUlf Lilleengen 	return (0);
647e09c00caSUlf Lilleengen }
648