remove extra mkfs.1
[minix.git] / lib / libpuffs / utility.c
blob0985c587d7be2d858c36609017e66b1f46bdc9dc
1 /* Created (MFS based):
2 * February 2010 (Evgeniy Ivanov)
3 */
5 #include "fs.h"
7 #include <stdarg.h>
9 #include "puffs.h"
10 #include "puffs_priv.h"
13 /*===========================================================================*
14 * no_sys *
15 *===========================================================================*/
16 int no_sys()
18 /* Somebody has used an illegal system call number */
19 lpuffs_debug("no_sys: invalid call %d\n", req_nr);
20 return(EINVAL);
24 /*===========================================================================*
25 * mfs_nul *
26 *===========================================================================*/
27 void mfs_nul_f(const char *file, int line, char *str, unsigned int len,
28 unsigned int maxlen)
30 if (len < maxlen && str[len-1] != '\0') {
31 lpuffs_debug("%s:%d string (length %d,maxlen %d) not null-terminated\n",
32 file, line, len, maxlen);
37 /*===========================================================================*
38 * clock_time *
39 *===========================================================================*/
40 time_t clock_time()
42 /* This routine returns the time in seconds since 1.1.1970. MINIX is an
43 * astrophysically naive system that assumes the earth rotates at a constant
44 * rate and that such things as leap seconds do not exist.
47 register int k;
48 clock_t uptime;
49 time_t boottime;
51 if ((k=getuptime2(&uptime, &boottime)) != OK)
52 panic("clock_time: getuptme2 failed: %d", k);
54 return( (time_t) (boottime + (uptime/sys_hz())));
58 /*===========================================================================*
59 * update_times *
60 *===========================================================================*/
61 int update_times(struct puffs_node *pn, int flags, time_t t)
63 int r;
64 struct vattr va;
65 time_t new_time;
66 PUFFS_MAKECRED(pcr, &global_kcred);
68 if (!flags)
69 return 0;
71 if (global_pu->pu_ops.puffs_node_setattr == NULL)
72 return EINVAL;
74 new_time = t != 0 ? t : clock_time();
76 puffs_vattr_null(&va);
77 /* librefuse modifies atime and mtime together,
78 * so set old values to avoid setting either one
79 * to PUFFS_VNOVAL (set by puffs_vattr_null).
81 va.va_atime.tv_sec = pn->pn_va.va_atime.tv_sec;
82 va.va_mtime.tv_sec = pn->pn_va.va_mtime.tv_sec;
84 if (flags & ATIME) {
85 va.va_atime.tv_sec = new_time;
86 va.va_atime.tv_nsec = 0;
88 if (flags & MTIME) {
89 va.va_mtime.tv_sec = new_time;
90 va.va_mtime.tv_nsec = 0;
92 if (flags & CTIME) {
93 va.va_ctime.tv_sec = new_time;
94 va.va_ctime.tv_nsec = 0;
97 r = global_pu->pu_ops.puffs_node_setattr(global_pu, pn, &va, pcr);
99 return(r);
103 /*===========================================================================*
104 * lpuffs_debug *
105 *===========================================================================*/
106 void lpuffs_debug(const char *format, ...)
108 char buffer[256];
109 va_list args;
110 va_start (args, format);
111 vsprintf (buffer,format, args);
112 printf("%s: %s", fs_name, buffer);
113 va_end (args);