From 0a3a3c6a8014d7f0f8819ad6103a706506ab8cf4 Mon Sep 17 00:00:00 2001 From: TaeJun Kwon Date: Thu, 20 Jul 2017 16:22:59 +0900 Subject: [PATCH] Execute fs_recover at bind. --- os/fs/driver/mtd/smart.c | 2 -- os/fs/smartfs/smartfs.h | 2 +- os/fs/smartfs/smartfs_smart.c | 24 +++++++++++++++++------- os/fs/smartfs/smartfs_utils.c | 6 +----- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/os/fs/driver/mtd/smart.c b/os/fs/driver/mtd/smart.c index 6887d30..9ccd50d 100644 --- a/os/fs/driver/mtd/smart.c +++ b/os/fs/driver/mtd/smart.c @@ -5322,8 +5322,6 @@ int smart_validatesector(FAR struct inode *inode, uint16_t logsector, char *vali SET_TO_TRUE(validsectors, physsector); return OK; } - - fdbg("physsector is corrupted!!\n"); return -EINVAL; } diff --git a/os/fs/smartfs/smartfs.h b/os/fs/smartfs/smartfs.h index 61995ed..7773d68 100644 --- a/os/fs/smartfs/smartfs.h +++ b/os/fs/smartfs/smartfs.h @@ -544,7 +544,7 @@ int set_used_byte_count(uint8_t *used, uint16_t count); uint16_t get_used_byte_count(uint8_t *used); #endif #ifdef CONFIG_SMARTFS_SECTOR_RECOVERY -int smartfs_recover(struct inode *mountpt); +int smartfs_recover(struct smartfs_mountpt_s *fs); int smart_validatesector(FAR struct inode *inode, uint16_t logsector, char *validsectors); int smart_recoversectors(FAR struct inode *inode, char *validsectors, int *nobsolete, int *nrecovered); diff --git a/os/fs/smartfs/smartfs_smart.c b/os/fs/smartfs/smartfs_smart.c index 70c483c..5fb6be5 100644 --- a/os/fs/smartfs/smartfs_smart.c +++ b/os/fs/smartfs/smartfs_smart.c @@ -1532,23 +1532,33 @@ static int smartfs_bind(FAR struct inode *blkdriver, const void *data, void **ha ret = smartfs_mount(fs, true); if (ret != 0) { - smartfs_semgive(fs); - kmm_free(fs); - return ret; + goto error_with_semaphore; } *handle = (void *)fs; #ifdef CONFIG_SMARTFS_JOURNALING ret = smartfs_journal_init(fs); if (ret != 0) { - smartfs_semgive(fs); - kmm_free(fs); - return ret; + fdbg("init failed!!\n"); + goto error_with_semaphore; + } +#endif + +#ifdef CONFIG_SMARTFS_SECTOR_RECOVERY + ret = smartfs_recover(fs); + if (ret != 0) { + fdbg("recovery failed!!\n"); + goto error_with_semaphore; } #endif + smartfs_semgive(fs); + return ret; - return OK; +error_with_semaphore: + smartfs_semgive(fs); + kmm_free(fs); + return ret; } /**************************************************************************** diff --git a/os/fs/smartfs/smartfs_utils.c b/os/fs/smartfs/smartfs_utils.c index c4b5a51..f1f4844 100644 --- a/os/fs/smartfs/smartfs_utils.c +++ b/os/fs/smartfs/smartfs_utils.c @@ -1826,10 +1826,9 @@ errout: * Description: Recovery after a power failure * ****************************************************************************/ -int smartfs_recover(struct inode *mountpt) +int smartfs_recover(struct smartfs_mountpt_s *fs) { int i, ret; - struct smartfs_mountpt_s *fs; uint8_t rootsector; uint16_t nsectors; char *validsectors; @@ -1838,7 +1837,6 @@ int smartfs_recover(struct inode *mountpt) int nrecovered; struct sector_queue_s *node; - fs = mountpt->i_private; nsectors = fs->fs_llformat.nsectors; rootsector = fs->fs_rootsector; @@ -1861,7 +1859,6 @@ int smartfs_recover(struct inode *mountpt) node->type = SMARTFS_SECTOR_TYPE_DIR; sq_addlast((FAR sq_entry_t *)node, &g_recovery_queue); - smartfs_semtake(fs); nusedsectors = 0; ret = smartfs_examine_sector(fs, validsectors, &nusedsectors); if (ret != OK) { @@ -1884,7 +1881,6 @@ int smartfs_recover(struct inode *mountpt) fdbg("Recovered Sectors : %d\n\n", nrecovered); errout_with_semaphore: - smartfs_semgive(fs); if (validsectors) { kmm_free(validsectors); } -- 2.7.4