Execute fs_recover at bind.
authorTaeJun Kwon <tj80.kwon@samsung.com>
Thu, 20 Jul 2017 07:22:59 +0000 (16:22 +0900)
committerKavya <kavya.nunna@partner.samsung.com>
Tue, 5 Sep 2017 08:23:33 +0000 (13:53 +0530)
os/fs/driver/mtd/smart.c
os/fs/smartfs/smartfs.h
os/fs/smartfs/smartfs_smart.c
os/fs/smartfs/smartfs_utils.c

index 6887d30..9ccd50d 100644 (file)
@@ -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;
 }
 
index 61995ed..7773d68 100644 (file)
@@ -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);
 
index 70c483c..5fb6be5 100644 (file)
@@ -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;
 }
 
 /****************************************************************************
index c4b5a51..f1f4844 100644 (file)
@@ -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);
        }