mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-26 00:17:23 +08:00
This patch introduces a remount feature for the DFS, allowing for the modification of mount parameters without unmounting the filesystem, the remount functionality helps modify certain mount flags (like `MS_RDONLY`) without requiring an unmount, providing more control over mounted filesystems in the system. The updates is essential for user space init proc to cleanup the runtime resource, ensuring clean handling of cached data and enhancing system robustness during power down processing. Changes: - Defined new constants for remount flags in `dfs_fs.h`. - Added the `dfs_remount()` function in `dfs_fs.c` to handle remount operations. - Introduced a check for unsupported flags and handle error conditions such as invalid paths or non-directory targets. - Updated the `dfs_mnt` structure in `dfs_mnt.h` to include a read-only flag (`MNT_RDONLY`). - The `dfs_remount()` function allows changing the read-only status of a mounted filesystem. - Added `MNT_LAZY_UMNT` and `MNT_RDONLY` flags to `dfs_mnt` structure. - Introduced `dfs_mnt_setflags` function for dynamic flag management. - Updated `dfs_remount` to utilize `dfs_mnt_setflags` for flag setting. - Enhanced unmount operations with `dfs_mnt_umount_iter` and lazy unmounting. - Added `dfs_pcache_clean` to handle cache cleanup for read-only mounts. - Improved error reporting in `dfs_umount` for better user feedback. - Refactored `sys_mount` to streamline parameter handling and support remounts. - Introduced `_cp_from_usr_string` helper for user-space string operations. - Updated internal APIs to ensure consistency in reference count management. Signed-off-by: Shell <smokewood@qq.com>
130 lines
2.9 KiB
C
130 lines
2.9 KiB
C
/*
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2023-05-05 RTT Implement dentry in dfs v2.0
|
|
*/
|
|
|
|
#ifndef DFS_PAGE_CACHE_H__
|
|
#define DFS_PAGE_CACHE_H__
|
|
|
|
#include <rtthread.h>
|
|
|
|
#ifdef RT_USING_PAGECACHE
|
|
|
|
#include <dfs_file.h>
|
|
#include <avl.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
struct rt_varea;
|
|
struct rt_aspace;
|
|
struct dfs_vnode;
|
|
struct dfs_dentry;
|
|
struct dfs_aspace;
|
|
|
|
struct dfs_mmap
|
|
{
|
|
rt_list_t mmap_node;
|
|
struct rt_aspace *aspace;
|
|
void *vaddr;
|
|
};
|
|
|
|
struct dfs_page
|
|
{
|
|
rt_list_t space_node;
|
|
rt_list_t dirty_node;
|
|
struct util_avl_struct avl_node;
|
|
rt_list_t mmap_head;
|
|
|
|
rt_atomic_t ref_count;
|
|
|
|
void *page;
|
|
off_t fpos;
|
|
size_t size;
|
|
size_t len;
|
|
int is_dirty;
|
|
rt_tick_t tick_ms;
|
|
|
|
struct dfs_aspace *aspace;
|
|
};
|
|
|
|
struct dfs_aspace_ops
|
|
{
|
|
ssize_t (*read)(struct dfs_file *file, struct dfs_page *page);
|
|
ssize_t (*write)(struct dfs_page *page);
|
|
};
|
|
|
|
struct dfs_aspace
|
|
{
|
|
rt_list_t hash_node, cache_node;
|
|
char *fullpath, *pathname;
|
|
struct dfs_mnt *mnt;
|
|
|
|
rt_list_t list_active, list_inactive;
|
|
rt_list_t list_dirty;
|
|
size_t pages_count;
|
|
|
|
struct util_avl_root avl_root;
|
|
struct dfs_page *avl_page;
|
|
|
|
rt_bool_t is_active;
|
|
|
|
struct rt_mutex lock;
|
|
rt_atomic_t ref_count;
|
|
|
|
struct dfs_vnode *vnode;
|
|
const struct dfs_aspace_ops *ops;
|
|
};
|
|
|
|
#ifndef RT_PAGECACHE_HASH_NR
|
|
#define RT_PAGECACHE_HASH_NR 1024
|
|
#endif
|
|
|
|
struct dfs_pcache
|
|
{
|
|
rt_list_t head[RT_PAGECACHE_HASH_NR];
|
|
rt_list_t list_active, list_inactive;
|
|
rt_atomic_t pages_count;
|
|
struct rt_mutex lock;
|
|
struct rt_messagequeue *mqueue;
|
|
rt_tick_t last_time_wb;
|
|
};
|
|
|
|
struct dfs_aspace *dfs_aspace_create(struct dfs_dentry *dentry, struct dfs_vnode *vnode, const struct dfs_aspace_ops *ops);
|
|
int dfs_aspace_destroy(struct dfs_aspace *aspace);
|
|
|
|
int dfs_aspace_read(struct dfs_file *file, void *buf, size_t count, off_t *pos);
|
|
int dfs_aspace_write(struct dfs_file *file, const void *buf, size_t count, off_t *pos);
|
|
int dfs_aspace_flush(struct dfs_aspace *aspace);
|
|
int dfs_aspace_clean(struct dfs_aspace *aspace);
|
|
|
|
void *dfs_aspace_mmap(struct dfs_file *file, struct rt_varea *varea, void *vaddr);
|
|
int dfs_aspace_unmap(struct dfs_file *file, struct rt_varea *varea);
|
|
int dfs_aspace_page_unmap(struct dfs_file *file, struct rt_varea *varea, void *vaddr);
|
|
int dfs_aspace_page_dirty(struct dfs_file *file, struct rt_varea *varea, void *vaddr);
|
|
|
|
off_t dfs_aspace_fpos(struct rt_varea *varea, void *vaddr);
|
|
void *dfs_aspace_vaddr(struct rt_varea *varea, off_t fpos);
|
|
|
|
int dfs_aspace_mmap_read(struct dfs_file *file, struct rt_varea *varea, void *data);
|
|
int dfs_aspace_mmap_write(struct dfs_file *file, struct rt_varea *varea, void *data);
|
|
|
|
void dfs_pcache_release(size_t count);
|
|
void dfs_pcache_unmount(struct dfs_mnt *mnt);
|
|
void dfs_pcache_clean(struct dfs_mnt *mnt);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|