<sys/ioccom.h>, <sys/ioctl.h>
[minix3.git] / lib / libpuffs / utility.c
blob03667561aa997b3dd6c08f8721a182a6c947606d
1 /* Created (MFS based):
2 * February 2010 (Evgeniy Ivanov)
3 */
5 #include "fs.h"
7 #include <assert.h>
8 #include <stdarg.h>
10 #include "puffs.h"
11 #include "puffs_priv.h"
14 /*===========================================================================*
15 * no_sys *
16 *===========================================================================*/
17 int no_sys()
19 /* Somebody has used an illegal system call number */
20 lpuffs_debug("no_sys: invalid call %d\n", req_nr);
21 return(EINVAL);
25 /*===========================================================================*
26 * mfs_nul *
27 *===========================================================================*/
28 void mfs_nul_f(const char *file, int line, char *str, unsigned int len,
29 unsigned int maxlen)
31 if (len < maxlen && str[len-1] != '\0') {
32 lpuffs_debug("%s:%d string (length %d,maxlen %d) not null-terminated\n",
33 file, line, len, maxlen);
38 /*===========================================================================*
39 * clock_timespec *
40 *===========================================================================*/
41 struct timespec clock_timespec()
43 /* This routine returns the time in seconds since 1.1.1970. MINIX is an
44 * astrophysically naive system that assumes the earth rotates at a constant
45 * rate and that such things as leap seconds do not exist.
47 static long system_hz = 0;
49 register int k;
50 struct timespec tv;
51 clock_t uptime;
52 clock_t realtime;
53 time_t boottime;
55 if (system_hz == 0) system_hz = sys_hz();
56 if ((k=getuptime(&uptime, &realtime, &boottime)) != OK)
57 panic("clock_timespec: getuptime failed: %d", k);
59 tv.tv_sec = (time_t) (boottime + (realtime/system_hz));
60 /* We do not want to overflow, and system_hz can be as high as 50kHz */
61 assert(system_hz < LONG_MAX/40000);
62 tv.tv_nsec = (realtime%system_hz) * 40000 / system_hz * 25000;
63 return tv;
67 /*===========================================================================*
68 * update_timens *
69 *===========================================================================*/
70 int update_timens(struct puffs_node *pn, int flags, struct timespec *t)
72 int r;
73 struct vattr va;
74 struct timespec new_time;
75 PUFFS_MAKECRED(pcr, &global_kcred);
77 if (!flags)
78 return 0;
80 if (global_pu->pu_ops.puffs_node_setattr == NULL)
81 return EINVAL;
83 new_time = t != NULL ? *t : clock_timespec();
85 puffs_vattr_null(&va);
86 /* librefuse modifies atime and mtime together,
87 * so set old values to avoid setting either one
88 * to PUFFS_VNOVAL (set by puffs_vattr_null).
90 va.va_atime = pn->pn_va.va_atime;
91 va.va_mtime = pn->pn_va.va_mtime;
93 if (flags & ATIME)
94 va.va_atime = new_time;
95 if (flags & MTIME)
96 va.va_mtime = new_time;
97 if (flags & CTIME)
98 va.va_ctime = new_time;
100 r = global_pu->pu_ops.puffs_node_setattr(global_pu, pn, &va, pcr);
102 return(r);
106 /*===========================================================================*
107 * lpuffs_debug *
108 *===========================================================================*/
109 void lpuffs_debug(const char *format, ...)
111 char buffer[256];
112 va_list args;
113 va_start (args, format);
114 vsprintf (buffer,format, args);
115 printf("%s: %s", fs_name, buffer);
116 va_end (args);