outb(2)

πŸ’… outb(2) β€” like, the port I/O page, bestie

okay so welcome to outb(2), a page from the System Calls Manual, and it's giving "low-level hardware vibes only." If you've ever wanted your userspace program to talk directly to I/O ports, this is the family of functions for you. Come on, let's get into it. ✨


🌸 NAME 🌸

outb, outw, outl, outsb, outsw, outsl, inb, inw, inl, insb, insw, insl, outb_p, outw_p, outl_p, inb_p, inw_p, inl_p β€” port I/O. that's it, that's the whole vibe. πŸŽ€


🧚 LIBRARY 🧚

Standard C library (libc, -lc). yep, just the regular libc, she's everywhere. πŸ’–


⭐ SYNOPSIS ⭐

#include <sys/io.h>

unsigned char inb(unsigned short port);
unsigned char inb_p(unsigned short port);
unsigned short inw(unsigned short port);
unsigned short inw_p(unsigned short port);
unsigned int inl(unsigned short port);
unsigned int inl_p(unsigned short port);

void outb(unsigned char value, unsigned short port);
void outb_p(unsigned char value, unsigned short port);
void outw(unsigned short value, unsigned short port);
void outw_p(unsigned short value, unsigned short port);
void outl(unsigned int value, unsigned short port);
void outl_p(unsigned int value, unsigned short port);

void insb(unsigned long count;
           unsigned short port, void addr[count],
           unsigned long count);
void insw(unsigned long count;
           unsigned short port, void addr[count],
           unsigned long count);
void insl(unsigned long count;
           unsigned short port, void addr[count],
           unsigned long count);
void outsb(unsigned long count;
           unsigned short port, const void addr[count],
           unsigned long count);
void outsw(unsigned long count;
           unsigned short port, const void addr[count],
           unsigned long count);
void outsl(unsigned long count;
           unsigned short port, const void addr[count],
           unsigned long count);

no cap, that's a lot of function signatures. but dw, they're all basically the same girl in different outfits. 🫢


πŸ’œ DESCRIPTION πŸ’œ

so this whole little family is here to do low-level port input and output. that's the whole job. periodt.

here's the decoder ring, bestie:

  • the out* functions do port output β€” you're writing out to the port πŸ’Œ
  • the in* functions do port input β€” you're reading in from the port πŸ“₯
  • the b-suffix functions are byte-width (one byte, baby)
  • the w-suffix functions are word-width
  • the _p-suffix functions pause until the I/O completes β€” they wait for the vibe check to finish before moving on ⏳

ngl, they're primarily designed for internal kernel use, but they can be used from user space too. main character energy either way. πŸ‘‘

lowkey important: you use ioperm(2) or, alternatively, iopl(2) to tell the kernel to allow the user space application to access the I/O ports in question. and if you don't do this? failure to do this will cause the application to receive a segmentation fault. πŸ’€ like, that's not a maybe, that's a promise. do the ioperm(2) thing. that's the rule. fr fr.

πŸ¦‹ VERSIONS πŸ¦‹

outb() and friends are hardware-specific. read that again, bestie, because there's a plot twist here:

the value argument is passed first, and the port argument is passed second.

that is the opposite order from most DOS implementations. so if you're coming over from DOS and your args feel backwards, they're not backwards, you're just on Linux now. πŸ™ˆ it's giving chaos but it's fine.


🌈 STANDARDS 🌈

Linux (x86, alpha). that's the whole list. iconic. πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘

those two are your besties forever, you literally cannot do the thing without them. 🫢


and that's the page!! this was outb(2) from Linux man-pages 6.20, dated 2026-09-11 β€” mwah, slay, go poke some ports responsibly πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: GPL-2.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms