RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
dfs_mnt.c 文件参考
#include <rtthread.h>
#include "dfs_private.h"
#include <dfs.h>
#include <dfs_dentry.h>
#include <dfs_mnt.h>
#include <dfs_pcache.h>
#include <rtdbg.h>
+ dfs_mnt.c 的引用(Include)关系图:

浏览该文件的源代码.

宏定义

#define DBG_TAG   "DFS.mnt"
 
#define DBG_LVL   DBG_WARNING
 

函数

 RT_OBJECT_HOOKLIST_DEFINE (dfs_mnt_umnt)
 
struct dfs_mntdfs_mnt_create (const char *path)
 
int dfs_mnt_insert (struct dfs_mnt *mnt, struct dfs_mnt *child)
 
int dfs_mnt_remove (struct dfs_mnt *mnt)
 
struct dfs_mntdfs_mnt_dev_lookup (rt_device_t dev_id)
 
struct dfs_mntdfs_mnt_lookup (const char *fullpath)
 
struct dfs_mntdfs_mnt_ref (struct dfs_mnt *mnt)
 
int dfs_mnt_unref (struct dfs_mnt *mnt)
 
int dfs_mnt_setflags (struct dfs_mnt *mnt, int flags)
 
int dfs_mnt_destroy (struct dfs_mnt *mnt)
 
const char * dfs_mnt_get_mounted_path (struct rt_device *device)
 
rt_bool_t dfs_mnt_has_child_mnt (struct dfs_mnt *mnt, const char *fullpath)
 
int dfs_mnt_list (struct dfs_mnt *mnt)
 
int dfs_mnt_foreach (struct dfs_mnt *(*func)(struct dfs_mnt *mnt, void *parameter), void *parameter)
 

宏定义说明

◆ DBG_TAG

#define DBG_TAG   "DFS.mnt"

在文件 dfs_mnt.c20 行定义.

◆ DBG_LVL

#define DBG_LVL   DBG_WARNING

在文件 dfs_mnt.c21 行定义.

函数说明

◆ RT_OBJECT_HOOKLIST_DEFINE()

RT_OBJECT_HOOKLIST_DEFINE ( dfs_mnt_umnt )

◆ dfs_mnt_create()

struct dfs_mnt * dfs_mnt_create ( const char * path)

在文件 dfs_mnt.c41 行定义.

42{
43 struct dfs_mnt *mnt = rt_calloc(1, sizeof(struct dfs_mnt));
44 if (mnt)
45 {
46 LOG_I("create mnt at %s", path);
47
48 mnt->fullpath = rt_strdup(path);
49 rt_list_init(&mnt->sibling);
50 rt_list_init(&mnt->child);
51 mnt->flags |= MNT_IS_ALLOCED;
52 rt_atomic_store(&(mnt->ref_count), 1);
53 }
54 else
55 {
56 rt_set_errno(-ENOMEM);
57 }
58
59 return mnt;
60}
#define MNT_IS_ALLOCED
rt_weak void * rt_calloc(rt_size_t count, rt_size_t size)
This function will contiguously allocate enough space for count objects that are size bytes of memory...
rt_inline void rt_list_init(rt_list_t *l)
initialize a list
#define rt_atomic_store(ptr, v)
#define LOG_I(...)
char * fullpath
rt_list_t sibling
rt_list_t child
rt_atomic_t ref_count

引用了 dfs_mnt::child, dfs_mnt::flags, dfs_mnt::fullpath, LOG_I, MNT_IS_ALLOCED, dfs_mnt::ref_count, rt_atomic_store, rt_calloc(), rt_list_init() , 以及 dfs_mnt::sibling.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ dfs_mnt_insert()

int dfs_mnt_insert ( struct dfs_mnt * mnt,
struct dfs_mnt * child )

在文件 dfs_mnt.c62 行定义.

63{
64 if (child)
65 {
66 if (mnt == RT_NULL)
67 {
68 /* insert into root */
69 mnt = dfs_mnt_lookup(child->fullpath);
70 if (mnt == RT_NULL || (strcmp(child->fullpath, "/") == 0))
71 {
72 /* it's root mnt */
73 mnt = child;
74 mnt->flags |= MNT_IS_LOCKED;
75
76 /* ref to gobal root */
77 if (_root_mnt)
78 {
79 child = _root_mnt;
80 rt_atomic_sub(&(_root_mnt->parent->ref_count), 1);
81 rt_atomic_sub(&(_root_mnt->ref_count), 1);
82 _root_mnt->flags &= ~MNT_IS_LOCKED;
83
84 _root_mnt = dfs_mnt_ref(mnt);
85 mnt->parent = dfs_mnt_ref(mnt);
86 mnt->flags |= MNT_IS_ADDLIST;
87
88 mkdir("/dev", 0777);
89 }
90 else
91 {
92 _root_mnt = dfs_mnt_ref(mnt);
93 }
94 }
95 }
96
97 if (mnt)
98 {
99 child->flags |= MNT_IS_ADDLIST;
100 if (child != mnt)
101 {
102 /* not the root, insert into the child list */
103 rt_list_insert_before(&mnt->child, &child->sibling);
104 /* child ref self */
105 dfs_mnt_ref(child);
106 }
107 /* parent ref parent */
108 child->parent = dfs_mnt_ref(mnt);
109 }
110 }
111
112 return 0;
113}
struct dfs_mnt * dfs_mnt_lookup(const char *fullpath)
struct dfs_mnt * dfs_mnt_ref(struct dfs_mnt *mnt)
#define MNT_IS_ADDLIST
#define MNT_IS_LOCKED
int mkdir(const char *path, mode_t mode)
rt_inline void rt_list_insert_before(rt_list_t *l, rt_list_t *n)
insert a node before a list
#define rt_atomic_sub(ptr, v)
#define RT_NULL
struct dfs_mnt * parent

引用了 dfs_mnt::child, dfs_mnt_lookup(), dfs_mnt_ref(), dfs_mnt::flags, mkdir(), MNT_IS_ADDLIST, MNT_IS_LOCKED, dfs_mnt::parent, rt_atomic_sub, rt_list_insert_before() , 以及 RT_NULL.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ dfs_mnt_remove()

int dfs_mnt_remove ( struct dfs_mnt * mnt)

在文件 dfs_mnt.c116 行定义.

117{
118 int ret = -RT_ERROR;
119
120 if (rt_list_isempty(&mnt->child))
121 {
122 rt_list_remove(&mnt->sibling);
123 if (mnt->parent)
124 {
125 /* parent unref parent */
126 rt_atomic_sub(&(mnt->parent->ref_count), 1);
127 }
128
129 ret = RT_EOK;
130 }
131 else
132 {
133 LOG_W("remove a mnt point:%s with child.", mnt->fullpath);
134 }
135
136 return ret;
137}
rt_inline void rt_list_remove(rt_list_t *n)
remove node from list.
rt_inline int rt_list_isempty(const rt_list_t *l)
tests whether a list is empty
#define LOG_W(...)

引用了 dfs_mnt::child, dfs_mnt::fullpath, LOG_W, dfs_mnt::parent, dfs_mnt::ref_count, rt_atomic_sub, rt_list_isempty(), rt_list_remove() , 以及 dfs_mnt::sibling.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ dfs_mnt_dev_lookup()

struct dfs_mnt * dfs_mnt_dev_lookup ( rt_device_t dev_id)

在文件 dfs_mnt.c163 行定义.

164{
165 struct dfs_mnt *mnt = _root_mnt;
166 struct dfs_mnt *ret = RT_NULL;
167
168 if (mnt)
169 {
170 dfs_lock();
171
172 if (mnt->dev_id == dev_id)
173 {
174 dfs_unlock();
175 return mnt;
176 }
177
178 ret = _dfs_mnt_dev_lookup(mnt, dev_id);
179
180 dfs_unlock();
181 }
182
183 return ret;
184}
rt_err_t dfs_lock(void)
定义 dfs.c:120
void dfs_unlock(void)
定义 dfs.c:137
rt_device_t dev_id

引用了 dfs_mnt::dev_id, dfs_lock(), dfs_unlock() , 以及 RT_NULL.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ dfs_mnt_lookup()

struct dfs_mnt * dfs_mnt_lookup ( const char * fullpath)

this function will return the file system mounted on specified path.

参数
paththe specified path string.
返回
the found file system or NULL if no file system mounted on specified path

在文件 dfs_mnt.c194 行定义.

195{
196 struct dfs_mnt *mnt = _root_mnt;
197 struct dfs_mnt *iter = RT_NULL;
198
199 if (mnt)
200 {
201 int mnt_len = rt_strlen(mnt->fullpath);
202
203 dfs_lock();
204 if ((strncmp(mnt->fullpath, fullpath, mnt_len) == 0) &&
205 (mnt_len == 1 || (fullpath[mnt_len] == '\0') || (fullpath[mnt_len] == '/')))
206 {
207 while (!rt_list_isempty(&mnt->child))
208 {
210 {
211 mnt_len = rt_strlen(iter->fullpath);
212 if ((strncmp(iter->fullpath, fullpath, mnt_len) == 0) &&
213 ((fullpath[mnt_len] == '\0') || (fullpath[mnt_len] == '/')))
214 {
215 mnt = iter;
216 break;
217 }
218 }
219
220 if (mnt != iter) break;
221 }
222 }
223 else
224 {
225 mnt = RT_NULL;
226 }
227 dfs_unlock();
228
229 if (mnt)
230 {
231 LOG_D("mnt_lookup: %s path @ mount point %p", fullpath, mnt);
232 DLOG(note, "mnt", "found mnt(%s)", mnt->fs_ops->name);
233 }
234 }
235
236 return mnt;
237}
#define rt_list_for_each_entry(pos, head, member)
#define DLOG(...)
定义 rtdbg.h:53
#define LOG_D(...)
const char * name
const struct dfs_filesystem_ops * fs_ops

引用了 dfs_mnt::child, dfs_lock(), dfs_unlock(), DLOG, dfs_mnt::fs_ops, dfs_mnt::fullpath, LOG_D, dfs_filesystem_ops::name, rt_list_for_each_entry, rt_list_isempty(), RT_NULL , 以及 dfs_mnt::sibling.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ dfs_mnt_ref()

struct dfs_mnt * dfs_mnt_ref ( struct dfs_mnt * mnt)

在文件 dfs_mnt.c239 行定义.

240{
241 if (mnt)
242 {
243 rt_atomic_add(&(mnt->ref_count), 1);
244 DLOG(note, "mnt", "mnt(%s),ref_count=%d", mnt->fs_ops->name, rt_atomic_load(&(mnt->ref_count)));
245 }
246
247 return mnt;
248}
#define rt_atomic_add(ptr, v)
#define rt_atomic_load(ptr)

引用了 DLOG, dfs_mnt::fs_ops, dfs_filesystem_ops::name, dfs_mnt::ref_count, rt_atomic_add , 以及 rt_atomic_load.

+ 这是这个函数的调用关系图:

◆ dfs_mnt_unref()

int dfs_mnt_unref ( struct dfs_mnt * mnt)

在文件 dfs_mnt.c250 行定义.

251{
252 rt_err_t ret = RT_EOK;
253 rt_base_t ref_count;
254
255 if (mnt)
256 {
257 ref_count = rt_atomic_sub(&(mnt->ref_count), 1) - 1;
258
259 if (ref_count == 0)
260 {
261 dfs_lock();
262
263 if (mnt->flags & MNT_IS_UMOUNT)
264 {
265 mnt->fs_ops->umount(mnt);
266
267 RT_OBJECT_HOOKLIST_CALL(dfs_mnt_umnt, (mnt));
268 }
269
270 /* free full path */
271 rt_free(mnt->fullpath);
272 mnt->fullpath = RT_NULL;
273
274 /* destroy self and the ref_count should be 0 */
275 DLOG(msg, "mnt", "mnt", DLOG_MSG, "free mnt(%s)", mnt->fs_ops->name);
276 rt_free(mnt);
277
278 dfs_unlock();
279 }
280 else
281 {
282 DLOG(note, "mnt", "mnt(%s),ref_count=%d", mnt->fs_ops->name, rt_atomic_load(&(mnt->ref_count)));
283 }
284 }
285
286 return ret;
287}
#define MNT_IS_UMOUNT
#define RT_OBJECT_HOOKLIST_CALL(name, argv)
rt_weak void rt_free(void *ptr)
This function will release the previously allocated memory block by rt_malloc. The released memory bl...
rt_int32_t rt_base_t
rt_base_t rt_err_t
int(* umount)(struct dfs_mnt *mnt)

引用了 dfs_lock(), dfs_unlock(), DLOG, dfs_mnt::flags, dfs_mnt::fs_ops, dfs_mnt::fullpath, MNT_IS_UMOUNT, dfs_filesystem_ops::name, dfs_mnt::ref_count, rt_atomic_load, rt_atomic_sub, rt_free(), RT_NULL, RT_OBJECT_HOOKLIST_CALL , 以及 dfs_filesystem_ops::umount.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ dfs_mnt_setflags()

int dfs_mnt_setflags ( struct dfs_mnt * mnt,
int flags )

在文件 dfs_mnt.c289 行定义.

290{
291 int error = 0;
292
293 if (flags & MS_RDONLY)
294 {
295 mnt->flags |= MNT_RDONLY;
296#ifdef RT_USING_PAGECACHE
297 dfs_pcache_clean(mnt);
298#endif
299 }
300
301 return error;
302}
#define MS_RDONLY
#define MNT_RDONLY

引用了 dfs_mnt::flags, MNT_RDONLY , 以及 MS_RDONLY.

+ 这是这个函数的调用关系图:

◆ dfs_mnt_destroy()

int dfs_mnt_destroy ( struct dfs_mnt * mnt)

在文件 dfs_mnt.c304 行定义.

305{
306 rt_err_t ret = RT_EOK;
307
308 if (mnt)
309 {
310 if (mnt->flags & MNT_IS_MOUNTED)
311 {
312 mnt->flags &= ~MNT_IS_MOUNTED;
313 mnt->flags |= MNT_IS_UMOUNT;
314 /* remote it from mnt list */
315 if (mnt->flags & MNT_IS_ADDLIST)
316 {
317 dfs_mnt_remove(mnt);
318 }
319 }
320
321 dfs_mnt_unref(mnt);
322 }
323
324 return ret;
325}
int dfs_mnt_remove(struct dfs_mnt *mnt)
int dfs_mnt_unref(struct dfs_mnt *mnt)
#define MNT_IS_MOUNTED

引用了 dfs_mnt_remove(), dfs_mnt_unref(), dfs_mnt::flags, MNT_IS_ADDLIST, MNT_IS_MOUNTED , 以及 MNT_IS_UMOUNT.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ dfs_mnt_get_mounted_path()

const char * dfs_mnt_get_mounted_path ( struct rt_device * device)

this function will return the mounted path for specified device.

参数
devicethe device object which is mounted.
返回
the mounted path or NULL if none device mounted.

在文件 dfs_mnt.c381 行定义.

382{
383 const char* path = RT_NULL;
384
385 if (_root_mnt)
386 {
387 struct dfs_mnt* mnt;
388
389 dfs_lock();
390 mnt = _dfs_mnt_foreach(_root_mnt, _mnt_cmp_devid, device);
391 dfs_unlock();
392
393 if (mnt) path = mnt->fullpath;
394 }
395
396 return path;
397}

引用了 dfs_lock(), dfs_unlock(), dfs_mnt::fullpath , 以及 RT_NULL.

+ 函数调用图:

◆ dfs_mnt_has_child_mnt()

rt_bool_t dfs_mnt_has_child_mnt ( struct dfs_mnt * mnt,
const char * fullpath )

在文件 dfs_mnt.c431 行定义.

432{
433 int ret = RT_FALSE;
434
435 if (mnt && fullpath)
436 {
437 struct dfs_mnt *m = RT_NULL;
438
439 dfs_lock();
440 m = _dfs_mnt_foreach(mnt, _mnt_cmp_path, (void*)fullpath);
441 dfs_unlock();
442
443 if (m)
444 {
445 ret = RT_TRUE;
446 }
447 }
448
449 return ret;
450}
#define RT_TRUE
#define RT_FALSE

引用了 dfs_lock(), dfs_unlock(), dfs_mnt::fullpath, RT_FALSE, RT_NULL , 以及 RT_TRUE.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ dfs_mnt_list()

int dfs_mnt_list ( struct dfs_mnt * mnt)

在文件 dfs_mnt.c452 行定义.

453{
454 if (!mnt) mnt = _root_mnt;
455
456 /* lock file system */
457 dfs_lock();
458 _dfs_mnt_foreach(mnt, _mnt_dump, RT_NULL);
459 /* unlock file system */
460 dfs_unlock();
461
462 return 0;
463}

引用了 dfs_lock(), dfs_unlock() , 以及 RT_NULL.

+ 函数调用图:

◆ dfs_mnt_foreach()

int dfs_mnt_foreach ( struct dfs_mnt *(* func )(struct dfs_mnt *mnt, void *parameter),
void * parameter )

在文件 dfs_mnt.c465 行定义.

466{
467 /* lock file system */
468 dfs_lock();
469 _dfs_mnt_foreach(_root_mnt, func, parameter);
470 /* unlock file system */
471 dfs_unlock();
472
473 return 0;
474}

引用了 dfs_lock() , 以及 dfs_unlock().

+ 函数调用图: