diff --git a/libc/decl/timeval.h b/libc/decl/timeval.h new file mode 100644 index 00000000..393e85f5 --- /dev/null +++ b/libc/decl/timeval.h @@ -0,0 +1,8 @@ +#ifndef _TIMEVAL_T_DECL +#define _TIMEVAL_T_DECL +struct timeval +{ + time_t tv_sec; + suseconds_t tv_usec; +}; +#endif diff --git a/libc/include/fsmarshall-msg.h b/libc/include/fsmarshall-msg.h index c46f9313..bbad39af 100644 --- a/libc/include/fsmarshall-msg.h +++ b/libc/include/fsmarshall-msg.h @@ -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 diff --git a/libc/include/fsmarshall.h b/libc/include/fsmarshall.h index 3bc2cfcc..1ae16ca1 100644 --- a/libc/include/fsmarshall.h +++ b/libc/include/fsmarshall.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include diff --git a/libc/include/sys/select.h b/libc/include/sys/select.h index 7737294a..12572861 100644 --- a/libc/include/sys/select.h +++ b/libc/include/sys/select.h @@ -33,11 +33,11 @@ __BEGIN_DECLS @include(time_t.h) @include(suseconds_t.h) +@include(timeval.h) __BEGIN_DECLS #include #include -#include __END_DECLS #define FD_SETSIZE 1024 diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h index c085201d..bc53134c 100644 --- a/libc/include/sys/stat.h +++ b/libc/include/sys/stat.h @@ -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); diff --git a/libc/include/sys/time.h b/libc/include/sys/time.h index d393acb2..6bcd030f 100644 --- a/libc/include/sys/time.h +++ b/libc/include/sys/time.h @@ -31,12 +31,7 @@ __BEGIN_DECLS @include(time_t.h) @include(suseconds_t.h) - -__END_DECLS - -#include - -__BEGIN_DECLS +@include(timeval.h) int gettimeofday(struct timeval* restrict tp, void* restrict tzp); diff --git a/mkinitrd/mkinitrd.cpp b/mkinitrd/mkinitrd.cpp index 7e340522..6aa269e1 100644 --- a/mkinitrd/mkinitrd.cpp +++ b/mkinitrd/mkinitrd.cpp @@ -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; } diff --git a/sortix/descriptor.cpp b/sortix/descriptor.cpp index 9ec02417..9167f49d 100644 --- a/sortix/descriptor.cpp +++ b/sortix/descriptor.cpp @@ -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) diff --git a/sortix/fs/user.cpp b/sortix/fs/user.cpp index b25e9267..bb683fff 100644 --- a/sortix/fs/user.cpp +++ b/sortix/fs/user.cpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include @@ -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(); diff --git a/sortix/include/sortix/kernel/descriptor.h b/sortix/include/sortix/kernel/descriptor.h index 8c0ec279..deca9ec0 100644 --- a/sortix/include/sortix/kernel/descriptor.h +++ b/sortix/include/sortix/kernel/descriptor.h @@ -35,7 +35,6 @@ #include 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); diff --git a/sortix/include/sortix/kernel/inode.h b/sortix/include/sortix/kernel/inode.h index 50d2ef80..00b08cad 100644 --- a/sortix/include/sortix/kernel/inode.h +++ b/sortix/include/sortix/kernel/inode.h @@ -35,7 +35,6 @@ #include 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); diff --git a/sortix/include/sortix/kernel/vnode.h b/sortix/include/sortix/kernel/vnode.h index bf8ce780..ace01ce1 100644 --- a/sortix/include/sortix/kernel/vnode.h +++ b/sortix/include/sortix/kernel/vnode.h @@ -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 #include 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); diff --git a/sortix/include/sortix/stat.h b/sortix/include/sortix/stat.h index 74b344a0..5ebd1c48 100644 --- a/sortix/include/sortix/stat.h +++ b/sortix/include/sortix/stat.h @@ -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 #include +#include __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; }; diff --git a/sortix/include/sortix/timeval.h b/sortix/include/sortix/timeval.h deleted file mode 100644 index 894186ac..00000000 --- a/sortix/include/sortix/timeval.h +++ /dev/null @@ -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 . - - sortix/timeval.h - Declares the struct timeval. - -*******************************************************************************/ - -#ifndef SORTIX_TIMEVAL_H -#define SORTIX_TIMEVAL_H - -#include - -__BEGIN_DECLS - -struct timeval -{ - time_t tv_sec; - suseconds_t tv_usec; -}; - -__END_DECLS - -#endif diff --git a/sortix/initrd.cpp b/sortix/initrd.cpp index 851021c9..c00a0039 100644 --- a/sortix/initrd.cpp +++ b/sortix/initrd.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #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 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; diff --git a/sortix/inode.cpp b/sortix/inode.cpp index e75ee311..13f4a600 100644 --- a/sortix/inode.cpp +++ b/sortix/inode.cpp @@ -24,6 +24,7 @@ #include #include +#include #include @@ -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; diff --git a/sortix/vnode.cpp b/sortix/vnode.cpp index 46c62be8..c5826d27 100644 --- a/sortix/vnode.cpp +++ b/sortix/vnode.cpp @@ -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)