[PATCH 10/14 v2] xfsprogs: Add a timer implementation for OS X

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



UPDATE:
- Instead of ifndef just call memset to zero the structure universally.

OS X does not have the timer used in xfs_repair.
Add a simple implementation providing the required
capabilities.

Signed-off-by: Jan Tulak <jtulak@xxxxxxxxxx>
---
 include/darwin.h  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 repair/progress.c |  3 +--
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/include/darwin.h b/include/darwin.h
index 1409c91..0d2f175 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -28,6 +28,7 @@
 #include <sys/ioctl.h>
 #include <sys/mount.h>
 #include <sys/types.h>
+#include <sys/time.h>
 #include <ftw.h>
 #include <mach/mach_time.h>
 #include <inttypes.h>
@@ -168,4 +169,51 @@ platform_discard_blocks(int fd, uint64_t start, uint64_t len)
 	return 0;
 }
 
+/*
+ * POSIX timer replacement.
+ * It really just do the minimum we need for xfs_repair.
+ * Also, as setitimer can't create multiple timers,
+ * the timerid things are useless - we have only one ITIMER_REAL
+ * timer.
+ */
+#define CLOCK_REALTIME ITIMER_REAL
+#define itimerspec itimerval
+typedef uint64_t timer_t;
+typedef double   timer_c;
+typedef clock_id_t clockid_t;
+
+
+static inline int timer_create (clockid_t __clock_id,
+                         struct sigevent *__restrict __evp,
+                         timer_t *__restrict timer)
+{
+	// set something, to initialize the variable, just in case
+	*timer = 0;
+	return 0;
+}
+
+static inline int timer_settime (timer_t timerid, int flags,
+                          const struct itimerspec *__restrict timerspec,
+                          struct itimerspec *__restrict ovalue)
+{
+	return setitimer(ITIMER_REAL, timerspec, ovalue);
+}
+
+static inline int timer_delete (timer_t timerid)
+{
+	struct itimerspec timespec;
+
+	timespec.it_interval.tv_sec=0;
+	timespec.it_interval.tv_usec=0;
+	timespec.it_value.tv_sec=0;
+	timespec.it_value.tv_usec=0;
+
+	return setitimer(ITIMER_REAL, &timespec, NULL);
+}
+
+static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
+{
+	return getitimer(ITIMER_REAL, value);
+}
+
 #endif	/* __XFS_DARWIN_H__ */
diff --git a/repair/progress.c b/repair/progress.c
index 27cbaef..418b803 100644
--- a/repair/progress.c
+++ b/repair/progress.c
@@ -183,10 +183,9 @@ progress_rpt_thread (void *p)
 	 * Specify a repeating timer that fires each MSG_INTERVAL seconds.
 	 */
 
+	memset(&timespec, 0, sizeof(timespec));
 	timespec.it_value.tv_sec = msgp->interval;
-	timespec.it_value.tv_nsec = 0;
 	timespec.it_interval.tv_sec = msgp->interval;
-	timespec.it_interval.tv_nsec = 0;
 
 	if (timer_create (CLOCK_REALTIME, NULL, &timerid))
 		do_error(_("progress_rpt: cannot create timer\n"));
-- 
2.5.1

_______________________________________________
xfs mailing list
xfs@xxxxxxxxxxx
http://oss.sgi.com/mailman/listinfo/xfs



[Index of Archives]     [Linux XFS Devel]     [Linux Filesystem Development]     [Filesystem Testing]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux