field_prep(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… field_prep(9) β€” Kernel API Manual ✨

okay bestie, welcome to field_prep(9) β€” it lives in the Kernel API Manual and it's genuinely one of the sweetest little helpers in the whole bitfield family. let me put you on 🫢


🌸 NAME 🌸

field_prep β€” prepare a bitfield element

lowkey does exactly what it says on the tin: it gets a field ready. no cap.


✨ SYNOPSIS ✨

field_prep (mask , val );

that's it. two things in, one gorgeous masked-and-shifted thing out. iconic.


πŸŽ€ ARGUMENTS πŸŽ€

  • mask β€” the shifted mask that defines the field's length and its position. and bestie, listen: it must be non-zero. fr fr, zero is not the vibe here. πŸ’€
  • val β€” the value you wanna put in the field. your main character value, if you will. πŸ‘‘

πŸ¦‹ RETURN πŸ¦‹

the field value, masked and shifted all the way to its final destination. it's giving "packed and ready to ship". ✈️


πŸ’– DESCRIPTION πŸ’–

so here's the tea: field_prep masks the value and shifts it up. that's the whole move. ✨

then β€” and this is the important part β€” the result should be combined with the other fields of the bitfield using logical OR. think of it like assembling your fit: each piece gets its own spot, then you OR them all together. πŸ”₯

now, the difference from FIELD_PREP (iykyk): with field_prep, mask is not limited to a compile-time constant. she's flexible. πŸ’… typical usage patterns are:

  • a value that's stored in a table πŸ“‹
  • a value calculated by shifting a constant by a variable number of bits πŸŒ€
but if you do want to make sure mask is a compile-time constant, please use FIELD_PREP directly instead. bestie, don't fight it β€” just call the right function. πŸ™ˆ

🌈 SEE ALSO 🌈

Kernel file ./include/linux/bitfield.h, plus the whole squad:

go read them, they all ate. πŸ‘‘


and that's the whole page, bestie β€” no crumbs left. this one lives in ./include/linux and was stamped October 2026 ⭐, so go forth and prep those fields. mwah πŸ’‹πŸ§šβ€β™€οΈ

πŸ“¦ where this page comes from