Add support for reading/writing FFS in non-native byte order, conditioned

to "options FFS_EI". The superblock and inodes (without blk addr) are
byteswapped at disk read/write time, other metadatas are byteswapped
when used (as they are acceeded directly in the buffer cache).
This required the addition of a "um_flags" field to struct ufsmount.
ffs_bswap.c contains superblock and inode byteswap routines also used
by userland utilities.
This commit is contained in:
bouyer 1998-03-18 15:57:26 +00:00
parent 63dfa5e1a1
commit 091dafd39f
18 changed files with 806 additions and 336 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: files,v 1.175 1998/02/19 00:28:52 thorpej Exp $
# $NetBSD: files,v 1.176 1998/03/18 15:57:30 bouyer Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@ -524,6 +524,7 @@ file ufs/ext2fs/ext2fs_vfsops.c ext2fs
file ufs/ext2fs/ext2fs_vnops.c ext2fs
file ufs/ffs/ffs_alloc.c ffs | mfs
file ufs/ffs/ffs_balloc.c ffs | mfs
file ufs/ffs/ffs_bswap.c (ffs | mfs | lfs) & ffs_ei
file ufs/ffs/ffs_inode.c ffs | mfs
file ufs/ffs/ffs_subr.c ffs | mfs
file ufs/ffs/ffs_tables.c ffs | mfs

View File

@ -1,4 +1,4 @@
/* $NetBSD: ext2fs_vfsops.c,v 1.10 1998/03/02 16:13:42 bouyer Exp $ */
/* $NetBSD: ext2fs_vfsops.c,v 1.11 1998/03/18 15:57:26 bouyer Exp $ */
/*
* Copyright (c) 1997 Manuel Bouyer.
@ -630,6 +630,7 @@ ext2fs_mountfs(devvp, mp, p)
mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_EXT2FS);
mp->mnt_maxsymlinklen = EXT2_MAXSYMLINKLEN;
mp->mnt_flag |= MNT_LOCAL;
ump->um_flags = 0;
ump->um_mountp = mp;
ump->um_dev = dev;
ump->um_devvp = devvp;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_alloc.c,v 1.18 1998/03/01 02:23:14 fvdl Exp $ */
/* $NetBSD: ffs_alloc.c,v 1.19 1998/03/18 15:57:27 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -49,24 +49,27 @@
#include <vm/vm.h>
#include <ufs/ufs/quota.h>
#include <ufs/ufs/ufsmount.h>
#include <ufs/ufs/inode.h>
#include <ufs/ufs/ufs_extern.h>
#include <ufs/ufs/ufs_bswap.h>
#include <ufs/ffs/fs.h>
#include <ufs/ffs/ffs_extern.h>
static ufs_daddr_t ffs_alloccg __P((struct inode *, int, ufs_daddr_t, int));
static ufs_daddr_t ffs_alloccgblk __P((struct fs *, struct cg *, ufs_daddr_t));
static ufs_daddr_t ffs_clusteralloc __P((struct inode *, int, ufs_daddr_t, int));
static ino_t ffs_dirpref __P((struct fs *));
static ufs_daddr_t ffs_fragextend __P((struct inode *, int, long, int, int));
static void ffs_fserr __P((struct fs *, u_int, char *));
static u_long ffs_hashalloc
__P((struct inode *, int, long, int,
ufs_daddr_t (*)(struct inode *, int, ufs_daddr_t, int)));
static ufs_daddr_t ffs_nodealloccg __P((struct inode *, int, ufs_daddr_t, int));
static ufs_daddr_t ffs_mapsearch __P((struct fs *, struct cg *, ufs_daddr_t,
int));
static ufs_daddr_t ffs_alloccg __P((struct inode *, int, ufs_daddr_t, int));
static ufs_daddr_t ffs_alloccgblk __P((struct mount *, struct fs *,
struct cg *, ufs_daddr_t));
static ufs_daddr_t ffs_clusteralloc __P((struct inode *, int, ufs_daddr_t, int));
static ino_t ffs_dirpref __P((struct fs *));
static ufs_daddr_t ffs_fragextend __P((struct inode *, int, long, int, int));
static void ffs_fserr __P((struct fs *, u_int, char *));
static u_long ffs_hashalloc __P((struct inode *, int, long, int,
ufs_daddr_t (*)(struct inode *, int, ufs_daddr_t,
int)));
static ufs_daddr_t ffs_nodealloccg __P((struct inode *, int, ufs_daddr_t, int));
static ufs_daddr_t ffs_mapsearch __P((int, struct fs *, struct cg *,
ufs_daddr_t, int));
#if defined(DIAGNOSTIC) || defined(DEBUG)
static int ffs_checkblk __P((struct inode *, ufs_daddr_t, long size));
#endif
@ -187,7 +190,7 @@ ffs_realloccg(ip, lbprev, bpref, osize, nsize, cred, bpp)
#endif /* DIAGNOSTIC */
if (cred->cr_uid != 0 && freespace(fs, fs->fs_minfree) <= 0)
goto nospace;
if ((bprev = ip->i_ffs_db[lbprev]) == 0) {
if ((bprev = ufs_rw32(ip->i_ffs_db[lbprev], UFS_IPNEEDSWAP(ip))) == 0) {
printf("dev = 0x%x, bsize = %d, bprev = %d, fs = %s\n",
ip->i_dev, fs->fs_bsize, bprev, fs->fs_fsmnt);
panic("ffs_realloccg: bad bprev");
@ -441,14 +444,15 @@ ffs_reallocblks(v)
if (!ffs_checkblk(ip,
dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->fs_bsize))
panic("ffs_reallocblks: unallocated block 2");
if (dbtofsb(fs, buflist->bs_children[i]->b_blkno) != *bap)
if (dbtofsb(fs, buflist->bs_children[i]->b_blkno) !=
ufs_rw32(*bap, UFS_MPNEEDSWAP(vp->v_mount)))
panic("ffs_reallocblks: alloc mismatch");
#endif
#ifdef DEBUG
if (prtrealloc)
printf(" %d,", *bap);
printf(" %d,", ufs_rw32(*bap, UFS_MPNEEDSWAP(vp->v_mount)));
#endif
*bap++ = blkno;
*bap++ = ufs_rw32(blkno, UFS_MPNEEDSWAP(vp->v_mount));
}
/*
* Next we must write out the modified inode and indirect blocks.
@ -670,7 +674,8 @@ ffs_blkpref(ip, lbn, indx, bap)
startcg =
ino_to_cg(fs, ip->i_number) + lbn / fs->fs_maxbpg;
else
startcg = dtog(fs, bap[indx - 1]) + 1;
startcg = dtog(fs,
ufs_rw32(bap[indx - 1], UFS_IPNEEDSWAP(ip)) + 1);
startcg %= fs->fs_ncg;
avgbfree = fs->fs_cstotal.cs_nbfree / fs->fs_ncg;
for (cg = startcg; cg < fs->fs_ncg; cg++)
@ -691,8 +696,9 @@ ffs_blkpref(ip, lbn, indx, bap)
* next block is requested contiguously, otherwise it is
* requested rotationally delayed by fs_rotdelay milliseconds.
*/
nextblk = bap[indx - 1] + fs->fs_frag;
if (indx < fs->fs_maxcontig || bap[indx - fs->fs_maxcontig] +
nextblk = ufs_rw32(bap[indx - 1], UFS_IPNEEDSWAP(ip)) + fs->fs_frag;
if (indx < fs->fs_maxcontig ||
ufs_rw32(bap[indx - fs->fs_maxcontig], UFS_IPNEEDSWAP(ip)) +
blkstofrags(fs, fs->fs_maxcontig) != nextblk)
return (nextblk);
if (fs->fs_rotdelay != 0)
@ -799,14 +805,14 @@ ffs_fragextend(ip, cg, bprev, osize, nsize)
return (NULL);
}
cgp = (struct cg *)bp->b_data;
if (!cg_chkmagic(cgp)) {
if (!cg_chkmagic(cgp, UFS_IPNEEDSWAP(ip))) {
brelse(bp);
return (NULL);
}
cgp->cg_time = time.tv_sec;
cgp->cg_time = ufs_rw32(time.tv_sec, UFS_IPNEEDSWAP(ip));
bno = dtogd(fs, bprev);
for (i = numfrags(fs, osize); i < frags; i++)
if (isclr(cg_blksfree(cgp), bno + i)) {
if (isclr(cg_blksfree(cgp, UFS_IPNEEDSWAP(ip)), bno + i)) {
brelse(bp);
return (NULL);
}
@ -817,14 +823,14 @@ ffs_fragextend(ip, cg, bprev, osize, nsize)
* allocate the extended piece
*/
for (i = frags; i < fs->fs_frag - bbase; i++)
if (isclr(cg_blksfree(cgp), bno + i))
if (isclr(cg_blksfree(cgp, UFS_IPNEEDSWAP(ip)), bno + i))
break;
cgp->cg_frsum[i - numfrags(fs, osize)]--;
ufs_add32(cgp->cg_frsum[i - numfrags(fs, osize)], -1, UFS_IPNEEDSWAP(ip));
if (i != frags)
cgp->cg_frsum[i - frags]++;
ufs_add32(cgp->cg_frsum[i - frags], 1, UFS_IPNEEDSWAP(ip));
for (i = numfrags(fs, osize); i < frags; i++) {
clrbit(cg_blksfree(cgp), bno + i);
cgp->cg_cs.cs_nffree--;
clrbit(cg_blksfree(cgp, UFS_IPNEEDSWAP(ip)), bno + i);
ufs_add32(cgp->cg_cs.cs_nffree, -1, UFS_IPNEEDSWAP(ip));
fs->fs_cstotal.cs_nffree--;
fs->fs_cs(fs, cg).cs_nffree--;
}
@ -851,6 +857,7 @@ ffs_alloccg(ip, cg, bpref, size)
struct buf *bp;
register int i;
int error, bno, frags, allocsiz;
const int needswap = UFS_IPNEEDSWAP(ip);
fs = ip->i_fs;
if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize)
@ -862,14 +869,14 @@ ffs_alloccg(ip, cg, bpref, size)
return (NULL);
}
cgp = (struct cg *)bp->b_data;
if (!cg_chkmagic(cgp) ||
if (!cg_chkmagic(cgp, needswap) ||
(cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) {
brelse(bp);
return (NULL);
}
cgp->cg_time = time.tv_sec;
cgp->cg_time = ufs_rw32(time.tv_sec, needswap);
if (size == fs->fs_bsize) {
bno = ffs_alloccgblk(fs, cgp, bpref);
bno = ffs_alloccgblk(ITOV(ip)->v_mount, fs, cgp, bpref);
bdwrite(bp);
return (bno);
}
@ -891,33 +898,33 @@ ffs_alloccg(ip, cg, bpref, size)
brelse(bp);
return (NULL);
}
bno = ffs_alloccgblk(fs, cgp, bpref);
bno = ffs_alloccgblk(ITOV(ip)->v_mount, fs, cgp, bpref);
bpref = dtogd(fs, bno);
for (i = frags; i < fs->fs_frag; i++)
setbit(cg_blksfree(cgp), bpref + i);
setbit(cg_blksfree(cgp, needswap), bpref + i);
i = fs->fs_frag - frags;
cgp->cg_cs.cs_nffree += i;
ufs_add32(cgp->cg_cs.cs_nffree, i, needswap);
fs->fs_cstotal.cs_nffree += i;
fs->fs_cs(fs, cg).cs_nffree += i;
fs->fs_cs(fs, cg).cs_nffree +=i;
fs->fs_fmod = 1;
cgp->cg_frsum[i]++;
ufs_add32(cgp->cg_frsum[i], 1, needswap);
bdwrite(bp);
return (bno);
}
bno = ffs_mapsearch(fs, cgp, bpref, allocsiz);
bno = ffs_mapsearch(needswap, fs, cgp, bpref, allocsiz);
if (bno < 0) {
brelse(bp);
return (NULL);
}
for (i = 0; i < frags; i++)
clrbit(cg_blksfree(cgp), bno + i);
cgp->cg_cs.cs_nffree -= frags;
clrbit(cg_blksfree(cgp, needswap), bno + i);
ufs_add32(cgp->cg_cs.cs_nffree, -frags, needswap);
fs->fs_cstotal.cs_nffree -= frags;
fs->fs_cs(fs, cg).cs_nffree -= frags;
fs->fs_fmod = 1;
cgp->cg_frsum[allocsiz]--;
ufs_add32(cgp->cg_frsum[allocsiz], -1, needswap);
if (frags != allocsiz)
cgp->cg_frsum[allocsiz - frags]++;
ufs_add32(cgp->cg_frsum[allocsiz - frags], 1, needswap);
bdwrite(bp);
return (cg * fs->fs_fpg + bno);
}
@ -934,7 +941,8 @@ ffs_alloccg(ip, cg, bpref, size)
* blocks may be fragmented by the routine that allocates them.
*/
static ufs_daddr_t
ffs_alloccgblk(fs, cgp, bpref)
ffs_alloccgblk(mp, fs, cgp, bpref)
struct mount *mp;
register struct fs *fs;
register struct cg *cgp;
ufs_daddr_t bpref;
@ -943,9 +951,11 @@ ffs_alloccgblk(fs, cgp, bpref)
int cylno, pos, delta;
short *cylbp;
register int i;
const int needswap = UFS_MPNEEDSWAP(mp);
if (bpref == 0 || dtog(fs, bpref) != cgp->cg_cgx) {
bpref = cgp->cg_rotor;
if (bpref == 0 ||
dtog(fs, bpref) != ufs_rw32(cgp->cg_cgx, needswap)) {
bpref = ufs_rw32(cgp->cg_rotor, needswap);
goto norot;
}
bpref = blknum(fs, bpref);
@ -953,7 +963,8 @@ ffs_alloccgblk(fs, cgp, bpref)
/*
* if the requested block is available, use it
*/
if (ffs_isblock(fs, cg_blksfree(cgp), fragstoblks(fs, bpref))) {
if (ffs_isblock(fs, cg_blksfree(cgp, needswap),
fragstoblks(fs, bpref))) {
bno = bpref;
goto gotit;
}
@ -972,23 +983,23 @@ ffs_alloccgblk(fs, cgp, bpref)
* check for a block available on the same cylinder
*/
cylno = cbtocylno(fs, bpref);
if (cg_blktot(cgp)[cylno] == 0)
if (cg_blktot(cgp, needswap)[cylno] == 0)
goto norot;
/*
* check the summary information to see if a block is
* available in the requested cylinder starting at the
* requested rotational position and proceeding around.
*/
cylbp = cg_blks(fs, cgp, cylno);
cylbp = cg_blks(fs, cgp, cylno, needswap);
pos = cbtorpos(fs, bpref);
for (i = pos; i < fs->fs_nrpos; i++)
if (cylbp[i] > 0)
if (ufs_rw16(cylbp[i], needswap) > 0)
break;
if (i == fs->fs_nrpos)
for (i = 0; i < pos; i++)
if (cylbp[i] > 0)
if (ufs_rw16(cylbp[i], needswap) > 0)
break;
if (cylbp[i] > 0) {
if (ufs_rw16(cylbp[i], needswap) > 0) {
/*
* found a rotational position, now find the actual
* block. A panic if none is actually there.
@ -1001,7 +1012,7 @@ ffs_alloccgblk(fs, cgp, bpref)
panic("ffs_alloccgblk: cyl groups corrupted");
}
for (i = fs_postbl(fs, pos)[i];; ) {
if (ffs_isblock(fs, cg_blksfree(cgp), bno + i)) {
if (ffs_isblock(fs, cg_blksfree(cgp, needswap), bno + i)) {
bno = blkstofrags(fs, (bno + i));
goto gotit;
}
@ -1019,22 +1030,23 @@ norot:
* no blocks in the requested cylinder, so take next
* available one in this cylinder group.
*/
bno = ffs_mapsearch(fs, cgp, bpref, (int)fs->fs_frag);
bno = ffs_mapsearch(needswap, fs, cgp, bpref, (int)fs->fs_frag);
if (bno < 0)
return (NULL);
cgp->cg_rotor = bno;
cgp->cg_rotor = ufs_rw32(bno, needswap);
gotit:
blkno = fragstoblks(fs, bno);
ffs_clrblock(fs, cg_blksfree(cgp), (long)blkno);
ffs_clusteracct(fs, cgp, blkno, -1);
cgp->cg_cs.cs_nbfree--;
ffs_clrblock(fs, cg_blksfree(cgp, needswap), (long)blkno);
ffs_clusteracct(needswap, fs, cgp, blkno, -1);
ufs_add32(cgp->cg_cs.cs_nbfree, -1, needswap);
fs->fs_cstotal.cs_nbfree--;
fs->fs_cs(fs, cgp->cg_cgx).cs_nbfree--;
fs->fs_cs(fs, ufs_rw32(cgp->cg_cgx, needswap)).cs_nbfree--;
cylno = cbtocylno(fs, bno);
cg_blks(fs, cgp, cylno)[cbtorpos(fs, bno)]--;
cg_blktot(cgp)[cylno]--;
ufs_add16(cg_blks(fs, cgp, cylno, needswap)[cbtorpos(fs, bno)], -1,
needswap);
ufs_add32(cg_blktot(cgp, needswap)[cylno], -1, needswap);
fs->fs_fmod = 1;
return (cgp->cg_cgx * fs->fs_fpg + bno);
return (ufs_rw32(cgp->cg_cgx, needswap) * fs->fs_fpg + bno);
}
/*
@ -1065,15 +1077,15 @@ ffs_clusteralloc(ip, cg, bpref, len)
NOCRED, &bp))
goto fail;
cgp = (struct cg *)bp->b_data;
if (!cg_chkmagic(cgp))
if (!cg_chkmagic(cgp, UFS_IPNEEDSWAP(ip)))
goto fail;
/*
* Check to see if a cluster of the needed size (or bigger) is
* available in this cylinder group.
*/
lp = &cg_clustersum(cgp)[len];
lp = &cg_clustersum(cgp, UFS_IPNEEDSWAP(ip))[len];
for (i = len; i <= fs->fs_contigsumsize; i++)
if (*lp++ > 0)
if (ufs_rw32(*lp++, UFS_IPNEEDSWAP(ip)) > 0)
break;
if (i > fs->fs_contigsumsize) {
/*
@ -1083,9 +1095,9 @@ ffs_clusteralloc(ip, cg, bpref, len)
* future cluster allocation requests can avoid reading
* the cylinder group map only to find no clusters.
*/
lp = &cg_clustersum(cgp)[len - 1];
lp = &cg_clustersum(cgp, UFS_IPNEEDSWAP(ip))[len - 1];
for (i = len - 1; i > 0; i--)
if (*lp-- > 0)
if (ufs_rw32(*lp--, UFS_IPNEEDSWAP(ip)) > 0)
break;
fs->fs_maxcluster[cg] = i;
goto fail;
@ -1105,10 +1117,11 @@ ffs_clusteralloc(ip, cg, bpref, len)
bpref = 0;
else
bpref = fragstoblks(fs, dtogd(fs, blknum(fs, bpref)));
mapp = &cg_clustersfree(cgp)[bpref / NBBY];
mapp = &cg_clustersfree(cgp, UFS_IPNEEDSWAP(ip))[bpref / NBBY];
map = *mapp++;
bit = 1 << (bpref % NBBY);
for (run = 0, got = bpref; got < cgp->cg_nclusterblks; got++) {
for (run = 0, got = bpref;
got < ufs_rw32(cgp->cg_nclusterblks, UFS_IPNEEDSWAP(ip)); got++) {
if ((map & bit) == 0) {
run = 0;
} else {
@ -1123,20 +1136,22 @@ ffs_clusteralloc(ip, cg, bpref, len)
bit = 1;
}
}
if (got == cgp->cg_nclusterblks)
if (got == ufs_rw32(cgp->cg_nclusterblks, UFS_IPNEEDSWAP(ip)))
goto fail;
/*
* Allocate the cluster that we have found.
*/
for (i = 1; i <= len; i++)
if (!ffs_isblock(fs, cg_blksfree(cgp), got - run + i))
if (!ffs_isblock(fs, cg_blksfree(cgp, UFS_IPNEEDSWAP(ip)),
got - run + i))
panic("ffs_clusteralloc: map mismatch");
bno = cg * fs->fs_fpg + blkstofrags(fs, got - run + 1);
if (dtog(fs, bno) != cg)
panic("ffs_clusteralloc: allocated out of group");
len = blkstofrags(fs, len);
for (i = 0; i < len; i += fs->fs_frag)
if ((got = ffs_alloccgblk(fs, cgp, bno + i)) != bno + i)
if ((got = ffs_alloccgblk(ITOV(ip)->v_mount, fs, cgp, bno + i))
!= bno + i)
panic("ffs_clusteralloc: lost block");
bdwrite(bp);
return (bno);
@ -1166,6 +1181,9 @@ ffs_nodealloccg(ip, cg, ipref, mode)
register struct cg *cgp;
struct buf *bp;
int error, start, len, loc, map, i;
#ifdef FFS_EI
const int needswap = UFS_IPNEEDSWAP(ip);
#endif
fs = ip->i_fs;
if (fs->fs_cs(fs, cg).cs_nifree == 0)
@ -1177,36 +1195,38 @@ ffs_nodealloccg(ip, cg, ipref, mode)
return (NULL);
}
cgp = (struct cg *)bp->b_data;
if (!cg_chkmagic(cgp) || cgp->cg_cs.cs_nifree == 0) {
if (!cg_chkmagic(cgp, needswap) || cgp->cg_cs.cs_nifree == 0) {
brelse(bp);
return (NULL);
}
cgp->cg_time = time.tv_sec;
cgp->cg_time = ufs_rw32(time.tv_sec, needswap);
if (ipref) {
ipref %= fs->fs_ipg;
if (isclr(cg_inosused(cgp), ipref))
if (isclr(cg_inosused(cgp, needswap), ipref))
goto gotit;
}
start = cgp->cg_irotor / NBBY;
len = howmany(fs->fs_ipg - cgp->cg_irotor, NBBY);
loc = skpc(0xff, len, &cg_inosused(cgp)[start]);
start = ufs_rw32(cgp->cg_irotor, needswap) / NBBY;
len = howmany(fs->fs_ipg - ufs_rw32(cgp->cg_irotor, needswap),
NBBY);
loc = skpc(0xff, len, &cg_inosused(cgp, needswap)[start]);
if (loc == 0) {
len = start + 1;
start = 0;
loc = skpc(0xff, len, &cg_inosused(cgp)[0]);
loc = skpc(0xff, len, &cg_inosused(cgp, needswap)[0]);
if (loc == 0) {
printf("cg = %d, irotor = %d, fs = %s\n",
cg, cgp->cg_irotor, fs->fs_fsmnt);
cg, ufs_rw32(cgp->cg_irotor, needswap),
fs->fs_fsmnt);
panic("ffs_nodealloccg: map corrupted");
/* NOTREACHED */
}
}
i = start + len - loc;
map = cg_inosused(cgp)[i];
map = cg_inosused(cgp, needswap)[i];
ipref = i * NBBY;
for (i = 1; i < (1 << NBBY); i <<= 1, ipref++) {
if ((map & i) == 0) {
cgp->cg_irotor = ipref;
cgp->cg_irotor = ufs_rw32(ipref, needswap);
goto gotit;
}
}
@ -1214,13 +1234,13 @@ ffs_nodealloccg(ip, cg, ipref, mode)
panic("ffs_nodealloccg: block not in map");
/* NOTREACHED */
gotit:
setbit(cg_inosused(cgp), ipref);
cgp->cg_cs.cs_nifree--;
setbit(cg_inosused(cgp, needswap), ipref);
ufs_add32(cgp->cg_cs.cs_nifree, -1, needswap);
fs->fs_cstotal.cs_nifree--;
fs->fs_cs(fs, cg).cs_nifree--;
fs->fs_cs(fs, cg).cs_nifree --;
fs->fs_fmod = 1;
if ((mode & IFMT) == IFDIR) {
cgp->cg_cs.cs_ndir++;
ufs_add32(cgp->cg_cs.cs_ndir, 1, needswap);
fs->fs_cstotal.cs_ndir++;
fs->fs_cs(fs, cg).cs_ndir++;
}
@ -1246,6 +1266,7 @@ ffs_blkfree(ip, bno, size)
struct buf *bp;
ufs_daddr_t blkno;
int i, error, cg, blk, frags, bbase;
const int needswap = UFS_MPNEEDSWAP(ITOV(ip)->v_mount);
fs = ip->i_fs;
if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0) {
@ -1266,69 +1287,71 @@ ffs_blkfree(ip, bno, size)
return;
}
cgp = (struct cg *)bp->b_data;
if (!cg_chkmagic(cgp)) {
if (!cg_chkmagic(cgp, needswap)) {
brelse(bp);
return;
}
cgp->cg_time = time.tv_sec;
cgp->cg_time = ufs_rw32(time.tv_sec, needswap);
bno = dtogd(fs, bno);
if (size == fs->fs_bsize) {
blkno = fragstoblks(fs, bno);
if (ffs_isblock(fs, cg_blksfree(cgp), blkno)) {
if (ffs_isblock(fs, cg_blksfree(cgp, needswap), blkno)) {
printf("dev = 0x%x, block = %d, fs = %s\n",
ip->i_dev, bno, fs->fs_fsmnt);
panic("blkfree: freeing free block");
}
ffs_setblock(fs, cg_blksfree(cgp), blkno);
ffs_clusteracct(fs, cgp, blkno, 1);
cgp->cg_cs.cs_nbfree++;
ffs_setblock(fs, cg_blksfree(cgp, needswap), blkno);
ffs_clusteracct(needswap, fs, cgp, blkno, 1);
ufs_add32(cgp->cg_cs.cs_nbfree, 1, needswap);
fs->fs_cstotal.cs_nbfree++;
fs->fs_cs(fs, cg).cs_nbfree++;
i = cbtocylno(fs, bno);
cg_blks(fs, cgp, i)[cbtorpos(fs, bno)]++;
cg_blktot(cgp)[i]++;
ufs_add16(cg_blks(fs, cgp, i, needswap)[cbtorpos(fs, bno)], 1,
needswap);
ufs_add32(cg_blktot(cgp, needswap)[i], 1, needswap);
} else {
bbase = bno - fragnum(fs, bno);
/*
* decrement the counts associated with the old frags
*/
blk = blkmap(fs, cg_blksfree(cgp), bbase);
ffs_fragacct(fs, blk, cgp->cg_frsum, -1);
blk = blkmap(fs, cg_blksfree(cgp, needswap), bbase);
ffs_fragacct(fs, blk, cgp->cg_frsum, -1, needswap);
/*
* deallocate the fragment
*/
frags = numfrags(fs, size);
for (i = 0; i < frags; i++) {
if (isset(cg_blksfree(cgp), bno + i)) {
if (isset(cg_blksfree(cgp, needswap), bno + i)) {
printf("dev = 0x%x, block = %d, fs = %s\n",
ip->i_dev, bno + i, fs->fs_fsmnt);
panic("blkfree: freeing free frag");
}
setbit(cg_blksfree(cgp), bno + i);
setbit(cg_blksfree(cgp, needswap), bno + i);
}
cgp->cg_cs.cs_nffree += i;
ufs_add32(cgp->cg_cs.cs_nffree, i, needswap);
fs->fs_cstotal.cs_nffree += i;
fs->fs_cs(fs, cg).cs_nffree += i;
fs->fs_cs(fs, cg).cs_nffree +=i;
/*
* add back in counts associated with the new frags
*/
blk = blkmap(fs, cg_blksfree(cgp), bbase);
ffs_fragacct(fs, blk, cgp->cg_frsum, 1);
blk = blkmap(fs, cg_blksfree(cgp, needswap), bbase);
ffs_fragacct(fs, blk, cgp->cg_frsum, 1, needswap);
/*
* if a complete block has been reassembled, account for it
*/
blkno = fragstoblks(fs, bbase);
if (ffs_isblock(fs, cg_blksfree(cgp), blkno)) {
cgp->cg_cs.cs_nffree -= fs->fs_frag;
if (ffs_isblock(fs, cg_blksfree(cgp, needswap), blkno)) {
ufs_add32(cgp->cg_cs.cs_nffree, -fs->fs_frag, needswap);
fs->fs_cstotal.cs_nffree -= fs->fs_frag;
fs->fs_cs(fs, cg).cs_nffree -= fs->fs_frag;
ffs_clusteracct(fs, cgp, blkno, 1);
cgp->cg_cs.cs_nbfree++;
ffs_clusteracct(needswap, fs, cgp, blkno, 1);
ufs_add32(cgp->cg_cs.cs_nbfree, 1, needswap);
fs->fs_cstotal.cs_nbfree++;
fs->fs_cs(fs, cg).cs_nbfree++;
i = cbtocylno(fs, bbase);
cg_blks(fs, cgp, i)[cbtorpos(fs, bbase)]++;
cg_blktot(cgp)[i]++;
ufs_add16(cg_blks(fs, cgp, i, needswap)[cbtorpos(fs, bbase)], 1,
needswap);
ufs_add32(cg_blktot(cgp, needswap)[i], 1, needswap);
}
}
fs->fs_fmod = 1;
@ -1366,17 +1389,18 @@ ffs_checkblk(ip, bno, size)
return 0;
}
cgp = (struct cg *)bp->b_data;
if (!cg_chkmagic(cgp)) {
if (!cg_chkmagic(cgp, UFS_IPNEEDSWAP(ip))) {
brelse(bp);
return 0;
}
bno = dtogd(fs, bno);
if (size == fs->fs_bsize) {
free = ffs_isblock(fs, cg_blksfree(cgp), fragstoblks(fs, bno));
free = ffs_isblock(fs, cg_blksfree(cgp, UFS_IPNEEDSWAP(ip)),
fragstoblks(fs, bno));
} else {
frags = numfrags(fs, size);
for (free = 0, i = 0; i < frags; i++)
if (isset(cg_blksfree(cgp), bno + i))
if (isset(cg_blksfree(cgp, UFS_IPNEEDSWAP(ip)), bno + i))
free++;
if (free != 0 && free != frags)
panic("checkblk: partially free fragment");
@ -1406,6 +1430,9 @@ ffs_vfree(v)
ino_t ino = ap->a_ino;
struct buf *bp;
int error, cg;
#ifdef FFS_EI
const int needswap = UFS_MPNEEDSWAP(ap->a_pvp->v_mount);
#endif
pip = VTOI(ap->a_pvp);
fs = pip->i_fs;
@ -1420,26 +1447,26 @@ ffs_vfree(v)
return (0);
}
cgp = (struct cg *)bp->b_data;
if (!cg_chkmagic(cgp)) {
if (!cg_chkmagic(cgp, needswap)) {
brelse(bp);
return (0);
}
cgp->cg_time = time.tv_sec;
cgp->cg_time = ufs_rw32(time.tv_sec, needswap);
ino %= fs->fs_ipg;
if (isclr(cg_inosused(cgp), ino)) {
if (isclr(cg_inosused(cgp, needswap), ino)) {
printf("dev = 0x%x, ino = %d, fs = %s\n",
pip->i_dev, ino, fs->fs_fsmnt);
if (fs->fs_ronly == 0)
panic("ifree: freeing free inode");
}
clrbit(cg_inosused(cgp), ino);
if (ino < cgp->cg_irotor)
cgp->cg_irotor = ino;
cgp->cg_cs.cs_nifree++;
clrbit(cg_inosused(cgp, needswap), ino);
if (ino < ufs_rw32(cgp->cg_irotor, needswap))
cgp->cg_irotor = ufs_rw32(ino, needswap);
ufs_add32(cgp->cg_cs.cs_nifree, 1, needswap);
fs->fs_cstotal.cs_nifree++;
fs->fs_cs(fs, cg).cs_nifree++;
if ((ap->a_mode & IFMT) == IFDIR) {
cgp->cg_cs.cs_ndir--;
ufs_add32(cgp->cg_cs.cs_ndir, -1, needswap);
fs->fs_cstotal.cs_ndir--;
fs->fs_cs(fs, cg).cs_ndir--;
}
@ -1455,7 +1482,8 @@ ffs_vfree(v)
* available.
*/
static ufs_daddr_t
ffs_mapsearch(fs, cgp, bpref, allocsiz)
ffs_mapsearch(needswap, fs, cgp, bpref, allocsiz)
int needswap;
register struct fs *fs;
register struct cg *cgp;
ufs_daddr_t bpref;
@ -1464,6 +1492,7 @@ ffs_mapsearch(fs, cgp, bpref, allocsiz)
ufs_daddr_t bno;
int start, len, loc, i;
int blk, field, subfield, pos;
int ostart, olen;
/*
* find the fragment by searching through the free block
@ -1472,32 +1501,37 @@ ffs_mapsearch(fs, cgp, bpref, allocsiz)
if (bpref)
start = dtogd(fs, bpref) / NBBY;
else
start = cgp->cg_frotor / NBBY;
start = ufs_rw32(cgp->cg_frotor, needswap) / NBBY;
len = howmany(fs->fs_fpg, NBBY) - start;
loc = scanc((u_int)len, (u_char *)&cg_blksfree(cgp)[start],
ostart = start;
olen = len;
loc = scanc((u_int)len, (u_char *)&cg_blksfree(cgp, needswap)[start],
(u_char *)fragtbl[fs->fs_frag],
(u_char)(1 << (allocsiz - 1 + (fs->fs_frag % NBBY))));
if (loc == 0) {
len = start + 1;
start = 0;
loc = scanc((u_int)len, (u_char *)&cg_blksfree(cgp)[0],
loc = scanc((u_int)len, (u_char *)&cg_blksfree(cgp, needswap)[0],
(u_char *)fragtbl[fs->fs_frag],
(u_char)(1 << (allocsiz - 1 + (fs->fs_frag % NBBY))));
if (loc == 0) {
printf("start = %d, len = %d, fs = %s\n",
start, len, fs->fs_fsmnt);
ostart, olen, fs->fs_fsmnt);
printf("offset=%d %d\n",
ufs_rw32(cgp->cg_freeoff, needswap),
(u_int32_t)cg_blksfree(cgp, needswap) - (u_int32_t)cgp);
panic("ffs_alloccg: map corrupted");
/* NOTREACHED */
}
}
bno = (start + len - loc) * NBBY;
cgp->cg_frotor = bno;
cgp->cg_frotor = ufs_rw32(bno, needswap);
/*
* found the byte in the map
* sift through the bits to find the selected frag
*/
for (i = bno + NBBY; bno < i; bno += fs->fs_frag) {
blk = blkmap(fs, cg_blksfree(cgp), bno);
blk = blkmap(fs, cg_blksfree(cgp, needswap), bno);
blk <<= 1;
field = around[allocsiz];
subfield = inside[allocsiz];
@ -1519,7 +1553,8 @@ ffs_mapsearch(fs, cgp, bpref, allocsiz)
* Cnt == 1 means free; cnt == -1 means allocating.
*/
void
ffs_clusteracct(fs, cgp, blkno, cnt)
ffs_clusteracct(needswap, fs, cgp, blkno, cnt)
int needswap;
struct fs *fs;
struct cg *cgp;
ufs_daddr_t blkno;
@ -1532,8 +1567,8 @@ ffs_clusteracct(fs, cgp, blkno, cnt)
if (fs->fs_contigsumsize <= 0)
return;
freemapp = cg_clustersfree(cgp);
sump = cg_clustersum(cgp);
freemapp = cg_clustersfree(cgp, needswap);
sump = cg_clustersum(cgp, needswap);
/*
* Allocate or clear the actual block.
*/
@ -1546,8 +1581,8 @@ ffs_clusteracct(fs, cgp, blkno, cnt)
*/
start = blkno + 1;
end = start + fs->fs_contigsumsize;
if (end >= cgp->cg_nclusterblks)
end = cgp->cg_nclusterblks;
if (end >= ufs_rw32(cgp->cg_nclusterblks, needswap))
end = ufs_rw32(cgp->cg_nclusterblks, needswap);
mapp = &freemapp[start / NBBY];
map = *mapp++;
bit = 1 << (start % NBBY);
@ -1590,19 +1625,20 @@ ffs_clusteracct(fs, cgp, blkno, cnt)
i = back + forw + 1;
if (i > fs->fs_contigsumsize)
i = fs->fs_contigsumsize;
sump[i] += cnt;
ufs_add32(sump[i], cnt, needswap);
if (back > 0)
sump[back] -= cnt;
ufs_add32(sump[back], -cnt, needswap);
if (forw > 0)
sump[forw] -= cnt;
ufs_add32(sump[forw], -cnt, needswap);
/*
* Update cluster summary information.
*/
lp = &sump[fs->fs_contigsumsize];
for (i = fs->fs_contigsumsize; i > 0; i--)
if (*lp-- > 0)
if (ufs_rw32(*lp--, needswap) > 0)
break;
fs->fs_maxcluster[cgp->cg_cgx] = i;
fs->fs_maxcluster[ufs_rw32(cgp->cg_cgx, needswap)] = i;
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_balloc.c,v 1.8 1998/03/01 02:23:14 fvdl Exp $ */
/* $NetBSD: ffs_balloc.c,v 1.9 1998/03/18 15:57:27 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -43,6 +43,7 @@
#include <sys/proc.h>
#include <sys/file.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <vm/vm.h>
@ -51,8 +52,10 @@
#endif
#include <ufs/ufs/quota.h>
#include <ufs/ufs/ufsmount.h>
#include <ufs/ufs/inode.h>
#include <ufs/ufs/ufs_extern.h>
#include <ufs/ufs/ufs_bswap.h>
#include <ufs/ffs/fs.h>
#include <ufs/ffs/ffs_extern.h>
@ -105,7 +108,8 @@ ffs_balloc(ip, lbn, size, cred, bpp, flags)
#else
vnode_pager_setsize(vp, ip->i_ffs_size);
#endif
ip->i_ffs_db[nb] = dbtofsb(fs, bp->b_blkno);
ip->i_ffs_db[nb] = ufs_rw32(dbtofsb(fs, bp->b_blkno),
UFS_MPNEEDSWAP(vp->v_mount));
ip->i_flag |= IN_CHANGE | IN_UPDATE;
if (flags & B_SYNC)
bwrite(bp);
@ -117,7 +121,7 @@ ffs_balloc(ip, lbn, size, cred, bpp, flags)
* The first NDADDR blocks are direct blocks
*/
if (lbn < NDADDR) {
nb = ip->i_ffs_db[lbn];
nb = ufs_rw32(ip->i_ffs_db[lbn], UFS_MPNEEDSWAP(vp->v_mount));
if (nb != 0 && ip->i_ffs_size >= (lbn + 1) * fs->fs_bsize) {
error = bread(vp, lbn, fs->fs_bsize, NOCRED, &bp);
if (error) {
@ -162,7 +166,8 @@ ffs_balloc(ip, lbn, size, cred, bpp, flags)
if (flags & B_CLRBUF)
clrbuf(bp);
}
ip->i_ffs_db[lbn] = dbtofsb(fs, bp->b_blkno);
ip->i_ffs_db[lbn] = ufs_rw32(dbtofsb(fs, bp->b_blkno),
UFS_MPNEEDSWAP(vp->v_mount));
ip->i_flag |= IN_CHANGE | IN_UPDATE;
*bpp = bp;
return (0);
@ -181,13 +186,14 @@ ffs_balloc(ip, lbn, size, cred, bpp, flags)
* Fetch the first indirect block allocating if necessary.
*/
--num;
nb = ip->i_ffs_ib[indirs[0].in_off];
nb = ufs_rw32(ip->i_ffs_ib[indirs[0].in_off],
UFS_MPNEEDSWAP(vp->v_mount));
allocib = NULL;
allocblk = allociblk;
if (nb == 0) {
pref = ffs_blkpref(ip, lbn, 0, (ufs_daddr_t *)0);
error = ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize,
cred, &newb);
error = ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize,
cred, &newb);
if (error)
return (error);
nb = newb;
@ -202,7 +208,7 @@ ffs_balloc(ip, lbn, size, cred, bpp, flags)
if ((error = bwrite(bp)) != 0)
goto fail;
allocib = &ip->i_ffs_ib[indirs[0].in_off];
*allocib = nb;
*allocib = ufs_rw32(nb, UFS_MPNEEDSWAP(vp->v_mount));
ip->i_flag |= IN_CHANGE | IN_UPDATE;
}
/*
@ -216,7 +222,7 @@ ffs_balloc(ip, lbn, size, cred, bpp, flags)
goto fail;
}
bap = (ufs_daddr_t *)bp->b_data;
nb = bap[indirs[i].in_off];
nb = ufs_rw32(bap[indirs[i].in_off], UFS_MPNEEDSWAP(vp->v_mount));
if (i == num)
break;
i += 1;
@ -245,7 +251,8 @@ ffs_balloc(ip, lbn, size, cred, bpp, flags)
brelse(bp);
goto fail;
}
bap[indirs[i - 1].in_off] = nb;
bap[indirs[i - 1].in_off] = ufs_rw32(nb,
UFS_MPNEEDSWAP(vp->v_mount));
/*
* If required, write synchronously, otherwise use
* delayed write.
@ -273,7 +280,7 @@ ffs_balloc(ip, lbn, size, cred, bpp, flags)
nbp->b_blkno = fsbtodb(fs, nb);
if (flags & B_CLRBUF)
clrbuf(nbp);
bap[indirs[i].in_off] = nb;
bap[indirs[i].in_off] = ufs_rw32(nb, UFS_MPNEEDSWAP(vp->v_mount));
/*
* If required, write synchronously, otherwise use
* delayed write.

124
sys/ufs/ffs/ffs_bswap.c Normal file
View File

@ -0,0 +1,124 @@
/* $NetBSD: ffs_bswap.c,v 1.1 1998/03/18 15:57:27 bouyer Exp $ */
/*
* Copyright (c) 1998 Manuel Bouyer.
*
* Redistribution and use in source and binary forms, with or without
* 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.
* 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.
* 3. All advertising materials mentioning features or use of this software
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/param.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/ufs_bswap.h>
#include <ufs/ffs/fs.h>
#include <ufs/ffs/ffs_extern.h>
void
ffs_sb_swap(o, n, ns)
struct fs *o, *n;
int ns;
{
int i;
u_int32_t *o32, *n32;
u_int16_t *o16, *n16;
/* in order to avoid a lot of lines, as the first 52 fields of
* the superblock are u_int32_t, we loop here to convert it.
*/
o32 = (u_int32_t *)o;
n32 = (u_int32_t *)n;
for (i=0; i< 52; i++)
n32[i] = bswap32(o32[i]);
n->fs_cpc = bswap32(o->fs_cpc);
n->fs_fscktime = bswap32(o->fs_fscktime);
n->fs_contigsumsize = bswap32(o->fs_contigsumsize);
n->fs_maxsymlinklen = bswap32(o->fs_maxsymlinklen);
n->fs_inodefmt = bswap32(o->fs_inodefmt);
n->fs_maxfilesize = bswap64(o->fs_maxfilesize);
n->fs_qbmask = bswap64(o->fs_qbmask);
n->fs_qfmask = bswap64(o->fs_qfmask);
n->fs_state = bswap32(o->fs_state);
n->fs_postblformat = bswap32(o->fs_postblformat);
n->fs_nrpos = bswap32(o->fs_nrpos);
n->fs_postbloff = bswap32(o->fs_postbloff);
n->fs_rotbloff = bswap32(o->fs_rotbloff);
n->fs_magic = bswap32(o->fs_magic);
/* byteswap the postbl */
o16 = (ufs_rw32(o->fs_postblformat, ns) == FS_42POSTBLFMT)
? o->fs_opostbl[0]
: (int16_t *)((u_int8_t *)o + ufs_rw32(o->fs_postbloff, ns));
n16 = (ufs_rw32(o->fs_postblformat, ns) == FS_42POSTBLFMT)
? n->fs_opostbl[0]
: (int16_t *)((u_int8_t *)n + ufs_rw32(n->fs_postbloff, ns));
for (i = 0;
i < ufs_rw32(o->fs_cpc, ns) * ufs_rw32(o->fs_nrpos, ns);
i++)
n16[i] = bswap16(o16[i]);
}
void
ffs_dinode_swap(o, n)
struct dinode *o, *n;
{
n->di_mode = bswap16(o->di_mode);
n->di_nlink = bswap16(o->di_nlink);
n->di_u.oldids[0] = bswap16(o->di_u.oldids[0]);
n->di_u.oldids[1] = bswap16(o->di_u.oldids[1]);
n->di_size = bswap64(o->di_size);
n->di_atime = bswap32(o->di_atime);
n->di_atimensec = bswap32(o->di_atimensec);
n->di_mtime = bswap32(o->di_mtime);
n->di_mtimensec = bswap32(o->di_mtimensec);
n->di_ctime = bswap32(o->di_ctime);
n->di_ctimensec = bswap32(o->di_ctimensec);
bcopy(o->di_db, n->di_db, (NDADDR + NIADDR) * sizeof(u_int32_t));
n->di_flags = bswap32(o->di_flags);
n->di_blocks = bswap32(o->di_blocks);
n->di_gen = bswap32(o->di_gen);
n->di_uid = bswap32(o->di_uid);
n->di_gid = bswap32(o->di_gid);
}
void
ffs_csum_swap(o, n, size)
struct csum *o, *n;
int size;
{
int i;
u_int32_t *oint, *nint;
oint = (u_int32_t*)o;
nint = (u_int32_t*)n;
for (i = 0; i < size / sizeof(u_int32_t); i++)
nint[i] = bswap32(oint[i]);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_extern.h,v 1.7 1998/03/01 02:23:14 fvdl Exp $ */
/* $NetBSD: ffs_extern.h,v 1.8 1998/03/18 15:57:27 bouyer Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -56,6 +56,7 @@ struct buf;
struct fid;
struct fs;
struct inode;
struct dinode;
struct mount;
struct nameidata;
struct proc;
@ -80,12 +81,17 @@ int ffs_valloc __P((void *));
ufs_daddr_t ffs_blkpref __P((struct inode *, ufs_daddr_t, int, ufs_daddr_t *));
void ffs_blkfree __P((struct inode *, ufs_daddr_t, long));
int ffs_vfree __P((void *));
void ffs_clusteracct __P((struct fs *, struct cg *, ufs_daddr_t, int));
void ffs_clusteracct __P((int, struct fs *, struct cg *, ufs_daddr_t, int));
/* ffs_balloc.c */
int ffs_balloc __P((struct inode *, ufs_daddr_t, int, struct ucred *,
struct buf **, int));
/* ffs_bswap.c */
void ffs_sb_swap __P((struct fs*, struct fs *, int));
void ffs_dinode_swap __P((struct dinode *, struct dinode *));
void ffs_csum_swap __P((struct csum *, struct csum *, int));
/* ffs_inode.c */
void ffs_init __P((void));
int ffs_update __P((void *));
@ -93,7 +99,7 @@ int ffs_truncate __P((void *));
/* ffs_subr.c */
int ffs_blkatoff __P((void *));
void ffs_fragacct __P((struct fs *, int, int32_t[], int));
void ffs_fragacct __P((struct fs *, int, int32_t[], int, int));
#ifdef DIAGNOSTIC
void ffs_checkoverlap __P((struct buf *, struct inode *));
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_inode.c,v 1.18 1998/03/01 02:23:14 fvdl Exp $ */
/* $NetBSD: ffs_inode.c,v 1.19 1998/03/18 15:57:27 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -59,6 +59,7 @@
#include <ufs/ufs/inode.h>
#include <ufs/ufs/ufsmount.h>
#include <ufs/ufs/ufs_extern.h>
#include <ufs/ufs/ufs_bswap.h>
#include <ufs/ffs/fs.h>
#include <ufs/ffs/ffs_extern.h>
@ -117,8 +118,12 @@ ffs_update(v)
brelse(bp);
return (error);
}
*((struct dinode *)bp->b_data +
ino_to_fsbo(fs, ip->i_number)) = ip->i_din.ffs_din;
if (UFS_MPNEEDSWAP(ap->a_vp->v_mount))
ffs_dinode_swap(&ip->i_din.ffs_din,
(struct dinode *)bp->b_data + ino_to_fsbo(fs, ip->i_number));
else
*((struct dinode *)bp->b_data +
ino_to_fsbo(fs, ip->i_number)) = ip->i_din.ffs_din;
if (ap->a_waitfor && (ap->a_vp->v_mount->mnt_flag & MNT_ASYNC) == 0)
return (bwrite(bp));
else {
@ -304,7 +309,7 @@ ffs_truncate(v)
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_ffs_ib[level];
bn = ufs_rw32(oip->i_ffs_ib[level], UFS_MPNEEDSWAP(ovp->v_mount));
if (bn != 0) {
error = ffs_indirtrunc(oip, indir_lbn[level],
fsbtodb(fs, bn), lastiblock[level], level, &count);
@ -327,7 +332,7 @@ ffs_truncate(v)
for (i = NDADDR - 1; i > lastblock; i--) {
register long bsize;
bn = oip->i_ffs_db[i];
bn = ufs_rw32(oip->i_ffs_db[i], UFS_MPNEEDSWAP(ovp->v_mount));
if (bn == 0)
continue;
oip->i_ffs_db[i] = 0;
@ -342,7 +347,7 @@ ffs_truncate(v)
* Finally, look for a change in size of the
* last direct block; release any frags.
*/
bn = oip->i_ffs_db[lastblock];
bn = ufs_rw32(oip->i_ffs_db[lastblock], UFS_MPNEEDSWAP(ovp->v_mount));
if (bn != 0) {
long oldspace, newspace;
@ -477,7 +482,7 @@ ffs_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 = ufs_rw32(bap[i], UFS_MPNEEDSWAP(vp->v_mount));
if (nb == 0)
continue;
if (level > SINGLE) {
@ -497,7 +502,7 @@ ffs_indirtrunc(ip, lbn, dbn, lastbn, level, countp)
*/
if (level > SINGLE && lastbn >= 0) {
last = lastbn % factor;
nb = bap[i];
nb = ufs_rw32(bap[i], UFS_MPNEEDSWAP(vp->v_mount));
if (nb != 0) {
error = ffs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
last, level - 1, &blkcount);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_subr.c,v 1.10 1998/03/01 02:23:14 fvdl Exp $ */
/* $NetBSD: ffs_subr.c,v 1.11 1998/03/18 15:57:28 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -41,15 +41,20 @@
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <ufs/ffs/ffs_extern.h>
#include <ufs/ufs/ufs_bswap.h>
#endif
#ifdef _KERNEL
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/buf.h>
#include <ufs/ufs/quota.h>
#include <ufs/ufs/ufsmount.h>
#include <ufs/ufs/inode.h>
#include <ufs/ufs/ufs_extern.h>
#include <ufs/ffs/fs.h>
#include <ufs/ffs/ffs_extern.h>
#include <ufs/ufs/ufs_bswap.h>
/*
* Return buffer with the contents of block "offset" from the beginning of
@ -94,11 +99,12 @@ ffs_blkatoff(v)
* of some frags.
*/
void
ffs_fragacct(fs, fragmap, fraglist, cnt)
ffs_fragacct(fs, fragmap, fraglist, cnt, needswap)
struct fs *fs;
int fragmap;
int32_t fraglist[];
int cnt;
int needswap;
{
int inblk;
register int field, subfield;
@ -113,7 +119,9 @@ ffs_fragacct(fs, fragmap, fraglist, cnt)
subfield = inside[siz];
for (pos = siz; pos <= fs->fs_frag; pos++) {
if ((fragmap & field) == subfield) {
fraglist[siz] += cnt;
fraglist[siz] = ufs_rw32(
ufs_rw32(fraglist[siz], needswap) + cnt,
needswap);
pos += siz;
field <<= siz;
subfield <<= siz;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_vfsops.c,v 1.33 1998/03/01 02:23:15 fvdl Exp $ */
/* $NetBSD: ffs_vfsops.c,v 1.34 1998/03/18 15:57:28 bouyer Exp $ */
/*
* Copyright (c) 1989, 1991, 1993, 1994
@ -62,6 +62,7 @@
#include <ufs/ufs/inode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ufs/ufs_extern.h>
#include <ufs/ufs/ufs_bswap.h>
#include <ufs/ffs/fs.h>
#include <ufs/ffs/ffs_extern.h>
@ -281,8 +282,8 @@ ffs_mount(mp, path, data, ndp, p)
if (fs->fs_clean & FS_WASCLEAN)
fs->fs_time = time.tv_sec;
else
printf("%s: file system not clean; please fsck(8)\n",
mp->mnt_stat.f_mntfromname);
printf("%s: file system not clean (fs_flags=%x); please fsck(8)\n",
mp->mnt_stat.f_mntfromname, fs->fs_clean);
(void) ffs_cgupdate(ump, MNT_WAIT);
}
return (0);
@ -309,7 +310,6 @@ ffs_reload(mountp, cred, p)
{
register struct vnode *vp, *nvp, *devvp;
struct inode *ip;
struct csum *space;
struct buf *bp;
struct fs *fs, *newfs;
struct partinfo dpart;
@ -334,13 +334,19 @@ ffs_reload(mountp, cred, p)
error = bread(devvp, (ufs_daddr_t)(SBOFF / size), SBSIZE, NOCRED, &bp);
if (error)
return (error);
newfs = (struct fs *)bp->b_data;
fs = VFSTOUFS(mountp)->um_fs;
newfs = malloc(fs->fs_sbsize, M_UFSMNT, M_WAITOK);
bcopy(bp->b_data, newfs, fs->fs_sbsize);
#ifdef FFS_EI
if (VFSTOUFS(mountp)->um_flags & UFS_NEEDSWAP)
ffs_sb_swap((struct fs*)bp->b_data, newfs, 0);
#endif
if (newfs->fs_magic != FS_MAGIC || newfs->fs_bsize > MAXBSIZE ||
newfs->fs_bsize < sizeof(struct fs)) {
brelse(bp);
free(newfs, M_UFSMNT);
return (EIO); /* XXX needs translation */
}
fs = VFSTOUFS(mountp)->um_fs;
/*
* Copy pointer fields back into superblock before copying in XXX
* new superblock. These should really be in the ufsmount. XXX
@ -352,13 +358,13 @@ ffs_reload(mountp, cred, p)
if (fs->fs_sbsize < SBSIZE)
bp->b_flags |= B_INVAL;
brelse(bp);
free(newfs, M_UFSMNT);
mountp->mnt_maxsymlinklen = fs->fs_maxsymlinklen;
ffs_oldfscompat(fs);
/*
* Step 3: re-read summary information from disk.
*/
blks = howmany(fs->fs_cssize, fs->fs_fsize);
space = fs->fs_csp[0];
for (i = 0; i < blks; i += fs->fs_frag) {
size = fs->fs_bsize;
if (i + fs->fs_frag > blks)
@ -367,7 +373,13 @@ ffs_reload(mountp, cred, p)
NOCRED, &bp);
if (error)
return (error);
bcopy(bp->b_data, fs->fs_csp[fragstoblks(fs, i)], (u_int)size);
#ifdef FFS_EI
if (UFS_MPNEEDSWAP(mountp))
ffs_csum_swap((struct csum*)bp->b_data,
(struct csum*)fs->fs_csp[fragstoblks(fs, i)], size);
else
#endif
bcopy(bp->b_data, fs->fs_csp[fragstoblks(fs, i)], (u_int)size);
brelse(bp);
}
/*
@ -411,8 +423,14 @@ loop:
vput(vp);
return (error);
}
ip->i_din.ffs_din = *((struct dinode *)bp->b_data +
ino_to_fsbo(fs, ip->i_number));
#ifdef FFS_EI
if (UFS_MPNEEDSWAP(mountp))
ffs_dinode_swap((struct dinode *)bp->b_data +
ino_to_fsbo(fs, ip->i_number), &ip->i_din.ffs_din);
else
#endif
ip->i_din.ffs_din = *((struct dinode *)bp->b_data +
ino_to_fsbo(fs, ip->i_number));
brelse(bp);
vput(vp);
simple_lock(&mntvnode_slock);
@ -430,18 +448,19 @@ ffs_mountfs(devvp, mp, p)
struct mount *mp;
struct proc *p;
{
register struct ufsmount *ump;
struct ufsmount *ump;
struct buf *bp;
register struct fs *fs;
struct fs *fs;
dev_t dev;
struct partinfo dpart;
caddr_t base, space;
int blks;
int error, i, size, ronly;
int error, i, size, ronly, needswap;
int32_t *lp;
struct ucred *cred;
extern struct vnode *rootvp;
u_int64_t maxfilesize; /* XXX */
u_int32_t sbsize;
dev = devvp->v_rdev;
cred = p ? p->p_ucred : NOCRED;
@ -472,27 +491,46 @@ ffs_mountfs(devvp, mp, p)
error = bread(devvp, (ufs_daddr_t)(SBOFF / size), SBSIZE, cred, &bp);
if (error)
goto out;
fs = (struct fs *)bp->b_data;
fs = (struct fs*)bp->b_data;
if (fs->fs_magic == FS_MAGIC) {
needswap = 0;
sbsize = fs->fs_sbsize;
#ifdef FFS_EI
} else if (fs->fs_magic == bswap32(FS_MAGIC)) {
needswap = 1;
sbsize = bswap32(fs->fs_sbsize);
#endif
} else {
error = EINVAL;
goto out;
}
fs = malloc((u_long)sbsize, M_UFSMNT, M_WAITOK);
bcopy(bp->b_data, fs, sbsize);
#ifdef FFS_EI
if (needswap)
ffs_sb_swap((struct fs*)bp->b_data, fs, 0);
#endif
if (fs->fs_magic != FS_MAGIC || fs->fs_bsize > MAXBSIZE ||
fs->fs_bsize < sizeof(struct fs)) {
error = EINVAL; /* XXX needs translation */
goto out;
goto out2;
}
/* XXX updating 4.2 FFS superblocks trashes rotational layout tables */
if (fs->fs_postblformat == FS_42POSTBLFMT && !ronly) {
error = EROFS; /* XXX what should be returned? */
goto out;
goto out2;
}
ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
bzero((caddr_t)ump, sizeof *ump);
ump->um_fs = malloc((u_long)fs->fs_sbsize, M_UFSMNT,
M_WAITOK);
bcopy(bp->b_data, ump->um_fs, (u_int)fs->fs_sbsize);
ump->um_fs = fs;
if (fs->fs_sbsize < SBSIZE)
bp->b_flags |= B_INVAL;
brelse(bp);
bp = NULL;
fs = ump->um_fs;
fs->fs_ronly = ronly;
if (ronly == 0) {
fs->fs_clean <<= 1;
@ -511,9 +549,16 @@ ffs_mountfs(devvp, mp, p)
cred, &bp);
if (error) {
free(base, M_UFSMNT);
goto out;
goto out2;
}
bcopy(bp->b_data, space, (u_int)size);
#ifdef FFS_EI
if (needswap)
ffs_csum_swap((struct csum*)bp->b_data,
(struct csum*)space, size);
else
#endif
bcopy(bp->b_data, space, (u_int)size);
fs->fs_csp[fragstoblks(fs, i)] = (struct csum *)space;
space += size;
brelse(bp);
@ -529,6 +574,10 @@ ffs_mountfs(devvp, mp, p)
mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_FFS);
mp->mnt_maxsymlinklen = fs->fs_maxsymlinklen;
mp->mnt_flag |= MNT_LOCAL;
#ifdef FFS_EI
if (needswap)
ump->um_flags |= UFS_NEEDSWAP;
#endif
ump->um_mountp = mp;
ump->um_dev = dev;
ump->um_devvp = devvp;
@ -544,12 +593,13 @@ ffs_mountfs(devvp, mp, p)
if (fs->fs_maxfilesize > maxfilesize) /* XXX */
fs->fs_maxfilesize = maxfilesize; /* XXX */
return (0);
out2:
free(fs, M_UFSMNT);
out:
if (bp)
brelse(bp);
(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, cred, p);
if (ump) {
free(ump->um_fs, M_UFSMNT);
free(ump, M_UFSMNT);
mp->mnt_data = (qaddr_t)0;
}
@ -851,7 +901,14 @@ ffs_vget(mp, ino, vpp)
*vpp = NULL;
return (error);
}
ip->i_din.ffs_din = *((struct dinode *)bp->b_data + ino_to_fsbo(fs, ino));
#ifdef FFS_EI
if (UFS_MPNEEDSWAP(mp))
ffs_dinode_swap((struct dinode *)bp->b_data + ino_to_fsbo(fs, ino),
&(ip->i_din.ffs_din));
else
#endif
ip->i_din.ffs_din =
*((struct dinode *)bp->b_data + ino_to_fsbo(fs, ino));
brelse(bp);
/*
@ -980,27 +1037,41 @@ ffs_sbupdate(mp, waitfor)
struct ufsmount *mp;
int waitfor;
{
register struct fs *dfs, *fs = mp->um_fs;
register struct fs *fs = mp->um_fs;
register struct buf *bp;
int i, error = 0;
int32_t saved_nrpos = fs->fs_nrpos;
int64_t saved_qbmask = fs->fs_qbmask;
int64_t saved_qfmask = fs->fs_qfmask;
u_int64_t saved_maxfilesize = fs->fs_maxfilesize;
bp = getblk(mp->um_devvp, SBOFF >> (fs->fs_fshift - fs->fs_fsbtodb),
(int)fs->fs_sbsize, 0, 0);
bcopy((caddr_t)fs, bp->b_data, (u_int)fs->fs_sbsize);
/* Restore compatibility to old file systems. XXX */
dfs = (struct fs *)bp->b_data; /* XXX */
if (fs->fs_postblformat == FS_42POSTBLFMT) /* XXX */
dfs->fs_nrpos = -1; /* XXX */
fs->fs_nrpos = -1; /* XXX */
if (fs->fs_inodefmt < FS_44INODEFMT) { /* XXX */
int32_t *lp, tmp; /* XXX */
/* XXX */
lp = (int32_t *)&dfs->fs_qbmask; /* XXX */
lp = (int32_t *)&fs->fs_qbmask; /* XXX nuke qfmask too */
tmp = lp[4]; /* XXX */
for (i = 4; i > 0; i--) /* XXX */
lp[i] = lp[i-1]; /* XXX */
lp[0] = tmp; /* XXX */
} /* XXX */
dfs->fs_maxfilesize = mp->um_savedmaxfilesize; /* XXX */
fs->fs_maxfilesize = mp->um_savedmaxfilesize; /* XXX */
bp = getblk(mp->um_devvp, SBOFF >> (fs->fs_fshift - fs->fs_fsbtodb),
(int)fs->fs_sbsize, 0, 0);
bcopy(fs, bp->b_data, fs->fs_sbsize);
#ifdef FFS_EI
if (mp->um_flags & UFS_NEEDSWAP)
ffs_sb_swap(fs, (struct fs*)bp->b_data, 1);
#endif
fs->fs_nrpos = saved_nrpos; /* XXX */
fs->fs_qbmask = saved_qbmask; /* XXX */
fs->fs_qfmask = saved_qfmask; /* XXX */
fs->fs_maxfilesize = saved_maxfilesize; /* XXX */
if (waitfor == MNT_WAIT)
error = bwrite(bp);
else
@ -1028,7 +1099,13 @@ ffs_cgupdate(mp, waitfor)
size = (blks - i) * fs->fs_fsize;
bp = getblk(mp->um_devvp, fsbtodb(fs, fs->fs_csaddr + i),
size, 0, 0);
bcopy(space, bp->b_data, (u_int)size);
#ifdef FFS_EI
if (mp->um_flags & UFS_NEEDSWAP)
ffs_csum_swap((struct csum*)space,
(struct csum*)bp->b_data, size);
else
#endif
bcopy(space, bp->b_data, (u_int)size);
space += size;
if (waitfor == MNT_WAIT)
error = bwrite(bp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: fs.h,v 1.8 1998/03/01 02:23:15 fvdl Exp $ */
/* $NetBSD: fs.h,v 1.9 1998/03/18 15:57:28 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@ -153,7 +153,7 @@ struct csum {
};
/*
* Super block for an FFS file system.
* Super block for an FFS file system in memory.
*/
struct fs {
int32_t fs_firstfield; /* historic file system linked list, */
@ -341,29 +341,37 @@ struct cg {
/*
* Macros for access to cylinder group array structures
*/
#define cg_blktot(cgp) \
(((cgp)->cg_magic != CG_MAGIC) \
#define cg_blktot(cgp, ns) \
((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) \
? (((struct ocg *)(cgp))->cg_btot) \
: ((int32_t *)((u_int8_t *)(cgp) + (cgp)->cg_btotoff)))
#define cg_blks(fs, cgp, cylno) \
(((cgp)->cg_magic != CG_MAGIC) \
: ((int32_t *)((u_int8_t *)(cgp) + \
ufs_rw32((cgp)->cg_btotoff, (ns)))))
#define cg_blks(fs, cgp, cylno, ns) \
((ufs_rw32((cgp)->cg_magic, ns) != CG_MAGIC) \
? (((struct ocg *)(cgp))->cg_b[cylno]) \
: ((int16_t *)((u_int8_t *)(cgp) + \
(cgp)->cg_boff) + (cylno) * (fs)->fs_nrpos))
#define cg_inosused(cgp) \
(((cgp)->cg_magic != CG_MAGIC) \
ufs_rw32((cgp)->cg_boff, (ns))) + \
(cylno) * (fs)->fs_nrpos))
#define cg_inosused(cgp, ns) \
((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) \
? (((struct ocg *)(cgp))->cg_iused) \
: ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_iusedoff)))
#define cg_blksfree(cgp) \
(((cgp)->cg_magic != CG_MAGIC) \
: ((u_int8_t *)((u_int8_t *)(cgp) + \
ufs_rw32((cgp)->cg_iusedoff, (ns)))))
#define cg_blksfree(cgp, ns) \
((ufs_rw32((cgp)->cg_magic, (ns)) != CG_MAGIC) \
? (((struct ocg *)(cgp))->cg_free) \
: ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_freeoff)))
#define cg_chkmagic(cgp) \
((cgp)->cg_magic == CG_MAGIC || ((struct ocg *)(cgp))->cg_magic == CG_MAGIC)
#define cg_clustersfree(cgp) \
((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_clusteroff))
#define cg_clustersum(cgp) \
((int32_t *)((u_int8_t *)(cgp) + (cgp)->cg_clustersumoff))
: ((u_int8_t *)((u_int8_t *)(cgp) + \
ufs_rw32((cgp)->cg_freeoff, (ns)))))
#define cg_chkmagic(cgp, ns) \
(ufs_rw32((cgp)->cg_magic, (ns)) == CG_MAGIC || \
ufs_rw32(((struct ocg *)(cgp))->cg_magic, (ns)) == \
CG_MAGIC)
#define cg_clustersfree(cgp, ns) \
((u_int8_t *)((u_int8_t *)(cgp) + \
ufs_rw32((cgp)->cg_clusteroff, (ns))))
#define cg_clustersum(cgp, ns) \
((int32_t *)((u_int8_t *)(cgp) + \
ufs_rw32((cgp)->cg_clustersumoff, (ns))))
/*
* The following structure is defined

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_vfsops.c,v 1.17 1998/03/01 22:16:39 fvdl Exp $ */
/* $NetBSD: lfs_vfsops.c,v 1.18 1998/03/18 15:57:28 bouyer Exp $ */
/*
* Copyright (c) 1989, 1991, 1993, 1994
@ -355,6 +355,7 @@ lfs_mountfs(devvp, mp, p)
mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_LFS);
mp->mnt_maxsymlinklen = fs->lfs_maxsymlinklen;
mp->mnt_flag |= MNT_LOCAL;
ump->um_flags = 0;
ump->um_mountp = mp;
ump->um_dev = dev;
ump->um_devvp = devvp;

View File

@ -1,4 +1,4 @@
/* $NetBSD: dir.h,v 1.9 1998/03/01 02:23:36 fvdl Exp $ */
/* $NetBSD: dir.h,v 1.10 1998/03/18 15:57:28 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -113,13 +113,15 @@ struct direct {
* null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
*/
#if (BYTE_ORDER == LITTLE_ENDIAN)
#define DIRSIZ(oldfmt, dp) \
((oldfmt) ? \
#define DIRSIZ(oldfmt, dp, needswap) \
(((oldfmt) && !(needswap)) ? \
((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_type+1 + 3) &~ 3)) : \
((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)))
#else
#define DIRSIZ(oldfmt, dp) \
((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
#define DIRSIZ(oldfmt, dp, needswap) \
(((oldfmt) && (needswap)) ? \
((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_type+1 + 3) &~ 3)) : \
((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)))
#endif
#define OLDDIRFMT 1
#define NEWDIRFMT 0

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_bmap.c,v 1.6 1998/03/01 02:23:36 fvdl Exp $ */
/* $NetBSD: ufs_bmap.c,v 1.7 1998/03/18 15:57:28 bouyer Exp $ */
/*
* Copyright (c) 1989, 1991, 1993
@ -55,6 +55,7 @@
#include <ufs/ufs/inode.h>
#include <ufs/ufs/ufsmount.h>
#include <ufs/ufs/ufs_extern.h>
#include <ufs/ufs/ufs_bswap.h>
/*
* Bmap converts a the logical block number of a file to its physical block
@ -145,19 +146,23 @@ ufs_bmaparray(vp, bn, bnp, ap, nump, runp)
num = *nump;
if (num == 0) {
*bnp = blkptrtodb(ump, ip->i_ffs_db[bn]);
*bnp = blkptrtodb(ump, ufs_rw32(ip->i_ffs_db[bn],
UFS_MPNEEDSWAP(vp->v_mount)));
if (*bnp == 0)
*bnp = -1;
else if (runp)
for (++bn; bn < NDADDR && *runp < maxrun &&
is_sequential(ump, ip->i_ffs_db[bn - 1], ip->i_ffs_db[bn]);
is_sequential(ump,
ufs_rw32(ip->i_ffs_db[bn - 1],
UFS_MPNEEDSWAP(vp->v_mount)),
ufs_rw32(ip->i_ffs_db[bn], UFS_MPNEEDSWAP(vp->v_mount)));
++bn, ++*runp);
return (0);
}
/* Get disk address out of indirect block array */
daddr = ip->i_ffs_ib[xap->in_off];
daddr = ufs_rw32(ip->i_ffs_ib[xap->in_off], UFS_MPNEEDSWAP(vp->v_mount));
devvp = VFSTOUFS(vp->v_mount)->um_devvp;
for (bp = NULL, ++xap; --num; ++xap) {
@ -197,13 +202,16 @@ ufs_bmaparray(vp, bn, bnp, ap, nump, runp)
return (error);
}
}
daddr = ((ufs_daddr_t *)bp->b_data)[xap->in_off];
daddr = ufs_rw32(((ufs_daddr_t *)bp->b_data)[xap->in_off],
UFS_MPNEEDSWAP(mp));
if (num == 1 && daddr && runp)
for (bn = xap->in_off + 1;
bn < MNINDIR(ump) && *runp < maxrun &&
is_sequential(ump, ((ufs_daddr_t *)bp->b_data)[bn - 1],
((ufs_daddr_t *)bp->b_data)[bn]);
is_sequential(ump,
ufs_rw32(((ufs_daddr_t *)bp->b_data)[bn - 1],
UFS_MPNEEDSWAP(mp)),
ufs_rw32(((ufs_daddr_t *)bp->b_data)[bn],
UFS_MPNEEDSWAP(mp)));
++bn, ++*runp);
}
if (bp)

74
sys/ufs/ufs/ufs_bswap.h Normal file
View File

@ -0,0 +1,74 @@
/* $NetBSD: ufs_bswap.h,v 1.1 1998/03/18 15:57:29 bouyer Exp $ */
/*
* Copyright (c) 1998 Manuel Bouyer.
*
* Redistribution and use in source and binary forms, with or without
* 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.
* 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.
* 3. All advertising materials mentioning features or use of this software
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#if !defined(_KERNEL) || defined(FFS_EI)
/* inlines for access to swaped datas */
static __inline u_int16_t ufs_rw16 __P((u_int16_t, int));
static __inline u_int32_t ufs_rw32 __P((u_int32_t, int));
static __inline u_int64_t ufs_rw64 __P((u_int64_t, int));
static __inline u_int16_t
ufs_rw16(a, ns)
u_int16_t a;
int ns;
{
return ((ns) ? bswap16(a) : (a));
}
static __inline u_int32_t
ufs_rw32(a, ns)
u_int32_t a;
int ns;
{
return ((ns) ? bswap32(a) : (a));
}
static __inline u_int64_t
ufs_rw64(a, ns)
u_int64_t a;
int ns;
{
return ((ns) ? bswap64(a) : (a));
}
#else
#define ufs_rw16(a, ns) (a)
#define ufs_rw32(a, ns) (a)
#define ufs_rw64(a, ns) (a)
#endif
#define ufs_add16(a, b, ns) \
(a) = ufs_rw16(ufs_rw16((a), (ns)) + (b), (ns))
#define ufs_add32(a, b, ns) \
(a) = ufs_rw32(ufs_rw32((a), (ns)) + (b), (ns))
#define ufs_add64(a, b, ns) \
(a) = ufs_rw64(ufs_rw64((a), (ns)) + (b), (ns))

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_extern.h,v 1.9 1998/03/01 02:23:36 fvdl Exp $ */
/* $NetBSD: ufs_extern.h,v 1.10 1998/03/18 15:57:29 bouyer Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -165,4 +165,16 @@ int ufs_vinit __P((struct mount *, int (**) __P((void *)),
int (**) __P((void *)), struct vnode **));
int ufs_makeinode __P((int, struct vnode *, struct vnode **,
struct componentname *));
__END_DECLS
/* Macros to access UFS flags */
#ifdef FFS_EI
#define UFS_MPNEEDSWAP(mp) (VFSTOUFS(mp)->um_flags & UFS_NEEDSWAP)
#define UFS_IPNEEDSWAP(ip) \
(VFSTOUFS(ITOV(ip)->v_mount)->um_flags & UFS_NEEDSWAP)
#else
#define UFS_MPNEEDSWAP(mp) (0)
#define UFS_IPNEEDSWAP(ip) (0)
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_lookup.c,v 1.14 1998/03/01 02:23:37 fvdl Exp $ */
/* $NetBSD: ufs_lookup.c,v 1.15 1998/03/18 15:57:29 bouyer Exp $ */
/*
* Copyright (c) 1989, 1993
@ -53,6 +53,7 @@
#include <ufs/ufs/dir.h>
#include <ufs/ufs/ufsmount.h>
#include <ufs/ufs/ufs_extern.h>
#include <ufs/ufs/ufs_bswap.h>
struct nchstats nchstats;
#ifdef DIAGNOSTIC
@ -61,7 +62,7 @@ int dirchk = 1;
int dirchk = 0;
#endif
#define FSFMT(vp) ((vp)->v_mount->mnt_maxsymlinklen <= 0)
#define FSFMT(vp) ((vp)->v_mount->mnt_maxsymlinklen <= 0)
/*
* Convert a component of a pathname into a pointer to a locked inode.
@ -130,6 +131,7 @@ ufs_lookup(v)
struct ucred *cred = cnp->cn_cred;
int flags = cnp->cn_flags;
int nameiop = cnp->cn_nameiop;
const int needswap = UFS_MPNEEDSWAP(ap->a_dvp->v_mount);
bp = NULL;
slotoffset = -1;
@ -139,6 +141,7 @@ ufs_lookup(v)
lockparent = flags & LOCKPARENT;
wantparent = flags & (LOCKPARENT|WANTPARENT);
/*
* Check accessiblity of directory.
*/
@ -294,15 +297,16 @@ searchloop:
* compaction is viable.
*/
if (slotstatus != FOUND) {
int size = ep->d_reclen;
int size = ufs_rw16(ep->d_reclen, needswap);
if (ep->d_ino != 0)
size -= DIRSIZ(FSFMT(vdp), ep);
size -= DIRSIZ(FSFMT(vdp), ep, needswap);
if (size > 0) {
if (size >= slotneeded) {
slotstatus = FOUND;
slotoffset = dp->i_offset;
slotsize = ep->d_reclen;
slotsize = ufs_rw16(ep->d_reclen,
needswap);
} else if (slotstatus == NONE) {
slotfreespace += size;
if (slotoffset == -1)
@ -310,7 +314,8 @@ searchloop:
if (slotfreespace >= slotneeded) {
slotstatus = COMPACT;
slotsize = dp->i_offset +
ep->d_reclen - slotoffset;
ufs_rw16(ep->d_reclen, needswap)
- slotoffset;
}
}
}
@ -320,14 +325,17 @@ searchloop:
* Check for a name match.
*/
if (ep->d_ino) {
# if (BYTE_ORDER == LITTLE_ENDIAN)
if (vdp->v_mount->mnt_maxsymlinklen > 0)
#if (BYTE_ORDER == LITTLE_ENDIAN)
if (vdp->v_mount->mnt_maxsymlinklen > 0 || needswap != 0)
namlen = ep->d_namlen;
else
namlen = ep->d_type;
# else
#else
if (vdp->v_mount->mnt_maxsymlinklen <= 0 && needswap != 0)
namlen = ep->d_type;
else
namlen = ep->d_namlen;
# endif
#endif
if (namlen == cnp->cn_namelen &&
!bcmp(cnp->cn_nameptr, ep->d_name,
(unsigned)namlen)) {
@ -340,7 +348,7 @@ searchloop:
ep->d_type == DT_WHT) {
slotstatus = FOUND;
slotoffset = dp->i_offset;
slotsize = ep->d_reclen;
slotsize = ufs_rw16(ep->d_reclen, needswap);
dp->i_reclen = slotsize;
/*
* This is used to set dp->i_endoff,
@ -363,15 +371,15 @@ searchloop:
numdirpasses--;
goto notfound;
}
dp->i_ino = ep->d_ino;
dp->i_reclen = ep->d_reclen;
dp->i_ino = ufs_rw32(ep->d_ino, needswap);
dp->i_reclen = ufs_rw16(ep->d_reclen, needswap);
brelse(bp);
goto found;
}
}
prevoff = dp->i_offset;
dp->i_offset += ep->d_reclen;
entryoffsetinblock += ep->d_reclen;
dp->i_offset += ufs_rw16(ep->d_reclen, needswap);
entryoffsetinblock += ufs_rw16(ep->d_reclen, needswap);
if (ep->d_ino)
enduseful = dp->i_offset;
}
@ -464,9 +472,11 @@ found:
* Check that directory length properly reflects presence
* of this entry.
*/
if (entryoffsetinblock + DIRSIZ(FSFMT(vdp), ep) > dp->i_ffs_size) {
if (entryoffsetinblock + DIRSIZ(FSFMT(vdp), ep, needswap) >
dp->i_ffs_size) {
ufs_dirbad(dp, dp->i_offset, "i_size too small");
dp->i_ffs_size = entryoffsetinblock + DIRSIZ(FSFMT(vdp), ep);
dp->i_ffs_size = entryoffsetinblock +
DIRSIZ(FSFMT(vdp), ep, needswap);
dp->i_flag |= IN_CHANGE | IN_UPDATE;
}
@ -639,20 +649,31 @@ ufs_dirbadentry(dp, ep, entryoffsetinblock)
{
register int i;
int namlen;
const int needswap = UFS_MPNEEDSWAP(dp->v_mount);
# if (BYTE_ORDER == LITTLE_ENDIAN)
if (dp->v_mount->mnt_maxsymlinklen > 0)
if (dp->v_mount->mnt_maxsymlinklen > 0 || needswap != 0)
namlen = ep->d_namlen;
else
namlen = ep->d_type;
# else
if (dp->v_mount->mnt_maxsymlinklen == 0 && needswap != 0)
namlen = ep->d_type;
else
namlen = ep->d_namlen;
# endif
if ((ep->d_reclen & 0x3) != 0 ||
ep->d_reclen > DIRBLKSIZ - (entryoffsetinblock & (DIRBLKSIZ - 1)) ||
ep->d_reclen < DIRSIZ(FSFMT(dp), ep) || namlen > MAXNAMLEN) {
if ((ufs_rw16(ep->d_reclen, needswap) & 0x3) != 0 ||
ufs_rw16(ep->d_reclen, needswap) >
DIRBLKSIZ - (entryoffsetinblock & (DIRBLKSIZ - 1)) ||
ufs_rw16(ep->d_reclen, needswap) <
DIRSIZ(FSFMT(dp), ep, needswap) ||
namlen > MAXNAMLEN) {
/*return (1); */
printf("First bad\n");
printf("First bad, reclen=%x, DIRSIZ=%d, namlen=%d, flags=%x "
"entryoffsetinblock=%d\n",
ufs_rw16(ep->d_reclen, needswap),
DIRSIZ(FSFMT(dp), ep, needswap),
namlen, dp->v_mount->mnt_flag, entryoffsetinblock);
goto bad;
}
if (ep->d_ino == 0)
@ -685,7 +706,7 @@ ufs_direnter(ip, dvp, cnp)
register struct componentname *cnp;
{
register struct inode *dp;
struct direct newdir;
struct direct newdir; /* In host byte order here, ufs_direnter2 swap it */
#ifdef DIAGNOSTIC
if ((cnp->cn_flags & SAVENAME) == 0)
@ -699,12 +720,8 @@ ufs_direnter(ip, dvp, cnp)
newdir.d_type = IFTODT(ip->i_ffs_mode);
else {
newdir.d_type = 0;
# if (BYTE_ORDER == LITTLE_ENDIAN)
{ u_char tmp = newdir.d_namlen;
newdir.d_namlen = newdir.d_type;
newdir.d_type = tmp; }
# endif
}
/* byte order swapping and new->old format conv handled by ufs_direnter2 */
return (ufs_direnter2(dvp, &newdir, cnp->cn_cred, cnp->cn_proc));
}
@ -728,9 +745,10 @@ ufs_direnter2(dvp, dirp, cr, p)
struct direct *ep, *nep;
int error, loc, spacefree;
char *dirbuf;
const int needswap = UFS_MPNEEDSWAP(dvp->v_mount);
dp = VTOI(dvp);
newentrysize = DIRSIZ(FSFMT(dvp), dirp);
newentrysize = DIRSIZ(0, dirp, 0);
if (dp->i_count == 0) {
/*
@ -742,7 +760,19 @@ ufs_direnter2(dvp, dirp, cr, p)
if (dp->i_offset & (DIRBLKSIZ - 1))
panic("ufs_direnter2: newblk");
auio.uio_offset = dp->i_offset;
dirp->d_reclen = DIRBLKSIZ;
dirp->d_reclen = ufs_rw16(DIRBLKSIZ, needswap);
dirp->d_ino = ufs_rw32(dirp->d_ino, needswap);
if (dvp->v_mount->mnt_maxsymlinklen <= 0)
#if (BYTE_ORDER == LITTLE_ENDIAN)
if (needswap == 0)
#else
if (needswap != 0)
#endif
{
u_char tmp = dirp->d_namlen;
dirp->d_namlen = dirp->d_type;
dirp->d_type = tmp;
}
auio.uio_resid = newentrysize;
aiov.iov_len = newentrysize;
aiov.iov_base = (caddr_t)dirp;
@ -795,21 +825,21 @@ ufs_direnter2(dvp, dirp, cr, p)
* space.
*/
ep = (struct direct *)dirbuf;
dsize = DIRSIZ(FSFMT(dvp), ep);
spacefree = ep->d_reclen - dsize;
for (loc = ep->d_reclen; loc < dp->i_count; ) {
dsize = DIRSIZ(FSFMT(dvp), ep, needswap);
spacefree = ufs_rw16(ep->d_reclen, needswap) - dsize;
for (loc = ufs_rw16(ep->d_reclen, needswap); loc < dp->i_count; ) {
nep = (struct direct *)(dirbuf + loc);
if (ep->d_ino) {
/* trim the existing slot */
ep->d_reclen = dsize;
ep->d_reclen = ufs_rw16(dsize, needswap);
ep = (struct direct *)((char *)ep + dsize);
} else {
/* overwrite; nothing there; header is ours */
spacefree += dsize;
}
dsize = DIRSIZ(FSFMT(dvp), nep);
spacefree += nep->d_reclen - dsize;
loc += nep->d_reclen;
dsize = DIRSIZ(FSFMT(dvp), nep, needswap);
spacefree += ufs_rw16(nep->d_reclen, needswap) - dsize;
loc += ufs_rw16(nep->d_reclen, needswap);
bcopy((caddr_t)nep, (caddr_t)ep, dsize);
}
/*
@ -817,7 +847,7 @@ ufs_direnter2(dvp, dirp, cr, p)
* copy in the new entry, and write out the block.
*/
if (ep->d_ino == 0 ||
(ep->d_ino == WINO &&
(ufs_rw32(ep->d_ino, needswap) == WINO &&
bcmp(ep->d_name, dirp->d_name, dirp->d_namlen) == 0)) {
if (spacefree + dsize < newentrysize)
panic("ufs_direnter2: compact1");
@ -826,9 +856,22 @@ ufs_direnter2(dvp, dirp, cr, p)
if (spacefree < newentrysize)
panic("ufs_direnter2: compact2");
dirp->d_reclen = spacefree;
ep->d_reclen = dsize;
ep->d_reclen = ufs_rw16(dsize, needswap);
ep = (struct direct *)((char *)ep + dsize);
}
dirp->d_reclen = ufs_rw16(dirp->d_reclen, needswap);
dirp->d_ino = ufs_rw32(dirp->d_ino, needswap);
if (dvp->v_mount->mnt_maxsymlinklen <= 0)
#if (BYTE_ORDER == LITTLE_ENDIAN)
if (needswap == 0)
#else
if (needswap != 0)
#endif
{
u_char tmp = dirp->d_namlen;
dirp->d_namlen = dirp->d_type;
dirp->d_type = tmp;
}
bcopy((caddr_t)dirp, (caddr_t)ep, (u_int)newentrysize);
error = VOP_BWRITE(bp);
dp->i_flag |= IN_CHANGE | IN_UPDATE;
@ -869,7 +912,7 @@ ufs_dirremove(dvp, cnp)
&bp);
if (error)
return (error);
ep->d_ino = WINO;
ep->d_ino = ufs_rw32(WINO, UFS_MPNEEDSWAP(dvp->v_mount));
ep->d_type = DT_WHT;
error = VOP_BWRITE(bp);
dp->i_flag |= IN_CHANGE | IN_UPDATE;
@ -896,7 +939,9 @@ ufs_dirremove(dvp, cnp)
(char **)&ep, &bp);
if (error)
return (error);
ep->d_reclen += dp->i_reclen;
ep->d_reclen = ufs_rw16(
ufs_rw16(ep->d_reclen, UFS_MPNEEDSWAP(dvp->v_mount)) + dp->i_reclen,
UFS_MPNEEDSWAP(dvp->v_mount));
error = VOP_BWRITE(bp);
dp->i_flag |= IN_CHANGE | IN_UPDATE;
return (error);
@ -920,7 +965,7 @@ ufs_dirrewrite(dp, ip, cnp)
error = VOP_BLKATOFF(vdp, (off_t)dp->i_offset, (char **)&ep, &bp);
if (error)
return (error);
ep->d_ino = ip->i_number;
ep->d_ino = ufs_rw32(ip->i_number, UFS_MPNEEDSWAP(vdp->v_mount));
if (vdp->v_mount->mnt_maxsymlinklen > 0)
ep->d_type = IFTODT(ip->i_ffs_mode);
error = VOP_BWRITE(bp);
@ -949,7 +994,8 @@ ufs_dirempty(ip, parentino, cred)
int error, count, namlen;
#define MINDIRSIZ (sizeof (struct dirtemplate) / 2)
for (off = 0; off < ip->i_ffs_size; off += dp->d_reclen) {
for (off = 0; off < ip->i_ffs_size;
off += ufs_rw16(dp->d_reclen, UFS_IPNEEDSWAP(ip))) {
error = vn_rdwr(UIO_READ, ITOV(ip), (caddr_t)dp, MINDIRSIZ, off,
UIO_SYSSPACE, IO_NODELOCKED, cred, &count, (struct proc *)0);
/*
@ -962,16 +1008,22 @@ ufs_dirempty(ip, parentino, cred)
if (dp->d_reclen == 0)
return (0);
/* skip empty entries */
if (dp->d_ino == 0 || dp->d_ino == WINO)
if (dp->d_ino == 0 ||
ufs_rw32(dp->d_ino, UFS_IPNEEDSWAP(ip)) == WINO)
continue;
/* accept only "." and ".." */
# if (BYTE_ORDER == LITTLE_ENDIAN)
if (ITOV(ip)->v_mount->mnt_maxsymlinklen > 0)
if (ITOV(ip)->v_mount->mnt_maxsymlinklen > 0 ||
UFS_IPNEEDSWAP(ip) != 0)
namlen = dp->d_namlen;
else
namlen = dp->d_type;
# else
namlen = dp->d_namlen;
if (ITOV(ip)->v_mount->mnt_maxsymlinklen == 0 &&
UFS_IPNEEDSWAP(ip) != 0)
namlen = dp->d_type;
else
namlen = dp->d_namlen;
# endif
if (namlen > 2)
return (0);
@ -984,7 +1036,8 @@ ufs_dirempty(ip, parentino, cred)
*/
if (namlen == 1)
continue;
if (dp->d_name[1] == '.' && dp->d_ino == parentino)
if (dp->d_name[1] == '.' &&
ufs_rw32(dp->d_ino, UFS_IPNEEDSWAP(ip)) == parentino)
continue;
return (0);
}
@ -1001,9 +1054,10 @@ ufs_checkpath(source, target, cred)
struct inode *source, *target;
struct ucred *cred;
{
struct vnode *vp;
struct vnode *vp = vp = ITOV(target);
int error, rootino, namlen;
struct dirtemplate dirbuf;
const int needswap = UFS_MPNEEDSWAP(vp->v_mount);
vp = ITOV(target);
if (target->i_number == source->i_number) {
@ -1026,11 +1080,16 @@ ufs_checkpath(source, target, cred)
if (error != 0)
break;
# if (BYTE_ORDER == LITTLE_ENDIAN)
if (vp->v_mount->mnt_maxsymlinklen > 0)
if (vp->v_mount->mnt_maxsymlinklen > 0 ||
needswap != 0)
namlen = dirbuf.dotdot_namlen;
else
namlen = dirbuf.dotdot_type;
# else
if (vp->v_mount->mnt_maxsymlinklen == 0 &&
needswap != 0)
namlen = dirbuf.dotdot_type;
else
namlen = dirbuf.dotdot_namlen;
# endif
if (namlen != 2 ||
@ -1039,14 +1098,15 @@ ufs_checkpath(source, target, cred)
error = ENOTDIR;
break;
}
if (dirbuf.dotdot_ino == source->i_number) {
if (ufs_rw32(dirbuf.dotdot_ino, needswap) == source->i_number) {
error = EINVAL;
break;
}
if (dirbuf.dotdot_ino == rootino)
if (ufs_rw32(dirbuf.dotdot_ino, needswap) == rootino)
break;
vput(vp);
error = VFS_VGET(vp->v_mount, dirbuf.dotdot_ino, &vp);
error = VFS_VGET(vp->v_mount,
ufs_rw32(dirbuf.dotdot_ino, needswap), &vp);
if (error) {
vp = NULL;
break;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_vnops.c,v 1.37 1998/03/10 11:56:40 kleink Exp $ */
/* $NetBSD: ufs_vnops.c,v 1.38 1998/03/18 15:57:29 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993, 1995
@ -71,6 +71,7 @@
#include <ufs/ufs/inode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ufs/ufsmount.h>
#include <ufs/ufs/ufs_bswap.h>
#include <ufs/ufs/ufs_extern.h>
#include <ufs/ext2fs/ext2fs_extern.h>
@ -143,7 +144,8 @@ ufs_mknod(v)
* Want to be able to use this to make badblock
* inodes, so don't truncate the dev number.
*/
ip->i_ffs_rdev = vap->va_rdev;
ip->i_ffs_rdev = ufs_rw32(vap->va_rdev,
UFS_MPNEEDSWAP((*vpp)->v_mount));
}
/*
* Remove inode so that it will be reloaded by VFS_VGET and
@ -292,7 +294,8 @@ ufs_getattr(v)
vap->va_nlink = ip->i_ffs_nlink;
vap->va_uid = ip->i_ffs_uid;
vap->va_gid = ip->i_ffs_gid;
vap->va_rdev = (dev_t)ip->i_ffs_rdev;
vap->va_rdev = ufs_rw32((dev_t)ip->i_ffs_rdev,
UFS_MPNEEDSWAP(vp->v_mount));
vap->va_size = ip->i_ffs_size;
vap->va_atime.tv_sec = ip->i_ffs_atime;
vap->va_atime.tv_nsec = ip->i_ffs_atimensec;
@ -746,6 +749,7 @@ ufs_whiteout(v)
newdir.d_namlen = cnp->cn_namelen;
bcopy(cnp->cn_nameptr, newdir.d_name, (unsigned)cnp->cn_namelen + 1);
newdir.d_type = DT_WHT;
/* byte order swapping handled by ufs_direnter2 */
error = ufs_direnter2(dvp, &newdir, cnp->cn_cred, cnp->cn_proc);
break;
@ -1112,11 +1116,16 @@ abortit:
tcnp->cn_cred, (int *)0, (struct proc *)0);
if (error == 0) {
# if (BYTE_ORDER == LITTLE_ENDIAN)
if (fvp->v_mount->mnt_maxsymlinklen <= 0)
if (fvp->v_mount->mnt_maxsymlinklen <= 0 &&
UFS_MPNEEDSWAP(fvp->v_mount) == 0)
namlen = dirbuf.dotdot_type;
else
namlen = dirbuf.dotdot_namlen;
# else
if (fvp->v_mount->mnt_maxsymlinklen <= 0 &&
UFS_MPNEEDSWAP(fvp->v_mount) != 0)
namlen = dirbuf.dotdot_type;
else
namlen = dirbuf.dotdot_namlen;
# endif
if (namlen != 2 ||
@ -1125,7 +1134,8 @@ abortit:
ufs_dirbad(xp, (doff_t)12,
"rename: mangled dir");
} else {
dirbuf.dotdot_ino = newparent;
dirbuf.dotdot_ino = ufs_rw32(newparent,
UFS_MPNEEDSWAP(fvp->v_mount));
(void) vn_rdwr(UIO_WRITE, fvp,
(caddr_t)&dirbuf,
sizeof (struct dirtemplate),
@ -1174,10 +1184,6 @@ static struct dirtemplate mastertemplate = {
0, 12, DT_DIR, 1, ".",
0, DIRBLKSIZ - 12, DT_DIR, 2, ".."
};
static struct odirtemplate omastertemplate = {
0, 12, 1, ".",
0, DIRBLKSIZ - 12, 2, ".."
};
/*
* Mkdir system call
@ -1197,7 +1203,7 @@ ufs_mkdir(v)
register struct componentname *cnp = ap->a_cnp;
register struct inode *ip, *dp;
struct vnode *tvp;
struct dirtemplate dirtemplate, *dtp;
struct dirtemplate dirtemplate;
struct timespec ts;
int error, dmode;
@ -1253,13 +1259,29 @@ ufs_mkdir(v)
goto bad;
/* Initialize directory with "." and ".." from static template. */
if (dvp->v_mount->mnt_maxsymlinklen > 0)
dtp = &mastertemplate;
else
dtp = (struct dirtemplate *)&omastertemplate;
dirtemplate = *dtp;
dirtemplate.dot_ino = ip->i_number;
dirtemplate.dotdot_ino = dp->i_number;
dirtemplate = mastertemplate;
dirtemplate.dot_ino = ufs_rw32(ip->i_number,
UFS_MPNEEDSWAP(dvp->v_mount));
dirtemplate.dotdot_ino = ufs_rw32(dp->i_number,
UFS_MPNEEDSWAP(dvp->v_mount));
dirtemplate.dot_reclen = ufs_rw16(dirtemplate.dot_reclen,
UFS_MPNEEDSWAP(dvp->v_mount));
dirtemplate.dotdot_reclen = ufs_rw16(dirtemplate.dotdot_reclen,
UFS_MPNEEDSWAP(dvp->v_mount));
if (dvp->v_mount->mnt_maxsymlinklen == 0) {
#if BYTE_ORDER == LITTLE_ENDIAN
if (UFS_MPNEEDSWAP(dvp->v_mount) == 0)
#else
if (UFS_MPNEEDSWAP(dvp->v_mount) != 0)
#endif
{
dirtemplate.dot_type = dirtemplate.dot_namlen;
dirtemplate.dotdot_type = dirtemplate.dotdot_namlen;
dirtemplate.dot_namlen = dirtemplate.dotdot_namlen = 0;
} else
dirtemplate.dot_type = dirtemplate.dotdot_type = 0;
}
error = vn_rdwr(UIO_WRITE, tvp, (caddr_t)&dirtemplate,
sizeof (dirtemplate), (off_t)0, UIO_SYSSPACE,
IO_NODELOCKED|IO_SYNC, cnp->cn_cred, (int *)0, (struct proc *)0);
@ -1451,48 +1473,61 @@ ufs_readdir(v)
lost = uio->uio_resid - count;
uio->uio_resid = count;
uio->uio_iov->iov_len = count;
# if (BYTE_ORDER == LITTLE_ENDIAN)
if (ap->a_vp->v_mount->mnt_maxsymlinklen > 0) {
error = VOP_READ(ap->a_vp, uio, 0, ap->a_cred);
} else {
struct dirent *dp, *edp;
struct uio auio;
struct iovec aiov;
caddr_t dirbuf;
int readcnt;
u_char tmp;
#if BYTE_ORDER == LITTLE_ENDIAN
if (ap->a_vp->v_mount->mnt_maxsymlinklen > 0 &&
UFS_MPNEEDSWAP(ap->a_vp->v_mount) == 0) {
#else
if (UFS_MPNEEDSWAP(ap->a_vp->v_mount) == 0) {
#endif
error = VOP_READ(ap->a_vp, uio, 0, ap->a_cred);
} else {
struct dirent *dp, *edp;
struct uio auio;
struct iovec aiov;
caddr_t dirbuf;
int readcnt;
u_char tmp;
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);
aiov.iov_base = dirbuf;
error = VOP_READ(ap->a_vp, &auio, 0, ap->a_cred);
if (error == 0) {
readcnt = count - auio.uio_resid;
edp = (struct dirent *)&dirbuf[readcnt];
for (dp = (struct dirent *)dirbuf; dp < edp; ) {
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);
aiov.iov_base = dirbuf;
error = VOP_READ(ap->a_vp, &auio, 0, ap->a_cred);
if (error == 0) {
readcnt = count - auio.uio_resid;
edp = (struct dirent *)&dirbuf[readcnt];
for (dp = (struct dirent *)dirbuf; dp < edp; ) {
#if BYTE_ORDER == LITTLE_ENDIAN
if (ap->a_vp->v_mount->mnt_maxsymlinklen == 0 &&
UFS_MPNEEDSWAP(ap->a_vp->v_mount) == 0) {
#else
if (ap->a_vp->v_mount->mnt_maxsymlinklen == 0 &&
UFS_MPNEEDSWAP(ap->a_vp->v_mount) != 0) {
#endif
tmp = dp->d_namlen;
dp->d_namlen = dp->d_type;
dp->d_type = tmp;
if (dp->d_reclen > 0) {
dp = (struct dirent *)
((char *)dp + dp->d_reclen);
} else {
error = EIO;
break;
}
}
if (dp >= edp)
error = uiomove(dirbuf, readcnt, uio);
dp->d_fileno = ufs_rw32(dp->d_fileno,
UFS_MPNEEDSWAP(ap->a_vp->v_mount));
dp->d_reclen = ufs_rw16(dp->d_reclen,
UFS_MPNEEDSWAP(ap->a_vp->v_mount));
if (dp->d_reclen > 0) {
dp = (struct dirent *)
((char *)dp + dp->d_reclen);
} else {
error = EIO;
break;
}
}
FREE(dirbuf, M_TEMP);
if (dp >= edp)
error = uiomove(dirbuf, readcnt, uio);
}
# else
error = VOP_READ(ap->a_vp, uio, 0, ap->a_cred);
# endif
FREE(dirbuf, M_TEMP);
}
if (!error && ap->a_ncookies) {
struct dirent *dp, *dpstart;
off_t *cookies, offstart;
@ -1894,7 +1929,9 @@ ufs_vinit(mntp, specops, fifoops, vpp)
case VCHR:
case VBLK:
vp->v_op = specops;
if ((nvp = checkalias(vp, ip->i_ffs_rdev, mntp)) != NULL) {
if ((nvp = checkalias(vp,
ufs_rw32(ip->i_ffs_rdev, UFS_MPNEEDSWAP(vp->v_mount)),
mntp)) != NULL) {
/*
* Discard unneeded vnode, but save its inode.
* Note that the lock is carried over in the inode

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufsmount.h,v 1.6 1998/03/01 02:23:38 fvdl Exp $ */
/* $NetBSD: ufsmount.h,v 1.7 1998/03/18 15:57:29 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -68,7 +68,7 @@ struct ufsmount {
struct mount *um_mountp; /* filesystem vfs structure */
dev_t um_dev; /* device mounted */
struct vnode *um_devvp; /* block device mounted vnode */
u_int32_t um_flags; /* UFS-specific flags - see below */
union { /* pointer to superblock */
struct fs *fs; /* FFS */
struct lfs *lfs; /* LFS */
@ -91,6 +91,9 @@ struct ufsmount {
u_int64_t um_savedmaxfilesize; /* XXX - limit maxfilesize */
};
/* UFS-specific flags */
#define UFS_NEEDSWAP 0x01 /* filesystem metadata need byte-swapping */
/*
* Flags describing the state of quotas.
*/