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

Function dfs_mnt_unref

components/dfs/dfs_v2/src/dfs_mnt.c:338–375  ·  view source on GitHub ↗

* @brief Decrease the reference count of a dfs_mnt structure instance and free it if necessary. * * This function decrements the reference count of the specified dfs_mnt structure. * If the reference count reaches zero after the decrement, it will perform the unmount operation, * trigger the unmount hook, free the allocated path memory, and finally free the dfs_mnt structure itself. * * @par

Source from the content-addressed store, hash-verified

336 * @return returns RT_EOK to indicate success.
337 */
338int dfs_mnt_unref(struct dfs_mnt *mnt)
339{
340 rt_err_t ret = RT_EOK;
341 rt_base_t ref_count;
342
343 if (mnt)
344 {
345 ref_count = rt_atomic_sub(&(mnt->ref_count), 1) - 1;
346
347 if (ref_count == 0)
348 {
349 dfs_lock();
350
351 if (mnt->flags & MNT_IS_UMOUNT)
352 {
353 mnt->fs_ops->umount(mnt);
354
355 RT_OBJECT_HOOKLIST_CALL(dfs_mnt_umnt, (mnt));
356 }
357
358 /* free full path */
359 rt_free(mnt->fullpath);
360 mnt->fullpath = RT_NULL;
361
362 /* destroy self and the ref_count should be 0 */
363 DLOG(msg, "mnt", "mnt", DLOG_MSG, "free mnt(%s)", mnt->fs_ops->name);
364 rt_free(mnt);
365
366 dfs_unlock();
367 }
368 else
369 {
370 DLOG(note, "mnt", "mnt(%s),ref_count=%d", mnt->fs_ops->name, rt_atomic_load(&(mnt->ref_count)));
371 }
372 }
373
374 return ret;
375}
376
377/**
378 * @brief Set specific flags for a dfs_mnt structure instance.

Callers 3

dfs_mnt_destroyFunction · 0.85
dfs_mountFunction · 0.85
dfs_dentry_unrefFunction · 0.85

Calls 3

rt_freeFunction · 0.85
dfs_lockFunction · 0.70
dfs_unlockFunction · 0.70

Tested by

no test coverage detected