From: Heesub Shin Date: Mon, 20 Mar 2017 07:01:55 +0000 (+0900) Subject: fs/smartfs: revert changes by samsung X-Git-Tag: 1.1_Public_Release~614^2~370 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fc82adaf5c7303f77cdf3ce56ff1b8be17d339ca;p=rtos%2Ftinyara.git fs/smartfs: revert changes by samsung mksmartfs() accepts a boolean value that specifies how to behave when the volume is already formatted, to prevent it from being damaged. However, the way of checking whether the volume is formatted or not is completely wrong. I never understand what the hell they thought when they had done this. Change-Id: Ic778c4ee66c0e66f3b50d97f02113f48117e82bf Signed-off-by: Heesub Shin --- diff --git a/os/fs/driver/mtd/smart.c b/os/fs/driver/mtd/smart.c index 5ee093a..82431f1 100644 --- a/os/fs/driver/mtd/smart.c +++ b/os/fs/driver/mtd/smart.c @@ -429,29 +429,12 @@ static const struct block_operations g_bops = { /**************************************************************************** * Private variables ****************************************************************************/ -static bool is_smart_formated; /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * This is used to format the flash in smartFs - ****************************************************************************/ -void smart_set_format_status(bool value) -{ - is_smart_formated = value; -} - -/**************************************************************************** - * This is used to know if flash is already formated by smartFs - ****************************************************************************/ -bool smart_get_format_status(void) -{ - return is_smart_formated; -} - -/**************************************************************************** * Name: smart_malloc * * Description: Perform allocations and keep track of amount of allocated @@ -2050,17 +2033,6 @@ static int smart_scan(FAR struct smart_struct_s *dev) goto err_out; } - /* Validate the format signature */ - - if (dev->rwbuffer[SMART_FMT_POS1] != SMART_FMT_SIG1 || dev->rwbuffer[SMART_FMT_POS2] != SMART_FMT_SIG2 || dev->rwbuffer[SMART_FMT_POS3] != SMART_FMT_SIG3 || dev->rwbuffer[SMART_FMT_POS4] != SMART_FMT_SIG4) { - /* Invalid signature on a sector claiming to be sector 0! - * What should we do? Release it?*/ - smart_set_format_status(false); - continue; - } - smart_set_format_status(true); - /* Mark the volume as formatted and set the sector size */ - dev->formatstatus = SMART_FMT_STAT_FORMATTED; dev->namesize = dev->rwbuffer[SMART_FMT_NAMESIZE_POS]; dev->formatversion = dev->rwbuffer[SMART_FMT_VERSION_POS]; @@ -5191,7 +5163,6 @@ int smart_initialize(int minor, FAR struct mtd_dev_s *mtd, FAR const char *partn used_block_divident = chunk_shift + 3; smart_sect_header_size = sizeof(struct smart_sect_header_s); #endif - smart_set_format_status(false); /* Sanity check */ #ifdef CONFIG_DEBUG diff --git a/os/fs/smartfs/smartfs_mksmartfs.c b/os/fs/smartfs/smartfs_mksmartfs.c index f86ba44..f7827a5 100644 --- a/os/fs/smartfs/smartfs_mksmartfs.c +++ b/os/fs/smartfs/smartfs_mksmartfs.c @@ -115,18 +115,10 @@ int mksmartfs(FAR const char *pathname, bool format) struct smart_format_s fmt; int ret; int x; - bool is_smart; uint8_t type; struct smart_read_write_s request; - if (format) { - is_smart = false; - } else { - is_smart = smart_get_format_status(); - } - /* Find the inode of the block driver indentified by 'source' */ - ret = open_blockdriver(pathname, 0, &inode); if (ret < 0) { fdbg("Failed to open %s\n", pathname); @@ -143,67 +135,61 @@ int mksmartfs(FAR const char *pathname, bool format) /* Validate the block device is a SMART device */ /* Perform a low-level SMART format */ - if (!is_smart) { #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - ret = inode->u.i_bops->ioctl(inode, BIOC_LLFORMAT, nrootdirs); + ret = inode->u.i_bops->ioctl(inode, BIOC_LLFORMAT, nrootdirs); #else - ret = inode->u.i_bops->ioctl(inode, BIOC_LLFORMAT, 0); + ret = inode->u.i_bops->ioctl(inode, BIOC_LLFORMAT, 0); #endif - if (ret != OK) { - fdbg("Error creating low-level format: %d\n", ret); - goto errout_with_driver; - } - } else { - fdbg("already smart\n"); + if (ret != OK) { + fdbg("Error creating low-level format: %d\n", ret); + goto errout_with_driver; } - /* Get the format information so we know how big the sectors are */ + /* Get the format information so we know how big the sectors are */ ret = inode->u.i_bops->ioctl(inode, BIOC_GETFORMAT, (unsigned long)&fmt); if (ret != OK) { fdbg("Error getting device low level format: %d\n", ret); goto errout_with_driver; } + /* Now Write the filesystem to media. Loop for each root dir entry and * allocate the reserved Root Dir Enty, then write a blank root dir for it. */ - type = SMARTFS_SECTOR_TYPE_DIR; request.offset = 0; request.count = 1; request.buffer = &type; x = 0; - if (!is_smart) { #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS - for (; x < nrootdirs; x++) + for (; x < nrootdirs; x++) #endif - { + { #ifdef CONFIG_SMARTFS_BAD_SECTOR - int allocated_sector = inode->u.i_bops->ioctl(inode, BIOC_ALLOCSECT, - SMARTFS_BSM_LOG_SECTOR_NUMBER); - if (allocated_sector != SMARTFS_BSM_LOG_SECTOR_NUMBER) { - allocated_sector = -EIO; - goto errout_with_driver; - } + int allocated_sector = inode->u.i_bops->ioctl(inode, BIOC_ALLOCSECT, + SMARTFS_BSM_LOG_SECTOR_NUMBER); + if (allocated_sector != SMARTFS_BSM_LOG_SECTOR_NUMBER) { + allocated_sector = -EIO; + goto errout_with_driver; + } #endif // CONFIG_SMARTFS_BAD_SECTOR - ret = inode->u.i_bops->ioctl(inode, BIOC_ALLOCSECT, SMARTFS_ROOT_DIR_SECTOR + x); - if (ret != SMARTFS_ROOT_DIR_SECTOR + x) { - ret = -EIO; - goto errout_with_driver; - } + ret = inode->u.i_bops->ioctl(inode, BIOC_ALLOCSECT, SMARTFS_ROOT_DIR_SECTOR + x); + if (ret != SMARTFS_ROOT_DIR_SECTOR + x) { + ret = -EIO; + goto errout_with_driver; + } - /* Mark this block as a directory entry */ + /* Mark this block as a directory entry */ - request.logsector = SMARTFS_ROOT_DIR_SECTOR + x; + request.logsector = SMARTFS_ROOT_DIR_SECTOR + x; - /* Issue a write to the sector, single byte */ + /* Issue a write to the sector, single byte */ - ret = inode->u.i_bops->ioctl(inode, BIOC_WRITESECT, (unsigned long)&request); - if (ret != 0) { - ret = -EIO; - goto errout_with_driver; - } + ret = inode->u.i_bops->ioctl(inode, BIOC_WRITESECT, (unsigned long)&request); + if (ret != 0) { + ret = -EIO; + goto errout_with_driver; } }