fatfs/src/ff.c
static FRESULT change_bitmap (
	FATFS* fs,	/* Filesystem object */
	DWORD clst,	/* Cluster number to change from */
	DWORD ncl,	/* Number of clusters to be changed */
	int bv		/* bit value to be set (0 or 1) */
)
{
	BYTE bm;
	UINT i;
	DWORD sect;


	clst -= 2;	/* The first bit corresponds to cluster #2 */
	sect = fs->bitbase + clst / 8 / SS(fs);	/* Sector address */
	i = clst / 8 % SS(fs);					/* Byte offset in the sector */
	bm = 1 << (clst % 8);					/* Bit mask in the byte */
	for (;;) {
		if (move_window(fs, sect++) != FR_OK) return FR_DISK_ERR;
		do {
			do {
				if (bv == (int)((fs->win[i] & bm) != 0)) return FR_INT_ERR;	/* Is the bit expected value? */
				fs->win[i] ^= bm;	/* Flip the bit */
				fs->wflag = 1;
				if (--ncl == 0) return FR_OK;	/* All bits processed? */
			} while (bm <<= 1);		/* Next bit */
			bm = 1;
		} while (++i < SS(fs));		/* Next byte */
		i = 0;
	}
}
/*----------------------------------------*/
/* Set/Clear a block of allocation bitmap */
/*----------------------------------------*/
Set/Clear a block of allocation bitmap
Set / Clear a block of allocation bitmap
static FRESULT change_bitmap (
	FATFS* fs,	
	DWORD clst,	
	DWORD ncl,	
	int bv		
)
{
	BYTE bm;
	UINT i;
	DWORD sect;
	clst -= 2;	
	sect = fs->bitbase + clst / 8 / SS(fs);	
	i = clst / 8 % SS(fs);					
	bm = 1 << (clst % 8);					
	for (;;) {
		if (move_window(fs, sect++) != FR_OK) return FR_DISK_ERR;
		do {
			do {
				if (bv == (int)((fs->win[i] & bm) != 0)) return FR_INT_ERR;	
				fs->win[i] ^= bm;	
				fs->wflag = 1;
				if (--ncl == 0) return FR_OK;	
			} while (bm <<= 1);		
			bm = 1;
		} while (++i < SS(fs));		
		i = 0;
	}
}
static FRESULT change_bitmap ( FATFS * fs , DWORD clst , DWORD ncl , int bv ) { BYTE bm ; UINT i ; DWORD sect ; clst -= 2 ; sect = fs -> bitbase + clst / 8 / SS ( fs ) ; i = clst / 8 % SS ( fs ) ; bm = 1 << ( clst % 8 ) ; for ( ; ; ) { if ( move_window ( fs , sect ++ ) != FR_OK ) return FR_DISK_ERR ; do { do { if ( bv == ( int ) ( ( fs -> win [ i ] & bm ) != 0 ) ) return FR_INT_ERR ; fs -> win [ i ] ^= bm ; fs -> wflag = 1 ; if ( -- ncl == 0 ) return FR_OK ; } while ( bm <<= 1 ) ; bm = 1 ; } while ( ++ i < SS ( fs ) ) ; i = 0 ; } }
Set/Clear a block of allocation bitmap
Set / Clear a block of allocation bitmap
/* Filesystem object */ /* Cluster number to change from */ /* Number of clusters to be changed */ /* bit value to be set (0 or 1) */ /* The first bit corresponds to cluster #2 */ /* Sector address */ /* Byte offset in the sector */ /* Bit mask in the byte */ /* Is the bit expected value? */ /* Flip the bit */ /* All bits processed? */ /* Next bit */ /* Next byte */