PMEM2_SOURCE_DELETE(3)

πŸ’– PMEM2_SOURCE_DELETE(3) πŸ’–

okay bestie, so this is a page from the PMDK Programmer's Manual and it's all about making and yeeting a persistent memory data source. yes, that PMDK. the memory one. sit down, grab a strawberry πŸ“, we're doing this.


✨ NAME ✨

pmem2_source_from_fd(), pmem2_source_delete() β€” creates or deletes an instance of persistent memory data source. that's it. that's the whole job. one makes it, one un-makes it. iconic duo behavior, honestly 🫢


✨ SYNOPSIS ✨

#include <libpmem2.h>

int pmem2_source_from_fd(struct pmem2_source *src, int fd);
int pmem2_source_delete(struct pmem2_source **src);

no cap, that's the whole vibe. two little functions. one include. slay. πŸ’…


✨ DESCRIPTION ✨

so. pmem2_source_from_fd() is the one that validates your file descriptor and then instantiates a brand new struct pmem2_source * object that describes the data source. it's giving "I checked your ID and you're on the list, come in" πŸŽ€

and listen, fd must be opened with O_RDONLY or O_RDWR mode. those are the only two fits it's accepting. if fd is invalid? the function fails. periodt. πŸ’€

then there's pmem2_source_delete(), our cleanup queen πŸ‘‘. she frees *src that came back from pmem2_source_from_fd() and sets *src to NULL. and if *src is already NULL? she does literally nothing. no drama, no crash, just vibes. the way that she's polite about it 😭


✨ RETURN VALUE ✨

  • pmem2_source_from_fd() returns 0 on success, or a negative error code on failure. so if you see a negative number, that's not a vibe check you passed bestie.
  • pmem2_source_delete() always returns 0. always. she has never known failure. main character energy fr fr. ✨

✨ ERRORS ✨

pmem2_source_from_fd() can fail with the following errors, so let's go through them one by one:

  • PMEM2_E_INVALID_FILE_HANDLE β€” fd is not an open and valid file descriptor. sorry babe, that handle is not real.
  • PMEM2_E_INVALID_FILE_HANDLE β€” fd is opened in O_WRONLY mode. yeah no, write-only is NOT it. we don't do that here πŸ™ˆ
  • PMEM2_E_INVALID_FILE_TYPE β€” fd points to a directory, block device, pipe, or socket. cute but wrong genre of file.
  • PMEM2_E_INVALID_FILE_TYPE β€” fd points to a character device other than Device DAX. so like… a character device that isn't Device DAX? nope, not on the guest list.

also, pmem2_source_from_fd() can return -ENOMEM in case of insufficient memory to allocate an instance of struct pmem2_source. ran out of room, the mall is full, we cannot allocate 😭

heads up bestie: notice how two of those errors share a name and two share another name β€” that's not a typo, that's literally how it's written. keep it exactly as-is, iykyk.

✨ SEE ALSO ✨

go read these next, they're the rest of the lore:


and that's the page!! thanks for coming to my ted talk. this was PMDK, dated 2025-07-24. love u, go delete some sources responsibly πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from