PMEM2_SOURCE_ALIGNMENT(3)

✨ pmem2_source_alignment() ✨

okay bestie, so this one's from the PMDK Programmer's Manual (yes, the whole PMDK era, we love her) and it's literally just one little function that tells you how your data source needs to be aligned. no cap. it's giving "small but mighty" πŸ’…


πŸ¦‹ NAME πŸ¦‹

pmem2_source_alignment() β€” returns data source alignment

like, it hands you the alignment. that's the whole job. iconic behavior honestly.


🌸 SYNOPSIS 🌸

#include <libpmem2.h>

struct pmem2_source;
int pmem2_source_alignment(const struct pmem2_source *source, size_t *alignment);

yes you need the header, yes you need a struct pmem2_source forward declaration, it's all there, don't skip it πŸŽ€


πŸ’– DESCRIPTION πŸ’–

okay so listen. the pmem2_source_alignment() function retrieves the alignment of offset and length that you need for pmem2_map_new(3) to actually succeed. like, if you don't align things right, the map call is gonna be upset with you and we don't want that energy 😭

the alignment gets stored in *alignment. that's the out-param, she's the main character here. periodt.


⭐ RETURN VALUE ⭐

pmem2_source_alignment() returns 0 on success. slay. ✨

but if the function fails? then *alignment is left unmodified (so don't go reading it thinking you got something, bestie, you did not) and a negative error code is returned instead. πŸ˜”


πŸ”₯ ERRORS πŸ”₯

pmem2_source_alignment() can fail with the following errors, and ngl some of these are very specific:

  • PMEM2_E_INVALID_ALIGNMENT_VALUE β€” the operating system returned an unexpected alignment value (eg. it is not a power of two). the OS is out here being chaotic, not us πŸ’€
  • PMEM2_E_INVALID_FILE_TYPE β€” the file descriptor points to a character device other than Device DAX.
  • PMEM2_E_INVALID_ALIGNMENT_FORMAT β€” the kernel query for Device DAX alignment returned data in an invalid format. rude of it.
  • -errno set by failing fstat(2), while trying to validate the file descriptor.
  • -errno set by failing realpath(3), while trying to determine whether fd points to a Device DAX.
  • -errno set by failing read(2), while trying to determine Device DAX's alignment.
  • -errno set by failing strtoull(3), while trying to determine Device DAX's alignment.
okay so a lot of these are -errno situations, meaning the error number from the underlying failing call comes back negated. so if you're checking return values, yes, negative. keep that in mind 🫢

🌈 SEE ALSO 🌈


and that's the whole page! this was PMDK, dated 2025-07-24. go forth and align your sources correctly, you got this πŸ’œπŸ§šβ€β™€οΈ

πŸ“¦ where this page comes from