-
Notifications
You must be signed in to change notification settings - Fork 18k
x/sys/unix: request for Ioctl*Int32 functions #45585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Adding If I remember correctly, |
Sure, will try to whip one up!
I didn't, which is why I suggested them more for symmetry than anything else. Some investigation gives me at least:
which justify I have now realized that I'm not sure |
Relevant discussion: #14873 (https://go-review.googlesource.com/c/sys/+/26650/) @robpike mentioned:
|
I started looking into implementing these, and it turns out that since 0cf1ed9 the Should I open a separate issue to improve docs for this function and/or change its signature? IMO its |
Hmmm... in #46060 a proposal for For my use case, I'm compiling against a 32 bit system, so it's a non-issue and I can safely assure that Maybe we should admit that not exposing the raw ioctl call is a mistake now? I've occasionally fell back to writing a syscall ioctl helper function because this package doesn't expose it && I couldn't find a compatible ioctl function signature. |
The names of the ioctl functions refer to C, so I think it's OK if Ah, I see the problem: the Go type is |
Rather annoyingly we might need four functions: I can see this bloat just continue increasing however. A quick search of github.com/vtolstov/go-ioctl appears to be a "de-facto" ioctl package for when the unix/syscall packages are not enough (it exposes an ioctl function taking in ioctls are a hot mess, and if the goal in this package is to try to support every single type, we'd end up playing catch-up with the ever increasing ioctl mess in the kernel. Adding helpers for the |
Addendum: I dug deeper into kernel code, and I think we'd actually need them for all of
thus basically every Some examples:
|
You don’t actually need both signed and unsigned types as converting between them explicitly keeps the same bit pattern. All the kernel knows is the size of the argument. They might be useful to have for clarity though. |
We arguably shouldn't have any of those: the The C signature of int ioctl(int fd, unsigned long request, ... /* arg */); A typed Go function signature corresponding to that might look like: func IoctlPtr(fd int, request uint, arg unsafe.Pointer) (int, Errno) Since that |
One very relevant usage of
ioctl
functions (at least on Linux) is for querying extended attributes in files. As seen in https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html ,What this means is that the
attr
field inioctl(fd, FS_IOC_GETFLAGS, &attr);
andioctl(fd, FS_IOC_SETFLAGS, &attr);
is always a 32-bit signed integer. This means that using theIoctlGetInt
andIoctlSetPointerInt
functions is wrong for these values, because Go'sint
will be 32-bit or 64-bit, depending on the platform's pointer width. It happens to work on little endian platforms, but it will definitely be wrong on 64-bit big endian platforms (so at least ppc64 and some mips, maybe aarch64be? not sure go supports that).x/sys/unix does provide
IoctlGetUint32
, but that has the wrong sign, unfortunately.There is a workaround, which is using
IoctlGetUint32
and converting to anint32
, and usingIoctlSetInt(fd, req, int(uintptr(unsafe.Pointer(attr)))
instead ofIoctlSetPointerInt
, but these are hardly ergonomic.Therefore, I would suggest providing
IoctlGetInt32
,IoctlSetPointerInt32
andIoctlSetInt32
functions. If homogenous coverage is desirable, a*Uint32
set could be added as well.The text was updated successfully, but these errors were encountered: