diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2001-09-18 01:21:56 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2001-09-18 01:21:56 +0000 |
commit | 57589e59ec7bf78b9cdcda66c031f6220a525c19 (patch) | |
tree | 47df10756f232d8ed0c0ff9dffc30df69a34c2f9 /sys | |
parent | b69dc1a7efbafedbe39b432bf15ed5a5b60316bf (diff) |
More of cleanups, reliability and endianness fixes from NetBSD.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/ufs/ext2fs/ext2fs_inode.c | 97 | ||||
-rw-r--r-- | sys/ufs/ext2fs/ext2fs_lookup.c | 274 |
2 files changed, 192 insertions, 179 deletions
diff --git a/sys/ufs/ext2fs/ext2fs_inode.c b/sys/ufs/ext2fs/ext2fs_inode.c index c49578233a3..ecf258ef1f2 100644 --- a/sys/ufs/ext2fs/ext2fs_inode.c +++ b/sys/ufs/ext2fs/ext2fs_inode.c @@ -1,5 +1,5 @@ -/* $OpenBSD: ext2fs_inode.c,v 1.14 2001/07/16 03:44:22 csapuntz Exp $ */ -/* $NetBSD: ext2fs_inode.c,v 1.1 1997/06/11 09:33:56 bouyer Exp $ */ +/* $OpenBSD: ext2fs_inode.c,v 1.15 2001/09/18 01:21:55 art Exp $ */ +/* $NetBSD: ext2fs_inode.c,v 1.24 2001/06/19 12:59:18 wiz Exp $ */ /* * Copyright (c) 1997 Manuel Bouyer. @@ -59,8 +59,8 @@ #include <ufs/ext2fs/ext2fs.h> #include <ufs/ext2fs/ext2fs_extern.h> -static int ext2fs_indirtrunc __P((struct inode *, daddr_t, daddr_t, - daddr_t, int, long *)); +static int ext2fs_indirtrunc __P((struct inode *, ufs_daddr_t, ufs_daddr_t, + ufs_daddr_t, int, long *)); int ext2fs_init(vfsp) @@ -78,9 +78,11 @@ ext2fs_inactive(v) { struct vop_inactive_args /* { struct vnode *a_vp; + struct proc *a_p; } */ *ap = v; - register struct vnode *vp = ap->a_vp; - register struct inode *ip = VTOI(vp); + struct vnode *vp = ap->a_vp; + struct inode *ip = VTOI(vp); + struct proc *p = ap->a_p; struct timespec ts; int error = 0; extern int prtactive; @@ -88,11 +90,14 @@ ext2fs_inactive(v) if (prtactive && vp->v_usecount != 0) vprint("ext2fs_inactive: pushing active", vp); /* Get rid of inodes related to stale file handles. */ - if (ip->i_e2fs_mode == 0 || ip->i_e2fs_dtime != 0) + if (ip->i_e2fs_mode == 0 || ip->i_e2fs_dtime != 0) goto out; + error = 0; if (ip->i_e2fs_nlink == 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) { - (void) ext2fs_truncate(ip, (off_t)0, 0, NOCRED); + if (ip->i_e2fs_size != 0) { + error = ext2fs_truncate(ip, (off_t)0, 0, NOCRED); + } TIMEVAL_TO_TIMESPEC(&time, &ts); ip->i_e2fs_dtime = ts.tv_sec; ip->i_flag |= IN_CHANGE | IN_UPDATE; @@ -102,13 +107,13 @@ ext2fs_inactive(v) ext2fs_update(ip, NULL, NULL, 0); } out: - VOP_UNLOCK(vp, 0, ap->a_p); + VOP_UNLOCK(vp, 0, p); /* * If we are done with the inode, reclaim it * so that it can be reused immediately. */ if (ip->i_e2fs_dtime != 0) - vrecycle(vp, (struct simplelock *)0, ap->a_p); + vrecycle(vp, NULL, p); return (error); } @@ -130,6 +135,7 @@ ext2fs_update(struct inode *ip, struct timespec *atime, struct timespec *mtime, struct buf *bp; int error; struct timespec ts; + caddr_t cp; if (ITOV(ip)->v_mount->mnt_flag & MNT_RDONLY) return (0); @@ -148,9 +154,10 @@ ext2fs_update(struct inode *ip, struct timespec *atime, struct timespec *mtime, brelse(bp); return (error); } - bcopy(&ip->i_din.e2fs_din, - ((struct ext2fs_dinode *)bp->b_data + ino_to_fsbo(fs, ip->i_number)), - sizeof(struct ext2fs_dinode)); + ip->i_flag &= ~(IN_MODIFIED); + cp = (caddr_t)bp->b_data + + (ino_to_fsbo(fs, ip->i_number) * EXT2_DINODE_SIZE); + e2fs_isave(&ip->i_din.e2fs_din, (struct ext2fs_dinode *)cp); if (waitfor) return (bwrite(bp)); else { @@ -170,14 +177,14 @@ int ext2fs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred) { struct vnode *ovp = ITOV(oip); - daddr_t lastblock; - daddr_t bn, lbn, lastiblock[NIADDR], indir_lbn[NIADDR]; - daddr_t oldblks[NDADDR + NIADDR], newblks[NDADDR + NIADDR]; - register struct m_ext2fs *fs; + ufs_daddr_t lastblock; + ufs_daddr_t bn, lbn, lastiblock[NIADDR], indir_lbn[NIADDR]; + ufs_daddr_t oldblks[NDADDR + NIADDR], newblks[NDADDR + NIADDR]; + struct m_ext2fs *fs; struct buf *bp; int offset, size, level; long count, nblocks, vflags, blocksreleased = 0; - register int i; + int i; int aflags, error, allerror; off_t osize; @@ -242,7 +249,7 @@ ext2fs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred) * Shorten the size of the file. If the file is not being * truncated to a block boundry, the contents of the * partial block following the end of the file must be - * zero'ed in case it ever become accessable again because + * zero'ed in case it ever become accessible again because * of subsequent file growth. */ offset = blkoff(fs, length); @@ -285,7 +292,7 @@ ext2fs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred) * will be returned to the free list. lastiblock values are also * normalized to -1 for calls to ext2fs_indirtrunc below. */ - bcopy((caddr_t)&oip->i_e2fs_blocks[0], (caddr_t)oldblks, sizeof oldblks); + memcpy((caddr_t)oldblks, (caddr_t)&oip->i_e2fs_blocks[0], sizeof oldblks); for (level = TRIPLE; level >= SINGLE; level--) if (lastiblock[level] < 0) { oip->i_e2fs_blocks[NDADDR + level] = 0; @@ -315,10 +322,10 @@ ext2fs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred) indir_lbn[DOUBLE] = indir_lbn[SINGLE] - NINDIR(fs) -1; indir_lbn[TRIPLE] = indir_lbn[DOUBLE] - NINDIR(fs) * NINDIR(fs) - 1; for (level = TRIPLE; level >= SINGLE; level--) { - bn = oip->i_e2fs_blocks[NDADDR + level]; + bn = fs2h32(oip->i_e2fs_blocks[NDADDR + level]); if (bn != 0) { error = ext2fs_indirtrunc(oip, indir_lbn[level], - fsbtodb(fs, bn), lastiblock[level], level, &count); + fsbtodb(fs, bn), lastiblock[level], level, &count); if (error) allerror = error; blocksreleased += count; @@ -336,27 +343,27 @@ ext2fs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred) * All whole direct blocks or frags. */ for (i = NDADDR - 1; i > lastblock; i--) { - bn = oip->i_e2fs_blocks[i]; + bn = fs2h32(oip->i_e2fs_blocks[i]); if (bn == 0) continue; oip->i_e2fs_blocks[i] = 0; ext2fs_blkfree(oip, bn); blocksreleased += btodb(fs->e2fs_bsize); } - if (lastblock < 0) - goto done; done: #ifdef DIAGNOSTIC for (level = SINGLE; level <= TRIPLE; level++) - if (newblks[NDADDR + level] != oip->i_e2fs_blocks[NDADDR + level]) - panic("itrunc1"); + if (newblks[NDADDR + level] != + oip->i_e2fs_blocks[NDADDR + level]) + panic("ext2fs_truncate1"); for (i = 0; i < NDADDR; i++) if (newblks[i] != oip->i_e2fs_blocks[i]) - panic("itrunc2"); + panic("ext2fs_truncate2"); if (length == 0 && - (ovp->v_dirtyblkhd.lh_first || ovp->v_cleanblkhd.lh_first)) - panic("itrunc3"); + (!LIST_EMPTY(&ovp->v_cleanblkhd) || + !LIST_EMPTY(&ovp->v_dirtyblkhd))) + panic("ext2fs_truncate3"); #endif /* DIAGNOSTIC */ /* * Put back the real size. @@ -380,18 +387,18 @@ done: */ static int ext2fs_indirtrunc(ip, lbn, dbn, lastbn, level, countp) - register struct inode *ip; - daddr_t lbn, lastbn; - daddr_t dbn; + struct inode *ip; + ufs_daddr_t lbn, lastbn; + ufs_daddr_t dbn; int level; long *countp; { - register int i; + int i; struct buf *bp; - register struct m_ext2fs *fs = ip->i_e2fs; - register daddr_t *bap; + struct m_ext2fs *fs = ip->i_e2fs; + ufs_daddr_t *bap; struct vnode *vp; - daddr_t *copy = NULL, nb, nlbn, last; + ufs_daddr_t *copy = NULL, nb, nlbn, last; long blkcount, factor; int nblocks, blocksreleased = 0; int error = 0, allerror = 0; @@ -433,11 +440,11 @@ ext2fs_indirtrunc(ip, lbn, dbn, lastbn, level, countp) return (error); } - bap = (daddr_t *)bp->b_data; - if (lastbn != -1) { - MALLOC(copy, daddr_t *, fs->e2fs_bsize, M_TEMP, M_WAITOK); - bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->e2fs_bsize); - bzero((caddr_t)&bap[last + 1], + bap = (ufs_daddr_t *)bp->b_data; + if (lastbn >= 0) { + MALLOC(copy, ufs_daddr_t *, fs->e2fs_bsize, M_TEMP, M_WAITOK); + memcpy((caddr_t)copy, (caddr_t)bap, (u_int)fs->e2fs_bsize); + memset((caddr_t)&bap[last + 1], 0, (u_int)(NINDIR(fs) - (last + 1)) * sizeof (u_int32_t)); error = bwrite(bp); if (error) @@ -451,12 +458,12 @@ ext2fs_indirtrunc(ip, lbn, dbn, lastbn, level, countp) for (i = NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last; i--, nlbn += factor) { - nb = bap[i]; + nb = fs2h32(bap[i]); if (nb == 0) continue; if (level > SINGLE) { error = ext2fs_indirtrunc(ip, nlbn, fsbtodb(fs, nb), - (daddr_t)-1, level - 1, + (ufs_daddr_t)-1, level - 1, &blkcount); if (error) allerror = error; @@ -471,7 +478,7 @@ ext2fs_indirtrunc(ip, lbn, dbn, lastbn, level, countp) */ if (level > SINGLE && lastbn >= 0) { last = lastbn % factor; - nb = bap[i]; + nb = fs2h32(bap[i]); if (nb != 0) { error = ext2fs_indirtrunc(ip, nlbn, fsbtodb(fs, nb), last, level - 1, &blkcount); diff --git a/sys/ufs/ext2fs/ext2fs_lookup.c b/sys/ufs/ext2fs/ext2fs_lookup.c index 2b96297783e..82bd81c7dbd 100644 --- a/sys/ufs/ext2fs/ext2fs_lookup.c +++ b/sys/ufs/ext2fs/ext2fs_lookup.c @@ -1,5 +1,5 @@ -/* $OpenBSD: ext2fs_lookup.c,v 1.10 2001/06/23 02:07:51 csapuntz Exp $ */ -/* $NetBSD: ext2fs_lookup.c,v 1.1 1997/06/11 09:33:59 bouyer Exp $ */ +/* $OpenBSD: ext2fs_lookup.c,v 1.11 2001/09/18 01:21:55 art Exp $ */ +/* $NetBSD: ext2fs_lookup.c,v 1.16 2000/08/03 20:29:26 thorpej Exp $ */ /* * Modified for NetBSD 1.2E @@ -25,17 +25,17 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: + * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * may be used to endorse or promote products derived from this software + * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -94,8 +94,8 @@ ext2fs_dirconv2ffs( e2dir, ffsdir) struct ext2fs_direct *e2dir; struct dirent *ffsdir; { - bzero(ffsdir, sizeof(struct dirent)); - ffsdir->d_fileno = e2dir->e2d_ino; + memset(ffsdir, 0, sizeof(struct dirent)); + ffsdir->d_fileno = fs2h32(e2dir->e2d_ino); ffsdir->d_namlen = e2dir->e2d_namlen; ffsdir->d_type = DT_UNKNOWN; /* don't know more here */ @@ -104,7 +104,8 @@ ext2fs_dirconv2ffs( e2dir, ffsdir) * XXX Rigth now this can't happen, but if one day * MAXNAMLEN != E2FS_MAXNAMLEN we should handle this more gracefully ! */ - if (e2dir->e2d_namlen > MAXNAMLEN) panic("ext2fs: e2dir->e2d_namlen"); + if (e2dir->e2d_namlen > MAXNAMLEN) + panic("ext2fs: e2dir->e2d_namlen\n"); #endif strncpy(ffsdir->d_name, e2dir->e2d_name, ffsdir->d_namlen); @@ -134,14 +135,15 @@ ext2fs_readdir(v) struct vnode *a_vp; struct uio *a_uio; struct ucred *a_cred; - int *a_eofflag; - u_long *a_cookies; + int **a_eofflag; + off_t **a_cookies; int ncookies; } */ *ap = v; - register struct uio *uio = ap->a_uio; + struct uio *uio = ap->a_uio; int error; - size_t count, readcnt, lost; - struct m_ext2fs *fs = VTOI(ap->a_vp)->i_e2fs; + size_t e2fs_count, readcnt; + struct vnode *vp = ap->a_vp; + struct m_ext2fs *fs = VTOI(vp)->i_e2fs; struct ext2fs_direct *dp; struct dirent dstd; @@ -149,83 +151,74 @@ ext2fs_readdir(v) struct iovec aiov; caddr_t dirbuf; off_t off = uio->uio_offset; - int ncookies = 0; u_long *cookies = NULL; - count = uio->uio_resid; + int nc = 0, ncookies = 0; + int e2d_reclen; + + if (vp->v_type != VDIR) + return (ENOTDIR); + + e2fs_count = uio->uio_resid; /* Make sure we don't return partial entries. */ - count -= (uio->uio_offset + count) & (fs->e2fs_bsize -1); - if (count <= 0) + e2fs_count -= (uio->uio_offset + e2fs_count) & (fs->e2fs_bsize -1); + if (e2fs_count <= 0) return (EINVAL); - lost = uio->uio_resid - count; - uio->uio_resid = count; - uio->uio_iov->iov_len = count; auio = *uio; auio.uio_iov = &aiov; auio.uio_iovcnt = 1; auio.uio_segflg = UIO_SYSSPACE; - aiov.iov_len = count; - MALLOC(dirbuf, caddr_t, count, M_TEMP, M_WAITOK); - bzero(dirbuf, count); - aiov.iov_base = dirbuf; - - error = VOP_READ(ap->a_vp, &auio, 0, ap->a_cred); - if (error) - goto err_exit; - - - readcnt = count - auio.uio_resid; - - for (dp = (struct ext2fs_direct *)dirbuf; - (char *)dp < (char *)dirbuf + readcnt; ) { - if (dp->e2d_reclen <= 0) { - error = EIO; - goto err_exit; - } - dp = (struct ext2fs_direct *) ((char *)dp + dp->e2d_reclen); - ncookies++; - } - - + aiov.iov_len = e2fs_count; + auio.uio_resid = e2fs_count; + MALLOC(dirbuf, caddr_t, e2fs_count, M_TEMP, M_WAITOK); if (ap->a_ncookies) { - MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP, - M_WAITOK); - *ap->a_ncookies = ncookies; + nc = ncookies = e2fs_count / 16; + cookies = malloc(sizeof (off_t) * ncookies, M_TEMP, M_WAITOK); *ap->a_cookies = cookies; } + memset(dirbuf, 0, e2fs_count); + aiov.iov_base = dirbuf; - - for (dp = (struct ext2fs_direct *)dirbuf; - (char *)dp < (char *)dirbuf + readcnt; ) { - - ext2fs_dirconv2ffs(dp, &dstd); - if(dstd.d_reclen > uio->uio_resid) { - break; - } - if ((error = uiomove((caddr_t)&dstd, dstd.d_reclen, uio)) != 0) { goto err_exit; + error = VOP_READ(ap->a_vp, &auio, 0, ap->a_cred); + if (error == 0) { + readcnt = e2fs_count - auio.uio_resid; + for (dp = (struct ext2fs_direct *)dirbuf; + (char *)dp < (char *)dirbuf + readcnt; ) { + e2d_reclen = fs2h16(dp->e2d_reclen); + if (e2d_reclen == 0) { + error = EIO; + break; + } + ext2fs_dirconv2ffs(dp, &dstd); + if(dstd.d_reclen > uio->uio_resid) { + break; + } + if ((error = uiomove((caddr_t)&dstd, dstd.d_reclen, uio)) != 0) { + break; + } + off = off + e2d_reclen; + if (cookies != NULL) { + *cookies++ = off; + if (--ncookies <= 0){ + break; /* out of cookies */ + } + } + /* advance dp */ + dp = (struct ext2fs_direct *) ((char *)dp + e2d_reclen); } - - off = off + dp->e2d_reclen; - - if (cookies) - *cookies++ = off; - - dp = (struct ext2fs_direct *) ((char *)dp + dp->e2d_reclen); /* advance dp */ + /* we need to correct uio_offset */ + uio->uio_offset = off; } - /* we need to correct uio_offset */ - uio->uio_offset = off; - -err_exit: FREE(dirbuf, M_TEMP); - - if (error && cookies) { - FREE(*ap->a_cookies, M_TEMP); - *ap->a_cookies = 0; - *ap->a_ncookies = 0; - } *ap->a_eofflag = VTOI(ap->a_vp)->i_e2fs_size <= uio->uio_offset; - uio->uio_resid += lost; - + if (ap->a_ncookies) { + if (error) { + free(*ap->a_cookies, M_TEMP); + *ap->a_ncookies = 0; + *ap->a_cookies = NULL; + } else + *ap->a_ncookies = nc - ncookies; + } return (error); } @@ -271,10 +264,10 @@ ext2fs_lookup(v) struct vnode **a_vpp; struct componentname *a_cnp; } */ *ap = v; - register struct vnode *vdp; /* vnode for directory being searched */ - register struct inode *dp; /* inode for directory being searched */ + struct vnode *vdp; /* vnode for directory being searched */ + struct inode *dp; /* inode for directory being searched */ struct buf *bp; /* a buffer of directory entries */ - register struct ext2fs_direct *ep; /* the current directory entry */ + struct ext2fs_direct *ep; /* the current directory entry */ int entryoffsetinblock; /* offset of ep in bp's buffer */ enum {NONE, COMPACT, FOUND} slotstatus; doff_t slotoffset; /* offset of area with free space */ @@ -312,6 +305,10 @@ ext2fs_lookup(v) if ((error = VOP_ACCESS(vdp, VEXEC, cred, cnp->cn_proc)) != 0) return (error); + if ((flags & ISLASTCN) && (vdp->v_mount->mnt_flag & MNT_RDONLY) && + (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) + return (EROFS); + /* * We now have a segment name to search for, and a directory to search. * @@ -440,10 +437,12 @@ searchloop: ep = (struct ext2fs_direct *) ((char *)bp->b_data + entryoffsetinblock); if (ep->e2d_reclen == 0 || - (dirchk && ext2fs_dirbadentry(vdp, ep, entryoffsetinblock))) { + (dirchk && + ext2fs_dirbadentry(vdp, ep, entryoffsetinblock))) { int i; ufs_dirbad(dp, dp->i_offset, "mangled entry"); - i = dirblksize - (entryoffsetinblock & (dirblksize - 1)); + i = dirblksize - + (entryoffsetinblock & (dirblksize - 1)); dp->i_offset += i; entryoffsetinblock += i; continue; @@ -456,7 +455,7 @@ searchloop: * compaction is viable. */ if (slotstatus != FOUND) { - int size = ep->e2d_reclen; + int size = fs2h16(ep->e2d_reclen); if (ep->e2d_ino != 0) size -= EXT2FS_DIRSIZ(ep->e2d_namlen); @@ -464,7 +463,7 @@ searchloop: if (size >= slotneeded) { slotstatus = FOUND; slotoffset = dp->i_offset; - slotsize = ep->e2d_reclen; + slotsize = fs2h16(ep->e2d_reclen); } else if (slotstatus == NONE) { slotfreespace += size; if (slotoffset == -1) @@ -472,7 +471,7 @@ searchloop: if (slotfreespace >= slotneeded) { slotstatus = COMPACT; slotsize = dp->i_offset + - ep->e2d_reclen - slotoffset; + fs2h16(ep->e2d_reclen) - slotoffset; } } } @@ -484,22 +483,22 @@ searchloop: if (ep->e2d_ino) { namlen = ep->e2d_namlen; if (namlen == cnp->cn_namelen && - !bcmp(cnp->cn_nameptr, ep->e2d_name, + !memcmp(cnp->cn_nameptr, ep->e2d_name, (unsigned)namlen)) { /* * Save directory entry's inode number and * reclen in ndp->ni_ufs area, and release * directory buffer. */ - dp->i_ino = ep->e2d_ino; - dp->i_reclen = ep->e2d_reclen; + dp->i_ino = fs2h32(ep->e2d_ino); + dp->i_reclen = fs2h16(ep->e2d_reclen); brelse(bp); goto found; } } prevoff = dp->i_offset; - dp->i_offset += ep->e2d_reclen; - entryoffsetinblock += ep->e2d_reclen; + dp->i_offset += fs2h16(ep->e2d_reclen); + entryoffsetinblock += fs2h16(ep->e2d_reclen); if (ep->e2d_ino) enduseful = dp->i_offset; } @@ -587,9 +586,10 @@ found: * of this entry. */ if (entryoffsetinblock + EXT2FS_DIRSIZ(ep->e2d_namlen) - > dp->i_e2fs_size) { + > dp->i_e2fs_size) { ufs_dirbad(dp, dp->i_offset, "i_size too small"); - dp->i_e2fs_size = entryoffsetinblock+EXT2FS_DIRSIZ(ep->e2d_namlen); + dp->i_e2fs_size = entryoffsetinblock + + EXT2FS_DIRSIZ(ep->e2d_namlen); dp->i_flag |= IN_CHANGE | IN_UPDATE; } @@ -740,29 +740,33 @@ found: static int ext2fs_dirbadentry(dp, de, entryoffsetinblock) struct vnode *dp; - register struct ext2fs_direct *de; + struct ext2fs_direct *de; int entryoffsetinblock; { int dirblksize = VTOI(dp)->i_e2fs->e2fs_bsize; char * error_msg = NULL; + int reclen = fs2h16(de->e2d_reclen); + int namlen = de->e2d_namlen; - if (de->e2d_reclen < EXT2FS_DIRSIZ(1)) /* e2d_namlen = 1 */ + if (reclen < EXT2FS_DIRSIZ(1)) /* e2d_namlen = 1 */ error_msg = "rec_len is smaller than minimal"; - else if (de->e2d_reclen % 4 != 0) + else if (reclen % 4 != 0) error_msg = "rec_len % 4 != 0"; - else if (de->e2d_reclen < EXT2FS_DIRSIZ(de->e2d_namlen)) + else if (reclen < EXT2FS_DIRSIZ(namlen)) error_msg = "reclen is too small for name_len"; - else if (entryoffsetinblock + de->e2d_reclen > dirblksize) + else if (entryoffsetinblock + reclen > dirblksize) error_msg = "directory entry across blocks"; - else if (de->e2d_ino > VTOI(dp)->i_e2fs->e2fs.e2fs_icount) + else if (fs2h32(de->e2d_ino) > + VTOI(dp)->i_e2fs->e2fs.e2fs_icount) error_msg = "inode out of bounds"; if (error_msg != NULL) { printf( "bad directory entry: %s\n" - "offset=%d, inode=%lu, rec_len=%d, name_len=%d \n", - error_msg, entryoffsetinblock, - (unsigned long) de->e2d_ino, de->e2d_reclen, de->e2d_namlen); + "offset=%d, inode=%lu, rec_len=%d, name_len=%d \n", + error_msg, entryoffsetinblock, + (unsigned long) fs2h32(de->e2d_ino), + reclen, namlen); panic("ext2fs_dirbadentry"); } return error_msg == NULL ? 0 : 1; @@ -780,10 +784,10 @@ int ext2fs_direnter(ip, dvp, cnp) struct inode *ip; struct vnode *dvp; - register struct componentname *cnp; + struct componentname *cnp; { - register struct ext2fs_direct *ep, *nep; - register struct inode *dp; + struct ext2fs_direct *ep, *nep; + struct inode *dp; struct buf *bp; struct ext2fs_direct newdir; struct iovec aiov; @@ -791,7 +795,7 @@ ext2fs_direnter(ip, dvp, cnp) u_int dsize; int error, loc, newentrysize, spacefree; char *dirbuf; - int dirblksize = ip->i_e2fs->e2fs_bsize; + int dirblksize = ip->i_e2fs->e2fs_bsize; #ifdef DIAGNOSTIC @@ -807,8 +811,8 @@ ext2fs_direnter(ip, dvp, cnp) } else { newdir.e2d_type = 0; }; - bcopy(cnp->cn_nameptr, newdir.e2d_name, (unsigned)cnp->cn_namelen + 1); - newentrysize = EXT2FS_DIRSIZ(newdir.e2d_namlen); + memcpy(newdir.e2d_name, cnp->cn_nameptr, (unsigned)cnp->cn_namelen + 1); + newentrysize = EXT2FS_DIRSIZ(cnp->cn_namelen); if (dp->i_count == 0) { /* * If dp->i_count is 0, then namei could find no @@ -819,7 +823,7 @@ ext2fs_direnter(ip, dvp, cnp) if (dp->i_offset & (dirblksize - 1)) panic("ext2fs_direnter: newblk"); auio.uio_offset = dp->i_offset; - newdir.e2d_reclen = dirblksize; + newdir.e2d_reclen = h2fs16(dirblksize); auio.uio_resid = newentrysize; aiov.iov_len = newentrysize; aiov.iov_base = (caddr_t)&newdir; @@ -864,21 +868,21 @@ ext2fs_direnter(ip, dvp, cnp) */ ep = (struct ext2fs_direct *)dirbuf; dsize = EXT2FS_DIRSIZ(ep->e2d_namlen); - spacefree = ep->e2d_reclen - dsize; - for (loc = ep->e2d_reclen; loc < dp->i_count; ) { + spacefree = fs2h16(ep->e2d_reclen) - dsize; + for (loc = fs2h16(ep->e2d_reclen); loc < dp->i_count; ) { nep = (struct ext2fs_direct *)(dirbuf + loc); if (ep->e2d_ino) { /* trim the existing slot */ - ep->e2d_reclen = dsize; + ep->e2d_reclen = h2fs16(dsize); ep = (struct ext2fs_direct *)((char *)ep + dsize); } else { /* overwrite; nothing there; header is ours */ spacefree += dsize; } dsize = EXT2FS_DIRSIZ(nep->e2d_namlen); - spacefree += nep->e2d_reclen - dsize; - loc += nep->e2d_reclen; - bcopy((caddr_t)nep, (caddr_t)ep, dsize); + spacefree += fs2h16(nep->e2d_reclen) - dsize; + loc += fs2h16(nep->e2d_reclen); + memcpy((caddr_t)ep, (caddr_t)nep, dsize); } /* * Update the pointer fields in the previous entry (if any), @@ -889,25 +893,25 @@ ext2fs_direnter(ip, dvp, cnp) if (spacefree + dsize < newentrysize) panic("ext2fs_direnter: compact1"); #endif - newdir.e2d_reclen = spacefree + dsize; + newdir.e2d_reclen = h2fs16(spacefree + dsize); } else { #ifdef DIAGNOSTIC if (spacefree < newentrysize) { printf("ext2fs_direnter: compact2 %u %u", - (u_int)spacefree, (u_int)newentrysize); + (u_int)spacefree, (u_int)newentrysize); panic("ext2fs_direnter: compact2"); } #endif - newdir.e2d_reclen = spacefree; - ep->e2d_reclen = dsize; + newdir.e2d_reclen = h2fs16(spacefree); + ep->e2d_reclen = h2fs16(dsize); ep = (struct ext2fs_direct *)((char *)ep + dsize); } - bcopy((caddr_t)&newdir, (caddr_t)ep, (u_int)newentrysize); + memcpy((caddr_t)ep, (caddr_t)&newdir, (u_int)newentrysize); error = VOP_BWRITE(bp); dp->i_flag |= IN_CHANGE | IN_UPDATE; if (!error && dp->i_endoff && dp->i_endoff < dp->i_e2fs_size) error = ext2fs_truncate(dp, (off_t)dp->i_endoff, IO_SYNC, - cnp->cn_cred); + cnp->cn_cred); return (error); } @@ -928,7 +932,7 @@ ext2fs_dirremove(dvp, cnp) struct vnode *dvp; struct componentname *cnp; { - register struct inode *dp; + struct inode *dp; struct ext2fs_direct *ep; struct buf *bp; int error; @@ -951,10 +955,10 @@ ext2fs_dirremove(dvp, cnp) * Collapse new free space into previous entry. */ error = ext2fs_bufatoff(dp, (off_t)(dp->i_offset - dp->i_count), - (char **)&ep, &bp); + (char **)&ep, &bp); if (error != 0) return (error); - ep->e2d_reclen += dp->i_reclen; + ep->e2d_reclen = h2fs16(fs2h16(ep->e2d_reclen) + dp->i_reclen); error = VOP_BWRITE(bp); dp->i_flag |= IN_CHANGE | IN_UPDATE; return (error); @@ -1000,19 +1004,19 @@ ext2fs_dirrewrite(dp, ip, cnp) */ int ext2fs_dirempty(ip, parentino, cred) - register struct inode *ip; + struct inode *ip; ino_t parentino; struct ucred *cred; { - register off_t off; + off_t off; struct ext2fs_dirtemplate dbuf; - register struct ext2fs_direct *dp = (struct ext2fs_direct *)&dbuf; + struct ext2fs_direct *dp = (struct ext2fs_direct *)&dbuf; int error, namlen; size_t count; #define MINDIRSIZ (sizeof (struct ext2fs_dirtemplate) / 2) - for (off = 0; off < ip->i_e2fs_size; off += dp->e2d_reclen) { + for (off = 0; off < ip->i_e2fs_size; off += fs2h16(dp->e2d_reclen)) { error = vn_rdwr(UIO_READ, ITOV(ip), (caddr_t)dp, MINDIRSIZ, off, UIO_SYSSPACE, IO_NODELOCKED, cred, &count, (struct proc *)0); /* @@ -1040,7 +1044,7 @@ ext2fs_dirempty(ip, parentino, cred) */ if (namlen == 1) continue; - if (dp->e2d_name[1] == '.' && dp->e2d_ino == parentino) + if (dp->e2d_name[1] == '.' && fs2h32(dp->e2d_ino) == parentino) continue; return (0); } @@ -1060,6 +1064,7 @@ ext2fs_checkpath(source, target, cred) struct vnode *vp; int error, rootino, namlen; struct ext2fs_dirtemplate dirbuf; + u_int32_t ino; vp = ITOV(target); if (target->i_number == source->i_number) { @@ -1077,8 +1082,9 @@ ext2fs_checkpath(source, target, cred) break; } error = vn_rdwr(UIO_READ, vp, (caddr_t)&dirbuf, - sizeof (struct ext2fs_dirtemplate), (off_t)0, UIO_SYSSPACE, - IO_NODELOCKED, cred, NULL, (struct proc *)0); + sizeof (struct ext2fs_dirtemplate), (off_t)0, + UIO_SYSSPACE, IO_NODELOCKED, cred, (size_t *)0, + (struct proc *)0); if (error != 0) break; namlen = dirbuf.dotdot_namlen; @@ -1088,14 +1094,15 @@ ext2fs_checkpath(source, target, cred) error = ENOTDIR; break; } - if (dirbuf.dotdot_ino == source->i_number) { + ino = fs2h32(dirbuf.dotdot_ino); + if (ino == source->i_number) { error = EINVAL; break; } - if (dirbuf.dotdot_ino == rootino) + if (ino == rootino) break; vput(vp); - error = VFS_VGET(vp->v_mount, dirbuf.dotdot_ino, &vp); + error = VFS_VGET(vp->v_mount, ino, &vp); if (error != 0) { vp = NULL; break; @@ -1111,4 +1118,3 @@ out: vput(vp); return (error); } - |