mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 21:05:07 +00:00
Kernel+LibC: Merge sys$stat() and sys$lstat()
There is now only one sys$stat() instead of two separate syscalls.
This commit is contained in:
parent
b67035c3ac
commit
580a94bc44
4 changed files with 24 additions and 35 deletions
|
@ -1783,41 +1783,25 @@ int Process::sys$fstat(int fd, stat* statbuf)
|
||||||
return description->fstat(*statbuf);
|
return description->fstat(*statbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$lstat(const char* user_path, size_t path_length, stat* user_statbuf)
|
int Process::sys$stat(const Syscall::SC_stat_params* user_params)
|
||||||
{
|
{
|
||||||
REQUIRE_PROMISE(rpath);
|
REQUIRE_PROMISE(rpath);
|
||||||
if (!validate_write_typed(user_statbuf))
|
Syscall::SC_stat_params params;
|
||||||
|
if (!validate_read_and_copy_typed(¶ms, user_params))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto path = get_syscall_path_argument(user_path, path_length);
|
if (!validate_write_typed(params.statbuf))
|
||||||
|
return -EFAULT;
|
||||||
|
auto path = get_syscall_path_argument(params.path);
|
||||||
if (path.is_error())
|
if (path.is_error())
|
||||||
return path.error();
|
return path.error();
|
||||||
auto metadata_or_error = VFS::the().lookup_metadata(path.value(), current_directory(), O_NOFOLLOW_NOERROR);
|
auto metadata_or_error = VFS::the().lookup_metadata(path.value(), current_directory(), params.follow_symlinks ? 0 : O_NOFOLLOW_NOERROR);
|
||||||
if (metadata_or_error.is_error())
|
if (metadata_or_error.is_error())
|
||||||
return metadata_or_error.error();
|
return metadata_or_error.error();
|
||||||
stat statbuf;
|
stat statbuf;
|
||||||
auto result = metadata_or_error.value().stat(statbuf);
|
auto result = metadata_or_error.value().stat(statbuf);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result;
|
return result;
|
||||||
copy_to_user(user_statbuf, &statbuf);
|
copy_to_user(params.statbuf, &statbuf);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Process::sys$stat(const char* user_path, size_t path_length, stat* user_statbuf)
|
|
||||||
{
|
|
||||||
REQUIRE_PROMISE(rpath);
|
|
||||||
if (!validate_write_typed(user_statbuf))
|
|
||||||
return -EFAULT;
|
|
||||||
auto path = get_syscall_path_argument(user_path, path_length);
|
|
||||||
if (path.is_error())
|
|
||||||
return path.error();
|
|
||||||
auto metadata_or_error = VFS::the().lookup_metadata(path.value(), current_directory());
|
|
||||||
if (metadata_or_error.is_error())
|
|
||||||
return metadata_or_error.error();
|
|
||||||
stat statbuf;
|
|
||||||
auto result = metadata_or_error.value().stat(statbuf);
|
|
||||||
if (result.is_error())
|
|
||||||
return result;
|
|
||||||
copy_to_user(user_statbuf, &statbuf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,8 +195,7 @@ public:
|
||||||
ssize_t sys$write(int fd, const u8*, ssize_t);
|
ssize_t sys$write(int fd, const u8*, ssize_t);
|
||||||
ssize_t sys$writev(int fd, const struct iovec* iov, int iov_count);
|
ssize_t sys$writev(int fd, const struct iovec* iov, int iov_count);
|
||||||
int sys$fstat(int fd, stat*);
|
int sys$fstat(int fd, stat*);
|
||||||
int sys$lstat(const char*, size_t, stat*);
|
int sys$stat(const Syscall::SC_stat_params*);
|
||||||
int sys$stat(const char*, size_t, stat*);
|
|
||||||
int sys$lseek(int fd, off_t, int whence);
|
int sys$lseek(int fd, off_t, int whence);
|
||||||
int sys$kill(pid_t pid, int sig);
|
int sys$kill(pid_t pid, int sig);
|
||||||
[[noreturn]] void sys$exit(int status);
|
[[noreturn]] void sys$exit(int status);
|
||||||
|
|
|
@ -56,7 +56,6 @@ typedef u32 socklen_t;
|
||||||
__ENUMERATE_SYSCALL(mmap) \
|
__ENUMERATE_SYSCALL(mmap) \
|
||||||
__ENUMERATE_SYSCALL(munmap) \
|
__ENUMERATE_SYSCALL(munmap) \
|
||||||
__ENUMERATE_SYSCALL(get_dir_entries) \
|
__ENUMERATE_SYSCALL(get_dir_entries) \
|
||||||
__ENUMERATE_SYSCALL(lstat) \
|
|
||||||
__ENUMERATE_SYSCALL(getcwd) \
|
__ENUMERATE_SYSCALL(getcwd) \
|
||||||
__ENUMERATE_SYSCALL(gettimeofday) \
|
__ENUMERATE_SYSCALL(gettimeofday) \
|
||||||
__ENUMERATE_SYSCALL(gethostname) \
|
__ENUMERATE_SYSCALL(gethostname) \
|
||||||
|
@ -413,6 +412,12 @@ struct SC_waitid_params {
|
||||||
int options;
|
int options;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SC_stat_params {
|
||||||
|
StringArgument path;
|
||||||
|
struct stat* statbuf;
|
||||||
|
bool follow_symlinks;
|
||||||
|
};
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
int sync();
|
int sync();
|
||||||
|
|
||||||
|
|
|
@ -278,24 +278,25 @@ int close(int fd)
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lstat(const char* path, struct stat* statbuf)
|
static int do_stat(const char* path, struct stat* statbuf, bool follow_symlinks)
|
||||||
{
|
{
|
||||||
if (!path) {
|
if (!path) {
|
||||||
errno = EFAULT;
|
errno = EFAULT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int rc = syscall(SC_lstat, path, strlen(path), statbuf);
|
Syscall::SC_stat_params params { { path, strlen(path) }, statbuf, follow_symlinks };
|
||||||
|
int rc = syscall(SC_stat, ¶ms);
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lstat(const char* path, struct stat* statbuf)
|
||||||
|
{
|
||||||
|
return do_stat(path, statbuf, false);
|
||||||
|
}
|
||||||
|
|
||||||
int stat(const char* path, struct stat* statbuf)
|
int stat(const char* path, struct stat* statbuf)
|
||||||
{
|
{
|
||||||
if (!path) {
|
return do_stat(path, statbuf, true);
|
||||||
errno = EFAULT;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
int rc = syscall(SC_stat, path, strlen(path), statbuf);
|
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fstat(int fd, struct stat* statbuf)
|
int fstat(int fd, struct stat* statbuf)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue