Skip to content
Merged
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
7 changes: 0 additions & 7 deletions fs/romfs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,4 @@ 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
130 changes: 25 additions & 105 deletions fs/romfs/fs_romfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,12 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
return ret;
}

#ifdef CONFIG_FS_ROMFS_WRITEABLE
if (oflags & (O_WRONLY | O_APPEND | O_TRUNC | O_CREAT))
ret = romfs_checkmount(rm);
if (ret < 0)
{
if (list_is_empty(&rm->rm_sparelist))
{
ferr("ERROR: RW not enabled, only O_RDONLY supported\n");
ret = -EACCES;
goto errout_with_lock;
}

nxrmutex_unlock(&rm->rm_lock);
nxsem_wait_uninterruptible(&rm->rm_sem);
nxrmutex_lock(&rm->rm_lock);
ferr("ERROR: romfs_checkmount failed: %d\n", ret);
goto errout_with_lock;
}
else
#endif

/* ROMFS is read-only. Any attempt to open with any kind of write
* access is not permitted.
Expand All @@ -219,21 +209,14 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
goto errout_with_lock;
}

ret = romfs_checkmount(rm);
if (ret < 0)
{
ferr("ERROR: romfs_checkmount failed: %d\n", ret);
goto errout_with_sem;
}

/* Locate the directory entry for this path */

ret = romfs_finddirentry(rm, &nodeinfo, relpath);
if (ret < 0)
{
ferr("ERROR: Failed to find directory directory entry for '%s': %d\n",
relpath, ret);
goto errout_with_sem;
goto errout_with_lock;
}

/* The full path exists -- but is the final component a file
Expand All @@ -250,7 +233,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,

ret = -EISDIR;
ferr("ERROR: '%s' is a directory\n", relpath);
goto errout_with_sem;
goto errout_with_lock;
}
else if (!IS_FILE(nodeinfo.rn_next))
{
Expand All @@ -264,7 +247,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,

ret = -ENXIO;
ferr("ERROR: '%s' is a special file\n", relpath);
goto errout_with_sem;
goto errout_with_lock;
}

/* Create an instance of the file private data to describe the opened
Expand All @@ -277,7 +260,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
{
ferr("ERROR: Failed to allocate private data\n");
ret = -ENOMEM;
goto errout_with_sem;
goto errout_with_lock;
}

/* Initialize the file private data (only need to initialize
Expand All @@ -295,7 +278,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
{
ferr("ERROR: Failed to locate start of file data: %d\n", ret);
fs_heap_free(rf);
goto errout_with_sem;
goto errout_with_lock;
}

/* Configure buffering to support access to this file */
Expand All @@ -305,34 +288,14 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
{
ferr("ERROR: Failed configure buffering: %d\n", ret);
fs_heap_free(rf);
goto errout_with_sem;
goto errout_with_lock;
}

/* Attach the private date to the struct file instance */

filep->f_priv = rf;
rm->rm_refs++;

#ifdef CONFIG_FS_ROMFS_WRITEABLE

/* If the file is only created for read */

if ((oflags & (O_WRONLY | O_APPEND | O_TRUNC | O_CREAT)) == O_CREAT)
{
nxsem_post(&rm->rm_sem);
}
#endif

nxrmutex_unlock(&rm->rm_lock);
return ret;

errout_with_sem:
#ifdef CONFIG_FS_ROMFS_WRITEABLE
if (oflags & (O_WRONLY | O_APPEND | O_TRUNC | O_CREAT))
{
nxsem_post(&rm->rm_sem);
}
#endif
rm->rm_refs++;

errout_with_lock:
nxrmutex_unlock(&rm->rm_lock);
Expand Down Expand Up @@ -369,13 +332,6 @@ static int romfs_close(FAR struct file *filep)
}

rm->rm_refs--;
#ifdef CONFIG_FS_ROMFS_WRITEABLE
if (filep->f_oflags & (O_WRONLY | O_APPEND | O_TRUNC))
{
nxsem_post(&rm->rm_sem);
}
#endif

nxrmutex_unlock(&rm->rm_lock);

/* Do not check if the mount is healthy. We must support closing of
Expand Down Expand Up @@ -1173,61 +1129,27 @@ static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
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 configuration from
* the ROMF header
*/

ret = romfs_fsconfigure(rm, data);
ret = romfs_fsconfigure(rm);
if (ret < 0)
{
#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;
}
ferr("ERROR: romfs_fsconfigure failed: %d\n", ret);
goto errout_with_buffer;
}

#ifdef CONFIG_FS_ROMFS_WRITEABLE
nxsem_init(&rm->rm_sem, 0, 1);
#endif

/* Mounted! */

*handle = rm;
return 0;

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

errout_with_mount:
nxrmutex_destroy(&rm->rm_lock);
Expand Down Expand Up @@ -1315,14 +1237,13 @@ static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver,

/* Release the mountpoint private data */

fs_heap_free(rm->rm_devbuffer);
if (!rm->rm_xipbase)
{
fs_heap_free(rm->rm_buffer);
}

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

/* Everything else follows in units of sectors */

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_blocks = SEC_NSECTORS(rm, rm->rm_volsize + SEC_NDXMASK(rm));
buf->f_bfree = 0;
buf->f_bavail = 0;
buf->f_namelen = NAME_MAX;

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

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

#include <stdint.h>
#include <stdbool.h>
Expand Down Expand Up @@ -119,20 +118,6 @@
* 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 @@ -156,11 +141,6 @@ 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 */
sem_t rm_sem; /* The semaphore to assume write safe */
#endif
};

/* This structure represents on open file under the mountpoint. An instance
Expand All @@ -186,7 +166,6 @@ 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 @@ -216,7 +195,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, FAR const void *data);
int romfs_fsconfigure(FAR struct romfs_mountpt_s *rm);
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 @@ -234,10 +213,6 @@ 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