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);
}
}
- 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);
}
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);
}
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;
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;
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;
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);
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);
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);
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);
struct puffs_usermount;
struct puffs_node;
-struct timespec;
/* Function prototypes. */
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)));
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) {
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);
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);
#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 *
*===========================================================================*/
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,
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)
lmfs_flushall();
if (superblock->s_dev != NO_DEV) {
- superblock->s_wtime = clock_time();
+ superblock->s_wtime = clock_time(NULL);
write_super(superblock);
}
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 */
}
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 */
}
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,
}
-/*===========================================================================*
- * 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 *
*===========================================================================*/
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;
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,
}
-/*===========================================================================*
- * 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 *
*===========================================================================*/
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;
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 */
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())));
-}
#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, ...)
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);
assert.c \
asynsend.c \
checkperms.c \
+ clock_time.c \
copyfd.c \
ds.c \
env_get_prm.c \
--- /dev/null
+
+#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;
+}
}
/* 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;
*===========================================================================*/
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);
}
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);
|| 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 */
/* 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
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 *
*===========================================================================*/