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,