Adopt struct timespec as the kernel time format.

Note: Incompatible ABI change.
This commit is contained in:
Jonas 'Sortie' Termansen 2013-03-22 20:19:45 +01:00
parent 46b86892de
commit 472155173d
17 changed files with 69 additions and 92 deletions

8
libc/decl/timeval.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _TIMEVAL_T_DECL
#define _TIMEVAL_T_DECL
struct timeval
{
time_t tv_sec;
suseconds_t tv_usec;
};
#endif

View File

@ -161,11 +161,11 @@ struct fsm_resp_write
size_t count;
};
#define FSM_REQ_UTIMES 18
struct fsm_req_utimes
#define FSM_REQ_UTIMENS 18
struct fsm_req_utimens
{
ino_t ino;
struct timeval times[2];
struct timespec times[2];
};
#define FSM_REQ_ISATTY 19

View File

@ -29,7 +29,7 @@
#include <sortix/stat.h>
#include <sortix/termios.h>
#include <sortix/timeval.h>
#include <sortix/timespec.h>
#include <fsmarshall-msg.h>

View File

@ -33,11 +33,11 @@ __BEGIN_DECLS
@include(time_t.h)
@include(suseconds_t.h)
@include(timeval.h)
__BEGIN_DECLS
#include <sortix/sigset.h>
#include <sortix/timespec.h>
#include <sortix/timeval.h>
__END_DECLS
#define FD_SETSIZE 1024

View File

@ -46,6 +46,16 @@ __END_DECLS
__BEGIN_DECLS
/* POSIX mandates that we define these compatibility macros to support programs
that are yet to embrace struct timespec. Nofify users that use the old names
by inserting macros that insert annoying warnings. If you really need the
old names to be compatible with older systems, you can check whether these
names are defined as macros and use the newer names and otherwise using these
older names. */
#define st_atime __PRAGMA_WARNING("st_atime is deprecated in favor of st_atim.tv_sec") st_atim.tv_sec
#define st_ctime __PRAGMA_WARNING("st_ctime is deprecated in favor of st_ctim.tv_sec") st_ctim.tv_sec
#define st_mtime __PRAGMA_WARNING("st_mtime is deprecated in favor of st_mtim.tv_sec") st_mtim.tv_sec
int chmod(const char* path, mode_t mode);
int fchmod(int fd, mode_t mode);
int fchmodat(int dirfd, const char* path, mode_t mode, int flags);

View File

@ -31,12 +31,7 @@ __BEGIN_DECLS
@include(time_t.h)
@include(suseconds_t.h)
__END_DECLS
#include <sortix/timeval.h>
__BEGIN_DECLS
@include(timeval.h)
int gettimeofday(struct timeval* restrict tp, void* restrict tzp);

View File

@ -181,8 +181,8 @@ Node* RecursiveSearch(const char* real_path, const char* virt_path,
node->refcount = 1;
node->mode = st.st_mode;
node->ino = (*ino)++;
node->ctime = st.st_ctime;
node->mtime = st.st_mtime;
node->ctime = st.st_ctim.tv_sec;
node->mtime = st.st_mtim.tv_sec;
char* real_path_clone = strdup(real_path);
if ( !real_path_clone ) { perror("strdup"); free(node); return NULL; }

View File

@ -268,9 +268,9 @@ ssize_t Descriptor::pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count, off_t
return vnode->pwrite(ctx, buf, count, off);
}
int Descriptor::utimes(ioctx_t* ctx, const struct timeval times[2])
int Descriptor::utimens(ioctx_t* ctx, const struct timespec times[2])
{
return vnode->utimes(ctx, times);
return vnode->utimens(ctx, times);
}
int Descriptor::isatty(ioctx_t* ctx)

View File

@ -36,7 +36,7 @@
#include <sortix/fcntl.h>
#include <sortix/stat.h>
#include <sortix/termios.h>
#include <sortix/timeval.h>
#include <sortix/timespec.h>
#include <fsmarshall-msg.h>
@ -194,7 +194,7 @@ public:
virtual ssize_t write(ioctx_t* ctx, const uint8_t* buf, size_t count);
virtual ssize_t pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count,
off_t off);
virtual int utimes(ioctx_t* ctx, const struct timeval times[2]);
virtual int utimens(ioctx_t* ctx, const struct timespec times[2]);
virtual int isatty(ioctx_t* ctx);
virtual ssize_t readdirents(ioctx_t* ctx, struct kernel_dirent* dirent,
size_t size, off_t start, size_t maxcount);
@ -833,17 +833,17 @@ ssize_t Unode::pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count, off_t off)
return ret;
}
int Unode::utimes(ioctx_t* /*ctx*/, const struct timeval times[2])
int Unode::utimens(ioctx_t* /*ctx*/, const struct timespec times[2])
{
Channel* channel = server->Connect();
if ( !channel )
return -1;
int ret = -1;
struct fsm_req_utimes msg;
struct fsm_req_utimens msg;
msg.ino = ino;
msg.times[0] = times[0];
msg.times[1] = times[1];
if ( SendMessage(channel, FSM_REQ_UTIMES, &msg, sizeof(msg)) &&
if ( SendMessage(channel, FSM_REQ_UTIMENS, &msg, sizeof(msg)) &&
RecvMessage(channel, FSM_RESP_SUCCESS, NULL, 0) )
ret = 0;
channel->KernelClose();

View File

@ -35,7 +35,6 @@
#include <sortix/kernel/refcount.h>
struct stat;
struct timeval;
struct winsize;
struct kernel_dirent;
@ -65,7 +64,7 @@ public:
ssize_t pread(ioctx_t* ctx, uint8_t* buf, size_t count, off_t off);
ssize_t write(ioctx_t* ctx, const uint8_t* buf, size_t count);
ssize_t pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count, off_t off);
int utimes(ioctx_t* ctx, const struct timeval times[2]);
int utimens(ioctx_t* ctx, const struct timespec timespec[2]);
int isatty(ioctx_t* ctx);
ssize_t readdirents(ioctx_t* ctx, struct kernel_dirent* dirent, size_t size,
size_t maxcount);

View File

@ -35,7 +35,6 @@
#include <sortix/kernel/refcount.h>
struct stat;
struct timeval;
struct winsize;
struct kernel_dirent;
@ -69,7 +68,7 @@ public:
virtual ssize_t write(ioctx_t* ctx, const uint8_t* buf, size_t count) = 0;
virtual ssize_t pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count,
off_t off) = 0;
virtual int utimes(ioctx_t* ctx, const struct timeval times[2]) = 0;
virtual int utimens(ioctx_t* ctx, const struct timespec timespec[2]) = 0;
virtual int isatty(ioctx_t* ctx) = 0;
virtual ssize_t readdirents(ioctx_t* ctx, struct kernel_dirent* dirent,
size_t size, off_t start, size_t maxcount) = 0;
@ -113,10 +112,9 @@ protected:
uid_t stat_uid;
gid_t stat_gid;
off_t stat_size;
time_t stat_atime;
time_t stat_mtime;
time_t stat_ctime;
/* TODO: stat_atim, stat_mtim, stat_ctim */
struct timespec stat_atim;
struct timespec stat_mtim;
struct timespec stat_ctim;
blksize_t stat_blksize;
blkcnt_t stat_blocks;
@ -136,7 +134,7 @@ public:
virtual ssize_t write(ioctx_t* ctx, const uint8_t* buf, size_t count);
virtual ssize_t pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count,
off_t off);
virtual int utimes(ioctx_t* ctx, const struct timeval times[2]);
virtual int utimens(ioctx_t* ctx, const struct timespec timespec[2]);
virtual int isatty(ioctx_t* ctx);
virtual ssize_t readdirents(ioctx_t* ctx, struct kernel_dirent* dirent,
size_t size, off_t start, size_t maxcount);

View File

@ -22,13 +22,14 @@
*******************************************************************************/
#ifndef SORTIX_VNODE_H
#define SORTIX_VNODE_H
#ifndef INCLUDE_SORTIX_KERNEL_VNODE_H
#define INCLUDE_SORTIX_KERNEL_VNODE_H
#include <sortix/timespec.h>
#include <sortix/kernel/refcount.h>
struct stat;
struct timeval;
struct winsize;
struct kernel_dirent;
@ -60,7 +61,7 @@ public:
ssize_t pread(ioctx_t* ctx, uint8_t* buf, size_t count, off_t off);
ssize_t write(ioctx_t* ctx, const uint8_t* buf, size_t count);
ssize_t pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count, off_t off);
int utimes(ioctx_t* ctx, const struct timeval times[2]);
int utimens(ioctx_t* ctx, const struct timespec timespec[2]);
int isatty(ioctx_t* ctx);
ssize_t readdirents(ioctx_t* ctx, struct kernel_dirent* dirent,
size_t size, off_t start, size_t maxcount);

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2012.
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
This file is part of Sortix.
@ -23,27 +23,28 @@
*******************************************************************************/
#ifndef SORTIX_STAT_H
#define SORTIX_STAT_H
#ifndef INCLUDE_SORTIX_STAT_H
#define INCLUDE_SORTIX_STAT_H
#include <features.h>
#include <sys/types.h>
#include <sortix/timespec.h>
__BEGIN_DECLS
struct stat
{
dev_t st_dev;
dev_t st_rdev;
ino_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
off_t st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
/* TODO: st_atim, st_mtim, st_ctim */
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
blksize_t st_blksize;
blkcnt_t st_blocks;
};

View File

@ -1,40 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2012.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix 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 General Public License for more
details.
You should have received a copy of the GNU General Public License along with
Sortix. If not, see <http://www.gnu.org/licenses/>.
sortix/timeval.h
Declares the struct timeval.
*******************************************************************************/
#ifndef SORTIX_TIMEVAL_H
#define SORTIX_TIMEVAL_H
#include <features.h>
__BEGIN_DECLS
struct timeval
{
time_t tv_sec;
suseconds_t tv_usec;
};
__END_DECLS
#endif

View File

@ -41,6 +41,7 @@
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <timespec.h>
#include "initrd.h"
@ -104,9 +105,9 @@ bool Stat(uint32_t ino, struct stat* st)
st->st_uid = inode->uid;
st->st_gid = inode->gid;
st->st_size = inode->size;
st->st_atime = inode->mtime;
st->st_ctime = inode->ctime;
st->st_mtime = inode->mtime;
st->st_atim = timespec_make(inode->mtime, 0);
st->st_ctim = timespec_make(inode->ctime, 0);
st->st_mtim = timespec_make(inode->mtime, 0);
st->st_blksize = 1;
st->st_blocks = inode->size;
return true;
@ -322,7 +323,7 @@ static bool ExtractNode(ioctx_t* ctx, uint32_t ino, Ref<Descriptor> node)
return false;
if ( node->chown(ctx, inode->uid, inode->gid) < 0 )
return false;
// TODO: utimes.
// TODO: utimens.
if ( INITRD_S_ISDIR(inode->mode) )
if ( !ExtractDir(ctx, ino, node) )
return false;

View File

@ -24,6 +24,7 @@
#include <errno.h>
#include <string.h>
#include <timespec.h>
#include <sortix/stat.h>
@ -45,10 +46,9 @@ AbstractInode::AbstractInode()
stat_uid = 0;
stat_gid = 0;
stat_size = 0;
stat_atime = 0;
stat_mtime = 0;
stat_ctime = 0;
/* TODO: stat_atim, stat_mtim, stat_ctim */
stat_atim = timespec_nul();
stat_ctim = timespec_nul();
stat_mtim = timespec_nul();
stat_blksize = 0;
stat_blocks = 0;
}
@ -78,13 +78,16 @@ int AbstractInode::stat(ioctx_t* ctx, struct stat* st)
ScopedLock lock(&metalock);
memset(&retst, 0, sizeof(retst));
retst.st_dev = dev;
retst.st_rdev = dev;
retst.st_ino = ino;
retst.st_mode = stat_mode;
retst.st_nlink = (nlink_t) stat_nlink;
retst.st_uid = stat_uid;
retst.st_gid = stat_gid;
retst.st_size = stat_size;
// TODO: Keep track of time.
retst.st_atim = stat_atim;
retst.st_ctim = stat_ctim;
retst.st_mtim = stat_mtim;
retst.st_blksize = stat_blksize;
retst.st_blocks = stat_size / 512;
if ( !ctx->copy_to_dest(st, &retst, sizeof(retst)) )
@ -149,7 +152,8 @@ ssize_t AbstractInode::pwrite(ioctx_t* /*ctx*/, const uint8_t* /*buf*/,
return errno = EBADF, -1;
}
int AbstractInode::utimes(ioctx_t* /*ctx*/, const struct timeval /*times*/[2])
int AbstractInode::utimens(ioctx_t* /*ctx*/, const struct timespec /*times*/[2])
{
// TODO: Implement this!
return 0;

View File

@ -144,9 +144,9 @@ ssize_t Vnode::pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count, off_t off)
return inode->pwrite(ctx, buf, count, off);
}
int Vnode::utimes(ioctx_t* ctx, const struct timeval times[2])
int Vnode::utimens(ioctx_t* ctx, const struct timespec times[2])
{
return inode->utimes(ctx, times);
return inode->utimens(ctx, times);
}
int Vnode::isatty(ioctx_t* ctx)