ext2fs_subr.c revision 1.6 1 /* $NetBSD: ext2fs_subr.c,v 1.6 2001/11/08 02:39:07 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1997 Manuel Bouyer.
5 * Copyright (c) 1982, 1986, 1989, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)ffs_subr.c 8.2 (Berkeley) 9/21/93
37 * Modified for ext2fs by Manuel Bouyer.
38 */
39
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: ext2fs_subr.c,v 1.6 2001/11/08 02:39:07 lukem Exp $");
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/vnode.h>
46 #include <sys/buf.h>
47 #include <ufs/ufs/inode.h>
48 #include <ufs/ext2fs/ext2fs.h>
49 #include <ufs/ext2fs/ext2fs_extern.h>
50
51 /*
52 * Return buffer with the contents of block "offset" from the beginning of
53 * directory "ip". If "res" is non-zero, fill it in with a pointer to the
54 * remaining space in the directory.
55 */
56 int
57 ext2fs_blkatoff(v)
58 void *v;
59 {
60 struct vop_blkatoff_args /* {
61 struct vnode *a_vp;
62 off_t a_offset;
63 char **a_res;
64 struct buf **a_bpp;
65 } */ *ap = v;
66 struct inode *ip;
67 struct m_ext2fs *fs;
68 struct buf *bp;
69 ufs_daddr_t lbn;
70 int error;
71
72 ip = VTOI(ap->a_vp);
73 fs = ip->i_e2fs;
74 lbn = lblkno(fs, ap->a_offset);
75
76 *ap->a_bpp = NULL;
77 if ((error = bread(ap->a_vp, lbn, fs->e2fs_bsize, NOCRED, &bp)) != 0) {
78 brelse(bp);
79 return (error);
80 }
81 if (ap->a_res)
82 *ap->a_res = (char *)bp->b_data + blkoff(fs, ap->a_offset);
83 *ap->a_bpp = bp;
84 return (0);
85 }
86
87 #ifdef DIAGNOSTIC
88 void
89 ext2fs_checkoverlap(bp, ip)
90 struct buf *bp;
91 struct inode *ip;
92 {
93 struct buf *ebp, *ep;
94 ufs_daddr_t start, last;
95 struct vnode *vp;
96
97 ebp = &buf[nbuf];
98 start = bp->b_blkno;
99 last = start + btodb(bp->b_bcount) - 1;
100 for (ep = buf; ep < ebp; ep++) {
101 if (ep == bp || (ep->b_flags & B_INVAL) ||
102 ep->b_vp == NULLVP)
103 continue;
104 if (VOP_BMAP(ep->b_vp, (ufs_daddr_t)0, &vp, (ufs_daddr_t)0, NULL))
105 continue;
106 if (vp != ip->i_devvp)
107 continue;
108 /* look for overlap */
109 if (ep->b_bcount == 0 || ep->b_blkno > last ||
110 ep->b_blkno + btodb(ep->b_bcount) <= start)
111 continue;
112 vprint("Disk overlap", vp);
113 printf("\tstart %d, end %d overlap start %d, end %ld\n",
114 start, last, ep->b_blkno,
115 ep->b_blkno + btodb(ep->b_bcount) - 1);
116 panic("Disk buffer overlap");
117 }
118 }
119 #endif
120