* @brief Unmount a filesystem from the specified path * * This function unmounts a filesystem from the given path. It performs the following operations: * 1. Normalizes the target path * 2. Looks up the mount point * 3. Checks if the filesystem can be safely unmounted * 4. Performs cleanup operations if unmounting is successful * * @param[in] specialfile The path of the filesystem to unmou
| 444 | * - Reference count > 1 and MNT_FORCE not specified |
| 445 | */ |
| 446 | int dfs_umount(const char *specialfile, int flags) |
| 447 | { |
| 448 | int ret = -1; |
| 449 | char *fullpath = RT_NULL; |
| 450 | struct dfs_mnt *mnt = RT_NULL; |
| 451 | |
| 452 | fullpath = dfs_normalize_path(NULL, specialfile); |
| 453 | if (fullpath) |
| 454 | { |
| 455 | DLOG(msg, "dfs", "mnt", DLOG_MSG, "mnt = dfs_mnt_lookup(%s)", fullpath); |
| 456 | mnt = dfs_mnt_lookup(fullpath); |
| 457 | if (mnt) |
| 458 | { |
| 459 | if (strcmp(mnt->fullpath, fullpath) == 0) |
| 460 | { |
| 461 | /* is the mount point */ |
| 462 | rt_base_t ref_count = rt_atomic_load(&(mnt->ref_count)); |
| 463 | |
| 464 | if (!(mnt->flags & MNT_IS_LOCKED) && rt_list_isempty(&mnt->child) && (ref_count == 1 || (flags & MNT_FORCE))) |
| 465 | { |
| 466 | #ifdef RT_USING_PAGECACHE |
| 467 | dfs_pcache_unmount(mnt); |
| 468 | #endif |
| 469 | /* destroy this mount point */ |
| 470 | DLOG(msg, "dfs", "mnt", DLOG_MSG, "dfs_mnt_destroy(mnt)"); |
| 471 | ret = dfs_mnt_destroy(mnt); |
| 472 | } |
| 473 | else |
| 474 | { |
| 475 | LOG_I("the file system is busy!"); |
| 476 | ret = -EBUSY; |
| 477 | } |
| 478 | } |
| 479 | else |
| 480 | { |
| 481 | LOG_I("the path:%s is not a mountpoint!", fullpath); |
| 482 | ret = -EINVAL; |
| 483 | } |
| 484 | } |
| 485 | else |
| 486 | { |
| 487 | LOG_I("no filesystem found."); |
| 488 | } |
| 489 | rt_free(fullpath); |
| 490 | } |
| 491 | else |
| 492 | { |
| 493 | rt_set_errno(-ENOTDIR); |
| 494 | } |
| 495 | |
| 496 | return ret; |
| 497 | } |
| 498 | |
| 499 | /* for compatibility */ |
| 500 | int dfs_unmount(const char *specialfile) |
no test coverage detected