* @brief Decrement reference count and release file resources when count reaches zero * * This function safely decrements the reference count of a file structure and releases * associated resources (dentry or vnode) when the reference count drops to zero. * * @param[in,out] file Pointer to the file structure to be unreferenced */
| 342 | * @param[in,out] file Pointer to the file structure to be unreferenced |
| 343 | */ |
| 344 | static void dfs_file_unref(struct dfs_file *file) |
| 345 | { |
| 346 | rt_err_t ret = RT_EOK; |
| 347 | |
| 348 | ret = dfs_file_lock(); |
| 349 | if (ret == RT_EOK) |
| 350 | { |
| 351 | if (rt_atomic_load(&(file->ref_count)) == 1) |
| 352 | { |
| 353 | /* should release this file */ |
| 354 | if (file->dentry) |
| 355 | { |
| 356 | DLOG(msg, "dfs_file", "dentry", DLOG_MSG, "dfs_dentry_unref(dentry(%s))", file->dentry->pathname); |
| 357 | dfs_dentry_unref(file->dentry); |
| 358 | file->dentry = RT_NULL; |
| 359 | } |
| 360 | else if (file->vnode) |
| 361 | { |
| 362 | if (file->vnode->ref_count > 1) |
| 363 | { |
| 364 | rt_atomic_sub(&(file->vnode->ref_count), 1); |
| 365 | } |
| 366 | else if (file->vnode->ref_count == 1) |
| 367 | { |
| 368 | rt_free(file->vnode); |
| 369 | file->vnode = RT_NULL; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | LOG_I("release a file: %p", file); |
| 374 | } |
| 375 | |
| 376 | dfs_file_unlock(); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * @brief Resolve the real path by resolving symbolic links and normalizing the path |
no test coverage detected