Annotation of kernel/bsd/ufs/lfs/lfs_balloc.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
                      7:  * Reserved.  This file contains Original Code and/or Modifications of
                      8:  * Original Code as defined in and that are subject to the Apple Public
                      9:  * Source License Version 1.1 (the "License").  You may not use this file
                     10:  * except in compliance with the License.  Please obtain a copy of the
                     11:  * License at http://www.apple.com/publicsource and read it before using
                     12:  * this file.
                     13:  * 
                     14:  * The Original Code and all software distributed under the License are
                     15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     19:  * License for the specific language governing rights and limitations
                     20:  * under the License.
                     21:  * 
                     22:  * @APPLE_LICENSE_HEADER_END@
                     23:  */
                     24: 
                     25: /*     $NetBSD: lfs_balloc.c,v 1.2 1994/06/29 06:46:49 cgd Exp $       */
                     26: 
                     27: /*
                     28:  * Copyright (c) 1989, 1991, 1993
                     29:  *     The Regents of the University of California.  All rights reserved.
                     30:  *
                     31:  * Redistribution and use in source and binary forms, with or without
                     32:  * modification, are permitted provided that the following conditions
                     33:  * are met:
                     34:  * 1. Redistributions of source code must retain the above copyright
                     35:  *    notice, this list of conditions and the following disclaimer.
                     36:  * 2. Redistributions in binary form must reproduce the above copyright
                     37:  *    notice, this list of conditions and the following disclaimer in the
                     38:  *    documentation and/or other materials provided with the distribution.
                     39:  * 3. All advertising materials mentioning features or use of this software
                     40:  *    must display the following acknowledgement:
                     41:  *     This product includes software developed by the University of
                     42:  *     California, Berkeley and its contributors.
                     43:  * 4. Neither the name of the University nor the names of its contributors
                     44:  *    may be used to endorse or promote products derived from this software
                     45:  *    without specific prior written permission.
                     46:  *
                     47:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     48:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     49:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     50:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     51:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     52:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     53:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     54:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     55:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     56:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     57:  * SUCH DAMAGE.
                     58:  *
                     59:  *     @(#)lfs_balloc.c        8.1 (Berkeley) 6/11/93
                     60:  */
                     61: #include <sys/param.h>
                     62: #include <sys/buf.h>
                     63: #include <sys/proc.h>
                     64: #include <sys/vnode.h>
                     65: #include <sys/mount.h>
                     66: #include <sys/resourcevar.h>
                     67: #include <sys/trace.h>
                     68: 
                     69: #include <miscfs/specfs/specdev.h>
                     70: 
                     71: #include <ufs/ufs/quota.h>
                     72: #include <ufs/ufs/inode.h>
                     73: #include <ufs/ufs/ufsmount.h>
                     74: 
                     75: #include <ufs/lfs/lfs.h>
                     76: #include <ufs/lfs/lfs_extern.h>
                     77: 
                     78: int
                     79: lfs_balloc(vp, iosize, lbn, bpp)
                     80:        struct vnode *vp;
                     81:        u_long iosize;
                     82:        daddr_t lbn;
                     83:        struct buf **bpp;
                     84: {
                     85:        struct buf *ibp, *bp;
                     86:        struct inode *ip;
                     87:        struct lfs *fs;
                     88:        struct indir indirs[NIADDR+2];
                     89:        daddr_t daddr;
                     90:        int bb, error, i, num;
                     91: 
                     92:        ip = VTOI(vp);
                     93:        fs = ip->i_lfs;
                     94: 
                     95:        /* 
                     96:         * Three cases: it's a block beyond the end of file, it's a block in
                     97:         * the file that may or may not have been assigned a disk address or
                     98:         * we're writing an entire block.  Note, if the daddr is unassigned,
                     99:         * the block might still have existed in the cache (if it was read
                    100:         * or written earlier).  If it did, make sure we don't count it as a
                    101:         * new block or zero out its contents.  If it did not, make sure
                    102:         * we allocate any necessary indirect blocks.
                    103:         */
                    104: 
                    105:        *bpp = NULL;
                    106:        if (error = ufs_bmaparray(vp, lbn, &daddr, &indirs[0], &num, NULL ))
                    107:                return (error);
                    108: 
                    109:        *bpp = bp = getblk(vp, lbn, fs->lfs_bsize, 0, 0);
                    110:        bb = VFSTOUFS(vp->v_mount)->um_seqinc;
                    111:        if (daddr == UNASSIGNED)
                    112:                /* May need to allocate indirect blocks */
                    113:                for (i = 1; i < num; ++i)
                    114:                        if (!indirs[i].in_exists) {
                    115:                                ibp =
                    116:                                    getblk(vp, indirs[i].in_lbn, fs->lfs_bsize,
                    117:                                        0, 0);
                    118:                                if (!(ibp->b_flags & (B_DONE | B_DELWRI))) {
                    119:                                        if (!ISSPACE(fs, bb, curproc->p_ucred)){
                    120:                                                ibp->b_flags |= B_INVAL;
                    121:                                                brelse(ibp);
                    122:                                                error = ENOSPC;
                    123:                                        } else {
                    124:                                                ip->i_blocks += bb;
                    125:                                                ip->i_lfs->lfs_bfree -= bb;
                    126:                                                clrbuf(ibp);
                    127:                                                error = VOP_BWRITE(ibp);
                    128:                                        }
                    129:                                } else
                    130:                                        panic ("Indirect block should not exist");
                    131:                        }
                    132:        if (error) {
                    133:                if (bp)
                    134:                        brelse(bp);
                    135:                return(error);
                    136:        }
                    137: 
                    138: 
                    139:        /* Now, we may need to allocate the data block */
                    140:        if (!(bp->b_flags & (B_CACHE | B_DONE | B_DELWRI))) {
                    141:                if (daddr == UNASSIGNED) 
                    142:                        if (!ISSPACE(fs, bb, curproc->p_ucred)) {
                    143:                                bp->b_flags |= B_INVAL;
                    144:                                brelse(bp);
                    145:                                return(ENOSPC);
                    146:                        } else {
                    147:                                ip->i_blocks += bb;
                    148:                                ip->i_lfs->lfs_bfree -= bb;
                    149:                                if (iosize != fs->lfs_bsize)
                    150:                                        clrbuf(bp);
                    151:                        }
                    152:                else if (iosize == fs->lfs_bsize)
                    153:                        bp->b_blkno = daddr;            /* Skip the I/O */
                    154:                else  {
                    155:                        bp->b_blkno = daddr;
                    156:                        bp->b_flags |= B_READ;
                    157:                        VOP_STRATEGY(bp);
                    158:                        return(biowait(bp));
                    159:                }
                    160:        }
                    161:        return (error);
                    162: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.