MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / wasmfs_unmount

Function wasmfs_unmount

system/lib/wasmfs/syscalls.cpp:878–907  ·  view source on GitHub ↗

wasmfs_unmount is similar to __syscall_unlinkat, but assumes AT_REMOVEDIR is true and will only unlink mountpoints (Empty and nonempty).

Source from the content-addressed store, hash-verified

876// wasmfs_unmount is similar to __syscall_unlinkat, but assumes AT_REMOVEDIR is
877// true and will only unlink mountpoints (Empty and nonempty).
878int wasmfs_unmount(const char* path) {
879 auto parsed = path::parseParent(path, AT_FDCWD);
880 if (auto err = parsed.getError()) {
881 return err;
882 }
883 auto& [parent, childNameView] = parsed.getParentChild();
884 std::string childName(childNameView);
885 auto lockedParent = parent->locked();
886 auto file = lockedParent.getChild(childName);
887 if (!file) {
888 return -ENOENT;
889 }
890 // Disallow removing the root directory, even if it is empty.
891 if (file == wasmFS.getRootDirectory()) {
892 return -EBUSY;
893 }
894
895 if (!file->dynCast<Directory>()) {
896 // A normal file or symlink.
897 return -ENOTDIR;
898 }
899
900 if (parent->getBackend() == file->getBackend()) {
901 // The child is not a valid mountpoint.
902 return -EINVAL;
903 }
904
905 // Input is valid, perform the unlink.
906 return lockedParent.removeChild(childName);
907}
908
909int __syscall_getdents64(int fd, void* dirp, size_t count) {
910 dirent* result = (dirent*)dirp;

Callers

nothing calls this directly

Calls 7

parseParentFunction · 0.85
getRootDirectoryMethod · 0.80
getBackendMethod · 0.80
getErrorMethod · 0.45
lockedMethod · 0.45
getChildMethod · 0.45
removeChildMethod · 0.45

Tested by

no test coverage detected