* @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
| 60 | * @note The created dentry will have its ref_count initialized to 1 and DENTRY_IS_ALLOCED flag set |
| 61 | */ |
| 62 | static 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 |
no test coverage detected