1/*- 2 * modified for Lites 1.1 3 * 4 * Aug 1995, Godmar Back (gback@cs.utah.edu) 5 * University of Utah, Department of Computer Science 6 */ 7/*- 8 * Copyright (c) 1982, 1986, 1989, 1993 --- 19 unchanged lines hidden (view full) --- 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)ffs_alloc.c 8.8 (Berkeley) 2/21/94 |
36 * $FreeBSD: head/sys/fs/ext2fs/ext2_alloc.c 254283 2013-08-13 15:40:43Z pfg $ |
37 */ 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/conf.h> 42#include <sys/vnode.h> 43#include <sys/stat.h> 44#include <sys/mount.h> --- 30 unchanged lines hidden (view full) --- 75 * If no block preference is given the following hierarchy is used 76 * to allocate a block: 77 * 1) allocate a block in the cylinder group that contains the 78 * inode for the file. 79 * 2) quadradically rehash into other cylinder groups, until an 80 * available block is located. 81 */ 82int |
83ext2_alloc(struct inode *ip, daddr_t lbn, e4fs_daddr_t bpref, int size, 84 struct ucred *cred, e4fs_daddr_t *bnp) |
85{ 86 struct m_ext2fs *fs; 87 struct ext2mount *ump; 88 int32_t bno; 89 int cg; 90 *bnp = 0; 91 fs = ip->i_e2fs; 92 ump = ip->i_ump; --- 68 unchanged lines hidden (view full) --- 161 struct inode *ip; 162 struct vnode *vp; 163 struct buf *sbp, *ebp; 164 uint32_t *bap, *sbap, *ebap = 0; 165 struct ext2mount *ump; 166 struct cluster_save *buflist; 167 struct indir start_ap[NIADDR + 1], end_ap[NIADDR + 1], *idp; 168 e2fs_lbn_t start_lbn, end_lbn; |
169 int soff; 170 e2fs_daddr_t newblk, blkno; |
171 int i, len, start_lvl, end_lvl, pref, ssize; 172 173 if (doreallocblks == 0) 174 return (ENOSPC); 175 176 vp = ap->a_vp; 177 ip = VTOI(vp); 178 fs = ip->i_e2fs; --- 67 unchanged lines hidden (view full) --- 246 /* 247 * Find the preferred location for the cluster. 248 */ 249 EXT2_LOCK(ump); 250 pref = ext2_blkpref(ip, start_lbn, soff, sbap, 0); 251 /* 252 * Search the block map looking for an allocation of the desired size. 253 */ |
254 if ((newblk = (e2fs_daddr_t)ext2_hashalloc(ip, dtog(fs, pref), pref, |
255 len, ext2_clusteralloc)) == 0){ 256 EXT2_UNLOCK(ump); 257 goto fail; 258 } 259 /* 260 * We have found a new contiguous block. 261 * 262 * First we have to replace the old block pointers with the new --- 283 unchanged lines hidden (view full) --- 546 * we note: blocknr == 0 means that we're about to allocate either 547 * a direct block or a pointer block at the first level of indirection 548 * (In other words, stuff that will go in i_db[] or i_ib[]) 549 * 550 * blocknr != 0 means that we're allocating a block that is none 551 * of the above. Then, blocknr tells us the number of the block 552 * that will hold the pointer 553 */ |
554e4fs_daddr_t 555ext2_blkpref(struct inode *ip, e2fs_lbn_t lbn, int indx, e2fs_daddr_t *bap, 556 e2fs_daddr_t blocknr) |
557{ 558 int tmp; 559 mtx_assert(EXT2_MTX(ip->i_ump), MA_OWNED); 560 561 /* if the next block is actually what we thought it is, 562 then set the goal to what we thought it should be 563 */ 564 if (ip->i_next_alloc_block == lbn && ip->i_next_alloc_goal != 0) --- 6 unchanged lines hidden (view full) --- 571 for (tmp = indx - 1; tmp >= 0; tmp--) 572 if (bap[tmp]) 573 return bap[tmp]; 574 575 /* else let's fall back to the blocknr, or, if there is none, 576 follow the rule that a block should be allocated near its inode 577 */ 578 return blocknr ? blocknr : |
579 (e2fs_daddr_t)(ip->i_block_group * |
580 EXT2_BLOCKS_PER_GROUP(ip->i_e2fs)) + 581 ip->i_e2fs->e2fs->e2fs_first_dblock; 582} 583 584/* 585 * Implement the cylinder overflow algorithm. 586 * 587 * The policy implemented by this algorithm is: --- 363 unchanged lines hidden (view full) --- 951 return (cg * fs->e2fs->e2fs_ipg + ipref +1); 952} 953 954/* 955 * Free a block or fragment. 956 * 957 */ 958void |
959ext2_blkfree(struct inode *ip, e4fs_daddr_t bno, long size) |
960{ 961 struct m_ext2fs *fs; 962 struct buf *bp; 963 struct ext2mount *ump; 964 int cg, error; 965 char *bbp; 966 967 fs = ip->i_e2fs; --- 146 unchanged lines hidden --- |