Deleted Added
full compact
ext2_vnops.c (253173) ext2_vnops.c (254260)
1/*-
2 * modified for EXT2FS support in 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

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

34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)ufs_vnops.c 8.7 (Berkeley) 2/3/94
41 * @(#)ufs_vnops.c 8.27 (Berkeley) 5/27/95
1/*-
2 * modified for EXT2FS support in 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

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

34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)ufs_vnops.c 8.7 (Berkeley) 2/3/94
41 * @(#)ufs_vnops.c 8.27 (Berkeley) 5/27/95
42 * $FreeBSD: head/sys/fs/ext2fs/ext2_vnops.c 253173 2013-07-10 22:03:01Z pfg $
42 * $FreeBSD: head/sys/fs/ext2fs/ext2_vnops.c 254260 2013-08-12 21:34:48Z pfg $
43 */
44
45#include "opt_suiddir.h"
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/kernel.h>
50#include <sys/fcntl.h>

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

79#include <fs/ext2fs/ext2_extern.h>
80#include <fs/ext2fs/ext2fs.h>
81#include <fs/ext2fs/ext2_dinode.h>
82#include <fs/ext2fs/ext2_dir.h>
83#include <fs/ext2fs/ext2_mount.h>
84
85static int ext2_makeinode(int mode, struct vnode *, struct vnode **, struct componentname *);
86static void ext2_itimes_locked(struct vnode *);
43 */
44
45#include "opt_suiddir.h"
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/kernel.h>
50#include <sys/fcntl.h>

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

79#include <fs/ext2fs/ext2_extern.h>
80#include <fs/ext2fs/ext2fs.h>
81#include <fs/ext2fs/ext2_dinode.h>
82#include <fs/ext2fs/ext2_dir.h>
83#include <fs/ext2fs/ext2_mount.h>
84
85static int ext2_makeinode(int mode, struct vnode *, struct vnode **, struct componentname *);
86static void ext2_itimes_locked(struct vnode *);
87static int ext4_ext_read(struct vop_read_args *);
88static int ext2_ind_read(struct vop_read_args *);
87
88static vop_access_t ext2_access;
89static int ext2_chmod(struct vnode *, int, struct ucred *, struct thread *);
90static int ext2_chown(struct vnode *, uid_t, gid_t, struct ucred *,
91 struct thread *);
92static vop_close_t ext2_close;
93static vop_create_t ext2_create;
94static vop_fsync_t ext2_fsync;

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

1322 */
1323static int
1324ext2_strategy(struct vop_strategy_args *ap)
1325{
1326 struct buf *bp = ap->a_bp;
1327 struct vnode *vp = ap->a_vp;
1328 struct inode *ip;
1329 struct bufobj *bo;
89
90static vop_access_t ext2_access;
91static int ext2_chmod(struct vnode *, int, struct ucred *, struct thread *);
92static int ext2_chown(struct vnode *, uid_t, gid_t, struct ucred *,
93 struct thread *);
94static vop_close_t ext2_close;
95static vop_create_t ext2_create;
96static vop_fsync_t ext2_fsync;

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

1324 */
1325static int
1326ext2_strategy(struct vop_strategy_args *ap)
1327{
1328 struct buf *bp = ap->a_bp;
1329 struct vnode *vp = ap->a_vp;
1330 struct inode *ip;
1331 struct bufobj *bo;
1330 int32_t blkno;
1332 int64_t blkno;
1331 int error;
1332
1333 ip = VTOI(vp);
1334 if (vp->v_type == VBLK || vp->v_type == VCHR)
1335 panic("ext2_strategy: spec");
1336 if (bp->b_blkno == bp->b_lblkno) {
1337 error = ext2_bmaparray(vp, bp->b_lblkno, &blkno, NULL, NULL);
1338 bp->b_blkno = blkno;

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

1602/*
1603 * Vnode op for reading.
1604 */
1605static int
1606ext2_read(struct vop_read_args *ap)
1607{
1608 struct vnode *vp;
1609 struct inode *ip;
1333 int error;
1334
1335 ip = VTOI(vp);
1336 if (vp->v_type == VBLK || vp->v_type == VCHR)
1337 panic("ext2_strategy: spec");
1338 if (bp->b_blkno == bp->b_lblkno) {
1339 error = ext2_bmaparray(vp, bp->b_lblkno, &blkno, NULL, NULL);
1340 bp->b_blkno = blkno;

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

1604/*
1605 * Vnode op for reading.
1606 */
1607static int
1608ext2_read(struct vop_read_args *ap)
1609{
1610 struct vnode *vp;
1611 struct inode *ip;
1612 int error;
1613
1614 vp = ap->a_vp;
1615 ip = VTOI(vp);
1616
1617 /*EXT4_EXT_LOCK(ip);*/
1618 if (ip->i_flags & EXT4_EXTENTS)
1619 error = ext4_ext_read(ap);
1620 else
1621 error = ext2_ind_read(ap);
1622 /*EXT4_EXT_UNLOCK(ip);*/
1623 return (error);
1624}
1625
1626
1627/*
1628 * Vnode op for reading.
1629 */
1630static int
1631ext2_ind_read(struct vop_read_args *ap)
1632{
1633 struct vnode *vp;
1634 struct inode *ip;
1610 struct uio *uio;
1611 struct m_ext2fs *fs;
1612 struct buf *bp;
1613 daddr_t lbn, nextlbn;
1614 off_t bytesinfile;
1615 long size, xfersize, blkoffset;
1616 int error, orig_resid, seqcount;
1617 int ioflag;

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

1753 return (vn_bmap_seekhole(ap->a_vp, ap->a_command,
1754 (off_t *)ap->a_data, ap->a_cred));
1755 default:
1756 return (ENOTTY);
1757 }
1758}
1759
1760/*
1635 struct uio *uio;
1636 struct m_ext2fs *fs;
1637 struct buf *bp;
1638 daddr_t lbn, nextlbn;
1639 off_t bytesinfile;
1640 long size, xfersize, blkoffset;
1641 int error, orig_resid, seqcount;
1642 int ioflag;

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

1778 return (vn_bmap_seekhole(ap->a_vp, ap->a_command,
1779 (off_t *)ap->a_data, ap->a_cred));
1780 default:
1781 return (ENOTTY);
1782 }
1783}
1784
1785/*
1786 * this function handles ext4 extents block mapping
1787 */
1788static int
1789ext4_ext_read(struct vop_read_args *ap)
1790{
1791 struct vnode *vp;
1792 struct inode *ip;
1793 struct uio *uio;
1794 struct m_ext2fs *fs;
1795 struct buf *bp;
1796 struct ext4_extent nex, *ep;
1797 struct ext4_extent_path path;
1798 daddr_t lbn, newblk;
1799 off_t bytesinfile;
1800 int cache_type;
1801 ssize_t orig_resid;
1802 int error;
1803 long size, xfersize, blkoffset;
1804
1805 vp = ap->a_vp;
1806 ip = VTOI(vp);
1807 uio = ap->a_uio;
1808 memset(&path, 0, sizeof(path));
1809
1810 orig_resid = uio->uio_resid;
1811 KASSERT(orig_resid >= 0, ("%s: uio->uio_resid < 0", __func__));
1812 if (orig_resid == 0)
1813 return (0);
1814 KASSERT(uio->uio_offset >= 0, ("%s: uio->uio_offset < 0", __func__));
1815 fs = ip->i_e2fs;
1816 if (uio->uio_offset < ip->i_size && uio->uio_offset >= fs->e2fs_maxfilesize)
1817 return (EOVERFLOW);
1818
1819 while (uio->uio_resid > 0) {
1820 if ((bytesinfile = ip->i_size - uio->uio_offset) <= 0)
1821 break;
1822 lbn = lblkno(fs, uio->uio_offset);
1823 size = blksize(fs, ip, lbn);
1824 blkoffset = blkoff(fs, uio->uio_offset);
1825
1826 xfersize = fs->e2fs_fsize - blkoffset;
1827 xfersize = MIN(xfersize, uio->uio_resid);
1828 xfersize = MIN(xfersize, bytesinfile);
1829
1830 /* get block from ext4 extent cache */
1831 cache_type = ext4_ext_in_cache(ip, lbn, &nex);
1832 switch (cache_type) {
1833 case EXT4_EXT_CACHE_NO:
1834 ext4_ext_find_extent(fs, ip, lbn, &path);
1835 ep = path.ep_ext;
1836 if (ep == NULL)
1837 return (EIO);
1838
1839 ext4_ext_put_cache(ip, ep, EXT4_EXT_CACHE_IN);
1840
1841 newblk = lbn - ep->e_blk + (ep->e_start_lo |
1842 (daddr_t)ep->e_start_hi << 32);
1843
1844 if (path.ep_bp != NULL) {
1845 brelse(path.ep_bp);
1846 path.ep_bp = NULL;
1847 }
1848 break;
1849
1850 case EXT4_EXT_CACHE_GAP:
1851 /* block has not been allocated yet */
1852 return (0);
1853
1854 case EXT4_EXT_CACHE_IN:
1855 newblk = lbn - nex.e_blk + (nex.e_start_lo |
1856 (daddr_t)nex.e_start_hi << 32);
1857 break;
1858
1859 default:
1860 panic("%s: invalid cache type", __func__);
1861 }
1862
1863 error = bread(ip->i_devvp, fsbtodb(fs, newblk), size, NOCRED, &bp);
1864 if (error) {
1865 brelse(bp);
1866 return (error);
1867 }
1868
1869 size -= bp->b_resid;
1870 if (size < xfersize) {
1871 if (size == 0) {
1872 bqrelse(bp);
1873 break;
1874 }
1875 xfersize = size;
1876 }
1877 error = uiomove(bp->b_data + blkoffset, (int)xfersize, uio);
1878 bqrelse(bp);
1879 if (error)
1880 return (error);
1881 }
1882
1883 return (0);
1884}
1885
1886/*
1761 * Vnode op for writing.
1762 */
1763static int
1764ext2_write(struct vop_write_args *ap)
1765{
1766 struct vnode *vp;
1767 struct uio *uio;
1768 struct inode *ip;

--- 171 unchanged lines hidden ---
1887 * Vnode op for writing.
1888 */
1889static int
1890ext2_write(struct vop_write_args *ap)
1891{
1892 struct vnode *vp;
1893 struct uio *uio;
1894 struct inode *ip;

--- 171 unchanged lines hidden ---