Skip to content

Commit ee88097

Browse files
committed
fatfs: Adopted the trim function in the FAT filesystem
1 parent 6e1b9e1 commit ee88097

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

features/filesystem/fat/ChaN/ffconf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
/ disk_ioctl() function. */
172172

173173

174-
#define _USE_TRIM 0
174+
#define _USE_TRIM 1
175175
/* This option switches ATA-TRIM feature. (0:Disable or 1:Enable)
176176
/ To enable Trim feature, also CTRL_TRIM command should be implemented to the
177177
/ disk_ioctl() function. */

features/filesystem/fat/FATFileSystem.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,15 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
244244
case GET_BLOCK_SIZE:
245245
*((DWORD*)buff) = 1; // default when not known
246246
return RES_OK;
247+
case CTRL_TRIM:
248+
if (_ffs[pdrv] == NULL) {
249+
return RES_NOTRDY;
250+
} else {
251+
DWORD *sectors = (DWORD*)buff;
252+
DWORD ssize = disk_get_sector_size(pdrv);
253+
int err = _ffs[pdrv]->trim(sectors[0]*ssize, (sectors[1]-sectors[0]+1)*ssize);
254+
return err ? RES_PARERR : RES_OK;
255+
}
247256
}
248257

249258
return RES_PARERR;

0 commit comments

Comments
 (0)