Move clock_time into libsys

Change-Id: Ibc5034617e6f6581de7c4a166ca075b3c357fa82
This commit is contained in:
David van Moolenbroek 2014-08-24 10:00:06 +00:00
parent 0dc5c83ec2
commit ad80a203db
26 changed files with 80 additions and 164 deletions

View file

@ -123,7 +123,7 @@ int fs_link(ino_t dir_nr, char *name, ino_t ino_nr)
if (r != OK) return(EINVAL);
cur_time = clock_timespec();
(void)clock_time(&cur_time);
update_timens(pn, CTIME, &cur_time);
update_timens(pn_dir, MTIME | CTIME, &cur_time);
@ -308,7 +308,7 @@ int fs_rename(ino_t old_dir_nr, char *old_name, ino_t new_dir_nr,
}
}
cur_time = clock_timespec();
(void)clock_time(&cur_time);
update_timens(old_dirp, MTIME | CTIME, &cur_time);
update_timens(new_dirp, MTIME | CTIME, &cur_time);
@ -366,7 +366,7 @@ int fs_unlink(ino_t dir_nr, char *name, int call)
}
if (pn->pn_va.va_nlink != 0) {
cur_time = clock_timespec();
(void)clock_time(&cur_time);
update_timens(pn, CTIME, &cur_time);
update_timens(pn_dir, MTIME | CTIME, &cur_time);
}

View file

@ -43,7 +43,7 @@ int fs_create(ino_t dir_nr, char *name, mode_t mode, uid_t uid, gid_t gid,
memset(&pni, 0, sizeof(pni));
pni.pni_cookie = (void** )&pn;
cur_time = clock_timespec();
(void)clock_time(&cur_time);
memset(&va, 0, sizeof(va));
va.va_type = VREG;
@ -127,7 +127,7 @@ int fs_mknod(ino_t dir_nr, char *name, mode_t mode, uid_t uid, gid_t gid,
memset(&pni, 0, sizeof(pni));
pni.pni_cookie = (void** )&pn;
cur_time = clock_timespec();
(void)clock_time(&cur_time);
memset(&va, 0, sizeof(va));
va.va_type = VDIR;
@ -196,7 +196,7 @@ int fs_mkdir(ino_t dir_nr, char *name, mode_t mode, uid_t uid, gid_t gid)
if ((pn_dir = puffs_pn_nodewalk(global_pu, 0, &dir_nr)) == NULL)
return(ENOENT);
cur_time = clock_timespec();
(void)clock_time(&cur_time);
memset(&pni, 0, sizeof(pni));
pni.pni_cookie = (void** )&pn;
@ -254,6 +254,7 @@ int fs_slink(ino_t dir_nr, char *name, uid_t uid, gid_t gid,
PUFFS_MAKECRED(pcr, &global_kcred);
struct puffs_cn pcn = {&pkcnp, (struct puffs_cred *) __UNCONST(pcr), {0,0,0}};
struct vattr va;
struct timespec cur_time;
/* Copy the link name's last component */
pcn.pcn_namelen = strlen(name);
@ -287,12 +288,14 @@ int fs_slink(ino_t dir_nr, char *name, uid_t uid, gid_t gid,
memset(&pni, 0, sizeof(pni));
pni.pni_cookie = (void** )&pn;
(void)clock_time(&cur_time);
memset(&va, 0, sizeof(va));
va.va_type = VLNK;
va.va_mode = (I_SYMBOLIC_LINK | RWX_MODES);
va.va_uid = uid;
va.va_gid = gid;
va.va_atime = va.va_mtime = va.va_ctime = clock_timespec();
va.va_atime = va.va_mtime = va.va_ctime = cur_time;
if (buildpath) {
r = puffs_path_pcnbuild(global_pu, &pcn, pn_dir);

View file

@ -27,7 +27,7 @@ int fs_chmod(ino_t ino_nr, mode_t *mode)
puffs_vattr_null(&va);
/* Clear setgid bit if file is not in caller's grp */
va.va_mode = (pn->pn_va.va_mode & ~ALL_MODES) | (*mode & ALL_MODES);
va.va_ctime = clock_timespec();
(void)clock_time(&va.va_ctime);
if (global_pu->pu_ops.puffs_node_setattr(global_pu, pn, &va, pcr) != 0)
return(EINVAL);
@ -55,7 +55,7 @@ int fs_chown(ino_t ino_nr, uid_t uid, gid_t gid, mode_t *mode)
va.va_uid = uid;
va.va_gid = gid;
va.va_mode = pn->pn_va.va_mode & ~(I_SET_UID_BIT | I_SET_GID_BIT);
va.va_ctime = clock_timespec();
(void)clock_time(&va.va_ctime);
if (global_pu->pu_ops.puffs_node_setattr(global_pu, pn, &va, pcr) != 0)
return(EINVAL);

View file

@ -3,7 +3,6 @@
struct puffs_usermount;
struct puffs_node;
struct timespec;
/* Function prototypes. */
@ -62,7 +61,6 @@ int fs_statvfs(struct statvfs *st);
int fs_utime(ino_t ino_nr, struct timespec *atime, struct timespec *mtime);
/* utility.c */
struct timespec clock_timespec(void);
int update_timens(struct puffs_node *pn, int fl, struct timespec *);
void lpuffs_debug(const char *format, ...)
__attribute__((__format__(__printf__, 1, 2)));

View file

@ -73,6 +73,7 @@ ssize_t fs_write(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
size_t bytes_left;
struct puffs_node *pn;
struct vattr va;
struct timespec cur_time;
PUFFS_MAKECRED(pcr, &global_kcred);
if ((pn = puffs_pn_nodewalk(global_pu, 0, &ino_nr)) == NULL) {
@ -88,10 +89,12 @@ ssize_t fs_write(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
if (global_pu->pu_ops.puffs_node_setattr == NULL)
return(EINVAL);
(void)clock_time(&cur_time);
puffs_vattr_null(&va);
if ((u_quad_t)(pos + bytes_left) > pn->pn_va.va_size)
va.va_size = bytes_left + pos;
va.va_ctime = va.va_mtime = clock_timespec();
va.va_ctime = va.va_mtime = cur_time;
va.va_atime = pn->pn_va.va_atime;
r = global_pu->pu_ops.puffs_node_setattr(global_pu, pn, &va, pcr);

View file

@ -22,11 +22,10 @@ int fs_utime(ino_t ino_nr, struct timespec *atime, struct timespec *mtime)
if( (pn = puffs_pn_nodewalk(global_pu, 0, &ino_nr)) == NULL)
return(EINVAL);
/* FIXME: shouldn't this check the special UTIME_ values? */
puffs_vattr_null(&va);
va.va_atime = *atime;
va.va_mtime = *mtime;
va.va_ctime = clock_timespec();
(void)clock_time(&va.va_ctime);
if (global_pu->pu_ops.puffs_node_setattr(global_pu, pn, &va, pcr) != 0)
return(EINVAL);

View file

@ -11,35 +11,6 @@
#include "puffs_priv.h"
/*===========================================================================*
* clock_timespec *
*===========================================================================*/
struct timespec clock_timespec(void)
{
/* This routine returns the time in seconds since 1.1.1970. MINIX is an
* astrophysically naive system that assumes the earth rotates at a constant
* rate and that such things as leap seconds do not exist.
*/
static long system_hz = 0;
register int k;
struct timespec tv;
clock_t uptime;
clock_t realtime;
time_t boottime;
if (system_hz == 0) system_hz = sys_hz();
if ((k=getuptime(&uptime, &realtime, &boottime)) != OK)
panic("clock_timespec: getuptime failed: %d", k);
tv.tv_sec = (time_t) (boottime + (realtime/system_hz));
/* We do not want to overflow, and system_hz can be as high as 50kHz */
assert(system_hz < LONG_MAX/40000);
tv.tv_nsec = (realtime%system_hz) * 40000 / system_hz * 25000;
return tv;
}
/*===========================================================================*
* update_timens *
*===========================================================================*/
@ -56,7 +27,10 @@ int update_timens(struct puffs_node *pn, int flags, struct timespec *t)
if (global_pu->pu_ops.puffs_node_setattr == NULL)
return EINVAL;
new_time = t != NULL ? *t : clock_timespec();
if (t != NULL)
new_time = *t;
else
(void)clock_time(&new_time);
puffs_vattr_null(&va);
/* librefuse modifies atime and mtime together,

View file

@ -289,7 +289,7 @@ void update_times(
if (sp->s_rd_only)
return; /* no updates for read-only file systems */
cur_time = clock_time();
cur_time = clock_time(NULL);
if (rip->i_update & ATIME)
rip->i_atime = cur_time;
if (rip->i_update & CTIME)

View file

@ -33,7 +33,7 @@ int fs_sync()
lmfs_flushall();
if (superblock->s_dev != NO_DEV) {
superblock->s_wtime = clock_time();
superblock->s_wtime = clock_time(NULL);
write_super(superblock);
}

View file

@ -149,7 +149,7 @@ int fs_readsuper()
if (!readonly) {
superblock->s_state = EXT2_ERROR_FS;
superblock->s_mnt_count++;
superblock->s_mtime = clock_time();
superblock->s_mtime = clock_time(NULL);
write_super(superblock); /* Commit info, we just set above */
}
@ -234,7 +234,7 @@ int fs_unmount()
put_inode(root_ip);
if (!superblock->s_rd_only) {
superblock->s_wtime = clock_time();
superblock->s_wtime = clock_time(NULL);
superblock->s_state = EXT2_VALID_FS;
write_super(superblock); /* Commit info, we just set above */
}

View file

@ -95,7 +95,6 @@ struct group_desc* get_group_desc(unsigned int bnum);
int fs_utime(void);
/* utility.c */
time_t clock_time(void);
unsigned conv2(int norm, int w);
long conv4(int norm, long x);
void mfs_nul_f(const char *file, int line, const char *str, unsigned int len,

View file

@ -51,28 +51,6 @@ long x; /* 32-bit long to be byte swapped */
}
/*===========================================================================*
* clock_time *
*===========================================================================*/
time_t clock_time()
{
/* This routine returns the time in seconds since 1.1.1970. MINIX is an
* astrophysically naive system that assumes the earth rotates at a constant
* rate and that such things as leap seconds do not exist.
*/
register int k;
clock_t uptime;
clock_t realtime;
time_t boottime;
if ( (k=getuptime(&uptime, &realtime, &boottime)) != OK)
panic("clock_time: getuptme2 failed: %d", k);
return( (time_t) (boottime + (realtime/sys_hz())));
}
/*===========================================================================*
* mfs_min *
*===========================================================================*/

View file

@ -369,7 +369,7 @@ register struct inode *rip; /* pointer to inode to be read/written */
sp = rip->i_sp; /* get pointer to super block. */
if (sp->s_rd_only) return; /* no updates for read-only file systems */
cur_time = clock_time();
cur_time = clock_time(NULL);
if (rip->i_update & ATIME) rip->i_atime = cur_time;
if (rip->i_update & CTIME) rip->i_ctime = cur_time;
if (rip->i_update & MTIME) rip->i_mtime = cur_time;

View file

@ -98,7 +98,6 @@ bit_t count_free_bits(struct super_block *sp, int map);
int fs_utime(void);
/* utility.c */
time_t clock_time(void);
unsigned conv2(int norm, int w);
long conv4(int norm, long x);
void mfs_nul_f(char *file, int line, char *str, unsigned int len,

View file

@ -47,28 +47,6 @@ long x; /* 32-bit long to be byte swapped */
}
/*===========================================================================*
* clock_time *
*===========================================================================*/
time_t clock_time()
{
/* This routine returns the time in seconds since 1.1.1970. MINIX is an
* astrophysically naive system that assumes the earth rotates at a constant
* rate and that such things as leap seconds do not exist.
*/
register int k;
clock_t uptime;
clock_t realtime;
time_t boottime;
if ( (k=getuptime(&uptime, &realtime, &boottime)) != OK)
panic("clock_time: getuptme2 failed: %d", k);
return( (time_t) (boottime + (realtime/sys_hz())));
}
/*===========================================================================*
* mfs_min *
*===========================================================================*/

View file

@ -329,7 +329,7 @@ struct inode *rip; /* pointer to inode to be read/written */
time_t cur_time;
cur_time = clock_time();
cur_time = clock_time(NULL);
if (rip->i_update & ATIME) rip->i_atime = cur_time;
if (rip->i_update & CTIME) rip->i_ctime = cur_time;
if (rip->i_update & MTIME) rip->i_mtime = cur_time;

View file

@ -47,7 +47,6 @@ int fs_newnode(message *fs_m_in, message *fs_m_out);
int fs_readwrite(message *fs_m_in, message *fs_m_out);
/* utility.c */
time_t clock_time(void);
int no_sys(message *pfs_m_in, message *pfs_m_out);
/* stadir.c */

View file

@ -10,25 +10,3 @@ int no_sys(message *pfs_m_in, message *pfs_m_out)
printf("no_sys: invalid call 0x%x to pfs\n", pfs_m_in->m_type);
return(EINVAL);
}
/*===========================================================================*
* clock_time *
*===========================================================================*/
time_t clock_time()
{
/* This routine returns the time in seconds since 1.1.1970. MINIX is an
* astrophysically naive system that assumes the earth rotates at a constant
* rate and that such things as leap seconds do not exist.
*/
int r;
clock_t uptime; /* Uptime in ticks */
clock_t realtime;
time_t boottime;
if ((r = getuptime(&uptime, &realtime, &boottime)) != OK)
panic("clock_time: getuptme2 failed: %d", r);
return( (time_t) (boottime + (realtime/sys_hz())));
}

View file

@ -46,6 +46,8 @@ int env_parse(const char *env, const char *fmt, int field,
#define fkey_events(fkeys, sfkeys) fkey_ctl(FKEY_EVENTS, (fkeys), (sfkeys))
int fkey_ctl(int req, int *fkeys, int *sfkeys);
struct timespec;
int printf(const char *fmt, ...);
void kputc(int c);
__dead void panic(const char *fmt, ...)
@ -64,6 +66,7 @@ u32_t tsc_64_to_micros(u64_t tsc);
u32_t tsc_to_micros(u32_t low, u32_t high);
u32_t tsc_get_khz(void);
u32_t micros_to_ticks(u32_t micros);
time_t clock_time(struct timespec *tv);
#if defined(__arm__)
void read_frclock(u32_t *frclk);
u32_t delta_frclock(u32_t base, u32_t cur);

View file

@ -17,6 +17,7 @@ SRCS+= \
assert.c \
asynsend.c \
checkperms.c \
clock_time.c \
copyfd.c \
ds.c \
env_get_prm.c \

View file

@ -0,0 +1,42 @@
#include "sysutil.h"
#include <sys/time.h>
/*
* This routine returns the time in seconds since 1.1.1970. MINIX is an
* astrophysically naive system that assumes the earth rotates at a constant
* rate and that such things as leap seconds do not exist. If a non-NULL
* pointer to a timespec structure is given, that structure is filled with
* the current time in subsecond precision.
*/
time_t
clock_time(struct timespec *tv)
{
uint32_t system_hz;
clock_t uptime, realtime;
time_t boottime, sec;
int r;
if ((r = getuptime(&uptime, &realtime, &boottime)) != OK)
panic("clock_time: getuptime failed: %d", r);
system_hz = sys_hz(); /* sys_hz() caches its return value */
sec = boottime + realtime / system_hz;
if (tv != NULL) {
tv->tv_sec = sec;
/*
* We do not want to overflow, and system_hz can be as high as
* 50kHz.
*/
if (system_hz < LONG_MAX / 40000)
tv->tv_nsec = (realtime % system_hz) * 40000 /
system_hz * 25000;
else
tv->tv_nsec = 0; /* bad, but what's better? */
}
return sec;
}

View file

@ -37,7 +37,7 @@ int fs_stat(ino_t ino_nr, struct stat *buf)
}
/* Take the current time as file time for all files. */
cur_time = time(NULL);
cur_time = clock_time(NULL);
buf->st_atime = cur_time;
buf->st_mtime = cur_time;
buf->st_ctime = cur_time;

View file

@ -89,21 +89,13 @@ int do_settime()
*===========================================================================*/
int do_time()
{
/* Perform the time(tp) system call. This returns the time in seconds since
* 1.1.1970. MINIX is an astrophysically naive system that assumes the earth
* rotates at a constant rate and that such things as leap seconds do not
* exist.
*/
clock_t ticks, realtime;
time_t boottime;
int s;
/* Perform the time(tp) system call. */
struct timespec tv;
if ( (s=getuptime(&ticks, &realtime, &boottime)) != OK)
panic("do_time couldn't get uptime: %d", s);
(void)clock_time(&tv);
mp->mp_reply.m_pm_lc_time.sec = boottime + (realtime / system_hz);
mp->mp_reply.m_pm_lc_time.nsec =
(uint32_t) ((realtime % system_hz) * 1000000000ULL / system_hz);
mp->mp_reply.m_pm_lc_time.sec = tv.tv_sec;
mp->mp_reply.m_pm_lc_time.nsec = tv.tv_nsec;
return(OK);
}

View file

@ -275,7 +275,6 @@ int tll_unlock(tll_t *tllp);
void tll_upgrade(tll_t *tllp);
/* utility.c */
struct timespec clock_timespec(void);
int copy_path(char *dest, size_t size);
int fetch_name(vir_bytes path, size_t len, char *dest);
int isokendpt_f(const char *f, int l, endpoint_t e, int *p, int ft);

View file

@ -98,7 +98,7 @@ int do_utimens(void)
|| actim.tv_nsec == UTIME_OMIT
|| modtim.tv_nsec == UTIME_NOW
|| modtim.tv_nsec == UTIME_OMIT) {
now = clock_timespec();
(void)clock_time(&now);
}
/* Build the request */

View file

@ -1,7 +1,6 @@
/* This file contains a few general purpose utility routines.
*
* The entry points into this file are
* clock_timespec: ask the clock task for the real time
* copy_path: copy a path name from a path request from userland
* fetch_name: go get a path name from user space
* panic: something awful has occurred; MINIX cannot continue
@ -123,34 +122,6 @@ int isokendpt_f(const char *file, int line, endpoint_t endpoint, int *proc,
return(failed ? EDEADEPT : OK);
}
/*===========================================================================*
* clock_timespec *
*===========================================================================*/
struct timespec clock_timespec(void)
{
/* This routine returns the time in seconds since 1.1.1970. MINIX is an
* astrophysically naive system that assumes the earth rotates at a constant
* rate and that such things as leap seconds do not exist.
*/
register int r;
struct timespec tv;
clock_t uptime;
clock_t realtime;
time_t boottime;
r = getuptime(&uptime, &realtime, &boottime);
if (r != OK)
panic("clock_timespec err: %d", r);
tv.tv_sec = boottime + (realtime/system_hz);
/* We do not want to overflow, and system_hz can be as high as 50kHz */
assert(system_hz < LONG_MAX/40000);
tv.tv_nsec = (realtime%system_hz) * 40000 / system_hz * 25000;
return tv;
}
/*===========================================================================*
* in_group *
*===========================================================================*/