On Fri, Nov 1, 2024 at 2:46 PM Zhaoming Luo <zhaoming1...@qq.com> wrote:
> diff --git a/hurd/pioctl.defs b/hurd/pioctl.defs
> new file mode 100644
> index 00000000..36fa8d3f
> --- /dev/null
> +++ b/hurd/pioctl.defs
> @@ -0,0 +1,34 @@
> +/* Definitions for /dev/rtc ioctls */
> +
> +/* Ioctl group 'p'; the subsystem is derived from calculations in
> +   hurd/ioctls.defs. */
> +subsystem pioctl 140000;
> +
> +#include <hurd/ioctl_types.defs>
> +
> +import "rtc.h";

This would only work when the generated C file is built in the rtc/ of
the Hurd source tree, right? Perhaps this should be <hurd/rtc/rtc.h>?

Do I understand it right that pioctl.defs *is* supposed to be
installed onto the target machine (in some sort of hurd-dev package),
as opposed to being a private implementation detail of the RTC server?

> +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;
> +}

Ack, the demuxer looks good.

> +
> +int
> +main (int argc, char **argv)
> +{
> +  error_t err;
> +  mach_port_t bootstrap;
> +
> +  mach_port_allocate (mach_task_self (),
> +                     MACH_PORT_RIGHT_RECEIVE, &fsys_identity);

I don't think you need this (nor the global variable) for anything.
libtrivfs already makes a fsys_id port that it uses in
trivfs_S_io_identity.

> +  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)
> +    return -1;

Rather, error (1, err, "trivfs_startup failed"). You can pick a
different exit code from 1, of course, but -1 is not a great code to
return from main.

> diff --git a/rtc/mig-mutate.h b/rtc/mig-mutate.h
> new file mode 100644
> index 00000000..e69de29b

You'd want to put something like the following into this file:

#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 IO_IMPORTS import "libtrivfs/mig-decls.h";

...and change 'io_t reqport' arguments in pioctl-ops.c to 'struct
trivfs_protid *cred'.

> diff --git a/rtc/pioctl-ops.c b/rtc/pioctl-ops.c
> new file mode 100644
> index 00000000..02f4c65f
> --- /dev/null
> +++ b/rtc/pioctl-ops.c
> @@ -0,0 +1,17 @@
> +#include "rtc_pioctl_S.h"
> +#include "rtc.h"
> +#include <hurd/hurd_types.h>
> +
> +/* 9 RTC_RD_TIME -- Read RTC time*/
> +kern_return_t
> +rtc_S_pioctl_rtc_rd_time (io_t reqport, struct rtc_time * time)
> +{
> +  return KERN_SUCCESS;
> +}

So this should start by doing something like:

if (!cred)
  return EOPNOTSUPP;
if (!(cred->po->openmodes & O_READ))
  return EBADF;

> +
> +/* 10 RTC_SET_TIME -- Set RTC time*/
> +kern_return_t
> +rtc_S_pioctl_rtc_set_time (io_t reqport, struct rtc_time time)
> +{
> +  return KERN_SUCCESS;
> +}

and this would check for O_WRITE then.

Sergey

Reply via email to