PMEM2_SOURCE_SIZE(3)

✨ PMEM2_SOURCE_SIZE(3) ✨

okay bestie, welcome to the PMDK Programmer's Manual πŸ’– you're about to learn how to ask a data source how big it is. it's giving "how many bytes are you, babe" and honestly? iconic.


🌸 NAME 🌸

pmem2_source_size() β€” returns the size of the data source


πŸŽ€ SYNOPSIS πŸŽ€

#include <libpmem2.h>

struct pmem2_source;
int pmem2_source_size(const struct pmem2_source *source, size_t *size);

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically, pmem2_source_size() goes and gets the size of the file β€” in bytes β€” the one pointed at by the file descriptor that's chillin' inside source. and then it just... drops it into *size. like a little gift. 🎁

The way this function is lowkey a hero: it hides all the quirkiness of Device DAX size detection. you don't gotta deal with that mess. it does. periodt. πŸ’…


πŸ‘‘ RETURN VALUE πŸ‘‘

pmem2_source_size() returns 0 on success. slay. ✨

but if it fails? the *size variable is left unmodified (like, untouched, no notes) and a negative error code is returned. sad girl hours. 😭


πŸ’€ ERRORS πŸ’€

pmem2_source_size() can fail with the following errors, bestie, so listen up:

  • PMEM2_E_INVALID_FILE_HANDLE β€” source contains an invalid file handle. not it. πŸ™ˆ
  • PMEM2_E_INVALID_FILE_TYPE β€” the file descriptor points to a directory, block device, pipe, or socket. wrong vibe entirely.
  • PMEM2_E_INVALID_FILE_TYPE β€” the file descriptor points to a character device that is not a Device DAX. close but no. πŸ’€
  • PMEM2_E_INVALID_SIZE_FORMAT β€” the kernel query for the Device DAX size came back with data in an invalid format. the kernel was not serving. 😭
  • -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 open(2), while trying to determine Device DAX's size.
  • -errno set by failing read(2), while trying to determine Device DAX's size.
  • -errno set by failing strtoull(3), while trying to determine Device DAX's size.

🌈 SEE ALSO 🌈

errno(3), fstat(2), realpath(3), open(2), read(2), strtoull(3), pmem2_config_new(3), libpmem2(7) and https://pmem.io

go read those too, iykyk 🫢


that's the whole page, bestie. this one's from the PMDK crew, dated 2025-07-24 β€” yeah she's a 2025 girlie and she ate. mwah πŸ’‹ 🧚

πŸ“¦ where this page comes from