CTOD(9)

πŸ“¦ version 11.0, in nixpkgs unstable

✨ NAME ✨

ctod β€” macros related to bytes, pages, and disk blocks. okay bestie, this is the ctod(9) page from the Kernel Developer’s Manual, and it’s lowkey your cheat sheet for all those conversions πŸ’…

🌸 SYNOPSIS 🌸

#include <sys/param.h>

size
ctod(size x);

size
dtoc(size x);

size
ctob(size x);

size
btoc(size x);

size
dbtob(size x);

size
btodb(size x);

πŸ¦‹ DESCRIPTION πŸ¦‹

The ctod family of macros can be used to convert between bytes, pages (β€œclicks”), and disk blocks. yes, pages are literally nicknamed β€œclicks” here β€” iykyk ✨

The possible conversions are giving a whole map, bestie β€” no cap, every single one:

  • ctod() β€” from pages to disk blocks
  • dtoc() β€” from disk blocks to pages
  • ctob() β€” from pages to bytes
  • btoc() β€” from bytes to pages
  • dbtob() β€” from disk blocks to bytes
  • btodb() β€” from bytes to disk blocks

These are typical macros that may appear with different names in other operating systems. Examples include btop() and btopr() in Solaris. not me spotting a crossover episode 🌈

πŸ’– SEE ALSO πŸ’–

  • param(3) β€” go peek at this too, bestie 🫢

πŸŽ€ HISTORY πŸŽ€

Some of these macros appeared in Version 7 AT&T UNIX. periodt β€” vintage icon behavior πŸ‘‘

πŸ’€ CAVEATS πŸ’€

bestie, hear me: the described macros make no assumptions about the type of the input parameter. A caller should ensure that neither integer overflow nor integer underflow are possible. fr fr, do your vibe check on the numbers before you send them πŸ’€

πŸ’– that’s the whole page, bestie β€” Debian, April 8, 2011, CTOD(9) signing off! πŸ’–

πŸ“¦ where this page comes from