On Mon, Oct 28, 2024 at 9:35 AM Zhaoming Luo <zhaoming1...@qq.com> wrote: > I see, so _IOR is a wrapper of _IOC for calculating an ioctl number. > This ioctl number is used for invoking the routine in the rtc server. We > need to define _IOT_rtc_time because calculating RTC_RD_TIME requires > the ioctl number of rtc, _IOT_rtc_time (like what's mentioned in > ioctls.h in glibc).
Rather: RTC_RD_TIME *is* the ioctl number. It's a compile-time constant that's #defined'd to an expression (_IOR(...)) that is computed (by the C compiler, at compile time) based on the value of _IOT_rtc_time. This _IOT_rtc_time should be another constant (one that you need to define), namely the iotcl type-encoding of the 'struct rtc_time' type — it should encode that the structure is basically just 9 ints, as Samuel said. User code would just use RTC_RD_TIME as a constant in an ioctl () call without caring about any particular encoding. The glibc ioctl () implementation would look at the RTC_RD_TIME value and understand that it should send an RPC with a particular ID (matching that of the pioctl_rtc_rd_time MIG routine exactly) with no data in the request message, and expect 9 ints in the reply, which it should memcpy out of the reply message into the user-provided buffer (the third argument to the ioctl call). To the user code, this is just like an ioctl () call on e.g. Linux. To the server (and rpctrace etc), it's just a call of the pioctl_rtc_rd_time MIG routine, and indeed on the server side, you can and should use the normal MIG mechanisms to handle it. Do you have a general understanding of how to write the server side of this -- a simple translator using trivfs? trans/hello.c is a basic example of that; please feel free to ask me questions if anything there is unclear. trans/null.c is also fairly simple, and is the actual implementation of /dev/null and /dev/full. Sergey