/****************************************************************************
* 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
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];
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
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);
/* 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;
}
}