summaryrefslogtreecommitdiffstats
path: root/sys/fs
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2012-01-01 20:47:33 +0000
committered <ed@FreeBSD.org>2012-01-01 20:47:33 +0000
commit2dd2060131bbfd7b617356a2384aa027270c3b9d (patch)
tree8961ac71ec869c6cb68bb78e29ccca26d39bef27 /sys/fs
parent5f479a9ff5848e7febb91161677e846f8167d4ea (diff)
downloadFreeBSD-src-2dd2060131bbfd7b617356a2384aa027270c3b9d.zip
FreeBSD-src-2dd2060131bbfd7b617356a2384aa027270c3b9d.tar.gz
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.
Diffstat (limited to 'sys/fs')
-rw-r--r--sys/fs/ext2fs/ext2_alloc.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/sys/fs/ext2fs/ext2_alloc.c b/sys/fs/ext2fs/ext2_alloc.c
index 5720c72..c834077 100644
--- a/sys/fs/ext2fs/ext2_alloc.c
+++ b/sys/fs/ext2fs/ext2_alloc.c
@@ -886,8 +886,8 @@ ext2_nodealloccg(struct inode *ip, int cg, daddr_t ipref, int mode)
struct m_ext2fs *fs;
struct buf *bp;
struct ext2mount *ump;
- int error, start, len, loc, map, i;
- char *ibp;
+ int error, start, len;
+ char *ibp, *loc;
ipref--; /* to avoid a lot of (ipref -1) */
if (ipref == -1)
ipref = 0;
@@ -921,25 +921,19 @@ ext2_nodealloccg(struct inode *ip, int cg, daddr_t ipref, int mode)
}
start = ipref / NBBY;
len = howmany(fs->e2fs->e2fs_ipg - ipref, NBBY);
- loc = skpc(0xff, len, &ibp[start]);
- if (loc == 0) {
+ loc = memcchr(&ibp[start], 0xff, len);
+ if (loc == NULL) {
len = start + 1;
start = 0;
- loc = skpc(0xff, len, &ibp[0]);
- if (loc == 0) {
+ loc = memcchr(&ibp[start], 0xff, len);
+ if (loc == NULL) {
printf("cg = %d, ipref = %lld, fs = %s\n",
cg, (long long)ipref, fs->e2fs_fsmnt);
panic("ext2fs_nodealloccg: map corrupted");
/* NOTREACHED */
}
}
- i = start + len - loc;
- 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;
+ ipref = (loc - ibp) * NBBY + ffs(~*loc) - 1;
gotit:
setbit(ibp, ipref);
EXT2_LOCK(ump);
@@ -1068,7 +1062,8 @@ ext2_vfree(pvp, ino, mode)
static daddr_t
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
@@ -1079,25 +1074,19 @@ ext2_mapsearch(struct m_ext2fs *fs, char *bbp, daddr_t bpref)
else
start = 0;
len = howmany(fs->e2fs->e2fs_fpg, NBBY) - start;
- loc = skpc(0xff, len, &bbp[start]);
- if (loc == 0) {
+ loc = memcchr(&bbp[start], 0xff, len);
+ if (loc == NULL) {
len = start + 1;
start = 0;
- loc = skpc(0xff, len, &bbp[start]);
- if (loc == 0) {
+ loc = memcchr(&bbp[start], 0xff, len);
+ if (loc == NULL) {
printf("start = %d, len = %d, fs = %s\n",
start, len, fs->e2fs_fsmnt);
panic("ext2fs_alloccg: map corrupted");
/* NOTREACHED */
}
}
- i = start + len - loc;
- 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);
+ return ((loc - bbp) * NBBY + ffs(~*loc) - 1);
}
/*
OpenPOWER on IntegriCloud