PMEMBLK_WRITE(3)

πŸ“¦
version 1.13.1 Β· 4 versions
, in debian trixie, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– PMEMBLK_READ(3) πŸ’–

okay bestie, we're in the PMDK Programmer's Manual today and we're talking about pmemblk_read() and pmemblk_write() β€” the iconic duo that reads and writes blocks from a block memory pool. yes, they're both marked DEPRECATED, we'll get to that, but first let's learn the lore πŸ¦‹


✨ NAME ✨

pmemblk_read()(DEPRECATED), pmemblk_write()(DEPRECATED) β€” read or write a block from a block memory pool πŸŽ€


🌸 SYNOPSIS 🌸

#include <libpmemblk.h>

int pmemblk_read(PMEMblkpool *pbp, void *buf, long long blockno);
int pmemblk_write(PMEMblkpool *pbp, const void *buf, long long blockno);

like, that's it. two little functions. two. and they're carrying the whole block-pool situation on their backs fr fr πŸ’…


πŸ‘‘ DESCRIPTION πŸ‘‘

🧚 pmemblk_read()

the pmemblk_read() function reads the block with block number blockno from memory pool pbp into the buffer buf. that's the whole job. she's a reader, she reads πŸ’œ

and here's the cute part β€” if you read a block that has never been written by pmemblk_write(), you don't get garbage, you don't get an error, you get a block of zeroes. brand new, all clean, all zeroes. slay ✨

πŸ¦‹ pmemblk_write()

the pmemblk_write() function writes a block from buf to block number blockno in the memory pool pbp.

and the way that this write is atomic with respect to other reads and writes?? no cap. it's giving main character energy πŸ”₯

not only that, but the write cannot be torn by program failure or system crash. on recovery, the block is guaranteed to contain either the old data or the new data, never a mixture of both. no franken-block, no half-and-half nonsense, no "oops we wrote 37 bytes of the new thing and 41 bytes of the old thing". it's one or the other, periodt πŸ’…

⚠️ heads up bestie: both of these functions are marked DEPRECATED. just so we're clear on the vibe check.

⭐ RETURN VALUE ⭐

  • on success 🫢 β€” both pmemblk_read() and pmemblk_write() return 0
  • on error 😭 β€” they return -1 and set errno appropriately

that's it, that's the whole contract. zero means we ate, negative one means check your errno.


🌈 SEE ALSO 🌈


PMDK πŸŽ€ written 2023-05-31 πŸŽ€ that's the version and date, mwah, take care of her, she's deprecated but she's still iconic πŸ‘‘πŸ’–

πŸ“¦ where this page comes from