1 /* $NetBSD: ffs_inode.c,v 1.108 2011/11/23 19:42:10 bouyer Exp $ */
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Wasabi Systems, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1982, 1986, 1989, 1993
34 * The Regents of the University of California. All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)ffs_inode.c 8.13 (Berkeley) 4/21/95
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: ffs_inode.c,v 1.108 2011/11/23 19:42:10 bouyer Exp $");
66 #if defined(_KERNEL_OPT)
68 #include "opt_quota.h"
71 #include <sys/param.h>
72 #include <sys/systm.h>
75 #include <sys/fstrans.h>
76 #include <sys/kauth.h>
77 #include <sys/kernel.h>
78 #include <sys/malloc.h>
79 #include <sys/mount.h>
81 #include <sys/resourcevar.h>
82 #include <sys/trace.h>
83 #include <sys/vnode.h>
84 #include <sys/wapbl.h>
86 #include <ufs/ufs/quota.h>
87 #include <ufs/ufs/inode.h>
88 #include <ufs/ufs/ufsmount.h>
89 #include <ufs/ufs/ufs_extern.h>
90 #include <ufs/ufs/ufs_bswap.h>
91 #include <ufs/ufs/ufs_wapbl.h>
93 #include <ufs/ffs/fs.h>
94 #include <ufs/ffs/ffs_extern.h>
96 static int ffs_indirtrunc(struct inode
*, daddr_t
, daddr_t
, daddr_t
, int,
100 * Update the access, modified, and inode change times as specified
101 * by the IN_ACCESS, IN_UPDATE, and IN_CHANGE flags respectively.
102 * The IN_MODIFIED flag is used to specify that the inode needs to be
103 * updated but that the times have already been set. The access
104 * and modified times are taken from the second and third parameters;
105 * the inode change time is always taken from the current time. If
106 * UPDATE_WAIT flag is set, or UPDATE_DIROP is set then wait for the
107 * disk write of the inode to complete.
111 ffs_update(struct vnode
*vp
, const struct timespec
*acc
,
112 const struct timespec
*mod
, int updflags
)
121 if (vp
->v_mount
->mnt_flag
& MNT_RDONLY
)
124 FFS_ITIMES(ip
, acc
, mod
, NULL
);
125 if (updflags
& UPDATE_CLOSE
)
126 flags
= ip
->i_flag
& (IN_MODIFIED
| IN_ACCESSED
);
128 flags
= ip
->i_flag
& IN_MODIFIED
;
133 if ((flags
& IN_MODIFIED
) != 0 &&
134 (vp
->v_mount
->mnt_flag
& MNT_ASYNC
) == 0) {
135 waitfor
= updflags
& UPDATE_WAIT
;
136 if ((updflags
& UPDATE_DIROP
) != 0)
137 waitfor
|= UPDATE_WAIT
;
142 * Ensure that uid and gid are correct. This is a temporary
143 * fix until fsck has been changed to do the update.
145 if (fs
->fs_magic
== FS_UFS1_MAGIC
&& /* XXX */
146 fs
->fs_old_inodefmt
< FS_44INODEFMT
) { /* XXX */
147 ip
->i_ffs1_ouid
= ip
->i_uid
; /* XXX */
148 ip
->i_ffs1_ogid
= ip
->i_gid
; /* XXX */
150 error
= bread(ip
->i_devvp
,
151 fsbtodb(fs
, ino_to_fsba(fs
, ip
->i_number
)),
152 (int)fs
->fs_bsize
, NOCRED
, B_MODIFY
, &bp
);
157 ip
->i_flag
&= ~(IN_MODIFIED
| IN_ACCESSED
);
158 /* Keep unlinked inode list up to date */
159 KDASSERT(DIP(ip
, nlink
) == ip
->i_nlink
);
161 if (ip
->i_nlink
> 0) {
162 UFS_WAPBL_UNREGISTER_INODE(ip
->i_ump
->um_mountp
,
163 ip
->i_number
, ip
->i_mode
);
165 UFS_WAPBL_REGISTER_INODE(ip
->i_ump
->um_mountp
,
166 ip
->i_number
, ip
->i_mode
);
169 if (fs
->fs_magic
== FS_UFS1_MAGIC
) {
170 cp
= (char *)bp
->b_data
+
171 (ino_to_fsbo(fs
, ip
->i_number
) * DINODE1_SIZE
);
173 if (UFS_FSNEEDSWAP(fs
))
174 ffs_dinode1_swap(ip
->i_din
.ffs1_din
,
175 (struct ufs1_dinode
*)cp
);
178 memcpy(cp
, ip
->i_din
.ffs1_din
, DINODE1_SIZE
);
180 cp
= (char *)bp
->b_data
+
181 (ino_to_fsbo(fs
, ip
->i_number
) * DINODE2_SIZE
);
183 if (UFS_FSNEEDSWAP(fs
))
184 ffs_dinode2_swap(ip
->i_din
.ffs2_din
,
185 (struct ufs2_dinode
*)cp
);
188 memcpy(cp
, ip
->i_din
.ffs2_din
, DINODE2_SIZE
);
198 #define SINGLE 0 /* index of single indirect block */
199 #define DOUBLE 1 /* index of double indirect block */
200 #define TRIPLE 2 /* index of triple indirect block */
202 * Truncate the inode oip to at most length size, freeing the
206 ffs_truncate(struct vnode
*ovp
, off_t length
, int ioflag
, kauth_cred_t cred
)
209 struct inode
*oip
= VTOI(ovp
);
210 daddr_t bn
, lastiblock
[NIADDR
], indir_lbn
[NIADDR
];
211 daddr_t blks
[NDADDR
+ NIADDR
];
213 int offset
, pgoffset
, level
;
214 int64_t count
, blocksreleased
= 0;
215 int i
, aflag
, nblocks
;
216 int error
, allerror
= 0;
219 struct ufsmount
*ump
= oip
->i_ump
;
221 if (ovp
->v_type
== VCHR
|| ovp
->v_type
== VBLK
||
222 ovp
->v_type
== VFIFO
|| ovp
->v_type
== VSOCK
) {
223 KASSERT(oip
->i_size
== 0);
230 if (ovp
->v_type
== VLNK
&&
231 (oip
->i_size
< ump
->um_maxsymlinklen
||
232 (ump
->um_maxsymlinklen
== 0 && DIP(oip
, blocks
) == 0))) {
233 KDASSERT(length
== 0);
234 memset(SHORTLINK(oip
), 0, (size_t)oip
->i_size
);
236 DIP_ASSIGN(oip
, size
, 0);
237 oip
->i_flag
|= IN_CHANGE
| IN_UPDATE
;
238 return (ffs_update(ovp
, NULL
, NULL
, 0));
240 if (oip
->i_size
== length
) {
241 /* still do a uvm_vnp_setsize() as writesize may be larger */
242 uvm_vnp_setsize(ovp
, length
);
243 oip
->i_flag
|= IN_CHANGE
| IN_UPDATE
;
244 return (ffs_update(ovp
, NULL
, NULL
, 0));
247 if (length
> ump
->um_maxfilesize
)
250 if ((oip
->i_flags
& SF_SNAPSHOT
) != 0)
254 aflag
= ioflag
& IO_SYNC
? B_SYNC
: 0;
257 * Lengthen the size of the file. We must ensure that the
258 * last byte of the file is allocated. Since the smallest
259 * value of osize is 0, length will be at least 1.
262 if (osize
< length
) {
263 if (lblkno(fs
, osize
) < NDADDR
&&
264 lblkno(fs
, osize
) != lblkno(fs
, length
) &&
265 blkroundup(fs
, osize
) != osize
) {
268 eob
= blkroundup(fs
, osize
);
269 uvm_vnp_setwritesize(ovp
, eob
);
270 error
= ufs_balloc_range(ovp
, osize
, eob
- osize
,
273 (void) ffs_truncate(ovp
, osize
,
274 ioflag
& IO_SYNC
, cred
);
277 if (ioflag
& IO_SYNC
) {
278 mutex_enter(ovp
->v_interlock
);
280 trunc_page(osize
& fs
->fs_bmask
),
281 round_page(eob
), PGO_CLEANIT
| PGO_SYNCIO
|
285 uvm_vnp_setwritesize(ovp
, length
);
286 error
= ufs_balloc_range(ovp
, length
- 1, 1, cred
, aflag
);
288 (void) ffs_truncate(ovp
, osize
, ioflag
& IO_SYNC
, cred
);
291 uvm_vnp_setsize(ovp
, length
);
292 oip
->i_flag
|= IN_CHANGE
| IN_UPDATE
;
293 KASSERT(ovp
->v_size
== oip
->i_size
);
294 return (ffs_update(ovp
, NULL
, NULL
, 0));
298 * When truncating a regular file down to a non-block-aligned size,
299 * we must zero the part of last block which is past the new EOF.
300 * We must synchronously flush the zeroed pages to disk
301 * since the new pages will be invalidated as soon as we
302 * inform the VM system of the new, smaller size.
303 * We must do this before acquiring the GLOCK, since fetching
304 * the pages will acquire the GLOCK internally.
305 * So there is a window where another thread could see a whole
306 * zeroed page past EOF, but that's life.
309 offset
= blkoff(fs
, length
);
310 pgoffset
= length
& PAGE_MASK
;
311 if (ovp
->v_type
== VREG
&& (pgoffset
!= 0 || offset
!= 0) &&
318 error
= ufs_balloc_range(ovp
, length
- 1, 1, cred
,
323 lbn
= lblkno(fs
, length
);
324 size
= blksize(fs
, oip
, lbn
);
325 eoz
= MIN(MAX(lblktosize(fs
, lbn
) + size
, round_page(pgoffset
)),
327 ubc_zerorange(&ovp
->v_uobj
, length
, eoz
- length
,
328 UBC_UNMAP_FLAG(ovp
));
329 if (round_page(eoz
) > round_page(length
)) {
330 mutex_enter(ovp
->v_interlock
);
331 error
= VOP_PUTPAGES(ovp
, round_page(length
),
333 PGO_CLEANIT
| PGO_DEACTIVATE
| PGO_JOURNALLOCKED
|
334 ((ioflag
& IO_SYNC
) ? PGO_SYNCIO
: 0));
340 genfs_node_wrlock(ovp
);
341 oip
->i_size
= length
;
342 DIP_ASSIGN(oip
, size
, length
);
343 uvm_vnp_setsize(ovp
, length
);
345 * Calculate index into inode's block list of
346 * last direct and indirect blocks (if any)
347 * which we want to keep. Lastblock is -1 when
348 * the file is truncated to 0.
350 lastblock
= lblkno(fs
, length
+ fs
->fs_bsize
- 1) - 1;
351 lastiblock
[SINGLE
] = lastblock
- NDADDR
;
352 lastiblock
[DOUBLE
] = lastiblock
[SINGLE
] - NINDIR(fs
);
353 lastiblock
[TRIPLE
] = lastiblock
[DOUBLE
] - NINDIR(fs
) * NINDIR(fs
);
354 nblocks
= btodb(fs
->fs_bsize
);
356 * Update file and block pointers on disk before we start freeing
357 * blocks. If we crash before free'ing blocks below, the blocks
358 * will be returned to the free list. lastiblock values are also
359 * normalized to -1 for calls to ffs_indirtrunc below.
362 for (level
= TRIPLE
; level
>= SINGLE
; level
--) {
363 blks
[NDADDR
+ level
] = DIP(oip
, ib
[level
]);
364 if (lastiblock
[level
] < 0 && blks
[NDADDR
+ level
] != 0) {
366 DIP_ASSIGN(oip
, ib
[level
], 0);
367 lastiblock
[level
] = -1;
370 for (i
= 0; i
< NDADDR
; i
++) {
371 blks
[i
] = DIP(oip
, db
[i
]);
372 if (i
> lastblock
&& blks
[i
] != 0) {
374 DIP_ASSIGN(oip
, db
[i
], 0);
377 oip
->i_flag
|= IN_CHANGE
| IN_UPDATE
;
379 error
= ffs_update(ovp
, NULL
, NULL
, UPDATE_WAIT
);
380 if (error
&& !allerror
)
385 * Having written the new inode to disk, save its new configuration
386 * and put back the old block pointers long enough to process them.
387 * Note that we save the new block configuration so we can check it
390 for (i
= 0; i
< NDADDR
; i
++) {
391 bn
= DIP(oip
, db
[i
]);
392 DIP_ASSIGN(oip
, db
[i
], blks
[i
]);
395 for (i
= 0; i
< NIADDR
; i
++) {
396 bn
= DIP(oip
, ib
[i
]);
397 DIP_ASSIGN(oip
, ib
[i
], blks
[NDADDR
+ i
]);
398 blks
[NDADDR
+ i
] = bn
;
402 DIP_ASSIGN(oip
, size
, osize
);
403 error
= vtruncbuf(ovp
, lastblock
+ 1, 0, 0);
404 if (error
&& !allerror
)
408 * Indirect blocks first.
410 indir_lbn
[SINGLE
] = -NDADDR
;
411 indir_lbn
[DOUBLE
] = indir_lbn
[SINGLE
] - NINDIR(fs
) - 1;
412 indir_lbn
[TRIPLE
] = indir_lbn
[DOUBLE
] - NINDIR(fs
) * NINDIR(fs
) - 1;
413 for (level
= TRIPLE
; level
>= SINGLE
; level
--) {
414 if (oip
->i_ump
->um_fstype
== UFS1
)
415 bn
= ufs_rw32(oip
->i_ffs1_ib
[level
],UFS_FSNEEDSWAP(fs
));
417 bn
= ufs_rw64(oip
->i_ffs2_ib
[level
],UFS_FSNEEDSWAP(fs
));
419 error
= ffs_indirtrunc(oip
, indir_lbn
[level
],
420 fsbtodb(fs
, bn
), lastiblock
[level
], level
, &count
);
423 blocksreleased
+= count
;
424 if (lastiblock
[level
] < 0) {
425 DIP_ASSIGN(oip
, ib
[level
], 0);
426 if (oip
->i_ump
->um_mountp
->mnt_wapbl
) {
427 UFS_WAPBL_REGISTER_DEALLOCATION(
428 oip
->i_ump
->um_mountp
,
429 fsbtodb(fs
, bn
), fs
->fs_bsize
);
431 ffs_blkfree(fs
, oip
->i_devvp
, bn
,
432 fs
->fs_bsize
, oip
->i_number
);
433 blocksreleased
+= nblocks
;
436 if (lastiblock
[level
] >= 0)
441 * All whole direct blocks or frags.
443 for (i
= NDADDR
- 1; i
> lastblock
; i
--) {
446 if (oip
->i_ump
->um_fstype
== UFS1
)
447 bn
= ufs_rw32(oip
->i_ffs1_db
[i
], UFS_FSNEEDSWAP(fs
));
449 bn
= ufs_rw64(oip
->i_ffs2_db
[i
], UFS_FSNEEDSWAP(fs
));
452 DIP_ASSIGN(oip
, db
[i
], 0);
453 bsize
= blksize(fs
, oip
, i
);
454 if ((oip
->i_ump
->um_mountp
->mnt_wapbl
) &&
455 (ovp
->v_type
!= VREG
)) {
456 UFS_WAPBL_REGISTER_DEALLOCATION(oip
->i_ump
->um_mountp
,
457 fsbtodb(fs
, bn
), bsize
);
459 ffs_blkfree(fs
, oip
->i_devvp
, bn
, bsize
, oip
->i_number
);
460 blocksreleased
+= btodb(bsize
);
466 * Finally, look for a change in size of the
467 * last direct block; release any frags.
469 if (oip
->i_ump
->um_fstype
== UFS1
)
470 bn
= ufs_rw32(oip
->i_ffs1_db
[lastblock
], UFS_FSNEEDSWAP(fs
));
472 bn
= ufs_rw64(oip
->i_ffs2_db
[lastblock
], UFS_FSNEEDSWAP(fs
));
474 long oldspace
, newspace
;
477 * Calculate amount of space we're giving
478 * back as old block size minus new block size.
480 oldspace
= blksize(fs
, oip
, lastblock
);
481 oip
->i_size
= length
;
482 DIP_ASSIGN(oip
, size
, length
);
483 newspace
= blksize(fs
, oip
, lastblock
);
485 panic("itrunc: newspace");
486 if (oldspace
- newspace
> 0) {
488 * Block number of space to be free'd is
489 * the old block # plus the number of frags
490 * required for the storage we're keeping.
492 bn
+= numfrags(fs
, newspace
);
493 if ((oip
->i_ump
->um_mountp
->mnt_wapbl
) &&
494 (ovp
->v_type
!= VREG
)) {
495 UFS_WAPBL_REGISTER_DEALLOCATION(
496 oip
->i_ump
->um_mountp
, fsbtodb(fs
, bn
),
497 oldspace
- newspace
);
499 ffs_blkfree(fs
, oip
->i_devvp
, bn
,
500 oldspace
- newspace
, oip
->i_number
);
501 blocksreleased
+= btodb(oldspace
- newspace
);
507 for (level
= SINGLE
; level
<= TRIPLE
; level
++)
508 if (blks
[NDADDR
+ level
] != DIP(oip
, ib
[level
]))
510 for (i
= 0; i
< NDADDR
; i
++)
511 if (blks
[i
] != DIP(oip
, db
[i
]))
514 (!LIST_EMPTY(&ovp
->v_cleanblkhd
) || !LIST_EMPTY(&ovp
->v_dirtyblkhd
)))
516 #endif /* DIAGNOSTIC */
518 * Put back the real size.
520 oip
->i_size
= length
;
521 DIP_ASSIGN(oip
, size
, length
);
522 DIP_ADD(oip
, blocks
, -blocksreleased
);
523 genfs_node_unlock(ovp
);
524 oip
->i_flag
|= IN_CHANGE
;
525 UFS_WAPBL_UPDATE(ovp
, NULL
, NULL
, 0);
526 #if defined(QUOTA) || defined(QUOTA2)
527 (void) chkdq(oip
, -blocksreleased
, NOCRED
, 0);
529 KASSERT(ovp
->v_type
!= VREG
|| ovp
->v_size
== oip
->i_size
);
534 * Release blocks associated with the inode ip and stored in the indirect
535 * block bn. Blocks are free'd in LIFO order up to (but not including)
536 * lastbn. If level is greater than SINGLE, the block is an indirect block
537 * and recursive calls to indirtrunc must be used to cleanse other indirect
540 * NB: triple indirect blocks are untested.
543 ffs_indirtrunc(struct inode
*ip
, daddr_t lbn
, daddr_t dbn
, daddr_t lastbn
,
544 int level
, int64_t *countp
)
548 struct fs
*fs
= ip
->i_fs
;
549 int32_t *bap1
= NULL
;
550 int64_t *bap2
= NULL
;
552 daddr_t nb
, nlbn
, last
;
554 int64_t blkcount
, factor
, blocksreleased
= 0;
556 int error
= 0, allerror
= 0;
558 const int needswap
= UFS_FSNEEDSWAP(fs
);
560 #define RBAP(ip, i) (((ip)->i_ump->um_fstype == UFS1) ? \
561 ufs_rw32(bap1[i], needswap) : ufs_rw64(bap2[i], needswap))
562 #define BAP_ASSIGN(ip, i, value) \
564 if ((ip)->i_ump->um_fstype == UFS1) \
571 * Calculate index in current block of last
572 * block to be kept. -1 indicates the entire
573 * block so we need not calculate the index.
576 for (i
= SINGLE
; i
< level
; i
++)
577 factor
*= NINDIR(fs
);
581 nblocks
= btodb(fs
->fs_bsize
);
583 * Get buffer of block pointers, zero those entries corresponding
584 * to blocks to be free'd, and update on disk copy first. Since
585 * double(triple) indirect before single(double) indirect, calls
586 * to bmap on these blocks will fail. However, we already have
587 * the on disk address, so we have to set the b_blkno field
588 * explicitly instead of letting bread do everything for us.
591 error
= ffs_getblk(vp
, lbn
, FFS_NOBLK
, fs
->fs_bsize
, false, &bp
);
596 if (bp
->b_oflags
& (BO_DONE
| BO_DELWRI
)) {
597 /* Braces must be here in case trace evaluates to nothing. */
598 trace(TR_BREADHIT
, pack(vp
, fs
->fs_bsize
), lbn
);
600 trace(TR_BREADMISS
, pack(vp
, fs
->fs_bsize
), lbn
);
601 curlwp
->l_ru
.ru_inblock
++; /* pay for read */
602 bp
->b_flags
|= B_READ
;
603 bp
->b_flags
&= ~B_COWDONE
; /* we change blkno below */
604 if (bp
->b_bcount
> bp
->b_bufsize
)
605 panic("ffs_indirtrunc: bad buffer size");
607 BIO_SETPRIO(bp
, BPRIO_TIMECRITICAL
);
608 VOP_STRATEGY(vp
, bp
);
611 error
= fscow_run(bp
, true);
619 if (ip
->i_ump
->um_fstype
== UFS1
)
620 bap1
= (int32_t *)bp
->b_data
;
622 bap2
= (int64_t *)bp
->b_data
;
624 copy
= malloc(fs
->fs_bsize
, M_TEMP
, M_WAITOK
);
625 memcpy((void *)copy
, bp
->b_data
, (u_int
)fs
->fs_bsize
);
626 for (i
= last
+ 1; i
< NINDIR(fs
); i
++)
627 BAP_ASSIGN(ip
, i
, 0);
631 if (ip
->i_ump
->um_fstype
== UFS1
)
632 bap1
= (int32_t *)copy
;
634 bap2
= (int64_t *)copy
;
638 * Recursively free totally unused blocks.
640 for (i
= NINDIR(fs
) - 1, nlbn
= lbn
+ 1 - i
* factor
; i
> last
;
641 i
--, nlbn
+= factor
) {
645 if (level
> SINGLE
) {
646 error
= ffs_indirtrunc(ip
, nlbn
, fsbtodb(fs
, nb
),
647 (daddr_t
)-1, level
- 1,
651 blocksreleased
+= blkcount
;
653 if ((ip
->i_ump
->um_mountp
->mnt_wapbl
) &&
654 ((level
> SINGLE
) || (ITOV(ip
)->v_type
!= VREG
))) {
655 UFS_WAPBL_REGISTER_DEALLOCATION(ip
->i_ump
->um_mountp
,
656 fsbtodb(fs
, nb
), fs
->fs_bsize
);
658 ffs_blkfree(fs
, ip
->i_devvp
, nb
, fs
->fs_bsize
,
660 blocksreleased
+= nblocks
;
664 * Recursively free last partial block.
666 if (level
> SINGLE
&& lastbn
>= 0) {
667 last
= lastbn
% factor
;
670 error
= ffs_indirtrunc(ip
, nlbn
, fsbtodb(fs
, nb
),
671 last
, level
- 1, &blkcount
);
674 blocksreleased
+= blkcount
;
681 brelse(bp
, BC_INVAL
);
684 *countp
= blocksreleased
;
689 ffs_itimes(struct inode
*ip
, const struct timespec
*acc
,
690 const struct timespec
*mod
, const struct timespec
*cre
)
694 if (!(ip
->i_flag
& (IN_ACCESS
| IN_CHANGE
| IN_UPDATE
| IN_MODIFY
))) {
699 if (ip
->i_flag
& IN_ACCESS
) {
702 DIP_ASSIGN(ip
, atime
, acc
->tv_sec
);
703 DIP_ASSIGN(ip
, atimensec
, acc
->tv_nsec
);
705 if (ip
->i_flag
& (IN_UPDATE
| IN_MODIFY
)) {
706 if ((ip
->i_flags
& SF_SNAPSHOT
) == 0) {
709 DIP_ASSIGN(ip
, mtime
, mod
->tv_sec
);
710 DIP_ASSIGN(ip
, mtimensec
, mod
->tv_nsec
);
714 if (ip
->i_flag
& (IN_CHANGE
| IN_MODIFY
)) {
717 DIP_ASSIGN(ip
, ctime
, cre
->tv_sec
);
718 DIP_ASSIGN(ip
, ctimensec
, cre
->tv_nsec
);
720 if (ip
->i_flag
& (IN_ACCESS
| IN_MODIFY
))
721 ip
->i_flag
|= IN_ACCESSED
;
722 if (ip
->i_flag
& (IN_UPDATE
| IN_CHANGE
))
723 ip
->i_flag
|= IN_MODIFIED
;
724 ip
->i_flag
&= ~(IN_ACCESS
| IN_CHANGE
| IN_UPDATE
| IN_MODIFY
);