mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 00:17:45 +00:00
Kernel+LibC: Add fstatat
The function fstatat can do the same thing as the stat and lstat functions. However, it can be passed the file descriptor of a directory which will be used when as the starting point for relative paths. This is contrary to stat and lstat which use the current working directory as the starting for relative paths.
This commit is contained in:
parent
875116c3e5
commit
e7310ba45a
6 changed files with 29 additions and 5 deletions
|
@ -422,6 +422,7 @@ struct SC_waitid_params {
|
|||
};
|
||||
|
||||
struct SC_stat_params {
|
||||
int dirfd;
|
||||
StringArgument path;
|
||||
struct stat* statbuf;
|
||||
int follow_symlinks;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/Process.h>
|
||||
|
@ -33,7 +34,20 @@ KResultOr<int> Process::sys$stat(Userspace<const Syscall::SC_stat_params*> user_
|
|||
auto path = get_syscall_path_argument(params.path);
|
||||
if (path.is_error())
|
||||
return path.error();
|
||||
auto metadata_or_error = VFS::the().lookup_metadata(path.value(), current_directory(), params.follow_symlinks ? 0 : O_NOFOLLOW_NOERROR);
|
||||
RefPtr<Custody> base;
|
||||
if (params.dirfd == AT_FDCWD) {
|
||||
base = current_directory();
|
||||
} else {
|
||||
auto base_description = file_description(params.dirfd);
|
||||
if (!base_description)
|
||||
return EBADF;
|
||||
if (!base_description->is_directory())
|
||||
return ENOTDIR;
|
||||
if (!base_description->custody())
|
||||
return EINVAL;
|
||||
base = base_description->custody();
|
||||
}
|
||||
auto metadata_or_error = VFS::the().lookup_metadata(path.value(), *base, params.follow_symlinks ? 0 : O_NOFOLLOW_NOERROR);
|
||||
if (metadata_or_error.is_error())
|
||||
return metadata_or_error.error();
|
||||
stat statbuf;
|
||||
|
|
|
@ -680,6 +680,7 @@ struct rtentry {
|
|||
#define RTF_GATEWAY 0x2 /* the route is a gateway and not an end host */
|
||||
|
||||
#define AT_FDCWD -100
|
||||
#define AT_SYMLINK_NOFOLLOW 0x100
|
||||
|
||||
#define PURGE_ALL_VOLATILE 0x1
|
||||
#define PURGE_ALL_CLEAN_INODE 0x2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue