pmem2_source_pread_mcsafe - Man Page

read source contents or write to the source in a safe manner


#include <libpmem2.h>

struct pmem2_source;
int pmem2_source_pread_mcsafe(struct pmem2_source *src, void *buf, size_t size,
        size_t offset);
int pmem2_source_pwrite_mcsafe(struct pmem2_source *src, void *buf, size_t size,
        size_t offset);


The pmem2_source_pread_mcsafe() function reads size bytes from the source src starting at offset offset into the buffer buf. The pmem2_source_pwrite_mcsafe() function writes size bytes from the buffer buf to the source src starting at the offset offset.

Above functions are capable of detecting bad blocks and handling the SIGBUS signal thrown when accessing a bad block. When a bad block is encountered, pmem2_source_pread_mcsafe() and pmem2_source_pwrite_mcsafe() functions return corresponding error. A signal handler for SIGBUS signal is registered using sigaction(2) for the running time of those operations. This capability is limited to POSIX systems.

For bad block detection and clearing, see pmem2_badblock_context_new(3), pmem2_badblock_next(3) and pmem2_badblock_clear(3).

Return Value

The pmem2_source_pread_mcsafe() and pmem2_source_pwrite_mcsafe() functions return 0 on success or a negative error code on failure.


The pmem2_source_pread_mcsafe() and pmem2_source_pwrite_mcsafe() can fail with the following errors:

Those operations can also return all errors from the underlying pread(2), pwrite(2), sigaction(2) functions on POSIX systems and ReadFile(), WriteFile() functions on Windows.

See Also

pread(2), pwrite(2), ReadFile(), WriteFile(), pmem2_badblock_clear(3), pmem2_badblock_context_new(3), pmem2_badblock_next(3), pmem2_source_from_fd(3), pmem2_source_from_handle(3), libpmem2(7) and <>

Referenced By

The man page pmem2_source_pwrite_mcsafe(3) is an alias of pmem2_source_pread_mcsafe(3).

2022-08-25 PMDK - pmem2 API version 1.0 PMDK Programmer's Manual