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
--- 23 unchanged lines hidden (view full) ---
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)ffs_balloc.c 8.4 (Berkeley) 9/23/93
40 * $FreeBSD: head/sys/gnu/fs/ext2fs/ext2_balloc.c 96752 2002-05-16 19:43:28Z iedowse $
41 */
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/bio.h>
46#include <sys/buf.h>
47#include <sys/lock.h>
48#include <sys/ucred.h>
--- 8 unchanged lines hidden (view full) ---
57/*
58 * Balloc defines the structure of file system storage
59 * by allocating the physical blocks on a device given
60 * the inode and the logical block number in a file.
61 */
62int
63ext2_balloc(ip, bn, size, cred, bpp, flags)
64 struct inode *ip;
65 daddr_t bn;
66 int size;
67 struct ucred *cred;
68 struct buf **bpp;
69 int flags;
70{
71 struct ext2_sb_info *fs;
72 daddr_t nb;
73 struct buf *bp, *nbp;
74 struct vnode *vp = ITOV(ip);
75 struct indir indirs[NIADDR + 2];
76 daddr_t newb, lbn, *bap, pref;
77 int osize, nsize, num, i, error;
78/*
79ext2_debug("ext2_balloc called (%d, %d, %d)\n",
80 ip->i_number, (int)bn, (int)size);
81*/
82 *bpp = NULL;
83 if (bn < 0)
84 return (EFBIG);
--- 84 unchanged lines hidden (view full) ---
169#endif
170 /*
171 * Fetch the first indirect block allocating if necessary.
172 */
173 --num;
174 nb = ip->i_ib[indirs[0].in_off];
175 if (nb == 0) {
176#if 0
177 pref = ext2_blkpref(ip, lbn, 0, (daddr_t *)0, 0);
178#else
179 /* see the comment by ext2_blkpref. What we do here is
180 to pretend that it'd be good for a block holding indirect
181 pointers to be allocated near its predecessor in terms
182 of indirection, or the last direct block.
183 We shamelessly exploit the fact that i_ib immediately
184 follows i_db.
185 Godmar thinks it make sense to allocate i_ib[0] immediately
--- 27 unchanged lines hidden (view full) ---
213 */
214 for (i = 1;;) {
215 error = bread(vp,
216 indirs[i].in_lbn, (int)fs->s_blocksize, NOCRED, &bp);
217 if (error) {
218 brelse(bp);
219 return (error);
220 }
221 bap = (daddr_t *)bp->b_data;
222 nb = bap[indirs[i].in_off];
223 if (i == num)
224 break;
225 i += 1;
226 if (nb != 0) {
227 brelse(bp);
228 continue;
229 }
230 if (pref == 0)
231#if 1
232 /* see the comment above and by ext2_blkpref
233 * I think this implements Linux policy, but
234 * does it really make sense to allocate to
235 * block containing pointers together ?
236 * Also, will it ever succeed ?
237 */
238 pref = ext2_blkpref(ip, lbn, indirs[i].in_off, bap,
239 bp->b_lblkno);
240#else
241 pref = ext2_blkpref(ip, lbn, 0, (daddr_t *)0, 0);
242#endif
243 if ((error =
244 ext2_alloc(ip, lbn, pref, (int)fs->s_blocksize, cred, &newb)) != 0) {
245 brelse(bp);
246 return (error);
247 }
248 nb = newb;
249 nbp = getblk(vp, indirs[i].in_lbn, fs->s_blocksize, 0, 0);
--- 65 unchanged lines hidden ---
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
--- 23 unchanged lines hidden (view full) ---
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)ffs_balloc.c 8.4 (Berkeley) 9/23/93
40 * $FreeBSD: head/sys/gnu/fs/ext2fs/ext2_balloc.c 96752 2002-05-16 19:43:28Z iedowse $
41 */
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/bio.h>
46#include <sys/buf.h>
47#include <sys/lock.h>
48#include <sys/ucred.h>
--- 8 unchanged lines hidden (view full) ---
57/*
58 * Balloc defines the structure of file system storage
59 * by allocating the physical blocks on a device given
60 * the inode and the logical block number in a file.
61 */
62int
63ext2_balloc(ip, bn, size, cred, bpp, flags)
64 struct inode *ip;
65 daddr_t bn;
66 int size;
67 struct ucred *cred;
68 struct buf **bpp;
69 int flags;
70{
71 struct ext2_sb_info *fs;
72 daddr_t nb;
73 struct buf *bp, *nbp;
74 struct vnode *vp = ITOV(ip);
75 struct indir indirs[NIADDR + 2];
76 daddr_t newb, lbn, *bap, pref;
77 int osize, nsize, num, i, error;
78/*
79ext2_debug("ext2_balloc called (%d, %d, %d)\n",
80 ip->i_number, (int)bn, (int)size);
81*/
82 *bpp = NULL;
83 if (bn < 0)
84 return (EFBIG);
--- 84 unchanged lines hidden (view full) ---
169#endif
170 /*
171 * Fetch the first indirect block allocating if necessary.
172 */
173 --num;
174 nb = ip->i_ib[indirs[0].in_off];
175 if (nb == 0) {
176#if 0
177 pref = ext2_blkpref(ip, lbn, 0, (daddr_t *)0, 0);
178#else
179 /* see the comment by ext2_blkpref. What we do here is
180 to pretend that it'd be good for a block holding indirect
181 pointers to be allocated near its predecessor in terms
182 of indirection, or the last direct block.
183 We shamelessly exploit the fact that i_ib immediately
184 follows i_db.
185 Godmar thinks it make sense to allocate i_ib[0] immediately
--- 27 unchanged lines hidden (view full) ---
213 */
214 for (i = 1;;) {
215 error = bread(vp,
216 indirs[i].in_lbn, (int)fs->s_blocksize, NOCRED, &bp);
217 if (error) {
218 brelse(bp);
219 return (error);
220 }
221 bap = (daddr_t *)bp->b_data;
222 nb = bap[indirs[i].in_off];
223 if (i == num)
224 break;
225 i += 1;
226 if (nb != 0) {
227 brelse(bp);
228 continue;
229 }
230 if (pref == 0)
231#if 1
232 /* see the comment above and by ext2_blkpref
233 * I think this implements Linux policy, but
234 * does it really make sense to allocate to
235 * block containing pointers together ?
236 * Also, will it ever succeed ?
237 */
238 pref = ext2_blkpref(ip, lbn, indirs[i].in_off, bap,
239 bp->b_lblkno);
240#else
241 pref = ext2_blkpref(ip, lbn, 0, (daddr_t *)0, 0);
242#endif
243 if ((error =
244 ext2_alloc(ip, lbn, pref, (int)fs->s_blocksize, cred, &newb)) != 0) {
245 brelse(bp);
246 return (error);
247 }
248 nb = newb;
249 nbp = getblk(vp, indirs[i].in_lbn, fs->s_blocksize, 0, 0);
--- 65 unchanged lines hidden ---