Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

part 1 of romfs extend to enable format function #13445

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions fs/mount/fs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ static const struct fsmap_t g_bdfsmap[] =
#ifdef MDFS_SUPPORT
/* File systems that require MTD drivers */

#ifdef CONFIG_FS_ROMFS
extern const struct mountpt_operations g_romfs_operations;
#endif
#ifdef CONFIG_FS_SPIFFS
extern const struct mountpt_operations g_spiffs_operations;
#endif
Expand Down
7 changes: 7 additions & 0 deletions fs/romfs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ config FS_ROMFS_CACHE_FILE_NSECTORS
---help---
The number of file cache sector

config FS_ROMFS_WRITEABLE
bool "Enable write extended feature in romfs"
default n
depends on FS_ROMFS_CACHE_NODE
---help---
Enable write extended feature in romfs

endif
83 changes: 60 additions & 23 deletions fs/romfs/fs_romfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,12 +1074,11 @@ static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
return -ENODEV;
}

if (INODE_IS_BLOCK(blkdriver) &&
blkdriver->u.i_bops->open != NULL &&
blkdriver->u.i_bops->open(blkdriver) != OK)
if (blkdriver->u.i_bops->open != NULL &&
(ret = blkdriver->u.i_bops->open(blkdriver)) != OK)
{
ferr("ERROR: No open method\n");
return -ENODEV;
return ret;
}

/* Create an instance of the mountpt state structure */
Expand All @@ -1088,7 +1087,8 @@ static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
if (!rm)
{
ferr("ERROR: Failed to allocate mountpoint structure\n");
return -ENOMEM;
ret = -ENOMEM;
goto errout;
}

/* Initialize the allocated mountpt state structure. The filesystem is
Expand All @@ -1105,18 +1105,51 @@ static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
if (ret < 0)
{
ferr("ERROR: romfs_hwconfigure failed: %d\n", ret);
goto errout;
goto errout_with_mount;
}

#ifdef CONFIG_FS_ROMFS_WRITEABLE
if (data && strstr(data, "rw") && strstr(data, "forceformat"))
{
ret = romfs_mkfs(rm);
if (ret < 0)
{
ferr("ERROR: romfs_mkfs failed: %d\n", ret);
goto errout_with_buffer;
}
}
#endif

/* Then complete the mount by getting the ROMFS configuratrion from
* the ROMF header
*/

ret = romfs_fsconfigure(rm);
ret = romfs_fsconfigure(rm, data);
if (ret < 0)
{
ferr("ERROR: romfs_fsconfigure failed: %d\n", ret);
goto errout_with_buffer;
#ifdef CONFIG_FS_ROMFS_WRITEABLE
if (data && strstr(data, "rw") && strstr(data, "autoformat"))
{
ret = romfs_mkfs(rm);
if (ret < 0)
{
ferr("ERROR: romfs_format failed: %d\n", ret);
goto errout_with_buffer;
}

ret = romfs_fsconfigure(rm, data);
if (ret < 0)
{
ferr("ERROR: romfs_fsconfigure failed: %d\n", ret);
goto errout_with_buffer;
}
}
else
#endif
{
ferr("ERROR: romfs_fsconfigure failed: %d\n", ret);
goto errout_with_buffer;
}
}

/* Mounted! */
Expand All @@ -1125,14 +1158,18 @@ static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
return OK;

errout_with_buffer:
if (!rm->rm_xipbase)
{
kmm_free(rm->rm_buffer);
}
kmm_free(rm->rm_devbuffer);

errout:
errout_with_mount:
nxrmutex_destroy(&rm->rm_lock);
kmm_free(rm);

errout:
if (blkdriver->u.i_bops->close != NULL)
{
blkdriver->u.i_bops->close(blkdriver);
}

return ret;
}

Expand Down Expand Up @@ -1177,7 +1214,7 @@ static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
* no open file references.
*/

ret = (flags != 0) ? -ENOSYS : -EBUSY;
ret = flags ? -ENOSYS : -EBUSY;
}
else
{
Expand Down Expand Up @@ -1208,13 +1245,12 @@ static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver,

/* Release the mountpoint private data */

if (!rm->rm_xipbase && rm->rm_buffer)
{
kmm_free(rm->rm_buffer);
}

kmm_free(rm->rm_devbuffer);
#ifdef CONFIG_FS_ROMFS_CACHE_NODE
romfs_freenode(rm->rm_root);
#endif
#ifdef CONFIG_FS_ROMFS_WRITEABLE
romfs_free_sparelist(&rm->rm_sparelist);
#endif
nxrmutex_destroy(&rm->rm_lock);
kmm_free(rm);
Expand Down Expand Up @@ -1272,9 +1308,10 @@ static int romfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)

/* Everything else follows in units of sectors */

buf->f_blocks = SEC_NSECTORS(rm, rm->rm_volsize + SEC_NDXMASK(rm));
buf->f_bfree = 0;
buf->f_bavail = 0;
buf->f_blocks = rm->rm_hwnsectors;
buf->f_bfree = buf->f_blocks -
SEC_NSECTORS(rm, rm->rm_volsize + SEC_NDXMASK(rm));
buf->f_bavail = buf->f_bfree;
buf->f_namelen = NAME_MAX;

errout_with_lock:
Expand Down
26 changes: 25 additions & 1 deletion fs/romfs/fs_romfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
****************************************************************************/

#include <nuttx/config.h>
#include <nuttx/list.h>

#include <stdint.h>
#include <stdbool.h>
Expand Down Expand Up @@ -116,6 +117,20 @@
* Public Types
****************************************************************************/

#ifdef CONFIG_FS_ROMFS_WRITEABLE
/* This structure represents the spare list. An instance of this
* structure is retained as file header and file data size on each mountpoint
* that is mounted with a romfs filesystem.
*/

struct romfs_sparenode_s
{
struct list_node node;
uint32_t start;
uint32_t end;
};
#endif

/* This structure represents the overall mountpoint state. An instance of
* this structure is retained as inode private data on each mountpoint that
* is mounted with a romfs filesystem.
Expand All @@ -139,6 +154,10 @@ struct romfs_mountpt_s
uint32_t rm_cachesector; /* Current sector in the rm_buffer */
FAR uint8_t *rm_xipbase; /* Base address of directly accessible media */
FAR uint8_t *rm_buffer; /* Device sector buffer, allocated if rm_xipbase==0 */
FAR uint8_t *rm_devbuffer; /* Device sector buffer, allocated for write if rm_xipbase != 0 */
#ifdef CONFIG_FS_ROMFS_WRITEABLE
struct list_node rm_sparelist; /* The list of spare space */
#endif
};

/* This structure represents on open file under the mountpoint. An instance
Expand All @@ -164,6 +183,7 @@ struct romfs_nodeinfo_s
uint32_t rn_next; /* Offset of the next file header+flags */
uint32_t rn_size; /* Size (if file) */
#ifdef CONFIG_FS_ROMFS_CACHE_NODE
uint32_t rn_origoffset; /* Offset of origin file header */
FAR struct romfs_nodeinfo_s **rn_child; /* The node array for link to lower level */
uint16_t rn_count; /* The count of node in rn_child level */
uint8_t rn_namesize; /* The length of name of the entry */
Expand Down Expand Up @@ -193,7 +213,7 @@ int romfs_hwread(FAR struct romfs_mountpt_s *rm, FAR uint8_t *buffer,
int romfs_filecacheread(FAR struct romfs_mountpt_s *rm,
FAR struct romfs_file_s *rf, uint32_t sector);
int romfs_hwconfigure(FAR struct romfs_mountpt_s *rm);
int romfs_fsconfigure(FAR struct romfs_mountpt_s *rm);
int romfs_fsconfigure(FAR struct romfs_mountpt_s *rm, FAR const void *data);
int romfs_fileconfigure(FAR struct romfs_mountpt_s *rm,
FAR struct romfs_file_s *rf);
int romfs_checkmount(FAR struct romfs_mountpt_s *rm);
Expand All @@ -211,6 +231,10 @@ int romfs_datastart(FAR struct romfs_mountpt_s *rm,
#ifdef CONFIG_FS_ROMFS_CACHE_NODE
void romfs_freenode(FAR struct romfs_nodeinfo_s *node);
#endif
#ifdef CONFIG_FS_ROMFS_WRITEABLE
int romfs_mkfs(FAR struct romfs_mountpt_s *rm);
void romfs_free_sparelist(FAR struct list_node *list);
#endif

#undef EXTERN
#if defined(__cplusplus)
Expand Down
Loading
Loading