From 4ab3fa3b5a45a509c954d8183f9c37770515dd31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 12 Jun 2009 09:31:25 +0000 Subject: [PATCH] * Added real_time_clock(), and real_time_clock_usecs(). * Added support for timespec stat times. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31012 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/fs_shell/fssh_api_wrapper.h | 4 +++ headers/private/fs_shell/fssh_stat.h | 16 +++++++--- src/tools/fs_shell/time.cpp | 35 ++++++++++++++------- src/tools/fs_shell/vfs.cpp | 9 ++++-- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/headers/private/fs_shell/fssh_api_wrapper.h b/headers/private/fs_shell/fssh_api_wrapper.h index 1a4c7d3eef..15615cff1c 100644 --- a/headers/private/fs_shell/fssh_api_wrapper.h +++ b/headers/private/fs_shell/fssh_api_wrapper.h @@ -1221,6 +1221,10 @@ #define st_size fssh_st_size #define st_rdev fssh_st_rdev #define st_blksize fssh_st_blksize +#define st_atim fssh_st_atim +#define st_mtim fssh_st_mtim +#define st_ctim fssh_st_ctim +#define st_crtim fssh_st_crtim #define st_atime fssh_st_atime #define st_mtime fssh_st_mtime #define st_ctime fssh_st_ctime diff --git a/headers/private/fs_shell/fssh_stat.h b/headers/private/fs_shell/fssh_stat.h index 94714faa39..c2a395a4b9 100644 --- a/headers/private/fs_shell/fssh_stat.h +++ b/headers/private/fs_shell/fssh_stat.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008, Haiku Inc. All Rights Reserved. + * Copyright 2002-2009, Haiku Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _FSSH_SYS_STAT_H_ @@ -20,10 +20,10 @@ struct fssh_stat { fssh_off_t fssh_st_size; /* size in bytes of this file */ fssh_dev_t fssh_st_rdev; /* device type (not used) */ fssh_size_t fssh_st_blksize; /* preferred block size for i/o */ - fssh_time_t fssh_st_atime; /* last access time */ - fssh_time_t fssh_st_mtime; /* last modification time */ - fssh_time_t fssh_st_ctime; /* last change time, not creation time */ - fssh_time_t fssh_st_crtime; /* creation time */ + fssh_timespec fssh_st_atim; /* last access time */ + fssh_timespec fssh_st_mtim; /* last modification time */ + fssh_timespec fssh_st_ctim; /* last change time, not creation time */ + fssh_timespec fssh_st_crtim; /* creation time */ // Haiku extensions: // TODO: we might also define special types for files and TTYs @@ -34,6 +34,12 @@ struct fssh_stat { }; typedef struct fssh_stat fssh_struct_stat; +/* compatibility with older apps */ +#define fssh_st_atime fssh_st_atim.tv_sec +#define fssh_st_mtime fssh_st_mtim.tv_sec +#define fssh_st_ctime fssh_st_ctim.tv_sec +#define fssh_st_crtime fssh_st_crtim.tv_sec + /* extended file types */ #define FSSH_S_ATTR_DIR 01000000000 /* attribute directory */ #define FSSH_S_ATTR 02000000000 /* attribute */ diff --git a/src/tools/fs_shell/time.cpp b/src/tools/fs_shell/time.cpp index c5c78b6d81..f79d0374ea 100644 --- a/src/tools/fs_shell/time.cpp +++ b/src/tools/fs_shell/time.cpp @@ -1,5 +1,7 @@ /* + * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. * Copyright 2007, Ingo Weinhold, bonefish@cs.tu-berlin.de. + * * Distributed under the terms of the MIT License. */ @@ -9,6 +11,7 @@ #include "fssh_time.h" #include +#include #include @@ -17,24 +20,12 @@ #if 0 -uint32_t -fssh_real_time_clock(void) -{ -} - - void fssh_set_real_time_clock(uint32_t secs_since_jan1_1970) { } -fssh_bigtime_t -fssh_real_time_clock_usecs(void) -{ -} - - fssh_status_t fssh_set_timezone(char *timezone) { @@ -42,6 +33,26 @@ fssh_set_timezone(char *timezone) #endif // 0 +uint32_t +fssh_real_time_clock(void) +{ + timeval tv; + gettimeofday(&tv, NULL); + + return tv.tv_sec; +} + + +fssh_bigtime_t +fssh_real_time_clock_usecs(void) +{ + timeval tv; + gettimeofday(&tv, NULL); + + return tv.tv_sec * 1000000LL + tv.tv_usec; +} + + fssh_bigtime_t fssh_system_time(void) { diff --git a/src/tools/fs_shell/vfs.cpp b/src/tools/fs_shell/vfs.cpp index e507622a86..2036a6ad53 100644 --- a/src/tools/fs_shell/vfs.cpp +++ b/src/tools/fs_shell/vfs.cpp @@ -1,12 +1,12 @@ /* - * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. * Distributed under the terms of the NewOS License. */ -/* Virtual File System and File System Interface Layer */ +/*! Virtual File System and File System Interface Layer */ #include "vfs.h" @@ -3828,6 +3828,11 @@ common_read_stat(struct file_descriptor *descriptor, struct fssh_stat *stat) FUNCTION(("common_read_stat: stat %p\n", stat)); + stat->fssh_st_atim.tv_nsec = 0; + stat->fssh_st_mtim.tv_nsec = 0; + stat->fssh_st_ctim.tv_nsec = 0; + stat->fssh_st_crtim.tv_nsec = 0; + fssh_status_t status = FS_CALL(vnode, read_stat, stat); // fill in the st_dev and st_ino fields