system/drivers/fatfs/sector.c
/*
 * PutBlock();
 *
 * "mode" determines where on the LRU list the block is written and if it
 * should be written immediately.
 *
 * Values inside "buf" determine whether a block is written to disk or left
 * for the caller to write blocks to disk by periodically calling SyncBuf().
 *
 * If writeback_delay == 0    write EVERYTHING IMMEDIATELY
 * If writethru_critical == 1  write BUF_IMMED blocks immediately.
 */
PutBlock();
"mode" determines where on the LRU list the block is written and if it
should be written immediately.

Values inside "buf" determine whether a block is written to disk or left
for the caller to write blocks to disk by periodically calling SyncBuf().

If writeback_delay == 0    write EVERYTHING IMMEDIATELY
If writethru_critical == 1  write BUF_IMMED blocks immediately.
PutBlock () ; " mode " determines where on the LRU list the block is written and if it should be written immediately . Values inside " buf " determine whether a block is written to disk or left for the caller to write blocks to disk by periodically calling SyncBuf () . If writeback_delay == 0 write EVERYTHING IMMEDIATELY If writethru_critical == 1 write BUF_IMMED blocks immediately .
struct Blk *BufPutBlock (struct Cache *cache, struct Blk *blk, int mode)
{
	int rc;
	if (mode & BUF_ONESHOT)
	{
		LIST_REM_ENTRY (&cache->lru_list, blk, lru_entry)
		LIST_ADD_TAIL (&cache->lru_list, blk, lru_entry);
	}
	if (mode & BUF_IMMED)
	{
		if (blk->dirty == true)
		{	
			blk->dirty = false;
			LIST_REM_ENTRY (&cache->dirty_list, blk, dirty_entry);
		}
		if (cache->writethru_critical != 0)
		{
			rc = BufWriteSector (cache, blk, BUF_IMMED);
			if (rc == 0)
			{
				return blk;
			}
			else
			{
				return NULL;
			}
		}
		return blk;
	}
	else
	{
		if (blk->dirty != true)
		{
			blk->dirty = true;
			LIST_ADD_TAIL (&cache->dirty_list, blk, dirty_entry);
		}
		if (cache->writeback_delay == 0)
		{
			rc = BufWriteSector (cache, blk, BUF_IMMED);
			if (rc == 0)
			{
				return blk;
			}
			else
			{
				return NULL;
			}
		}
		return blk;
	}
}
struct Blk * BufPutBlock ( struct Cache * cache , struct Blk * blk , int mode ) { int rc ; if ( mode & BUF_ONESHOT ) { LIST_REM_ENTRY ( & cache -> lru_list , blk , lru_entry ) LIST_ADD_TAIL ( & cache -> lru_list , blk , lru_entry ) ; } if ( mode & BUF_IMMED ) { if ( blk -> dirty == true ) { blk -> dirty = false ; LIST_REM_ENTRY ( & cache -> dirty_list , blk , dirty_entry ) ; } if ( cache -> writethru_critical != 0 ) { rc = BufWriteSector ( cache , blk , BUF_IMMED ) ; if ( rc == 0 ) { return blk ; } else { return NULL ; } } return blk ; } else { if ( blk -> dirty != true ) { blk -> dirty = true ; LIST_ADD_TAIL ( & cache -> dirty_list , blk , dirty_entry ) ; } if ( cache -> writeback_delay == 0 ) { rc = BufWriteSector ( cache , blk , BUF_IMMED ) ; if ( rc == 0 ) { return blk ; } else { return NULL ; } } return blk ; } }
PutBlock();
 "mode" determines where on the LRU list the block is written and if it
 should be written immediately.
PutBlock () ; " mode " determines where on the LRU list the block is written and if it should be written immediately .
//				SetError (EIO); /* Mark as dirty and place on tail of dirty list */ //				SetError (EIO);