mirror of
https://git.sr.ht/~cismonx/bookmarkfs
synced 2025-06-07 19:58:50 +00:00
xstd: add helper function for getting current time
Also, don't bother with failed clock_gettime() calls.
This commit is contained in:
parent
d7c7ec0174
commit
00f40beec7
5 changed files with 26 additions and 30 deletions
|
@ -808,10 +808,7 @@ build_ts (
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (ts->tv_nsec == UTIME_NOW) {
|
if (ts->tv_nsec == UTIME_NOW) {
|
||||||
if (unlikely(0 != clock_gettime(CLOCK_REALTIME, ts))) {
|
xgetrealtime(ts);
|
||||||
log_printf("clock_gettime(): %s", xstrerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: May overflow if system time is badly wrong,
|
// XXX: May overflow if system time is badly wrong,
|
||||||
|
|
|
@ -2085,10 +2085,7 @@ usecs_now (
|
||||||
if (ts_buf == NULL) {
|
if (ts_buf == NULL) {
|
||||||
ts_buf = &ts_tmp;
|
ts_buf = &ts_tmp;
|
||||||
}
|
}
|
||||||
if (unlikely(0 != clock_gettime(CLOCK_REALTIME, ts_buf))) {
|
xgetrealtime(ts_buf);
|
||||||
log_printf("clock_gettime(): %s", xstrerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return timespec_to_usecs(ts_buf);
|
return timespec_to_usecs(ts_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
src/fs_ops.c
26
src/fs_ops.c
|
@ -235,7 +235,6 @@ static int bm_setattr (uint64_t, int, bool, struct fuse_file_info const *,
|
||||||
static int bm_setxattr (uint64_t, char const *, void const *, size_t, int);
|
static int bm_setxattr (uint64_t, char const *, void const *, size_t, int);
|
||||||
static int bm_write (fuse_req_t, int, char const *, size_t, off_t,
|
static int bm_write (fuse_req_t, int, char const *, size_t, off_t,
|
||||||
struct fs_file_handle *);
|
struct fs_file_handle *);
|
||||||
static int current_time (struct timespec *);
|
|
||||||
static void do_delete (fuse_req_t, fuse_ino_t, char const *);
|
static void do_delete (fuse_req_t, fuse_ino_t, char const *);
|
||||||
static void do_readdir (fuse_req_t, fuse_ino_t, size_t, off_t, uint32_t,
|
static void do_readdir (fuse_req_t, fuse_ino_t, size_t, off_t, uint32_t,
|
||||||
struct fuse_file_info const *);
|
struct fuse_file_info const *);
|
||||||
|
@ -798,7 +797,7 @@ bm_open (
|
||||||
// We choose to silently ignore O_TRUNC.
|
// We choose to silently ignore O_TRUNC.
|
||||||
if ((flags & O_ACCMODE) != O_RDONLY) {
|
if ((flags & O_ACCMODE) != O_RDONLY) {
|
||||||
fh->data_len = 0;
|
fh->data_len = 0;
|
||||||
current_time(&fh->mtime);
|
xgetrealtime(&fh->mtime);
|
||||||
fh->flags |= FH_FLAG_DIRTY;
|
fh->flags |= FH_FLAG_DIRTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1091,9 +1090,7 @@ bm_setattr (
|
||||||
memset(fh->buf + fh->data_len, 0, new_len - fh->data_len);
|
memset(fh->buf + fh->data_len, 0, new_len - fh->data_len);
|
||||||
}
|
}
|
||||||
fh->data_len = new_len;
|
fh->data_len = new_len;
|
||||||
if (unlikely(0 != current_time(&fh->mtime))) {
|
xgetrealtime(&fh->mtime);
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
fh->flags |= FH_FLAG_DIRTY;
|
fh->flags |= FH_FLAG_DIRTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1104,9 +1101,7 @@ bm_setattr (
|
||||||
|
|
||||||
struct timespec ts = { .tv_nsec = UTIME_OMIT };
|
struct timespec ts = { .tv_nsec = UTIME_OMIT };
|
||||||
if (mask & TO_SET(ATIME_NOW, MTIME_NOW)) {
|
if (mask & TO_SET(ATIME_NOW, MTIME_NOW)) {
|
||||||
if (unlikely(0 != current_time(&ts))) {
|
xgetrealtime(&ts);
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timespec times[] = { ts, ts };
|
struct timespec times[] = { ts, ts };
|
||||||
|
@ -1195,9 +1190,7 @@ bm_write (
|
||||||
fh->data_len = req_off_max;
|
fh->data_len = req_off_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(0 != current_time(&fh->mtime))) {
|
xgetrealtime(&fh->mtime);
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
// We're tempted to free the cookie here, however,
|
// We're tempted to free the cookie here, however,
|
||||||
// that would make a read following a writeback always realloc the buffer.
|
// that would make a read following a writeback always realloc the buffer.
|
||||||
fh->flags |= FH_FLAG_DIRTY;
|
fh->flags |= FH_FLAG_DIRTY;
|
||||||
|
@ -1205,17 +1198,6 @@ bm_write (
|
||||||
return send_reply(write, req, req_buf_len);
|
return send_reply(write, req, req_buf_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
current_time (
|
|
||||||
struct timespec *ts
|
|
||||||
) {
|
|
||||||
if (unlikely(0 != clock_gettime(CLOCK_REALTIME, ts))) {
|
|
||||||
log_printf("clock_gettime(): %s", xstrerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_delete (
|
do_delete (
|
||||||
fuse_req_t req,
|
fuse_req_t req,
|
||||||
|
|
10
src/xstd.c
10
src/xstd.c
|
@ -86,6 +86,16 @@ xfsync (
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xgetrealtime (
|
||||||
|
struct timespec *ts
|
||||||
|
) {
|
||||||
|
if (0 != clock_gettime(CLOCK_REALTIME, ts)) {
|
||||||
|
log_printf("clock_gettime(): %s", xstrerror(errno));
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
xmalloc (
|
xmalloc (
|
||||||
size_t size
|
size_t size
|
||||||
|
|
10
src/xstd.h
10
src/xstd.h
|
@ -24,6 +24,7 @@
|
||||||
#define BOOKMARKFS_XSTD_H_
|
#define BOOKMARKFS_XSTD_H_
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
|
@ -119,6 +120,15 @@ xfsync (
|
||||||
int fd
|
int fd
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like clock_gettime(CLOCK_REALTIME, ts), but aborts on error.
|
||||||
|
*/
|
||||||
|
BOOKMARKFS_INTERNAL
|
||||||
|
void
|
||||||
|
xgetrealtime (
|
||||||
|
struct timespec *ts
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like malloc(), but never returns NULL.
|
* Like malloc(), but never returns NULL.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue