2011-11-14 12:53:05 +01:00
|
|
|
/* Created (MFS based):
|
|
|
|
* February 2010 (Evgeniy Ivanov)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
|
|
|
|
2013-04-07 10:42:26 +02:00
|
|
|
#include <assert.h>
|
2011-11-14 12:53:05 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "puffs.h"
|
|
|
|
#include "puffs_priv.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* no_sys *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int no_sys()
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
/* Somebody has used an illegal system call number */
|
|
|
|
lpuffs_debug("no_sys: invalid call %d\n", req_nr);
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* mfs_nul *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void mfs_nul_f(const char *file, int line, char *str, unsigned int len,
|
2011-11-14 12:53:05 +01:00
|
|
|
unsigned int maxlen)
|
|
|
|
{
|
|
|
|
if (len < maxlen && str[len-1] != '\0') {
|
|
|
|
lpuffs_debug("%s:%d string (length %d,maxlen %d) not null-terminated\n",
|
|
|
|
file, line, len, maxlen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2013-04-07 10:42:26 +02:00
|
|
|
* clock_timespec *
|
2011-11-14 12:53:05 +01:00
|
|
|
*===========================================================================*/
|
2013-04-07 10:42:26 +02:00
|
|
|
struct timespec clock_timespec()
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
/* 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.
|
|
|
|
*/
|
2013-04-07 10:42:26 +02:00
|
|
|
static long system_hz = 0;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
register int k;
|
2013-04-07 10:42:26 +02:00
|
|
|
struct timespec tv;
|
2011-11-14 12:53:05 +01:00
|
|
|
clock_t uptime;
|
2013-03-29 22:48:22 +01:00
|
|
|
clock_t realtime;
|
2011-11-14 12:53:05 +01:00
|
|
|
time_t boottime;
|
|
|
|
|
2013-04-07 10:42:26 +02:00
|
|
|
if (system_hz == 0) system_hz = sys_hz();
|
2013-03-29 22:48:22 +01:00
|
|
|
if ((k=getuptime(&uptime, &realtime, &boottime)) != OK)
|
2013-04-07 10:42:26 +02:00
|
|
|
panic("clock_timespec: getuptime failed: %d", k);
|
2011-11-14 12:53:05 +01:00
|
|
|
|
2013-04-07 10:42:26 +02:00
|
|
|
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;
|
2011-11-14 12:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2013-04-07 10:42:26 +02:00
|
|
|
* update_timens *
|
2011-11-14 12:53:05 +01:00
|
|
|
*===========================================================================*/
|
2013-04-07 10:42:26 +02:00
|
|
|
int update_timens(struct puffs_node *pn, int flags, struct timespec *t)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct vattr va;
|
2013-04-07 10:42:26 +02:00
|
|
|
struct timespec new_time;
|
2011-11-14 12:53:05 +01:00
|
|
|
PUFFS_MAKECRED(pcr, &global_kcred);
|
|
|
|
|
|
|
|
if (!flags)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (global_pu->pu_ops.puffs_node_setattr == NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
2013-04-07 10:42:26 +02:00
|
|
|
new_time = t != NULL ? *t : clock_timespec();
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
puffs_vattr_null(&va);
|
|
|
|
/* librefuse modifies atime and mtime together,
|
|
|
|
* so set old values to avoid setting either one
|
|
|
|
* to PUFFS_VNOVAL (set by puffs_vattr_null).
|
|
|
|
*/
|
2013-04-07 10:42:26 +02:00
|
|
|
va.va_atime = pn->pn_va.va_atime;
|
|
|
|
va.va_mtime = pn->pn_va.va_mtime;
|
|
|
|
|
|
|
|
if (flags & ATIME)
|
|
|
|
va.va_atime = new_time;
|
|
|
|
if (flags & MTIME)
|
|
|
|
va.va_mtime = new_time;
|
|
|
|
if (flags & CTIME)
|
|
|
|
va.va_ctime = new_time;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
r = global_pu->pu_ops.puffs_node_setattr(global_pu, pn, &va, pcr);
|
|
|
|
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* lpuffs_debug *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void lpuffs_debug(const char *format, ...)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
char buffer[256];
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
|
|
|
vsprintf (buffer,format, args);
|
|
|
|
printf("%s: %s", fs_name, buffer);
|
|
|
|
va_end (args);
|
|
|
|
}
|