MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / dfs_mnt_insert

Function dfs_mnt_insert

components/dfs/dfs_v2/src/dfs_mnt.c:85–136  ·  view source on GitHub ↗

* @brief Insert a child mount point into the mount tree. * * This function inserts a child mount point into the specified parent mount point's child list. * If the parent mount point is not provided, it will try to find the appropriate mount point based on the child's path. * If the child mount point is the root, it will update the global root mount point accordingly. * * @param[in,out] mnt

Source from the content-addressed store, hash-verified

83 * @return Always returns 0 to indicate success.
84 */
85int dfs_mnt_insert(struct dfs_mnt* mnt, struct dfs_mnt* child)
86{
87 if (child)
88 {
89 if (mnt == RT_NULL)
90 {
91 /* insert into root */
92 mnt = dfs_mnt_lookup(child->fullpath);
93 if (mnt == RT_NULL || (strcmp(child->fullpath, "/") == 0))
94 {
95 /* it's root mnt */
96 mnt = child;
97 mnt->flags |= MNT_IS_LOCKED;
98
99 /* ref to gobal root */
100 if (_root_mnt)
101 {
102 child = _root_mnt;
103 rt_atomic_sub(&(_root_mnt->parent->ref_count), 1);
104 rt_atomic_sub(&(_root_mnt->ref_count), 1);
105 _root_mnt->flags &= ~MNT_IS_LOCKED;
106
107 _root_mnt = dfs_mnt_ref(mnt);
108 mnt->parent = dfs_mnt_ref(mnt);
109 mnt->flags |= MNT_IS_ADDLIST;
110
111 mkdir("/dev", 0777);
112 }
113 else
114 {
115 _root_mnt = dfs_mnt_ref(mnt);
116 }
117 }
118 }
119
120 if (mnt)
121 {
122 child->flags |= MNT_IS_ADDLIST;
123 if (child != mnt)
124 {
125 /* not the root, insert into the child list */
126 rt_list_insert_before(&mnt->child, &child->sibling);
127 /* child ref self */
128 dfs_mnt_ref(child);
129 }
130 /* parent ref parent */
131 child->parent = dfs_mnt_ref(mnt);
132 }
133 }
134
135 return 0;
136}
137
138/**
139 * @brief Remove a mount point from the mount tree.

Callers 1

dfs_mountFunction · 0.85

Calls 4

dfs_mnt_lookupFunction · 0.85
dfs_mnt_refFunction · 0.85
rt_list_insert_beforeFunction · 0.85
mkdirFunction · 0.70

Tested by

no test coverage detected