From owner-svn-src-head@FreeBSD.ORG Sun Jan 1 20:47:34 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 89372106564A; Sun, 1 Jan 2012 20:47:34 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 68C9C8FC0A; Sun, 1 Jan 2012 20:47:34 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q01KlYOB029882; Sun, 1 Jan 2012 20:47:34 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q01KlYtb029879; Sun, 1 Jan 2012 20:47:34 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201201012047.q01KlYtb029879@svn.freebsd.org> From: Ed Schouten Date: Sun, 1 Jan 2012 20:47:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r229200 - in head/sys: fs/ext2fs ufs/ffs X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Jan 2012 20:47:34 -0000 Author: ed Date: Sun Jan 1 20:47:33 2012 New Revision: 229200 URL: http://svn.freebsd.org/changeset/base/229200 Log: 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. Modified: head/sys/fs/ext2fs/ext2_alloc.c head/sys/ufs/ffs/ffs_alloc.c Modified: head/sys/fs/ext2fs/ext2_alloc.c ============================================================================== --- head/sys/fs/ext2fs/ext2_alloc.c Sun Jan 1 20:30:48 2012 (r229199) +++ head/sys/fs/ext2fs/ext2_alloc.c Sun Jan 1 20:47:33 2012 (r229200) @@ -886,8 +886,8 @@ ext2_nodealloccg(struct inode *ip, int c 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 c } 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 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); } /* Modified: head/sys/ufs/ffs/ffs_alloc.c ============================================================================== --- head/sys/ufs/ffs/ffs_alloc.c Sun Jan 1 20:30:48 2012 (r229199) +++ head/sys/ufs/ffs/ffs_alloc.c Sun Jan 1 20:47:33 2012 (r229200) @@ -1745,9 +1745,9 @@ ffs_nodealloccg(ip, cg, ipref, mode, unu struct cg *cgp; struct buf *bp, *ibp; struct ufsmount *ump; - u_int8_t *inosused; + u_int8_t *inosused, *loc; struct ufs2_dinode *dp2; - int error, start, len, loc, map, i; + int error, start, len, i; fs = ip->i_fs; ump = ip->i_ump; @@ -1777,25 +1777,19 @@ ffs_nodealloccg(ip, cg, ipref, mode, unu } start = cgp->cg_irotor / NBBY; len = howmany(fs->fs_ipg - cgp->cg_irotor, NBBY); - loc = skpc(0xff, len, &inosused[start]); - if (loc == 0) { + loc = memcchr(&inosused[start], 0xff, len); + if (loc == NULL) { len = start + 1; start = 0; - loc = skpc(0xff, len, &inosused[0]); - if (loc == 0) { + loc = memcchr(&inosused[start], 0xff, len); + if (loc == NULL) { printf("cg = %d, irotor = %ld, fs = %s\n", cg, (long)cgp->cg_irotor, fs->fs_fsmnt); panic("ffs_nodealloccg: map corrupted"); /* NOTREACHED */ } } - i = start + len - loc; - 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; + ipref = (loc - inosused) * NBBY + ffs(~*loc) - 1; cgp->cg_irotor = ipref; gotit: /*