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 */ /* Timestamp feature */
#if _FS_NORTC #if _FS_NORTC == 1
#define GET_FATTIME() ((DWORD)_NORTC_YEAR << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16) #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 #else
#define GET_FATTIME() get_fattime() #define GET_FATTIME() get_fattime()
#endif #endif
@@ -3496,22 +3499,24 @@ FRESULT f_unlink (
if (dir[DIR_Attr] & AM_RDO) if (dir[DIR_Attr] & AM_RDO)
res = FR_DENIED; /* Cannot remove R/O object */ 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); dclst = ld_clust(dj.fs, dir);
if (!dclst) { if (dir[DIR_Attr] & AM_DIR) { /* Is it a sub-dir? */
res = FR_INT_ERR; if (!dclst) {
} else { /* Make sure the sub-directory is empty */ res = FR_INT_ERR;
mem_cpy(&sdj, &dj, sizeof (DIR)); } else { /* Make sure the sub-directory is empty */
sdj.sclust = dclst; mem_cpy(&sdj, &dj, sizeof (DIR));
res = dir_sdi(&sdj, 2); /* Exclude dot entries */ sdj.sclust = dclst;
if (res == FR_OK) { res = dir_sdi(&sdj, 2); /* Exclude dot entries */
res = dir_read(&sdj, 0); /* Read an item */ if (res == FR_OK) {
if (res == FR_OK /* Not empty directory */ res = dir_read(&sdj, 0); /* Read an item */
if (res == FR_OK /* Not empty directory */
#if _FS_RPATH #if _FS_RPATH
|| dclst == dj.fs->cdir /* or current directory */ || dclst == dj.fs->cdir /* or current directory */
#endif #endif
) res = FR_DENIED; ) res = FR_DENIED;
if (res == FR_NO_FILE) res = FR_OK; /* It is empty */ if (res == FR_NO_FILE) res = FR_OK; /* It is empty */
}
} }
} }
} }