mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 13:27:01 +08:00
Revert "romfs:extend romfs to enable write"
This reverts commit ac6fff747a7a6122e61de373350148331a94692f. This reverts commit c83e3f651b967c64b5652a6bd2e96bcae48417b4. This reverts commit 133db24d072457331134b683ad7b84c8a002feb9. This reverts commit 5c1248ec38964e7886b23e65f732241c5d870d69. This reverts commit 2cc850b6dcbad904282f1a326f52bff054251591. This reverts commit 49cad84508e7db903068180fe4ebdfaef335efac. Signed-off-by: guohao15 <guohao15@xiaomi.com>
This commit is contained in:
@@ -27,11 +27,4 @@ config FS_ROMFS_CACHE_FILE_NSECTORS
|
|||||||
---help---
|
---help---
|
||||||
The number of file cache sector
|
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
|
endif
|
||||||
|
|||||||
+25
-105
@@ -191,22 +191,12 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_FS_ROMFS_WRITEABLE
|
ret = romfs_checkmount(rm);
|
||||||
if (oflags & (O_WRONLY | O_APPEND | O_TRUNC | O_CREAT))
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
if (list_is_empty(&rm->rm_sparelist))
|
ferr("ERROR: romfs_checkmount failed: %d\n", ret);
|
||||||
{
|
goto errout_with_lock;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ROMFS is read-only. Any attempt to open with any kind of write
|
/* ROMFS is read-only. Any attempt to open with any kind of write
|
||||||
* access is not permitted.
|
* access is not permitted.
|
||||||
@@ -219,13 +209,6 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
goto errout_with_lock;
|
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 */
|
/* Locate the directory entry for this path */
|
||||||
|
|
||||||
ret = romfs_finddirentry(rm, &nodeinfo, relpath);
|
ret = romfs_finddirentry(rm, &nodeinfo, relpath);
|
||||||
@@ -233,7 +216,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
{
|
{
|
||||||
ferr("ERROR: Failed to find directory directory entry for '%s': %d\n",
|
ferr("ERROR: Failed to find directory directory entry for '%s': %d\n",
|
||||||
relpath, ret);
|
relpath, ret);
|
||||||
goto errout_with_sem;
|
goto errout_with_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The full path exists -- but is the final component a file
|
/* The full path exists -- but is the final component a file
|
||||||
@@ -250,7 +233,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
|
|
||||||
ret = -EISDIR;
|
ret = -EISDIR;
|
||||||
ferr("ERROR: '%s' is a directory\n", relpath);
|
ferr("ERROR: '%s' is a directory\n", relpath);
|
||||||
goto errout_with_sem;
|
goto errout_with_lock;
|
||||||
}
|
}
|
||||||
else if (!IS_FILE(nodeinfo.rn_next))
|
else if (!IS_FILE(nodeinfo.rn_next))
|
||||||
{
|
{
|
||||||
@@ -264,7 +247,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
|
|
||||||
ret = -ENXIO;
|
ret = -ENXIO;
|
||||||
ferr("ERROR: '%s' is a special file\n", relpath);
|
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
|
/* Create an instance of the file private data to describe the opened
|
||||||
@@ -277,7 +260,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
{
|
{
|
||||||
ferr("ERROR: Failed to allocate private data\n");
|
ferr("ERROR: Failed to allocate private data\n");
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto errout_with_sem;
|
goto errout_with_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the file private data (only need to initialize
|
/* Initialize the file private data (only need to initialize
|
||||||
@@ -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);
|
ferr("ERROR: Failed to locate start of file data: %d\n", ret);
|
||||||
fs_heap_free(rf);
|
fs_heap_free(rf);
|
||||||
goto errout_with_sem;
|
goto errout_with_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configure buffering to support access to this file */
|
/* Configure buffering to support access to this file */
|
||||||
@@ -305,35 +288,15 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||||||
{
|
{
|
||||||
ferr("ERROR: Failed configure buffering: %d\n", ret);
|
ferr("ERROR: Failed configure buffering: %d\n", ret);
|
||||||
fs_heap_free(rf);
|
fs_heap_free(rf);
|
||||||
goto errout_with_sem;
|
goto errout_with_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Attach the private date to the struct file instance */
|
/* Attach the private date to the struct file instance */
|
||||||
|
|
||||||
filep->f_priv = rf;
|
filep->f_priv = rf;
|
||||||
|
|
||||||
rm->rm_refs++;
|
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
|
|
||||||
|
|
||||||
errout_with_lock:
|
errout_with_lock:
|
||||||
nxrmutex_unlock(&rm->rm_lock);
|
nxrmutex_unlock(&rm->rm_lock);
|
||||||
return ret;
|
return ret;
|
||||||
@@ -369,13 +332,6 @@ static int romfs_close(FAR struct file *filep)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rm->rm_refs--;
|
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);
|
nxrmutex_unlock(&rm->rm_lock);
|
||||||
|
|
||||||
/* Do not check if the mount is healthy. We must support closing of
|
/* Do not check if the mount is healthy. We must support closing of
|
||||||
@@ -1173,61 +1129,27 @@ static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
|
|||||||
goto errout_with_mount;
|
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
|
/* Then complete the mount by getting the ROMFS configuration from
|
||||||
* the ROMF header
|
* the ROMF header
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = romfs_fsconfigure(rm, data);
|
ret = romfs_fsconfigure(rm);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_FS_ROMFS_WRITEABLE
|
ferr("ERROR: romfs_fsconfigure failed: %d\n", ret);
|
||||||
if (data && strstr(data, "rw") && strstr(data, "autoformat"))
|
goto errout_with_buffer;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_FS_ROMFS_WRITEABLE
|
|
||||||
nxsem_init(&rm->rm_sem, 0, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Mounted! */
|
/* Mounted! */
|
||||||
|
|
||||||
*handle = rm;
|
*handle = rm;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
errout_with_buffer:
|
errout_with_buffer:
|
||||||
fs_heap_free(rm->rm_devbuffer);
|
if (!rm->rm_xipbase)
|
||||||
|
{
|
||||||
|
fs_heap_free(rm->rm_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
errout_with_mount:
|
errout_with_mount:
|
||||||
nxrmutex_destroy(&rm->rm_lock);
|
nxrmutex_destroy(&rm->rm_lock);
|
||||||
@@ -1315,14 +1237,13 @@ static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
|
|||||||
|
|
||||||
/* Release the mountpoint private data */
|
/* 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
|
#ifdef CONFIG_FS_ROMFS_CACHE_NODE
|
||||||
romfs_freenode(rm->rm_root);
|
romfs_freenode(rm->rm_root);
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_FS_ROMFS_WRITEABLE
|
|
||||||
nxsem_destroy(&rm->rm_sem);
|
|
||||||
romfs_free_sparelist(&rm->rm_sparelist);
|
|
||||||
#endif
|
#endif
|
||||||
nxrmutex_destroy(&rm->rm_lock);
|
nxrmutex_destroy(&rm->rm_lock);
|
||||||
fs_heap_free(rm);
|
fs_heap_free(rm);
|
||||||
@@ -1381,10 +1302,9 @@ static int romfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)
|
|||||||
|
|
||||||
/* Everything else follows in units of sectors */
|
/* Everything else follows in units of sectors */
|
||||||
|
|
||||||
buf->f_blocks = rm->rm_hwnsectors;
|
buf->f_blocks = SEC_NSECTORS(rm, rm->rm_volsize + SEC_NDXMASK(rm));
|
||||||
buf->f_bfree = buf->f_blocks -
|
buf->f_bfree = 0;
|
||||||
SEC_NSECTORS(rm, rm->rm_volsize + SEC_NDXMASK(rm));
|
buf->f_bavail = 0;
|
||||||
buf->f_bavail = buf->f_bfree;
|
|
||||||
buf->f_namelen = NAME_MAX;
|
buf->f_namelen = NAME_MAX;
|
||||||
|
|
||||||
errout_with_lock:
|
errout_with_lock:
|
||||||
|
|||||||
+1
-26
@@ -28,7 +28,6 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#include <nuttx/list.h>
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -119,20 +118,6 @@
|
|||||||
* Public Types
|
* 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 represents the overall mountpoint state. An instance of
|
||||||
* this structure is retained as inode private data on each mountpoint that
|
* this structure is retained as inode private data on each mountpoint that
|
||||||
* is mounted with a romfs filesystem.
|
* is mounted with a romfs filesystem.
|
||||||
@@ -156,11 +141,6 @@ struct romfs_mountpt_s
|
|||||||
uint32_t rm_cachesector; /* Current sector in the rm_buffer */
|
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_xipbase; /* Base address of directly accessible media */
|
||||||
FAR uint8_t *rm_buffer; /* Device sector buffer, allocated if rm_xipbase==0 */
|
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
|
/* This structure represents on open file under the mountpoint. An instance
|
||||||
@@ -186,7 +166,6 @@ struct romfs_nodeinfo_s
|
|||||||
uint32_t rn_next; /* Offset of the next file header+flags */
|
uint32_t rn_next; /* Offset of the next file header+flags */
|
||||||
uint32_t rn_size; /* Size (if file) */
|
uint32_t rn_size; /* Size (if file) */
|
||||||
#ifdef CONFIG_FS_ROMFS_CACHE_NODE
|
#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 */
|
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 */
|
uint16_t rn_count; /* The count of node in rn_child level */
|
||||||
uint8_t rn_namesize; /* The length of name of the entry */
|
uint8_t rn_namesize; /* The length of name of the entry */
|
||||||
@@ -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,
|
int romfs_filecacheread(FAR struct romfs_mountpt_s *rm,
|
||||||
FAR struct romfs_file_s *rf, uint32_t sector);
|
FAR struct romfs_file_s *rf, uint32_t sector);
|
||||||
int romfs_hwconfigure(FAR struct romfs_mountpt_s *rm);
|
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,
|
int romfs_fileconfigure(FAR struct romfs_mountpt_s *rm,
|
||||||
FAR struct romfs_file_s *rf);
|
FAR struct romfs_file_s *rf);
|
||||||
int romfs_checkmount(FAR struct romfs_mountpt_s *rm);
|
int romfs_checkmount(FAR struct romfs_mountpt_s *rm);
|
||||||
@@ -234,10 +213,6 @@ int romfs_datastart(FAR struct romfs_mountpt_s *rm,
|
|||||||
#ifdef CONFIG_FS_ROMFS_CACHE_NODE
|
#ifdef CONFIG_FS_ROMFS_CACHE_NODE
|
||||||
void romfs_freenode(FAR struct romfs_nodeinfo_s *node);
|
void romfs_freenode(FAR struct romfs_nodeinfo_s *node);
|
||||||
#endif
|
#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
|
#undef EXTERN
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
|||||||
+58
-372
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user