From 13ace061fa119d8df11791cc889e3d280464b08e Mon Sep 17 00:00:00 2001 From: Richard Curnow Date: Wed, 6 Jul 2005 22:49:13 +0000 Subject: [PATCH] Further fixes to avoid use of linux kernel header files --- chrony_timex.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++ io_linux.h | 70 ++++++++++++++++++++++++------------------------- wrap_adjtimex.c | 9 +------ 3 files changed, 102 insertions(+), 43 deletions(-) create mode 100644 chrony_timex.h diff --git a/chrony_timex.h b/chrony_timex.h new file mode 100644 index 0000000..348d01f --- /dev/null +++ b/chrony_timex.h @@ -0,0 +1,66 @@ +/* Taken from /usr/include/linux/timex.h. Avoids the need to + * include kernel header files. */ + +#ifndef CHRONY_TIMEX_H +#define CHRONY_TIMEX_H + +#include + +struct timex { + unsigned int modes; /* mode selector */ + long offset; /* time offset (usec) */ + long freq; /* frequency offset (scaled ppm) */ + long maxerror; /* maximum error (usec) */ + long esterror; /* estimated error (usec) */ + int status; /* clock command/status */ + long constant; /* pll time constant */ + long precision; /* clock precision (usec) (read only) */ + long tolerance; /* clock frequency tolerance (ppm) + * (read only) + */ + struct timeval time; /* (read only) */ + long tick; /* (modified) usecs between clock ticks */ + + long ppsfreq; /* pps frequency (scaled ppm) (ro) */ + long jitter; /* pps jitter (us) (ro) */ + int shift; /* interval duration (s) (shift) (ro) */ + long stabil; /* pps stability (scaled ppm) (ro) */ + long jitcnt; /* jitter limit exceeded (ro) */ + long calcnt; /* calibration intervals (ro) */ + long errcnt; /* calibration errors (ro) */ + long stbcnt; /* stability limit exceeded (ro) */ + + int :32; int :32; int :32; int :32; + int :32; int :32; int :32; int :32; + int :32; int :32; int :32; int :32; +}; + +#define ADJ_FREQUENCY 0x0002 /* frequency offset */ +#define ADJ_STATUS 0x0010 /* clock status */ +#define ADJ_TICK 0x4000 /* tick value */ +#define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */ + +#define SHIFT_USEC 16 /* frequency offset scale (shift) */ + +#define STA_PLL 0x0001 /* enable PLL updates (rw) */ +#define STA_PPSFREQ 0x0002 /* enable PPS freq discipline (rw) */ +#define STA_PPSTIME 0x0004 /* enable PPS time discipline (rw) */ +#define STA_FLL 0x0008 /* select frequency-lock mode (rw) */ + +#define STA_INS 0x0010 /* insert leap (rw) */ +#define STA_DEL 0x0020 /* delete leap (rw) */ +#define STA_UNSYNC 0x0040 /* clock unsynchronized (rw) */ +#define STA_FREQHOLD 0x0080 /* hold frequency (rw) */ + +#define STA_PPSSIGNAL 0x0100 /* PPS signal present (ro) */ +#define STA_PPSJITTER 0x0200 /* PPS signal jitter exceeded (ro) */ +#define STA_PPSWANDER 0x0400 /* PPS signal wander exceeded (ro) */ +#define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */ + +#define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */ + +/* This doesn't seem to be in any include files !! */ + +extern int adjtimex(struct timex *); + +#endif /* CHRONY_TIMEX_H */ diff --git a/io_linux.h b/io_linux.h index f6f1a93..c6f6f30 100644 --- a/io_linux.h +++ b/io_linux.h @@ -7,54 +7,54 @@ /* Hmm. These constants vary a bit between systems. */ /* (__sh__ includes both sh and sh64) */ #if defined(__i386__) || defined(__sh__) -#define _IOC_NRBITS 8 -#define _IOC_TYPEBITS 8 -#define _IOC_SIZEBITS 14 -#define _IOC_DIRBITS 2 +#define CHRONY_IOC_NRBITS 8 +#define CHRONY_IOC_TYPEBITS 8 +#define CHRONY_IOC_SIZEBITS 14 +#define CHRONY_IOC_DIRBITS 2 -#define _IOC_NONE 0U -#define _IOC_WRITE 1U -#define _IOC_READ 2U +#define CHRONY_IOC_NONE 0U +#define CHRONY_IOC_WRITE 1U +#define CHRONY_IOC_READ 2U #elif defined(__alpha__) || defined(__sparc__) -#define _IOC_NRBITS 8 -#define _IOC_TYPEBITS 8 -#define _IOC_SIZEBITS 13 -#define _IOC_DIRBITS 2 +#define CHRONY_IOC_NRBITS 8 +#define CHRONY_IOC_TYPEBITS 8 +#define CHRONY_IOC_SIZEBITS 13 +#define CHRONY_IOC_DIRBITS 2 -#define _IOC_NONE 1U -#define _IOC_READ 2U -#define _IOC_WRITE 4U +#define CHRONY_IOC_NONE 1U +#define CHRONY_IOC_READ 2U +#define CHRONY_IOC_WRITE 4U #else #error "I don't know the values of the _IOC_* constants for your architecture" #endif -#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) -#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) -#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) -#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) +#define CHRONY_IOC_NRMASK ((1 << CHRONY_IOC_NRBITS)-1) +#define CHRONY_IOC_TYPEMASK ((1 << CHRONY_IOC_TYPEBITS)-1) +#define CHRONY_IOC_SIZEMASK ((1 << CHRONY_IOC_SIZEBITS)-1) +#define CHRONY_IOC_DIRMASK ((1 << CHRONY_IOC_DIRBITS)-1) -#define _IOC_NRSHIFT 0 -#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) -#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) -#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) +#define CHRONY_IOC_NRSHIFT 0 +#define CHRONY_IOC_TYPESHIFT (CHRONY_IOC_NRSHIFT+CHRONY_IOC_NRBITS) +#define CHRONY_IOC_SIZESHIFT (CHRONY_IOC_TYPESHIFT+CHRONY_IOC_TYPEBITS) +#define CHRONY_IOC_DIRSHIFT (CHRONY_IOC_SIZESHIFT+CHRONY_IOC_SIZEBITS) -#define _IOC(dir,type,nr,size) \ - (((dir) << _IOC_DIRSHIFT) | \ - ((type) << _IOC_TYPESHIFT) | \ - ((nr) << _IOC_NRSHIFT) | \ - ((size) << _IOC_SIZESHIFT)) +#define CHRONY_IOC(dir,type,nr,size) \ + (((dir) << CHRONY_IOC_DIRSHIFT) | \ + ((type) << CHRONY_IOC_TYPESHIFT) | \ + ((nr) << CHRONY_IOC_NRSHIFT) | \ + ((size) << CHRONY_IOC_SIZESHIFT)) /* used to create numbers */ -#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) -#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) -#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) -#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size)) +#define CHRONY_IO(type,nr) CHRONY_IOC(CHRONY_IOC_NONE,(type),(nr),0) +#define CHRONY_IOR(type,nr,size) CHRONY_IOC(CHRONY_IOC_READ,(type),(nr),sizeof(size)) +#define CHRONY_IOW(type,nr,size) CHRONY_IOC(CHRONY_IOC_WRITE,(type),(nr),sizeof(size)) +#define CHRONY_IOWR(type,nr,size) CHRONY_IOC(CHRONY_IOC_READ|CHRONY_IOC_WRITE,(type),(nr),sizeof(size)) -#define RTC_UIE_ON _IO('p', 0x03) /* Update int. enable on */ -#define RTC_UIE_OFF _IO('p', 0x04) /* ... off */ +#define RTC_UIE_ON CHRONY_IO('p', 0x03) /* Update int. enable on */ +#define RTC_UIE_OFF CHRONY_IO('p', 0x04) /* ... off */ -#define RTC_RD_TIME _IOR('p', 0x09, struct rtc_time) /* Read RTC time */ -#define RTC_SET_TIME _IOW('p', 0x0a, struct rtc_time) /* Set RTC time */ +#define RTC_RD_TIME CHRONY_IOR('p', 0x09, struct rtc_time) /* Read RTC time */ +#define RTC_SET_TIME CHRONY_IOW('p', 0x0a, struct rtc_time) /* Set RTC time */ /* From mc146818.h */ #define RTC_UIE 0x10 /* update-finished interrupt enable */ diff --git a/wrap_adjtimex.c b/wrap_adjtimex.c index 8d97f50..9571ec4 100644 --- a/wrap_adjtimex.c +++ b/wrap_adjtimex.c @@ -36,16 +36,9 @@ #define _LOOSE_KERNEL_NAMES -#include -#include -#include - +#include "chrony_timex.h" #include "wrap_adjtimex.h" -/* This doesn't seem to be in any include files !! */ - -extern int adjtimex(struct timex *); - int TMX_SetTick(long tick) {