compat_ptr_ioctl(9)
π compat_ptr_ioctl(9) β like, the Kernel API Manual, but make it cute β¨
okay so bestie, welcome to the compat_ptr_ioctl page from the Kernel API Manual π this one's short but she's important, so grab your little iced coffee and let's get into it π
πΈ NAME πΈ
compat_ptr_ioctl β the generic implementation of the .compat_ioctl file operation. that's it, that's the whole vibe β¨
π¦ SYNOPSIS π¦
long compat_ptr_ioctl (struct file *file , unsigned int cmd , unsigned long arg );
like, here's her whole signature, no cap π
π ARGUMENTS π
fileβ the file you're operating on. the main character of this whole story, literally π«Άcmdβ the ioctl command number. yes, the number. keep track of it bestie π’argβ the argument to the ioctl. whatever you're passing in, this is it π
π₯ DESCRIPTION π₯
okay so hear me out, this one is not normally called as a function. it's not that kind of girl. instead, you set it in struct file_operations like this:
.compat_ioctl = compat_ptr_ioctl,
iconic, right? one line and you're done π«
On most architectures, compat_ptr_ioctl literally just passes all the arguments straight through to the corresponding ->ioctl handler. no drama, no extra steps, just vibes π
The exception β and yes there's always an exception β is arch/s390, where compat_ptr clears the top bit of a 32-bit pointer value. so user space pointers to the second 2GB end up aliasing the first 2GB, exactly like it works for native 32-bit s390 user space. that's just how s390 does it, we don't make the rules π€·ββοΈ
Because of all that, compat_ptr_ioctl must therefore be used only with ioctl functions that either ignore the argument entirely, or pass a pointer to a compatible data type. don't be out here using it for anything else, please, i'm begging π
and now the serious part, bestie, pay attention π if any ioctl command handled byfops->unlocked_ioctlpasses a plain integer instead of a pointer, or if any of the passed data types is incompatible between 32-bit and 64-bit architectures, then a proper handler is required instead ofcompat_ptr_ioctl. like, an actual real one. not this shortcut. periodt β
π§ SEE ALSO π§
- Kernel file
./fs/ioctl.cβvfs_ioctl(9) fiemap_fill_next_extent(9)fiemap_prep(9)
go read those too, iykyk πβ¨
aaaand that's the page!! π
cute little sign-off for you: this one lives in ./fs, dated October 2026 β so it's giving future-file energy, and honestly? obsessed ππ¦
bye bestie, go forth and handle your ioctls responsibly π π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms