Deleted Added
full compact
ext2_bmap.c (252103) ext2_bmap.c (254260)
1/*-
2 * Copyright (c) 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 18 unchanged lines hidden (view full) ---

27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)ufs_bmap.c 8.7 (Berkeley) 3/21/95
1/*-
2 * Copyright (c) 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 18 unchanged lines hidden (view full) ---

27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)ufs_bmap.c 8.7 (Berkeley) 3/21/95
35 * $FreeBSD: head/sys/fs/ext2fs/ext2_bmap.c 252103 2013-06-23 02:44:42Z pfg $
35 * $FreeBSD: head/sys/fs/ext2fs/ext2_bmap.c 254260 2013-08-12 21:34:48Z pfg $
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/bio.h>
41#include <sys/buf.h>
42#include <sys/proc.h>
43#include <sys/vnode.h>
44#include <sys/mount.h>
45#include <sys/resourcevar.h>
46#include <sys/stat.h>
47
48#include <fs/ext2fs/inode.h>
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/bio.h>
41#include <sys/buf.h>
42#include <sys/proc.h>
43#include <sys/vnode.h>
44#include <sys/mount.h>
45#include <sys/resourcevar.h>
46#include <sys/stat.h>
47
48#include <fs/ext2fs/inode.h>
49#include <fs/ext2fs/fs.h>
49#include <fs/ext2fs/ext2fs.h>
50#include <fs/ext2fs/ext2fs.h>
51#include <fs/ext2fs/ext2_dinode.h>
50#include <fs/ext2fs/ext2_extern.h>
51#include <fs/ext2fs/ext2_mount.h>
52
52#include <fs/ext2fs/ext2_extern.h>
53#include <fs/ext2fs/ext2_mount.h>
54
55static int ext4_bmapext(struct vnode *, int32_t, int64_t *, int *, int *);
56
53/*
54 * Bmap converts the logical block number of a file to its physical block
55 * number on the disk. The conversion is done by using the logical block
56 * number to index into the array of block pointers described by the dinode.
57 */
58int
59ext2_bmap(struct vop_bmap_args *ap)
60{
57/*
58 * Bmap converts the logical block number of a file to its physical block
59 * number on the disk. The conversion is done by using the logical block
60 * number to index into the array of block pointers described by the dinode.
61 */
62int
63ext2_bmap(struct vop_bmap_args *ap)
64{
61 int32_t blkno;
65 int64_t blkno;
62 int error;
63
64 /*
65 * Check for underlying vnode requests and ensure that logical
66 * to physical mapping is requested.
67 */
68 if (ap->a_bop != NULL)
69 *ap->a_bop = &VTOI(ap->a_vp)->i_devvp->v_bufobj;
70 if (ap->a_bnp == NULL)
71 return (0);
72
66 int error;
67
68 /*
69 * Check for underlying vnode requests and ensure that logical
70 * to physical mapping is requested.
71 */
72 if (ap->a_bop != NULL)
73 *ap->a_bop = &VTOI(ap->a_vp)->i_devvp->v_bufobj;
74 if (ap->a_bnp == NULL)
75 return (0);
76
73 error = ext2_bmaparray(ap->a_vp, ap->a_bn, &blkno,
74 ap->a_runp, ap->a_runb);
77 if (VTOI(ap->a_vp)->i_flags & EXT4_EXTENTS)
78 error = ext4_bmapext(ap->a_vp, ap->a_bn, &blkno,
79 ap->a_runp, ap->a_runb);
80 else
81 error = ext2_bmaparray(ap->a_vp, ap->a_bn, &blkno,
82 ap->a_runp, ap->a_runb);
75 *ap->a_bnp = blkno;
76 return (error);
77}
78
79/*
83 *ap->a_bnp = blkno;
84 return (error);
85}
86
87/*
88 * This function converts the logical block number of a file to
89 * its physical block number on the disk within ext4 extents.
90 */
91static int
92ext4_bmapext(struct vnode *vp, int32_t bn, int64_t *bnp, int *runp, int *runb)
93{
94 struct inode *ip;
95 struct m_ext2fs *fs;
96 struct ext4_extent *ep;
97 struct ext4_extent_path path;
98 daddr_t lbn;
99
100 ip = VTOI(vp);
101 fs = ip->i_e2fs;
102 lbn = bn;
103
104 /*
105 * TODO: need to implement read ahead to improve the performance.
106 */
107 if (runp != NULL)
108 *runp = 0;
109
110 if (runb != NULL)
111 *runb = 0;
112
113 ext4_ext_find_extent(fs, ip, lbn, &path);
114 ep = path.ep_ext;
115 if (ep == NULL)
116 return (EIO);
117
118 *bnp = fsbtodb(fs, lbn - ep->e_blk +
119 (ep->e_start_lo | (daddr_t)ep->e_start_hi << 32));
120
121 if (*bnp == 0)
122 *bnp = -1;
123
124 return (0);
125}
126
127/*
80 * Indirect blocks are now on the vnode for the file. They are given negative
81 * logical block numbers. Indirect blocks are addressed by the negative
82 * address of the first data block to which they point. Double indirect blocks
83 * are addressed by one less than the address of the first indirect block to
84 * which they point. Triple indirect blocks are addressed by one less than
85 * the address of the first double indirect block to which they point.
86 *
87 * ext2_bmaparray does the bmap conversion, and if requested returns the
88 * array of logical blocks which must be traversed to get to a block.
89 * Each entry contains the offset into that block that gets you to the
90 * next block and the disk address of the block (if it is assigned).
91 */
92
93int
128 * Indirect blocks are now on the vnode for the file. They are given negative
129 * logical block numbers. Indirect blocks are addressed by the negative
130 * address of the first data block to which they point. Double indirect blocks
131 * are addressed by one less than the address of the first indirect block to
132 * which they point. Triple indirect blocks are addressed by one less than
133 * the address of the first double indirect block to which they point.
134 *
135 * ext2_bmaparray does the bmap conversion, and if requested returns the
136 * array of logical blocks which must be traversed to get to a block.
137 * Each entry contains the offset into that block that gets you to the
138 * next block and the disk address of the block (if it is assigned).
139 */
140
141int
94ext2_bmaparray(struct vnode *vp, int32_t bn, int32_t *bnp, int *runp, int *runb)
142ext2_bmaparray(struct vnode *vp, int32_t bn, int64_t *bnp, int *runp, int *runb)
95{
96 struct inode *ip;
97 struct buf *bp;
98 struct ext2mount *ump;
99 struct mount *mp;
100 struct vnode *devvp;
101 struct indir a[NIADDR+1], *ap;
102 daddr_t daddr;

--- 213 unchanged lines hidden ---
143{
144 struct inode *ip;
145 struct buf *bp;
146 struct ext2mount *ump;
147 struct mount *mp;
148 struct vnode *devvp;
149 struct indir a[NIADDR+1], *ap;
150 daddr_t daddr;

--- 213 unchanged lines hidden ---