Simple ext2fs allocation routine cleanups

gnehzuil gnehzuil at gmail.com
Wed Feb 23 14:02:46 UTC 2011


Hi John,

I can try to do some tests. :-)

Best regards,
lz

On 02/23/2011 09:11 PM, John Baldwin wrote:
> I have some small changes to ext2fs to use ffs() to simplify some of the
> allocation routines.  The changes compile, but I have not had time to generate
> a test ext2fs file system to run-test them.  If someone has some spare cycles
> to setup a test file system and try them out I would appreciate it.  Otherwise
> I will get to it eventually.  Given that this hasn't been run-tested yet, I
> would not recommend using it for a production ext2fs since it may completely
> trash the filesystem.
>
> Index: ext2_alloc.c
> ===================================================================
> --- ext2_alloc.c	(revision 218951)
> +++ ext2_alloc.c	(working copy)
> @@ -815,16 +815,12 @@
>   		}
>   	}
>   	i = start + len - loc;
> -	map = ibp[i];
> -	ipref = i * NBBY;
> -	for (i = 1; i<  (1<<  NBBY); i<<= 1, ipref++) {
> -		if ((map&  i) == 0) {
> -			goto gotit;
> -		}
> +	map = ibp[i] ^ 0xff;
> +	if (map == 0) {
> +		printf("fs = %s\n", fs->e2fs_fsmnt);
> +		panic("ext2fs_nodealloccg: block not in map");
>   	}
> -	printf("fs = %s\n", fs->e2fs_fsmnt);
> -	panic("ext2fs_nodealloccg: block not in map");
> -	/* NOTREACHED */
> +	ipref = i * NBBY + ffs(map);
>   gotit:
>   	setbit(ibp, ipref);
>   	EXT2_LOCK(ump);
> @@ -952,7 +948,6 @@
>   static daddr_t
>   ext2_mapsearch(struct m_ext2fs *fs, char *bbp, daddr_t bpref)
>   {
> -	daddr_t bno;
>   	int start, len, loc, i, map;
>
>   	/*
> @@ -977,15 +972,12 @@
>   		}
>   	}
>   	i = start + len - loc;
> -	map = bbp[i];
> -	bno = i * NBBY;
> -	for (i = 1; i<  (1<<  NBBY); i<<= 1, bno++) {
> -		if ((map&  i) == 0)
> -			return (bno);
> +	map = bbp[i] ^ 0xff;
> +	if (map == 0) {
> +		printf("fs = %s\n", fs->e2fs_fsmnt);
> +		panic("ext2fs_mapsearch: block not in map");
>   	}
> -	printf("fs = %s\n", fs->e2fs_fsmnt);
> -	panic("ext2fs_mapsearch: block not in map");
> -	/* NOTREACHED */
> +	return (i * NBBY + ffs(map));
>   }
>
>   /*
>



More information about the freebsd-fs mailing list