ioctl

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: ioctl

Post by Love4Boobies »

Two important things that I haven't seen mentioned here:
  • ioctl is actually only defined for STREAMS. It's much less general than people usually think.
  • The STREAMS interface is being deprecated.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: ioctl

Post by Combuster »

Not in those words, but still:
I wrote:Since all the official posix things ioctl was meant to do is pretty much useless, any meaningful use of ioctl you will be seeing in practice is just nonportable code talking to (linux-)specific interfaces
:wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: ioctl

Post by Brynet-Inc »

Regardless of inevitable deprecation by standards bodies, ioctl() won't be disappearing any time soon.

The DRM (Direct Rendering Manager) interface is one API using ioctl that is widely implemented on both BSD, Linux and other Unix systems.. IMHO, it is more portable then some other monstrosities, such as "/sys or /proc".

On BSD, several drivers or "pseudo-devices" expose an ioctl() interface, it is handy for potentially unportable things like power management, network configuration, manipulating ttys (init/getty/shells/terminal emulators).. or even controlling ones tape drives. :-)

Userland programs can use preprocessor directives and/or return values/errno for dealing with OS-specific backends, but for system utilities that are inherently unportable, it may not even matter.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: ioctl

Post by Brynet-Inc »

Love4Boobies wrote:Two important things that I haven't seen mentioned here:
  • ioctl is actually only defined for STREAMS. It's much less general than people usually think.
  • The STREAMS interface is being deprecated.
V7 Unix introduced ioctl() as a general device control interface, and it was adopted by BSD developers (..in reality, everybody) for that purpose.

The STREAMS ioctl specified in POSIX was optional and implemented by precisely nobody.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: ioctl

Post by Love4Boobies »

Well, that is a bit of an exaggeration but STREAMS was indeed never popular (because of BSD sockets, etc.), which is why it is obsolescent, even if it is interesting. The point I was trying to make is the same one Combuster had made in a previous post (that I originally missed): Many people use the same name, ioctl, for many different routines. Talking about the portability of a non-POSIX ioctl makes as much sense as talking about the portability of kmain.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: ioctl

Post by Brynet-Inc »

Love4Boobies wrote:Well, that is a bit of an exaggeration but STREAMS was indeed never popular (because of BSD sockets, etc.), which is why it is obsolescent, even if it is interesting. The point I was trying to make is the same one Combuster had made in a previous post (that I originally missed): Many people use the same name, ioctl, for many different routines. Talking about the portability of a non-POSIX ioctl makes as much sense as talking about the portability of kmain.
But it was specified, just not by POSIX.. it was specified in V7 Unix, it was in specified 2BSD/4BSD, and even Linux. There are many such examples of de facto standards in the wild that are looked upon favourably, like BSD's glob() or OpenBSD's strlcpy/strlcat().

I'm not saying that ioctl() requests are portable, but the semantics of the interface is perhaps.. by consensus.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: ioctl

Post by Combuster »

Well then, by that argument, everybody should use system(), because it's C89+ and POSIX, and therefore even more portable. :evil:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: ioctl

Post by Brynet-Inc »

Combuster wrote:Well then, by that argument, everybody should use system(), because it's C89+ and POSIX, and therefore even more portable. :evil:
Well, you've convinced me. I guess I'll stop using exec*(). :wink:
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: ioctl

Post by Love4Boobies »

No one talked about not using things---only about not being able to using them portably. That said, you can use both system and exec quite portably in an UNIX environment, as long as the code on the other side is cross-platform. There is no equivalent option for ioctl.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply