Fixes #2027: Deleting file on radio does not actually frees clusters (patch from upstream)

This commit is contained in:
Damjan Adamic
2015-01-23 18:49:07 +01:00
parent f131119ca1
commit 1cccbac519
+20 -15
View File
@@ -163,8 +163,11 @@
/* Timestamp feature */
#if _FS_NORTC
#define GET_FATTIME() ((DWORD)_NORTC_YEAR << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)
#if _FS_NORTC == 1
#if _NORTC_YEAR < 1980 || _NORTC_YEAR > 2107 || _NORTC_MON < 1 || _NORTC_MON > 12 || _NORTC_MDAY < 1 || _NORTC_MDAY > 31
#error Invalid _FS_NORTC settings
#endif
#define GET_FATTIME() ((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)
#else
#define GET_FATTIME() get_fattime()
#endif
@@ -3496,22 +3499,24 @@ FRESULT f_unlink (
if (dir[DIR_Attr] & AM_RDO)
res = FR_DENIED; /* Cannot remove R/O object */
}
if (res == FR_OK && (dir[DIR_Attr] & AM_DIR)) { /* Is it a sub-dir? */
if (res == FR_OK) {
dclst = ld_clust(dj.fs, dir);
if (!dclst) {
res = FR_INT_ERR;
} else { /* Make sure the sub-directory is empty */
mem_cpy(&sdj, &dj, sizeof (DIR));
sdj.sclust = dclst;
res = dir_sdi(&sdj, 2); /* Exclude dot entries */
if (res == FR_OK) {
res = dir_read(&sdj, 0); /* Read an item */
if (res == FR_OK /* Not empty directory */
if (dir[DIR_Attr] & AM_DIR) { /* Is it a sub-dir? */
if (!dclst) {
res = FR_INT_ERR;
} else { /* Make sure the sub-directory is empty */
mem_cpy(&sdj, &dj, sizeof (DIR));
sdj.sclust = dclst;
res = dir_sdi(&sdj, 2); /* Exclude dot entries */
if (res == FR_OK) {
res = dir_read(&sdj, 0); /* Read an item */
if (res == FR_OK /* Not empty directory */
#if _FS_RPATH
|| dclst == dj.fs->cdir /* or current directory */
|| dclst == dj.fs->cdir /* or current directory */
#endif
) res = FR_DENIED;
if (res == FR_NO_FILE) res = FR_OK; /* It is empty */
) res = FR_DENIED;
if (res == FR_NO_FILE) res = FR_OK; /* It is empty */
}
}
}
}