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

Function _dentry_create

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

* @brief Create a new directory entry (dentry) structure * * @param[in] mnt Pointer to the mount point structure * @param[in] path Path string for the dentry (absolute or relative) * @param[in] is_rela_path Flag indicating if path is relative (RT_TRUE) or absolute (RT_FALSE) * * @return struct dfs_dentry* Pointer to newly created dentry, or NULL if creation failed * * @note The created den

Source from the content-addressed store, hash-verified

60 * @note The created dentry will have its ref_count initialized to 1 and DENTRY_IS_ALLOCED flag set
61 */
62static struct dfs_dentry *_dentry_create(struct dfs_mnt *mnt, char *path, rt_bool_t is_rela_path)
63{
64 struct dfs_dentry *dentry = RT_NULL;
65
66 if (mnt == RT_NULL || path == RT_NULL)
67 {
68 return dentry;
69 }
70
71 dentry = (struct dfs_dentry *)rt_calloc(1, sizeof(struct dfs_dentry));
72 if (dentry)
73 {
74 char *dentry_path = path;
75 if (!is_rela_path)
76 {
77 int mntpoint_len = strlen(mnt->fullpath);
78
79 if (rt_strncmp(mnt->fullpath, dentry_path, mntpoint_len) == 0)
80 {
81 dentry_path += mntpoint_len;
82 }
83 }
84
85 dentry->pathname = strlen(dentry_path) ? rt_strdup(dentry_path) : rt_strdup(path);
86 dentry->mnt = dfs_mnt_ref(mnt);
87
88 rt_atomic_store(&(dentry->ref_count), 1);
89 dentry->flags |= DENTRY_IS_ALLOCED;
90
91 LOG_I("create a dentry:%p for %s", dentry, mnt->fullpath);
92 }
93
94 return dentry;
95}
96
97/**
98 * @brief Create a new directory entry (dentry) with absolute path

Callers 2

dfs_dentry_createFunction · 0.85
dfs_dentry_create_relaFunction · 0.85

Calls 4

rt_callocFunction · 0.85
rt_strncmpFunction · 0.85
rt_strdupFunction · 0.85
dfs_mnt_refFunction · 0.85

Tested by

no test coverage detected