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

Function dfs_file_unref

components/dfs/dfs_v2/src/dfs_file.c:344–378  ·  view source on GitHub ↗

* @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 */

Source from the content-addressed store, hash-verified

342 * @param[in,out] file Pointer to the file structure to be unreferenced
343 */
344static 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

Callers 2

dfs_file_openFunction · 0.85
dfs_file_closeFunction · 0.85

Calls 4

dfs_dentry_unrefFunction · 0.85
rt_freeFunction · 0.85
dfs_file_lockFunction · 0.70
dfs_file_unlockFunction · 0.70

Tested by

no test coverage detected