namespace kafs {
namespace afs {
+class opr_time;
constexpr unsigned int FS_PORT = 7000; /* AFS file server port */
constexpr unsigned int FS_SERVICE = 1; /* AFS File Service ID */
}
service_yfs,
};
+class Time {
+ struct timespec ts;
+ bool has_nsecs;
+public:
+ Time() {
+ ts.tv_sec = 0;
+ ts.tv_nsec = 0;
+ has_nsecs = false;
+ }
+ Time(time_t t) {
+ ts.tv_sec = t;
+ ts.tv_nsec = 0;
+ has_nsecs = false;
+ }
+ Time(const kafs::afs::opr_time &t);
+ inline time_t seconds() const { return ts.tv_sec; }
+};
+
class Context : public rxrpc::refcount {
public:
rxrpc::ref<rxrpc::Endpoint> endpoint;
--- /dev/null
+/* Miscellaneous routines.
+ *
+ * Copyright (C) 2020 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include "kafs.H"
+#include "afs_xg.H"
+
+/*
+ * Convert a signed 100ns-resolution 64-bit time into a kafs time.
+ */
+kafs::Time::Time(const kafs::afs::opr_time &yt)
+{
+ unsigned long long abs_t, div, rem, t = yt.time;
+
+ /*
+ * Unfortunately can not use normal 64 bit division on 32 bit arch, but
+ * the alternative, do_div, does not work with negative numbers so have
+ * to special case them
+ */
+ if (t < 0) {
+ abs_t = -t;
+ div = abs_t / 10000000;
+ rem = abs_t % 10000000;
+ ts.tv_sec = -(div * 100);
+ ts.tv_nsec = rem;
+ } else {
+ abs_t = t;
+ div = abs_t / 10000000;
+ rem = abs_t % 10000000;
+ ts.tv_sec = div * 100;
+ ts.tv_nsec = rem;
+ }
+
+ has_nsecs = true;
+}
+