From 7bcc1c9bd4add82ca6d53aa22e12e620551ba172 Mon Sep 17 00:00:00 2001 From: Lucjan Bryndza Date: Wed, 10 Mar 2021 17:49:06 +0200 Subject: [PATCH] [EGD-6013] Fix no copy syscall Due to lack of some filesystem syscalls std::filesystem::copy functions family doesn't work. This path add missing syscalls in the FS layer. --- board/rt1051/newlib/io_syscalls.cpp | 18 +++++++++- .../purefs/fs/drivers/filesystem_littlefs.hpp | 3 +- .../src/purefs/fs/filesystem_littlefs.cpp | 9 ++++- .../internal/newlib/vfs_io_syscalls.hpp | 6 +++- module-vfs/src/newlib/vfs_io_syscalls.cpp | 36 ++++++++++++++++++- 5 files changed, 67 insertions(+), 5 deletions(-) diff --git a/board/rt1051/newlib/io_syscalls.cpp b/board/rt1051/newlib/io_syscalls.cpp index e348539ec98a0e58fe69d27095efe8ed49be847c..6b1a927e0d38a782e512a8a7222703fefc0deb63 100644 --- a/board/rt1051/newlib/io_syscalls.cpp +++ b/board/rt1051/newlib/io_syscalls.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include #include @@ -150,4 +150,20 @@ extern "C" { utils::internal::syscalls::env_unlock(reent->_errno); } + ssize_t readlink(const char *path, char *buf, size_t buflen) + { + return syscalls::readlink(_REENT->_errno, path, buf, buflen); + } + int symlink(const char *name1, const char *name2) + { + return syscalls::symlink(_REENT->_errno, name1, name2); + } + long fpathconf(int fd, int name) + { + return syscalls::fpathconf(_REENT->_errno, fd, name); + } + long pathconf(const char *path, int name) + { + return syscalls::pathconf(_REENT->_errno, path, name); + } } diff --git a/module-vfs/drivers/include/purefs/fs/drivers/filesystem_littlefs.hpp b/module-vfs/drivers/include/purefs/fs/drivers/filesystem_littlefs.hpp index 1ec3aef39fd9f6842f1680fc5ce6b9ecd75817c2..5be17eaa3e398ae30ec51a0db8ebd57c8df29fbb 100644 --- a/module-vfs/drivers/include/purefs/fs/drivers/filesystem_littlefs.hpp +++ b/module-vfs/drivers/include/purefs/fs/drivers/filesystem_littlefs.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -37,6 +37,7 @@ namespace purefs::fs::drivers auto unlink(fsmount mnt, std::string_view name) noexcept -> int override; auto rename(fsmount mnt, std::string_view oldname, std::string_view newname) noexcept -> int override; auto mkdir(fsmount mnt, std::string_view path, int mode) noexcept -> int override; + auto fchmod(fsfile zfile, mode_t mode) noexcept -> int override; /** Directory support API */ auto diropen(fsmount mnt, std::string_view path) noexcept -> fsdir override; diff --git a/module-vfs/drivers/src/purefs/fs/filesystem_littlefs.cpp b/module-vfs/drivers/src/purefs/fs/filesystem_littlefs.cpp index 818b8409e8ee0674feedf11f23b72e77f26a3658..fbe3a168ca63da969a100874ab6998126a07d17f 100644 --- a/module-vfs/drivers/src/purefs/fs/filesystem_littlefs.cpp +++ b/module-vfs/drivers/src/purefs/fs/filesystem_littlefs.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include @@ -448,4 +448,11 @@ namespace purefs::fs::drivers return invoke_lfs(dirstate, ::lfs_dir_close); } + auto filesystem_littlefs::fchmod(fsfile zfile, mode_t mode) noexcept -> int + { + // Littlefs doesn't support chmod() so we need that path exists + struct stat filestat; + return fstat(zfile, filestat); + } + } // namespace purefs::fs::drivers diff --git a/module-vfs/include/internal/newlib/vfs_io_syscalls.hpp b/module-vfs/include/internal/newlib/vfs_io_syscalls.hpp index c038a061fd029a6ffaa67837855b083a6ad9ff6b..a9af35a8fa42c4b921f50df7650e4ddf3b209d64 100644 --- a/module-vfs/include/internal/newlib/vfs_io_syscalls.hpp +++ b/module-vfs/include/internal/newlib/vfs_io_syscalls.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -43,5 +43,9 @@ namespace vfsn::internal::syscalls const void *data); int umount(int &_errno_, const char *special_file); int statvfs(int &_errno_, const char *path, struct statvfs *buf); + ssize_t readlink(int &_errno_, const char *path, char *buf, size_t buflen); + int symlink(int &_errno_, const char *name1, const char *name2); + long fpathconf(int &_errno, int fd, int name); + long pathconf(int &_errno, const char *path, int name); } // namespace vfsn::internal::syscalls diff --git a/module-vfs/src/newlib/vfs_io_syscalls.cpp b/module-vfs/src/newlib/vfs_io_syscalls.cpp index e3461c43717d8ef1f2d8e5d188a8198ee4261021..45ecf8f871d3992c56d04955f09d1c1b067d5a6f 100644 --- a/module-vfs/src/newlib/vfs_io_syscalls.cpp +++ b/module-vfs/src/newlib/vfs_io_syscalls.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include @@ -364,5 +364,39 @@ namespace vfsn::internal::syscalls data); } + ssize_t readlink(int &_errno_, const char *path, char *buf, size_t buflen) + { + // Symlinks are not supported. According to man(2) symlink EINVAL when is not symlink. + _errno_ = EINVAL; + return -1; + } + + int symlink(int &_errno_, const char *name1, const char *name2) + { + return invoke_fs(_errno_, &purefs::fs::filesystem::symlink, name1, name2); + } + + long fpathconf(int &_errno, int fd, int name) + { + if (name == _PC_PATH_MAX) { + return PATH_MAX; + } + else { + _errno = EINVAL; + return -1; + } + } + + long pathconf(int &_errno, const char *path, int name) + { + if (name == _PC_PATH_MAX) { + return PATH_MAX; + } + else { + _errno = EINVAL; + return -1; + } + } + } // namespace vfsn::internal::syscalls