uint16_t sectorsize, prerelease;
uint16_t logicalsector;
uint16_t loser;
+ uint16_t winner;
uint32_t readaddress;
uint32_t offset;
uint16_t seq1;
}
for (sector = 0; sector < totalsectors; sector++) {
+ winner = sector;
fvdbg("Scan sector %d\n", sector);
/* Calculate the read address for this sector */
#else
loser = dupsector;
#endif
+ winner = sector;
} else {
/* We keep the original mapping and seq2 is the loser */
loser = sector;
+#ifndef CONFIG_MTD_SMART_MINIMIZE_RAM
+ winner = dev->sMap[logicalsector];
+#else
+ winner = smart_cache_lookup(dev, logicalsector);
+#endif
}
/* Now release the loser sector */
#ifndef CONFIG_MTD_SMART_MINIMIZE_RAM
/* Update the logical to physical sector map */
- dev->sMap[logicalsector] = sector;
+ dev->sMap[logicalsector] = winner;
#else
/* Mark the logical sector as used in the bitmap */
dev->sBitMap[logicalsector >> 3] |= 1 << (logicalsector & 0x07);
if (logicalsector < dev->reservedsector) {
- smart_add_sector_to_cache(dev, logicalsector, sector, __LINE__);
+ smart_add_sector_to_cache(dev, logicalsector, winner, __LINE__);
}
#endif
}
char *filename;
uint16_t oldflags;
uint16_t oldoffset;
+ uint16_t firstsector;
mode_t mode;
uint16_t type;
struct smart_read_write_s req;
}
direntry = (struct smartfs_entry_header_s *)&req.buffer[oldoffset];
- oldflags = direntry->flags;
+ if (ENTRY_VALID(direntry)) {
+ oldflags = direntry->flags;
#ifdef CONFIG_SMARTFS_ALIGNED_ACCESS
- type = (smartfs_rdle16(&oldflags) & SMARTFS_DIRENT_TYPE);
- mode = (smartfs_rdle16(&oldflags) & SMARTFS_DIRENT_MODE);
+ type = (smartfs_rdle16(&oldflags) & SMARTFS_DIRENT_TYPE);
+ mode = (smartfs_rdle16(&oldflags) & SMARTFS_DIRENT_MODE);
#else
- type = oldflags & SMARTFS_DIRENT_TYPE;
- mode = oldflags & SMARTFS_DIRENT_MODE;
+ type = oldflags & SMARTFS_DIRENT_TYPE;
+ mode = oldflags & SMARTFS_DIRENT_MODE;
#endif
- /* Now create new entry at new location */
- entry->generic_1 = (uint16_t)mode;
- memcpy(j_mgr->buffer + sizeof(struct smartfs_logging_entry_s), filename, entry->datalen);
- ret = smartfs_redo_create(fs, type, (uint16_t)direntry->firstsector);
- if (ret != OK) {
- goto errout;
- }
+ firstsector = (uint16_t)direntry->firstsector;
+ /* Now create new entry at new location */
+ entry->generic_1 = (uint16_t)mode;
+ memcpy(j_mgr->buffer + sizeof(struct smartfs_logging_entry_s), filename, entry->datalen);
+ ret = smartfs_redo_create(fs, type, firstsector);
+ if (ret != OK) {
+ goto errout;
+ }
- /* Set old entry to inactive */
+ /* Set old entry to inactive */
#if CONFIG_SMARTFS_ERASEDSTATE == 0xFF
- oldflags &= ~SMARTFS_DIRENT_ACTIVE;
+ oldflags &= ~SMARTFS_DIRENT_ACTIVE;
#else
- oldflags |= SMARTFS_DIRENT_ACTIVE;
+ oldflags |= SMARTFS_DIRENT_ACTIVE;
#endif
- direntry->flags = oldflags;
+ direntry->flags = oldflags;
- req.offset = oldoffset + offsetof(struct smartfs_entry_header_s, flags);
- req.count = sizeof(direntry->flags);
- req.buffer = (uint8_t *)&direntry->flags;
- ret = FS_IOCTL(fs, BIOC_WRITESECT, (unsigned long)&req);
+ req.offset = oldoffset + offsetof(struct smartfs_entry_header_s, flags);
+ req.count = sizeof(direntry->flags);
+ req.buffer = (uint8_t *)&direntry->flags;
+ ret = FS_IOCTL(fs, BIOC_WRITESECT, (unsigned long)&req);
+ } else {
+ ret = OK;
+ }
errout:
if (filename) {
kmm_free(filename);