* @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
| 279 | * - If vnode is successfully obtained, adds dentry to hash table |
| 280 | */ |
| 281 | struct 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 |
no test coverage detected