#include "vfs.h"
#include <vfscore/fs.h>
+#include <uk/posix-time.h>
+
extern struct task *main_task;
static int
/*
* Convert a timeval struct to a timespec one.
*/
-static void convert_timeval(struct timespec *to, const struct timeval *from)
+static int convert_timeval(struct timespec *to, const struct timeval *from)
{
if (from) {
to->tv_sec = from->tv_sec;
to->tv_nsec = from->tv_usec * 1000; // Convert microseconds to nanoseconds
- } else {
- clock_gettime(CLOCK_REALTIME, to);
+ return 0;
}
+
+ return uk_sys_clock_gettime(CLOCK_REALTIME, to);
}
int
return EINVAL;
// Convert each element of timeval array to the timespec type
- convert_timeval(×pec_times[0], times ? times + 0 : NULL);
- convert_timeval(×pec_times[1], times ? times + 1 : NULL);
+ error = convert_timeval(×pec_times[0], times ? times + 0 : NULL);
+ if (unlikely(error)) {
+ /*
+ * convert_timeval calls clock_gettime which should not have
+ * positive return values so do a sanity check here in the
+ * error case instead of having it in the success path as
+ * well.
+ */
+ UK_ASSERT(error < 0);
+ /*
+ * However, at the end, this function returns positive
+ * error values.
+ */
+ return -error;
+ }
+
+ error = convert_timeval(×pec_times[1], times ? times + 1 : NULL);
+ if (unlikely(error)) {
+ UK_ASSERT(error < 0);
+ return -error;
+ }
if (flags & AT_SYMLINK_NOFOLLOW) {
struct dentry *ddp;
time->tv_nsec == UTIME_OMIT);
}
-static void timespec_init(struct timespec *out, const struct timespec *in)
+static int timespec_init(struct timespec *out, const struct timespec *in)
{
- if (in == NULL || in->tv_nsec == UTIME_NOW) {
- clock_gettime(CLOCK_REALTIME, out);
- } else {
- out->tv_sec = in->tv_sec;
- out->tv_nsec = in->tv_nsec;
- }
+ if (in == NULL || in->tv_nsec == UTIME_NOW)
+ return uk_sys_clock_gettime(CLOCK_REALTIME, out);
+
+ out->tv_sec = in->tv_sec;
+ out->tv_nsec = in->tv_nsec;
+
+ return 0;
}
int
!timespec_is_valid(×[1])))
return EINVAL;
- timespec_init(×pec_times[0], times + 0);
- timespec_init(×pec_times[1], times + 1);
+ error = timespec_init(×pec_times[0], times + 0);
+ if (unlikely(error)) {
+ /*
+ * timespec_init calls clock_gettime which should not
+ * have positive return values so do a sanity check
+ * here in the error case instead of having it in the
+ * success path as well.
+ */
+ UK_ASSERT(error < 0);
+ /*
+ * However, at the end, this function returns positive
+ * error values.
+ */
+ return -error;
+ }
+
+ error = timespec_init(×pec_times[1], times + 1);
+ if (unlikely(error)) {
+ UK_ASSERT(error < 0);
+ return -error;
+ }
} else {
- timespec_init(×pec_times[0], NULL);
- timespec_init(×pec_times[1], NULL);
+ error = timespec_init(×pec_times[0], NULL);
+ if (unlikely(error)) {
+ UK_ASSERT(error < 0);
+ return -error;
+ }
+
+ error = timespec_init(×pec_times[1], NULL);
+ if (unlikely(error)) {
+ UK_ASSERT(error < 0);
+ return -error;
+ }
}
/* utimensat should return ENOENT when pathname is empty */