提交 6eac1e16 编写于 作者: F Far

Feature: scandir format optimization.

1. Before formating, user los_disk_cache_clear to clear the Bcache;
2. FATFS readdir use dir_read_massive to use the Bcache write block to improve readdir performance

Change-Id: I2820b86f533377b40b823e45e5c8734e8f115c7f
上级 85c45160
......@@ -88,7 +88,7 @@ DRESULT disk_read (
#ifndef __LITEOS_M__
int result;
result = los_part_read((int)pdrv, (void *)buff, sector, (UINT32)count);
result = los_part_read((int)pdrv, (void *)buff, sector, (UINT32)count, TRUE);
if (result == 0)
return RES_OK;
......@@ -102,12 +102,32 @@ DRESULT disk_read (
#endif
}
#ifndef __LITEOS_M__
DRESULT disk_read_readdir (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */
QWORD sector, /* Start sector in LBA */
UINT count /* Number of sectors to read */
)
{
int result;
result = los_part_read((int)pdrv, (void *)buff, sector, (UINT32)count, FALSE);
if (result == 0)
return RES_OK;
else
return RES_ERROR;
}
#endif
#ifndef __LITEOS_M__
DRESULT disk_raw_read (int id, void *buff, QWORD sector, UINT32 count)
{
int result;
result = los_disk_read(id, buff, sector, count);
result = los_disk_read(id, buff, sector, count, TRUE);
if (result == 0)
return RES_OK;
......
......@@ -38,6 +38,7 @@ DSTATUS disk_status (BYTE pdrv);
DRESULT disk_read (BYTE pdrv, BYTE* buff, QWORD sector, UINT count);
DRESULT disk_write (BYTE pdrv, const BYTE* buff, QWORD sector, UINT count);
#ifndef __LITEOS_M__
DRESULT disk_read_readdir (BYTE pdrv, BYTE* buff, QWORD sector, UINT count);
DRESULT disk_raw_read (int id, void* buff, QWORD sector, UINT32 count);
DRESULT disk_raw_write (int id, void* buff, QWORD sector, UINT32 count);
#endif
......
......@@ -923,8 +923,34 @@ FRESULT move_window ( /* Returns FR_OK or FR_DISK_ERR */
return res;
}
#ifndef __LITEOS_M__
FRESULT move_window_readdir ( /* Returns FR_OK or FR_DISK_ERR */
FATFS* fs, /* File system object */
QWORD sector /* Sector number to make appearance in the fs->win[] */
)
{
FRESULT res = FR_OK;
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
/* Forced the fs point to its parents */
if (ISCHILD(fs)) fs = PARENTFS(fs);
#endif
if (sector != fs->winsect) { /* Window offset changed? */
#if !FF_FS_READONLY
res = sync_window(fs); /* Write-back changes */
#endif
if (res == FR_OK) { /* Fill sector window with new data */
if (disk_read_readdir(fs->pdrv, fs->win, sector, 1) != RES_OK) {
sector = 0xFFFFFFFF; /* Invalidate window if read data is not valid */
res = FR_DISK_ERR;
}
fs->winsect = sector;
}
}
return res;
}
#endif
#if !FF_FS_READONLY
/*-----------------------------------------------------------------------*/
......@@ -1827,6 +1853,61 @@ FRESULT dir_read (
#endif /* FF_FS_MINIMIZE <= 1 || FF_USE_LABEL || FF_FS_RPATH >= 2 */
#ifndef __LITEOS_M__
FRESULT dir_read_massive (
DIR* dp, /* Pointer to the directory object */
int vol /* Filtered by 0:file/directory or 1:volume label */
)
{
FRESULT res = FR_NO_FILE;
FATFS *fs = dp->obj.fs;
BYTE attr, b;
#if FF_USE_LFN
BYTE ord = 0xFF, sum = 0xFF;
#endif
while (dp->sect) {
res = move_window_readdir(fs, dp->sect);
if (res != FR_OK) break;
b = dp->dir[DIR_Name]; /* Test for the entry type */
if (b == 0) {
res = FR_NO_FILE; break; /* Reached to end of the directory */
}
/* On the FAT/FAT32 volume */
dp->obj.attr = attr = dp->dir[DIR_Attr] & AM_MASK; /* Get attribute */
#if FF_USE_LFN /* LFN configuration */
if (b == DDEM || b == '.' || (int)((attr & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */
ord = 0xFF;
} else {
if (attr == AM_LFN) { /* An LFN entry is found */
if (b & LLEF) { /* Is it start of an LFN sequence? */
sum = dp->dir[LDIR_Chksum];
b &= (BYTE)~LLEF; ord = b;
dp->blk_ofs = dp->dptr;
}
/* Check LFN validity and capture it */
ord = (b == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(fs->lfnbuf, dp->dir)) ? ord - 1 : 0xFF;
} else { /* An SFN entry is found */
if (ord != 0 || sum != sum_sfn(dp->dir)) { /* Is there a valid LFN? */
dp->blk_ofs = 0xFFFFFFFF; /* It has no LFN. */
}
break;
}
}
#else /* Non LFN configuration */
if (b != DDEM && b != '.' && attr != AM_LFN && (int)((attr & ~AM_ARC) == AM_VOL) == vol) { /* Is it a valid entry? */
break;
}
#endif
res = dir_next(dp, 0); /* Next entry */
if (res != FR_OK) break;
}
if (res != FR_OK) dp->sect = 0; /* Terminate the read operation on error or EOT */
return res;
}
#endif
/*-----------------------------------------------------------------------*/
......@@ -5982,6 +6063,7 @@ FRESULT _mkfs(los_part *partition, int sector, int opt, BYTE *work, UINT len)
}
/* Initialize FAT area */
los_disk_cache_clear(pdrv);
mem_set(buf, 0, (UINT)szb_buf);
sect = b_fat; /* FAT start sector */
for (i = 0; i < n_fats; i++) { /* Initialize FATs each */
......
......@@ -470,6 +470,9 @@ void unlock_fs (FATFS *fs, FRESULT res);
FRESULT dir_sdi (DIR *dp, DWORD ofs);
FRESULT dir_find(DIR *dp);
FRESULT dir_read(DIR *dp, int vol);
#ifndef __LITEOS_M__
FRESULT dir_read_massive(DIR *dp, int vol);
#endif
FRESULT dir_remove(DIR *dp);
FRESULT dir_next(DIR *dp, int stretch);
FRESULT dir_register(DIR *dp);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册