packing(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– packing(9) πŸ’–

okay so welcome to the Kernel API Manual, bestie β€” section 9, the packing page. This one is lowkey a translator between number formats, and we're gonna get you through it. πŸ’…

✨ NAME ✨

packing β€” converts numbers (currently u64) between a packed and an unpacked format. Unpacked means laid out in memory in the CPU's native understanding of integers, while packed means anything else that requires translation. That's the whole vibe check: native layout vs. needs-translation layout. πŸ¦‹

πŸŽ€ SYNOPSIS πŸŽ€

int packing (void *pbuf , u64 *uval , int startbit , int endbit , size_t pbuflen , enum packing_op op , u8 quirks );

πŸ’… ARGUMENTS πŸ’…

  • pbuf β€” pointer to a buffer holding the packed value. That's where the packed bits live.
  • uval β€” pointer to an u64 holding the unpacked value. That's the native-layout number.
  • startbit β€” the index (in logical notation, compensated for quirks) where the packed value starts within pbuf. It must be larger than, or equal to, endbit. Bestie, respect the order. 🫢
  • endbit β€” the index (in logical notation, compensated for quirks) where the packed value ends within pbuf. It must be smaller than, or equal to, startbit. Yep, same relationship, other side.
  • pbuflen β€” the length in bytes of the packed buffer pointed to by pbuf. It's giving "know your buffer size." πŸ“
  • op β€” if PACK, then uval will be treated as const pointer and copied (packed) into pbuf, between startbit and endbit. If UNPACK, then pbuf will be treated as const pointer and the logical value between startbit and endbit will be copied (unpacked) to uval. Two directions, one enum, no cap. πŸ”
  • quirks β€” a bit mask of QUIRK_LITTLE_ENDIAN, QUIRK_LSW32_IS_FIRST and QUIRK_MSB_ON_THE_RIGHT. These are the little endian/bit-order gremlins and you gotta name them. 🧚

⚠️ NOTE ⚠️

this is deprecated, prefer to use pack or unpack in new code.

No cap, deprecated means deprecated. If you're writing new code, use pack or unpack, not this. 😭

πŸ”₯ RETURN πŸ”₯

0 on success, EINVAL or ERANGE if called incorrectly. Assuming correct usage, return code may be discarded. If op is PACK, pbuf is modified. If op is UNPACK, uval is modified.

So: success is 0; bad calls get EINVAL or ERANGE; and if you're using it correctly, you can discard the return code. Also heads up: PACK mutates pbuf, UNPACK mutates uval. Main character mutation energy. πŸ‘‘

🌈 SEE ALSO 🌈

Kernel file ./lib/packing.c, plus calculate_box_addr(9), pack(9), unpack(9), pack_fields_u8(9), pack_fields_u16(9), unpack_fields_u8(9), unpack_fields_u16(9). Go read those next, bestie. πŸ’–


and that's the page, bestie β€” brought to you by the Kernel API Manual, source/version ./lib, dated October 2026. packing(9) out. πŸŽ€πŸ’…βœ¨

πŸ“¦ where this page comes from