1PMEM2_SOURCE_PREAD_MCSAFE(3)PMDK Programmer's ManualPMEM2_SOURCE_PREAD_MCSAFE(3)
2
3
4
6 pmem2_source_pread_mcsafe(), pmem2_source_pwrite_mcsafe() - read source
7 contents or write to the source in a safe manner
8
10 #include <libpmem2.h>
11
12 struct pmem2_source;
13 int pmem2_source_pread_mcsafe(struct pmem2_source *src, void *buf, size_t size,
14 size_t offset);
15 int pmem2_source_pwrite_mcsafe(struct pmem2_source *src, void *buf, size_t size,
16 size_t offset);
17
19 The pmem2_source_pread_mcsafe() function reads size bytes from the
20 source src starting at offset offset into the buffer buf. The
21 pmem2_source_pwrite_mcsafe() function writes size bytes from the buffer
22 buf to the source src starting at the offset offset.
23
24 Above functions are capable of detecting bad blocks and handling the
25 SIGBUS signal thrown when accessing a bad block. When a bad block is
26 encountered, pmem2_source_pread_mcsafe() and pmem2_source_pwrite_mc‐
27 safe() functions return corresponding error. A signal handler for SIG‐
28 BUS signal is registered using sigaction(2) for the running time of
29 those operations. This capability is limited to POSIX systems.
30
31 For bad block detection and clearing, see pmem2_badblock_con‐
32 text_new(3), pmem2_badblock_next(3) and pmem2_badblock_clear(3).
33
35 The pmem2_source_pread_mcsafe() and pmem2_source_pwrite_mcsafe() func‐
36 tions return 0 on success or a negative error code on failure.
37
39 The pmem2_source_pread_mcsafe() and pmem2_source_pwrite_mcsafe() can
40 fail with the following errors:
41
42 • PMEM2_E_IO_FAIL - a physical I/O error occurred during the read/write
43 operation, a possible bad block encountered.
44
45 • PMEM2_E_LENGTH_OUT_OF_RANGE - read/write operation size size from
46 offset offset goes beyond the file length.
47
48 • PMEM2_E_SOURCE_TYPE_NOT_SUPPORTED - read/write operation doesn't sup‐
49 port provided source, only sources created with
50 pmem2_source_from_fd(3) and pmem2_source_from_handle(3) are support‐
51 ed.
52
53 Those operations can also return all errors from the underlying
54 pread(2), pwrite(2), sigaction(2) functions on POSIX systems and Read‐
55 File(), WriteFile() functions on Windows.
56
58 pread(2), pwrite(2), ReadFile(), WriteFile(), pmem2_badblock_clear(3),
59 pmem2_badblock_context_new(3), pmem2_badblock_next(3),
60 pmem2_source_from_fd(3), pmem2_source_from_handle(3), libpmem2(7) and
61 <https://pmem.io>
62
63
64
65PMDK - pmem2 API version 1.0 2022-05-24 PMEM2_SOURCE_PREAD_MCSAFE(3)