--- rtc/Makefile | 19 +++++++++++ rtc/main.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ rtc/mig-mutate.h | 4 +++ rtc/pioctl-ops.c | 28 +++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 rtc/Makefile create mode 100644 rtc/main.c create mode 100644 rtc/mig-mutate.h create mode 100644 rtc/pioctl-ops.c
diff --git a/rtc/Makefile b/rtc/Makefile new file mode 100644 index 00000000..dd0e19d2 --- /dev/null +++ b/rtc/Makefile @@ -0,0 +1,19 @@ +dir := rtc +makemode := server + +SRCS = main.c pioctl-ops.c +MIGSRCS = pioctlServer.c + +OBJS = main.o pioctlServer.o pioctl-ops.o + +HURDLIBS = trivfs shouldbeinlibc ports + +target = rtc + +include ../Makeconf + +MIGCOMSFLAGS += -prefix rtc_ +mig-sheader-prefix = rtc_ +pioctl-MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h + +rtc_pioctl_S.h pioctlServer.c: mig-mutate.h diff --git a/rtc/main.c b/rtc/main.c new file mode 100644 index 00000000..114fb497 --- /dev/null +++ b/rtc/main.c @@ -0,0 +1,88 @@ + +#include <version.h> + +#include <error.h> +#include <argp.h> +#include <nullauth.h> +#include <hurd/trivfs.h> +#include <hurd/ports.h> +#include <hurd/rtc.h> + +#include "rtc_pioctl_S.h" + +const char *argp_program_version = STANDARD_HURD_VERSION (rtc); + +struct trivfs_control *rtccntl; + +int trivfs_fstype = FSTYPE_DEV; +int trivfs_fsid = 0; +int trivfs_support_read = 0; +int trivfs_support_write = 0; +int trivfs_support_exec = 0; +int trivfs_allow_open = O_READ | O_WRITE; + +static const struct argp_option options[] = +{ + {0} +}; + +/* TODO: adding option */ +static error_t +parse_opt (int opt, char *arg, struct argp_state *state) +{ + return ARGP_ERR_UNKNOWN; +} + +static const struct argp rtc_argp = +{ options, parse_opt, 0, "RTC device" }; + +int +demuxer (mach_msg_header_t *inp, mach_msg_header_t *outp) +{ + mig_routine_t routine; + if ((routine = rtc_pioctl_server_routine (inp)) || + (routine = NULL, trivfs_demuxer (inp, outp))) + { + if (routine) + (*routine) (inp, outp); + return TRUE; + } + else + return FALSE; +} + +int +main (int argc, char **argv) +{ + error_t err; + mach_port_t bootstrap; + + argp_parse (&rtc_argp, argc, argv, 0, 0, 0); + + task_get_bootstrap_port (mach_task_self (), &bootstrap); + if (bootstrap == MACH_PORT_NULL) + error (1, 0, "Must be started as a translator"); + + /* Reply to our parent */ + err = trivfs_startup (bootstrap, 0, 0, 0, 0, 0, &rtccntl); + mach_port_deallocate (mach_task_self (), bootstrap); + if (err) + error (1, err, "trivfs_startup failed"); + + /* Launch. */ + ports_manage_port_operations_multithread (rtccntl->pi.bucket, demuxer, + 30 * 1000, 2 * 60 * 1000, 0); + + return 0; +} + +void +trivfs_modify_stat (struct trivfs_protid *cred, struct stat *st) +{ +} + +error_t +trivfs_goaway (struct trivfs_control *fsys, int flags) +{ + exit (0); +} diff --git a/rtc/mig-mutate.h b/rtc/mig-mutate.h new file mode 100644 index 00000000..cbf156c7 --- /dev/null +++ b/rtc/mig-mutate.h @@ -0,0 +1,4 @@ +#define IO_INTRAN trivfs_protid_t trivfs_begin_using_protid (io_t) +#define IO_INTRAN_PAYLOAD trivfs_protid_t trivfs_begin_using_protid_payload +#define IO_DESTRUCTOR trivfs_end_using_protid (trivfs_protid_t) +#define PIOCTL_IMPORTS import "../libtrivfs/mig-decls.h"; diff --git a/rtc/pioctl-ops.c b/rtc/pioctl-ops.c new file mode 100644 index 00000000..44038e26 --- /dev/null +++ b/rtc/pioctl-ops.c @@ -0,0 +1,28 @@ +/* Server side implementation for rtc device */ + +/* This implementation is largely based on sys-utils/hwclock from util-linux */ + +#include "rtc_pioctl_S.h" +#include <hurd/rtc.h> +#include <hurd/hurd_types.h> + +/* 9 RTC_RD_TIME -- Read RTC time */ +kern_return_t +rtc_S_pioctl_rtc_rd_time (struct trivfs_protid *cred, struct rtc_time *time) +{ + if (!cred) { + return EOPNOTSUPP; + } + if (!(cred->po->openmodes & O_READ)) + return EBADF; + return KERN_SUCCESS; +} + +/* 10 RTC_SET_TIME -- Set RTC time */ +kern_return_t +rtc_S_pioctl_rtc_set_time (struct trivfs_protid *cred, struct rtc_time time) +{ + if (!(cred->po->openmodes & O_WRITE)) + return EBADF; + return KERN_SUCCESS; +} -- 2.47.0