Deleted Added
full compact
ext2_subr.c (252103) ext2_subr.c (254260)
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_subr.c 8.2 (Berkeley) 9/21/93
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_subr.c 8.2 (Berkeley) 9/21/93
36 * $FreeBSD: head/sys/fs/ext2fs/ext2_subr.c 252103 2013-06-23 02:44:42Z pfg $
36 * $FreeBSD: head/sys/fs/ext2fs/ext2_subr.c 254260 2013-08-12 21:34:48Z pfg $
37 */
38
39#include <sys/param.h>
40
41#include <sys/proc.h>
42#include <sys/systm.h>
43#include <sys/bio.h>
44#include <sys/buf.h>
45#include <sys/lock.h>
46#include <sys/ucred.h>
47#include <sys/vnode.h>
48
49#include <fs/ext2fs/inode.h>
50#include <fs/ext2fs/ext2_extern.h>
51#include <fs/ext2fs/ext2fs.h>
52#include <fs/ext2fs/fs.h>
37 */
38
39#include <sys/param.h>
40
41#include <sys/proc.h>
42#include <sys/systm.h>
43#include <sys/bio.h>
44#include <sys/buf.h>
45#include <sys/lock.h>
46#include <sys/ucred.h>
47#include <sys/vnode.h>
48
49#include <fs/ext2fs/inode.h>
50#include <fs/ext2fs/ext2_extern.h>
51#include <fs/ext2fs/ext2fs.h>
52#include <fs/ext2fs/fs.h>
53
54#ifdef KDB
53#include <fs/ext2fs/ext2_extents.h>
55#include <fs/ext2fs/ext2_mount.h>
54#include <fs/ext2fs/ext2_mount.h>
55#include <fs/ext2fs/ext2_dinode.h>
56
56
57#ifdef KDB
57void ext2_checkoverlap(struct buf *, struct inode *);
58#endif
59
60/*
61 * Return buffer with the contents of block "offset" from the beginning of
62 * directory "ip". If "res" is non-zero, fill it in with a pointer to the
63 * remaining space in the directory.
64 */
65int
66ext2_blkatoff(struct vnode *vp, off_t offset, char **res, struct buf **bpp)
67{
68 struct inode *ip;
69 struct m_ext2fs *fs;
70 struct buf *bp;
71 e2fs_lbn_t lbn;
72 int bsize, error;
58void ext2_checkoverlap(struct buf *, struct inode *);
59#endif
60
61/*
62 * Return buffer with the contents of block "offset" from the beginning of
63 * directory "ip". If "res" is non-zero, fill it in with a pointer to the
64 * remaining space in the directory.
65 */
66int
67ext2_blkatoff(struct vnode *vp, off_t offset, char **res, struct buf **bpp)
68{
69 struct inode *ip;
70 struct m_ext2fs *fs;
71 struct buf *bp;
72 e2fs_lbn_t lbn;
73 int bsize, error;
74 daddr_t newblk;
75 struct ext4_extent *ep;
76 struct ext4_extent_path path;
73
74 ip = VTOI(vp);
75 fs = ip->i_e2fs;
76 lbn = lblkno(fs, offset);
77 bsize = blksize(fs, ip, lbn);
77
78 ip = VTOI(vp);
79 fs = ip->i_e2fs;
80 lbn = lblkno(fs, offset);
81 bsize = blksize(fs, ip, lbn);
78
79 *bpp = NULL;
82 *bpp = NULL;
80 if ((error = bread(vp, lbn, bsize, NOCRED, &bp)) != 0) {
83
84 /*
85 * The EXT4_EXTENTS requires special treatment, otherwise we can
86 * fall back to the normal path.
87 */
88 if (!(ip->i_flags & EXT4_EXTENTS))
89 goto normal;
90
91 memset(&path, 0, sizeof(path));
92 if (ext4_ext_find_extent(fs, ip, lbn, &path) == NULL)
93 goto normal;
94 ep = path.ep_ext;
95 if (ep == NULL)
96 goto normal;
97
98 newblk = lbn - ep->e_blk +
99 (ep->e_start_lo | (daddr_t)ep->e_start_hi << 32);
100
101 if (path.ep_bp != NULL) {
102 brelse(path.ep_bp);
103 path.ep_bp = NULL;
104 }
105 error = bread(ip->i_devvp, fsbtodb(fs, newblk), bsize, NOCRED, &bp);
106 if (error != 0) {
81 brelse(bp);
82 return (error);
83 }
84 if (res)
85 *res = (char *)bp->b_data + blkoff(fs, offset);
107 brelse(bp);
108 return (error);
109 }
110 if (res)
111 *res = (char *)bp->b_data + blkoff(fs, offset);
112 /*
113 * If EXT4_EXTENTS is enabled we would get a wrong offset so
114 * reset b_offset here.
115 */
116 bp->b_offset = lbn * bsize;
86 *bpp = bp;
87 return (0);
117 *bpp = bp;
118 return (0);
119
120normal:
121 if (*bpp == NULL) {
122 if ((error = bread(vp, lbn, bsize, NOCRED, &bp)) != 0) {
123 brelse(bp);
124 return (error);
125 }
126 if (res)
127 *res = (char *)bp->b_data + blkoff(fs, offset);
128 *bpp = bp;
129 }
130 return (0);
88}
89
90#ifdef KDB
91void
92ext2_checkoverlap(struct buf *bp, struct inode *ip)
93{
94 struct buf *ebp, *ep;
95 int32_t start, last;

--- 125 unchanged lines hidden ---
131}
132
133#ifdef KDB
134void
135ext2_checkoverlap(struct buf *bp, struct inode *ip)
136{
137 struct buf *ebp, *ep;
138 int32_t start, last;

--- 125 unchanged lines hidden ---