getbsize(3bsd)

πŸ“¦
version 0.12.2 Β· 2 versions
  • 0.12.2 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.11.5 Β· ubuntu jammy
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ getbsize β€” get preferred block size ✨

okay bestie, so we're in getbsize(3bsd) territory, a lil LOCAL page from the BSD world, and honestly? it's giving "quiet utility that runs the whole vibe." let's get into it πŸ’…


🌸 LIBRARY 🌸

Utility functions from BSD systems β€” that's libbsd, link it with -lbsd. 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <stdlib.h>
(See libbsd(7) for include usage.)

char *
getbsize(int *headerlenp, long *blocksizep);
heads up bestie: peep libbsd(7) for the whole include-usage situation, it's a whole thing.

πŸ‘‘ DESCRIPTION πŸ‘‘

so getbsize() hands you back a preferred block size β€” the number that system utilities like df(1), du(1), ls(1) and systat(1) use when they're reporting stuff to you. and where does it get that number? from the BLOCKSIZE environment variable, no cap. ✨

and BLOCKSIZE can be written a few different ways:

  • straight up in bytes, just a plain number πŸ“
  • in multiples of a kilobyte β€” number followed by K or k
  • in multiples of a megabyte β€” number followed by M or m
  • in multiples of a gigabyte β€” number followed by G or g
⚠️ the multiples must be integers. no decimals, no fractions, don't try it bestie. 🫠

now, the valid range for BLOCKSIZE is 512 bytes all the way up to 1 gigabyte. and here's the dramatic part:

  • sizes less than 512 bytes get rounded up to 512 bytes ⬆️
  • sizes greater than 1 GB get rounded down to 1 GB ⬇️

and in each of those cases, getbsize() produces a warning message. so like… it'll still work, but it's gonna tell you about it. periodt. πŸ’€


πŸŽ€ what you actually get back πŸŽ€

getbsize() returns a pointer to a null-terminated string describing the block size β€” something like β€œ1K-blocks”. iconic lil label tbh. ✨

and then:

  • the memory that headerlenp points at gets filled in with the length of that string β€” and no, the terminating null does not count, we're not counting that bestie πŸ™ˆ
  • the memory that blocksizep points at gets filled in with the block size, in bytes

so like, one pointer gives you the pretty string, the other gives you the actual number. both. at once. main character energy fr fr. πŸ‘‘


πŸ’– SEE ALSO πŸ’–


🌈 HISTORY 🌈

getbsize() first appeared in 4.4BSD. an OG, a legend, a founding mother of block sizes. πŸ’œ


and that's the whole page bestie, you ate it πŸ’…βœ¨ this lil slice of Debian-flavored BSD goodness is dated November 16, 2012, and yeah the footer is literally just Debian and getbsize(3bsd) β€” so consider yourself signed off on, mwah πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from