Migrate ufs and ext2fs from skpc() to memcchr().

While there, remove a useless check from the code. memcchr() always
returns characters unequal to 0xff in this case, so inosused[i] ^ 0xff
can never be equal to zero. Also, the fact that memcchr() returns a
pointer instead of the number of bytes until the end, makes conversion
to an offset far more easy.
This commit is contained in:
Ed Schouten 2012-01-01 20:47:33 +00:00
parent a4ec012311
commit 8f8d30274a
2 changed files with 21 additions and 38 deletions

View File

@ -886,8 +886,8 @@ ext2_nodealloccg(struct inode *ip, int cg, daddr_t ipref, int mode)
struct m_ext2fs *fs; struct m_ext2fs *fs;
struct buf *bp; struct buf *bp;
struct ext2mount *ump; struct ext2mount *ump;
int error, start, len, loc, map, i; int error, start, len;
char *ibp; char *ibp, *loc;
ipref--; /* to avoid a lot of (ipref -1) */ ipref--; /* to avoid a lot of (ipref -1) */
if (ipref == -1) if (ipref == -1)
ipref = 0; ipref = 0;
@ -921,25 +921,19 @@ ext2_nodealloccg(struct inode *ip, int cg, daddr_t ipref, int mode)
} }
start = ipref / NBBY; start = ipref / NBBY;
len = howmany(fs->e2fs->e2fs_ipg - ipref, NBBY); len = howmany(fs->e2fs->e2fs_ipg - ipref, NBBY);
loc = skpc(0xff, len, &ibp[start]); loc = memcchr(&ibp[start], 0xff, len);
if (loc == 0) { if (loc == NULL) {
len = start + 1; len = start + 1;
start = 0; start = 0;
loc = skpc(0xff, len, &ibp[0]); loc = memcchr(&ibp[start], 0xff, len);
if (loc == 0) { if (loc == NULL) {
printf("cg = %d, ipref = %lld, fs = %s\n", printf("cg = %d, ipref = %lld, fs = %s\n",
cg, (long long)ipref, fs->e2fs_fsmnt); cg, (long long)ipref, fs->e2fs_fsmnt);
panic("ext2fs_nodealloccg: map corrupted"); panic("ext2fs_nodealloccg: map corrupted");
/* NOTREACHED */ /* NOTREACHED */
} }
} }
i = start + len - loc; ipref = (loc - ibp) * NBBY + ffs(~*loc) - 1;
map = ibp[i] ^ 0xff;
if (map == 0) {
printf("fs = %s\n", fs->e2fs_fsmnt);
panic("ext2fs_nodealloccg: block not in map");
}
ipref = i * NBBY + ffs(map) - 1;
gotit: gotit:
setbit(ibp, ipref); setbit(ibp, ipref);
EXT2_LOCK(ump); EXT2_LOCK(ump);
@ -1068,7 +1062,8 @@ ext2_vfree(pvp, ino, mode)
static daddr_t static daddr_t
ext2_mapsearch(struct m_ext2fs *fs, char *bbp, daddr_t bpref) ext2_mapsearch(struct m_ext2fs *fs, char *bbp, daddr_t bpref)
{ {
int start, len, loc, i, map; char *loc;
int start, len;
/* /*
* find the fragment by searching through the free block * find the fragment by searching through the free block
@ -1079,25 +1074,19 @@ ext2_mapsearch(struct m_ext2fs *fs, char *bbp, daddr_t bpref)
else else
start = 0; start = 0;
len = howmany(fs->e2fs->e2fs_fpg, NBBY) - start; len = howmany(fs->e2fs->e2fs_fpg, NBBY) - start;
loc = skpc(0xff, len, &bbp[start]); loc = memcchr(&bbp[start], 0xff, len);
if (loc == 0) { if (loc == NULL) {
len = start + 1; len = start + 1;
start = 0; start = 0;
loc = skpc(0xff, len, &bbp[start]); loc = memcchr(&bbp[start], 0xff, len);
if (loc == 0) { if (loc == NULL) {
printf("start = %d, len = %d, fs = %s\n", printf("start = %d, len = %d, fs = %s\n",
start, len, fs->e2fs_fsmnt); start, len, fs->e2fs_fsmnt);
panic("ext2fs_alloccg: map corrupted"); panic("ext2fs_alloccg: map corrupted");
/* NOTREACHED */ /* NOTREACHED */
} }
} }
i = start + len - loc; return ((loc - bbp) * NBBY + ffs(~*loc) - 1);
map = bbp[i] ^ 0xff;
if (map == 0) {
printf("fs = %s\n", fs->e2fs_fsmnt);
panic("ext2fs_mapsearch: block not in map");
}
return (i * NBBY + ffs(map) - 1);
} }
/* /*

View File

@ -1745,9 +1745,9 @@ ffs_nodealloccg(ip, cg, ipref, mode, unused)
struct cg *cgp; struct cg *cgp;
struct buf *bp, *ibp; struct buf *bp, *ibp;
struct ufsmount *ump; struct ufsmount *ump;
u_int8_t *inosused; u_int8_t *inosused, *loc;
struct ufs2_dinode *dp2; struct ufs2_dinode *dp2;
int error, start, len, loc, map, i; int error, start, len, i;
fs = ip->i_fs; fs = ip->i_fs;
ump = ip->i_ump; ump = ip->i_ump;
@ -1777,25 +1777,19 @@ ffs_nodealloccg(ip, cg, ipref, mode, unused)
} }
start = cgp->cg_irotor / NBBY; start = cgp->cg_irotor / NBBY;
len = howmany(fs->fs_ipg - cgp->cg_irotor, NBBY); len = howmany(fs->fs_ipg - cgp->cg_irotor, NBBY);
loc = skpc(0xff, len, &inosused[start]); loc = memcchr(&inosused[start], 0xff, len);
if (loc == 0) { if (loc == NULL) {
len = start + 1; len = start + 1;
start = 0; start = 0;
loc = skpc(0xff, len, &inosused[0]); loc = memcchr(&inosused[start], 0xff, len);
if (loc == 0) { if (loc == NULL) {
printf("cg = %d, irotor = %ld, fs = %s\n", printf("cg = %d, irotor = %ld, fs = %s\n",
cg, (long)cgp->cg_irotor, fs->fs_fsmnt); cg, (long)cgp->cg_irotor, fs->fs_fsmnt);
panic("ffs_nodealloccg: map corrupted"); panic("ffs_nodealloccg: map corrupted");
/* NOTREACHED */ /* NOTREACHED */
} }
} }
i = start + len - loc; ipref = (loc - inosused) * NBBY + ffs(~*loc) - 1;
map = inosused[i] ^ 0xff;
if (map == 0) {
printf("fs = %s\n", fs->fs_fsmnt);
panic("ffs_nodealloccg: block not in map");
}
ipref = i * NBBY + ffs(map) - 1;
cgp->cg_irotor = ipref; cgp->cg_irotor = ipref;
gotit: gotit:
/* /*