RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
dfs_pcache.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2023, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2023-05-05 RTT Implement dentry in dfs v2.0
9 */
10
11#ifndef DFS_PAGE_CACHE_H__
12#define DFS_PAGE_CACHE_H__
13
14#include <rtthread.h>
15
16#ifdef RT_USING_PAGECACHE
17
18#include <dfs_file.h>
19#include <avl.h>
20
21#ifdef __cplusplus
22extern "C"
23{
24#endif
25
26struct rt_varea;
27struct rt_aspace;
28struct dfs_vnode;
29struct dfs_dentry;
30struct dfs_aspace;
31
32struct dfs_mmap
33{
34 rt_list_t mmap_node;
35 struct rt_aspace *aspace;
36 void *vaddr;
37};
38
39struct dfs_page
40{
41 rt_list_t space_node;
42 rt_list_t dirty_node;
43 struct util_avl_struct avl_node;
44 rt_list_t mmap_head;
45
46 rt_atomic_t ref_count;
47
48 void *page;
49 off_t fpos;
50 size_t size;
51 size_t len;
52 int is_dirty;
53 rt_tick_t tick_ms;
54
55 struct dfs_aspace *aspace;
56};
57
58struct dfs_aspace_ops
59{
60 ssize_t (*read)(struct dfs_file *file, struct dfs_page *page);
61 ssize_t (*write)(struct dfs_page *page);
62};
63
64struct dfs_aspace
65{
66 rt_list_t hash_node, cache_node;
67 char *fullpath, *pathname;
68 struct dfs_mnt *mnt;
69
70 rt_list_t list_active, list_inactive;
71 rt_list_t list_dirty;
72 size_t pages_count;
73
74 struct util_avl_root avl_root;
75 struct dfs_page *avl_page;
76
77 rt_bool_t is_active;
78
79 struct rt_mutex lock;
80 rt_atomic_t ref_count;
81
82 struct dfs_vnode *vnode;
83 const struct dfs_aspace_ops *ops;
84};
85
86#ifndef RT_PAGECACHE_HASH_NR
87#define RT_PAGECACHE_HASH_NR 1024
88#endif
89
90struct dfs_pcache
91{
92 rt_list_t head[RT_PAGECACHE_HASH_NR];
93 rt_list_t list_active, list_inactive;
94 rt_atomic_t pages_count;
95 struct rt_mutex lock;
96 struct rt_messagequeue *mqueue;
97 rt_tick_t last_time_wb;
98};
99
100struct dfs_aspace *dfs_aspace_create(struct dfs_dentry *dentry, struct dfs_vnode *vnode, const struct dfs_aspace_ops *ops);
101int dfs_aspace_destroy(struct dfs_aspace *aspace);
102
103int dfs_aspace_read(struct dfs_file *file, void *buf, size_t count, off_t *pos);
104int dfs_aspace_write(struct dfs_file *file, const void *buf, size_t count, off_t *pos);
105int dfs_aspace_flush(struct dfs_aspace *aspace);
106int dfs_aspace_clean(struct dfs_aspace *aspace);
107
108void *dfs_aspace_mmap(struct dfs_file *file, struct rt_varea *varea, void *vaddr);
109int dfs_aspace_unmap(struct dfs_file *file, struct rt_varea *varea);
110int dfs_aspace_page_unmap(struct dfs_file *file, struct rt_varea *varea, void *vaddr);
111int dfs_aspace_page_dirty(struct dfs_file *file, struct rt_varea *varea, void *vaddr);
112
113off_t dfs_aspace_fpos(struct rt_varea *varea, void *vaddr);
114void *dfs_aspace_vaddr(struct rt_varea *varea, off_t fpos);
115
116int dfs_aspace_mmap_read(struct dfs_file *file, struct rt_varea *varea, void *data);
117int dfs_aspace_mmap_write(struct dfs_file *file, struct rt_varea *varea, void *data);
118
119void dfs_pcache_release(size_t count);
120void dfs_pcache_unmount(struct dfs_mnt *mnt);
121void dfs_pcache_clean(struct dfs_mnt *mnt);
122
123#ifdef __cplusplus
124}
125#endif
126
127#endif
128
129#endif
ssize_t write(int fd, const void *buf, size_t len)
ssize_t read(int fd, void *buf, size_t len)
int rt_bool_t
rt_uint32_t rt_tick_t
rt_base_t rt_atomic_t
struct rt_list_node rt_list_t