mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add utimensat(2) and futimens(2).
This commit is contained in:
parent
472155173d
commit
ee106231c4
9 changed files with 218 additions and 13 deletions
|
@ -190,6 +190,7 @@ fstatat.o \
|
|||
fstat.o \
|
||||
fsync.o \
|
||||
ftruncate.o \
|
||||
futimens.o \
|
||||
getc.o \
|
||||
getcwd.o \
|
||||
getdtablesize.o \
|
||||
|
@ -270,6 +271,8 @@ unlinkat.o \
|
|||
unlink.o \
|
||||
uptime.o \
|
||||
usleep.o \
|
||||
utimensat.o \
|
||||
utimens.o \
|
||||
utime.o \
|
||||
vscanf.o \
|
||||
wait.o \
|
||||
|
|
34
libc/futimens.cpp
Normal file
34
libc/futimens.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
futimens.cpp
|
||||
Change file last access and modification times.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
// TODO: You cannot currently pass array types to the DEFN_SYSCALL* family.
|
||||
DEFN_SYSCALL2(int, sys_futimens, SYSCALL_FUTIMENS, int, const struct timespec*);
|
||||
|
||||
extern "C" int futimens(int fd, const struct timespec times[2])
|
||||
{
|
||||
return sys_futimens(fd, times);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -22,10 +22,8 @@
|
|||
|
||||
*******************************************************************************/
|
||||
|
||||
/* TODO: Make this header comply with POSIX-1.2008, if it makes sense. */
|
||||
|
||||
#ifndef _SYS_STAT_H
|
||||
#define _SYS_STAT_H 1
|
||||
#ifndef INCLUDE_SYS_STAT_H
|
||||
#define INCLUDE_SYS_STAT_H
|
||||
|
||||
#include <features.h>
|
||||
|
||||
|
@ -42,6 +40,7 @@ __BEGIN_DECLS
|
|||
@include(time_t.h)
|
||||
__END_DECLS
|
||||
|
||||
#include <sortix/timespec.h>
|
||||
#include <sortix/stat.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
@ -61,11 +60,19 @@ int fchmod(int fd, mode_t mode);
|
|||
int fchmodat(int dirfd, const char* path, mode_t mode, int flags);
|
||||
int fstat(int fd, struct stat* st);
|
||||
int fstatat(int dirfd, const char* path, struct stat* buf, int flags);
|
||||
int futimens(int fd, const struct timespec times[2]);
|
||||
int lstat(const char* restrict path, struct stat* restrict st);
|
||||
int mkdir(const char* path, mode_t mode);
|
||||
int mkdirat(int dirfd, const char* path, mode_t mode);
|
||||
/* TODO: mkfifo */
|
||||
/* TODO: mkfifoat */
|
||||
/* TODO: mknod? */
|
||||
/* TODO: mknodat? */
|
||||
int stat(const char* restrict path, struct stat* restrict st);
|
||||
mode_t umask(mode_t mask);
|
||||
int utimens(const char* path, const struct timespec times[2]);
|
||||
int utimensat(int dirfd, const char* path, const struct timespec times[2],
|
||||
int flags);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
44
libc/include/utime.h
Normal file
44
libc/include/utime.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
utime.h
|
||||
Deprecated interface to change the file access and moficiation times.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef INCLUDE_UTIME_H
|
||||
#define INCLUDE_UTIME_H
|
||||
|
||||
#include <features.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
@include(time_t.h)
|
||||
|
||||
struct utimbuf
|
||||
{
|
||||
time_t actime;
|
||||
time_t modtime;
|
||||
};
|
||||
|
||||
int utime(const char* filename, const struct utimbuf* times);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
|
@ -22,14 +22,20 @@
|
|||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
//#include <utime.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <utime.h>
|
||||
#include <time.h>
|
||||
#include <timespec.h>
|
||||
|
||||
// TODO: This interface has been deprecated by utimens (although that's a
|
||||
// non-standard Sortix extension, in which case by utimensat) - it'd be
|
||||
// nice to remove this at some point.
|
||||
extern "C" int utime(const char* filepath, const struct utimbuf* times)
|
||||
{
|
||||
(void) filepath;
|
||||
(void) times;
|
||||
// TODO: Sure, I did that! There is no kernel support for this yet.
|
||||
return 0;
|
||||
struct timespec ts_times[2];
|
||||
ts_times[0] = timespec_make(times->actime, 0);
|
||||
ts_times[1] = timespec_make(times->modtime, 0);
|
||||
return utimens(filepath, ts_times);
|
||||
}
|
||||
|
|
33
libc/utimens.cpp
Normal file
33
libc/utimens.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
utimens.cpp
|
||||
Change file last access and modification times.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
extern "C"
|
||||
int utimens(const char* path, const struct timespec times[2])
|
||||
{
|
||||
return utimensat(AT_FDCWD, path, times, 0);
|
||||
}
|
39
libc/utimensat.cpp
Normal file
39
libc/utimensat.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
utimensat.cpp
|
||||
Change file last access and modification times.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
// TODO: You cannot currently pass array types to the DEFN_SYSCALL* family.
|
||||
DEFN_SYSCALL4(int, sys_utimensat, SYSCALL_UTIMENSAT, int, const char*,
|
||||
const struct timespec*, int);
|
||||
|
||||
extern "C"
|
||||
int utimensat(int dirfd, const char* path, const struct timespec times[2],
|
||||
int flags)
|
||||
{
|
||||
return sys_utimensat(dirfd, path, times, flags);
|
||||
}
|
|
@ -106,6 +106,8 @@
|
|||
#define SYSCALL_SETEUID 82
|
||||
#define SYSCALL_SETEGID 83
|
||||
#define SYSCALL_IOCTL 84
|
||||
#define SYSCALL_MAX_NUM 85 /* index of highest constant + 1 */
|
||||
#define SYSCALL_UTIMENSAT 85
|
||||
#define SYSCALL_FUTIMENS 86
|
||||
#define SYSCALL_MAX_NUM 87 /* index of highest constant + 1 */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -450,6 +450,41 @@ static int sys_chmod(const char* path, mode_t mode)
|
|||
return sys_fchmodat(AT_FDCWD, path, mode, 0);
|
||||
}
|
||||
|
||||
static int sys_futimens(int fd, const struct timespec user_times[2])
|
||||
{
|
||||
struct timespec times[2];
|
||||
if ( !CopyFromUser(times, user_times, sizeof(times)) )
|
||||
return -1;
|
||||
Ref<Descriptor> desc = CurrentProcess()->GetDescriptor(fd);
|
||||
if ( !desc )
|
||||
return -1;
|
||||
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
||||
return desc->utimens(&ctx, times);
|
||||
}
|
||||
|
||||
static int sys_utimensat(int dirfd, const char* path,
|
||||
const struct timespec user_times[2], int flags)
|
||||
{
|
||||
if ( flags )
|
||||
return errno = ENOTSUP, -1;
|
||||
struct timespec times[2];
|
||||
if ( !CopyFromUser(times, user_times, sizeof(times)) )
|
||||
return -1;
|
||||
char* pathcopy = GetStringFromUser(path);
|
||||
if ( !pathcopy )
|
||||
return -1;
|
||||
ioctx_t ctx; SetupUserIOCtx(&ctx);
|
||||
const char* relpath = pathcopy;
|
||||
Ref<Descriptor> from = PrepareLookup(&relpath, dirfd);
|
||||
if ( !from ) { delete[] pathcopy; return -1; }
|
||||
Ref<Descriptor> desc = from->open(&ctx, relpath, O_WRITE);
|
||||
from.Reset();
|
||||
delete[] pathcopy;
|
||||
if ( !desc )
|
||||
return -1;
|
||||
return desc->utimens(&ctx, times);
|
||||
}
|
||||
|
||||
static int sys_linkat(int olddirfd, const char* oldpath,
|
||||
int newdirfd, const char* newpath,
|
||||
int flags)
|
||||
|
@ -608,6 +643,7 @@ void Init()
|
|||
Syscall::Register(SYSCALL_FSTAT, (void*) sys_fstat);
|
||||
Syscall::Register(SYSCALL_FSYNC, (void*) sys_fsync);
|
||||
Syscall::Register(SYSCALL_FTRUNCATE, (void*) sys_ftruncate);
|
||||
Syscall::Register(SYSCALL_FUTIMENS, (void*) sys_futimens);
|
||||
Syscall::Register(SYSCALL_GETTERMMODE, (void*) sys_gettermmode);
|
||||
Syscall::Register(SYSCALL_IOCTL, (void*) sys_ioctl);
|
||||
Syscall::Register(SYSCALL_ISATTY, (void*) sys_isatty);
|
||||
|
@ -632,6 +668,7 @@ void Init()
|
|||
Syscall::Register(SYSCALL_TRUNCATE, (void*) sys_truncate);
|
||||
Syscall::Register(SYSCALL_UNLINKAT, (void*) sys_unlinkat);
|
||||
Syscall::Register(SYSCALL_UNLINK, (void*) sys_unlink);
|
||||
Syscall::Register(SYSCALL_UTIMENSAT, (void*) sys_utimensat);
|
||||
Syscall::Register(SYSCALL_WRITE, (void*) sys_write);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue