Deleted Added
full compact
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)ffs_inode.c 8.5 (Berkeley) 12/30/93
34 * $Id: ffs_inode.c,v 1.6 1994/08/29 06:09:13 davidg Exp $
34 * $Id: ffs_inode.c,v 1.7 1994/09/02 10:24:55 davidg Exp $
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/mount.h>
40#include <sys/proc.h>
41#include <sys/file.h>
42#include <sys/buf.h>

--- 67 unchanged lines hidden (view full) ---

110 /*
111 * Ensure that uid and gid are correct. This is a temporary
112 * fix until fsck has been changed to do the update.
113 */
114 if (fs->fs_inodefmt < FS_44INODEFMT) { /* XXX */
115 ip->i_din.di_ouid = ip->i_uid; /* XXX */
116 ip->i_din.di_ogid = ip->i_gid; /* XXX */
117 } /* XXX */
118 if (error = bread(ip->i_devvp,
119 fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
120 (int)fs->fs_bsize, NOCRED, &bp)) {
118 error = bread(ip->i_devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
119 (int)fs->fs_bsize, NOCRED, &bp);
120 if (error) {
121 brelse(bp);
122 return (error);
123 }
124 *((struct dinode *)bp->b_data +
125 ino_to_fsbo(fs, ip->i_number)) = ip->i_din;
126 if (ap->a_waitfor)
127 return (bwrite(bp));
128 else {

--- 49 unchanged lines hidden (view full) ---

178 oip->i_flag |= IN_CHANGE | IN_UPDATE;
179 return (VOP_UPDATE(ovp, &tv, &tv, 1));
180 }
181 if (oip->i_size == length) {
182 oip->i_flag |= IN_CHANGE | IN_UPDATE;
183 return (VOP_UPDATE(ovp, &tv, &tv, 0));
184 }
185#ifdef QUOTA
186 if (error = getinoquota(oip))
186 error = getinoquota(oip);
187 if (error)
188 return (error);
189#endif
190 vnode_pager_setsize(ovp, (u_long)length);
191 fs = oip->i_fs;
192 osize = oip->i_size;
193 /*
194 * Lengthen the size of the file. We must ensure that the
195 * last byte of the file is allocated. Since the smallest
196 * value of osize is 0, length will be at least 1.
197 */
198 if (osize < length) {
199 offset = blkoff(fs, length - 1);
200 lbn = lblkno(fs, length - 1);
201 aflags = B_CLRBUF;
202 if (ap->a_flags & IO_SYNC)
203 aflags |= B_SYNC;
203 if (error = ffs_balloc(oip, lbn, offset + 1, ap->a_cred, &bp,
204 aflags))
204 error = ffs_balloc(oip, lbn, offset + 1, ap->a_cred,
205 &bp, aflags);
206 if (error)
207 return (error);
208 oip->i_size = length;
209 if (aflags & IO_SYNC)
210 bwrite(bp);
211 else
212 bawrite(bp);
213 oip->i_flag |= IN_CHANGE | IN_UPDATE;
214 return (VOP_UPDATE(ovp, &tv, &tv, 1));

--- 8 unchanged lines hidden (view full) ---

223 offset = blkoff(fs, length);
224 if (offset == 0) {
225 oip->i_size = length;
226 } else {
227 lbn = lblkno(fs, length);
228 aflags = B_CLRBUF;
229 if (ap->a_flags & IO_SYNC)
230 aflags |= B_SYNC;
229 if (error = ffs_balloc(oip, lbn, offset, ap->a_cred, &bp,
230 aflags))
231 error = ffs_balloc(oip, lbn, offset, ap->a_cred, &bp, aflags);
232 if (error)
233 return (error);
234 oip->i_size = length;
235 size = blksize(fs, oip, lbn);
236 bzero((char *)bp->b_data + offset, (u_int)(size - offset));
237 allocbuf(bp, size);
238 if (aflags & IO_SYNC)
239 bwrite(bp);
240 else

--- 20 unchanged lines hidden (view full) ---

261 for (level = TRIPLE; level >= SINGLE; level--)
262 if (lastiblock[level] < 0) {
263 oip->i_ib[level] = 0;
264 lastiblock[level] = -1;
265 }
266 for (i = NDADDR - 1; i > lastblock; i--)
267 oip->i_db[i] = 0;
268 oip->i_flag |= IN_CHANGE | IN_UPDATE;
267 if (error = VOP_UPDATE(ovp, &tv, &tv, MNT_WAIT))
269 error = VOP_UPDATE(ovp, &tv, &tv, MNT_WAIT);
270 if (error)
271 allerror = error;
272 /*
273 * Having written the new inode to disk, save its new configuration
274 * and put back the old block pointers long enough to process them.
275 * Note that we save the new block configuration so we can check it
276 * when we are done.
277 */
278 bcopy((caddr_t)&oip->i_db[0], (caddr_t)newblks, sizeof newblks);

--- 181 unchanged lines hidden (view full) ---

460 * Recursively free totally unused blocks.
461 */
462 for (i = NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last;
463 i--, nlbn += factor) {
464 nb = bap[i];
465 if (nb == 0)
466 continue;
467 if (level > SINGLE) {
465 if (error = ffs_indirtrunc(ip, nlbn,
466 fsbtodb(fs, nb), (daddr_t)-1, level - 1, &blkcount))
468 error = ffs_indirtrunc(ip, nlbn,
469 fsbtodb(fs, nb), (daddr_t)-1, level - 1, &blkcount);
470 if (error)
471 allerror = error;
472 blocksreleased += blkcount;
473 }
474 ffs_blkfree(ip, nb, fs->fs_bsize);
475 blocksreleased += nblocks;
476 }
477
478 /*
479 * Recursively free last partial block.
480 */
481 if (level > SINGLE && lastbn >= 0) {
482 last = lastbn % factor;
483 nb = bap[i];
484 if (nb != 0) {
481 if (error = ffs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
482 last, level - 1, &blkcount))
485 error = ffs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
486 last, level - 1, &blkcount);
487 if (error)
488 allerror = error;
489 blocksreleased += blkcount;
490 }
491 }
492 FREE(copy, M_TEMP);
493 *countp = blocksreleased;
494 return (allerror);
495}