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

Function dfs_dentry_lookup

components/dfs/dfs_v2/src/dfs_dentry.c:281–353  ·  view source on GitHub ↗

* @brief Look up a directory entry (dentry) in the filesystem * * @param[in] mnt Pointer to the mount point structure * @param[in] path Path string to look up * @param[in] flags Additional lookup flags (currently unused) * * @return struct dfs_dentry* Pointer to found/created dentry (with increased ref_count), or NULL if not found * * @note This function first searches for dentry in hash t

Source from the content-addressed store, hash-verified

279 * - If vnode is successfully obtained, adds dentry to hash table
280 */
281struct dfs_dentry *dfs_dentry_lookup(struct dfs_mnt *mnt, const char *path, uint32_t flags)
282{
283 struct dfs_dentry *dentry;
284 struct dfs_vnode *vnode = RT_NULL;
285 int mntpoint_len = strlen(mnt->fullpath);
286
287 if (rt_strncmp(mnt->fullpath, path, mntpoint_len) == 0)
288 {
289 path += mntpoint_len;
290 if ((*path) == '\0')
291 {
292 /* root */
293 path = "/";
294 }
295 }
296 dfs_file_lock();
297 dentry = _dentry_hash_lookup(mnt, path);
298 if (!dentry)
299 {
300 if (mnt->fs_ops->lookup)
301 {
302 DLOG(activate, "dentry");
303 /* not in hash table, create it */
304 DLOG(msg, "dentry", "dentry", DLOG_MSG, "dfs_dentry_create_rela(mnt=%s, path=%s)", mnt->fullpath, path);
305 dentry = dfs_dentry_create_rela(mnt, (char*)path);
306 if (dentry)
307 {
308 DLOG(msg, "dentry", mnt->fs_ops->name, DLOG_MSG, "vnode=fs_ops->lookup(dentry)");
309
310 if (dfs_is_mounted(mnt) == 0)
311 {
312 vnode = mnt->fs_ops->lookup(dentry);
313 }
314
315 if (vnode)
316 {
317 DLOG(msg, mnt->fs_ops->name, "dentry", DLOG_MSG_RET, "return vnode");
318 dentry->vnode = vnode; /* the refcount of created vnode is 1. no need to reference */
319 dfs_file_lock();
320 rt_list_insert_after(&hash_head.head[_dentry_hash(mnt, path)], &dentry->hashlist);
321 dentry->flags |= DENTRY_IS_ADDHASH;
322 dfs_file_unlock();
323
324 if (dentry->flags & (DENTRY_IS_ALLOCED | DENTRY_IS_ADDHASH)
325 && !(dentry->flags & DENTRY_IS_OPENED))
326 {
327 rt_err_t ret = dfs_file_lock();
328 if (ret == RT_EOK)
329 {
330 dentry->flags |= DENTRY_IS_OPENED;
331 dfs_file_unlock();
332 }
333 }
334 }
335 else
336 {
337 DLOG(msg, mnt->fs_ops->name, "dentry", DLOG_MSG_RET, "no dentry");
338

Callers 12

_try_readlinkFunction · 0.85
dfs_file_openFunction · 0.85
dfs_file_statFunction · 0.85
dfs_file_lstatFunction · 0.85
dfs_file_setattrFunction · 0.85
dfs_file_unlinkFunction · 0.85
dfs_file_linkFunction · 0.85
dfs_file_symlinkFunction · 0.85
dfs_file_readlinkFunction · 0.85
dfs_file_renameFunction · 0.85
dfs_file_isdirFunction · 0.85
dfs_mountFunction · 0.85

Calls 9

rt_strncmpFunction · 0.85
_dentry_hash_lookupFunction · 0.85
dfs_dentry_create_relaFunction · 0.85
dfs_is_mountedFunction · 0.85
rt_list_insert_afterFunction · 0.85
_dentry_hashFunction · 0.85
dfs_dentry_unrefFunction · 0.85
dfs_file_lockFunction · 0.70
dfs_file_unlockFunction · 0.70

Tested by

no test coverage detected