Discontinuation of the project
The libpmemblk project will no longer be maintained by Intel.
- Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases,
or updates, to this project.
- Intel no longer accepts patches to this project.
- If you have an ongoing need to use this project, are interested in independently developing it, or would like to
maintain patches for the open source software community, please create your own fork of this project.
- You will find more information here.
The libpmemblk library
libpmemblk implements a pmem-resident array of blocks,
all the same size, where a block is updated atomically with
respect to power failure or program interruption (no torn
blocks).
This library is provided for cases requiring large arrays
of objects at least 512 bytes each. Most
developers will find higher level libraries like
libpmemobj to be more generally useful.
Man pages that contains a list of the Linux interfaces provided:
Man pages that contains a list of the Windows interfaces provided:
NOTE
NOTICE:
The libpmemblk library is deprecated since PMDK 1.13.0 release
and will be removed in the PMDK 1.14.0 release.
libpmemblk Examples
| 37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
 | #include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <libpmemblk.h>
/* size of the pmemblk pool -- 1 GB */
#define	POOL_SIZE ((off_t)(1 << 30))
/* size of each element in the pmem pool */
#define	ELEMENT_SIZE 1024
int
main(int argc, char *argv[])
{
	const char path[] = "/pmem-fs/myfile";
	PMEMblkpool *pbp;
	size_t nelements;
	char buf[ELEMENT_SIZE];
    /* create the pmemblk pool or open it if it already exists */
	pbp = pmemblk_create(path, ELEMENT_SIZE, POOL_SIZE, 0666);
	if (pbp == NULL)
	    pbp = pmemblk_open(path, ELEMENT_SIZE);
	if (pbp == NULL) {
		perror(path);
		exit(1);
	}
	/* how many elements fit into the file? */
	nelements = pmemblk_nblock(pbp);
	printf("file holds %zu elements\n", nelements);
	/* store a block at index 5 */
	strcpy(buf, "hello, world");
	if (pmemblk_write(pbp, buf, 5) < 0) {
		perror("pmemblk_write");
		exit(1);
	}
	/* read the block at index 10 (reads as zeros initially) */
	if (pmemblk_read(pbp, buf, 10) < 0) {
		perror("pmemblk_read");
		exit(1);
	}
	/* zero out the block at index 5 */
	if (pmemblk_set_zero(pbp, 5) < 0) {
		perror("pmemblk_set_zero");
		exit(1);
	}
	/* ... */
	pmemblk_close(pbp);
}
 |