compat_ptr_ioctl(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 by fops->unlocked_ioctl passes 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 of compat_ptr_ioctl. like, an actual real one. not this shortcut. periodt βœ‹

🧚 SEE ALSO 🧚

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