* Copyright (c) 1989, 1991, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
* @(#)lfs_balloc.c 8.2 (Berkeley) %G%
#include <sys/resourcevar.h>
#include <miscfs/specfs/specdev.h>
#include <ufs/ufs/quota.h>
#include <ufs/ufs/inode.h>
#include <ufs/ufs/ufsmount.h>
#include <ufs/lfs/lfs_extern.h>
lfs_balloc(vp
, iosize
, lbn
, bpp
)
struct indir indirs
[NIADDR
+2];
* Three cases: it's a block beyond the end of file, it's a block in
* the file that may or may not have been assigned a disk address or
* we're writing an entire block. Note, if the daddr is unassigned,
* the block might still have existed in the cache (if it was read
* or written earlier). If it did, make sure we don't count it as a
* new block or zero out its contents. If it did not, make sure
* we allocate any necessary indirect blocks.
if (error
= ufs_bmaparray(vp
, lbn
, &daddr
, &indirs
[0], &num
, NULL
))
*bpp
= bp
= getblk(vp
, lbn
, fs
->lfs_bsize
, 0, 0);
bb
= VFSTOUFS(vp
->v_mount
)->um_seqinc
;
/* May need to allocate indirect blocks */
for (i
= 1; i
< num
; ++i
)
if (!indirs
[i
].in_exists
) {
getblk(vp
, indirs
[i
].in_lbn
, fs
->lfs_bsize
,
if (!(ibp
->b_flags
& (B_DONE
| B_DELWRI
))) {
if (!ISSPACE(fs
, bb
, curproc
->p_ucred
)){
ip
->i_lfs
->lfs_bfree
-= bb
;
panic ("Indirect block should not exist");
/* Now, we may need to allocate the data block */
if (!(bp
->b_flags
& (B_CACHE
| B_DONE
| B_DELWRI
))) {
if (!ISSPACE(fs
, bb
, curproc
->p_ucred
)) {
ip
->i_lfs
->lfs_bfree
-= bb
;
if (iosize
!= fs
->lfs_bsize
)
else if (iosize
== fs
->lfs_bsize
)
bp
->b_blkno
= daddr
; /* Skip the I/O */