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