1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 14:25:06 +00:00

Kernel: Make utime() take path+length, remove SmapDisabler

This commit is contained in:
Andreas Kling 2020-01-06 12:23:30 +01:00
parent 1226fec19e
commit 53bda09d15
3 changed files with 18 additions and 17 deletions

View file

@ -1432,25 +1432,21 @@ int Process::sys$close(int fd)
return rc; return rc;
} }
int Process::sys$utime(const char* pathname, const utimbuf* buf) int Process::sys$utime(const char* user_path, size_t path_length, const utimbuf* user_buf)
{ {
SmapDisabler disabler; if (user_buf && !validate_read_typed(user_buf))
if (!validate_read_str(pathname))
return -EFAULT; return -EFAULT;
if (buf && !validate_read_typed(buf)) auto path = get_syscall_path_argument(user_path, path_length);
return -EFAULT; if (path.is_error())
time_t atime; return path.error();
time_t mtime; utimbuf buf;
if (buf) { if (user_buf) {
atime = buf->actime; copy_from_user(&buf, user_buf, sizeof(buf));
mtime = buf->modtime;
} else { } else {
struct timeval now; auto now = kgettimeofday();
kgettimeofday(now); buf = { now.tv_sec, now.tv_sec };
mtime = now.tv_sec;
atime = now.tv_sec;
} }
return VFS::the().utime(StringView(pathname), current_directory(), atime, mtime); return VFS::the().utime(path.value(), current_directory(), buf.actime, buf.modtime);
} }
int Process::sys$access(const char* user_path, size_t path_length, int mode) int Process::sys$access(const char* user_path, size_t path_length, int mode)

View file

@ -176,7 +176,7 @@ public:
int sys$ioctl(int fd, unsigned request, unsigned arg); int sys$ioctl(int fd, unsigned request, unsigned arg);
int sys$mkdir(const char* pathname, size_t path_length, mode_t mode); int sys$mkdir(const char* pathname, size_t path_length, mode_t mode);
clock_t sys$times(tms*); clock_t sys$times(tms*);
int sys$utime(const char* pathname, const struct utimbuf*); int sys$utime(const char* pathname, size_t path_length, const struct utimbuf*);
int sys$link(const char* old_path, const char* new_path); int sys$link(const char* old_path, const char* new_path);
int sys$unlink(const char* pathname); int sys$unlink(const char* pathname);
int sys$symlink(const char* target, const char* linkpath); int sys$symlink(const char* target, const char* linkpath);

View file

@ -1,12 +1,17 @@
#include <Kernel/Syscall.h> #include <Kernel/Syscall.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#include <utime.h> #include <utime.h>
extern "C" { extern "C" {
int utime(const char* pathname, const struct utimbuf* buf) int utime(const char* pathname, const struct utimbuf* buf)
{ {
int rc = syscall(SC_utime, (u32)pathname, (u32)buf); if (!pathname) {
errno = EFAULT;
return -1;
}
int rc = syscall(SC_utime, pathname, strlen(pathname), buf);
__RETURN_WITH_ERRNO(rc, rc, -1); __RETURN_WITH_ERRNO(rc, rc, -1);
} }
} }