PMEM2_BADBLOCK_CONTEXT_NEW(3)
π pmem2_badblock_context_new(), pmem2_badblock_context_delete() π
okay bestie, so this is from the PMDK Programmer's Manual and it's literally all about making and unmaking a lil context so you can go find and yeet bad blocks. two functions, one mission, let's get into it π«Ά
β¨ SYNOPSIS β¨
#include <libpmem2.h>
struct pmem2_source;
struct pmem2_badblock_context;
int pmem2_badblock_context_new(
struct pmem2_badblock_context **bbctx,
const struct pmem2_source *src);
void pmem2_badblock_context_delete(
struct pmem2_badblock_context **bbctx);
πΈ DESCRIPTION πΈ
So pmem2_badblock_context_new() is the one that spins up a brand new (opaque, mysterious, main-character) bad block context structure called pmem2_badblock_context. what's it for? it's the lil handle you use to read and clear bad blocks, courtesy of pmem2_badblock_next() and pmem2_badblock_clear(). it hands the context back to you through the pointer at *bbctx. slay β¨
this fresh context gets initialized with values read from the source you pass in as the first argument (src). periodt.
now, what even is a bad block, bestie? a bad block is an uncorrectable media error β a chunk of storage media that's either inaccessible or unwritable because of permanent physical damage. and here's the scary part π: with memory-mapped I/O, if a process tries to touch (read or write) that corrupted block, it gets terminated by the SIGBUS signal. no warning, no vibe check, just gone. π
then there's pmem2_badblock_context_delete(), the cleanup queen. she frees the *bbctx that pmem2_badblock_context_new() gave you and sets *bbctx to NULL. and if *bbctx is already NULL? she does absolutely nothing. no operation, no drama, no notes. π
β RETURN VALUE β
pmem2_badblock_context_new()β returns0on success, or a negative error code if it's not feeling it today πpmem2_badblock_context_new()β sets*bbctxtoNULLwhen it fails, so you're never left holding a fake one π«Άpmem2_badblock_context_delete()β returns literally nothing. void. silent. iconic.
π₯ ERRORS π₯
pmem2_badblock_context_new() can fail with any of these, and ngl there's a lot of them:
PMEM2_E_INVALID_FILE_TYPEβsrcis not a regular file nor a character device. wrong vibe entirely πPMEM2_E_DAX_REGION_NOT_FOUNDβ cannot find a DAX region for the givensrc. she's lost in the sauce πPMEM2_E_CANNOT_READ_BOUNDSβ cannot read offset or size of the namespace of the givensrc. the numbers said no πPMEM2_E_NOSUPPβ when the OS does not support this functionality. the operating system said "not my era" π«-ENOMEMβ out of memory. brain empty, no thoughts, no RAM π΅-errnoβ set by failingndctl_new, while trying to create a new ndctl context.-errnoβ set by failingfstat(2), while trying to validate the file descriptor ofsrc.-errnoβ set by failingrealpath(3), while trying to get the canonicalized absolute sysfs pathname of DAX device given insrc.-errnoβ set by failingopen(2), while trying to open the FSDAX device matching with thesrc.-errnoβ set by failingread(2), while trying to read from the FSDAX device matching with thesrc.-errnoβ set by failingndctl_region_get_resource, while reading an offset of the region of the givensrc.-errnoβ set by failing fiemapioctl(2), while reading file extents of the givensrc.
ok so the pattern here is: a bunch of system calls can flop and each one just hands you its own -errno. check your errno, bestie, it's telling you everything π
π SEE ALSO π
pmem2_badblock_next(3), pmem2_badblock_clear(3), libpmem2(7) and https://pmem.io
go read those next, i promise they're giving the same energy π
mwah π this page is brought to you by PMDK, dated 2025-07-24 β that's the whole source/version + date situation, and yes, she ate. go clear some bad blocks, bestie, you got this π¦β¨
π¦ where this page comes from
- fedora 43: libpmem2-devel 2.1.0-4.fc43 Β· BSD-3-Clause
- π the page's license: BSD-3-Clause
- Copyright 2020-2023, Intel Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms