static void pool_create(const wchar_t *path, size_t poolsize, unsigned mode) { char *upath = ut_toUTF8(path); PMEMlogpool *plp = pmemlog_createW(path, poolsize, mode); if (plp == NULL) UT_OUT("!%s: pmemlog_create", upath); else { os_stat_t stbuf; STATW(path, &stbuf); UT_OUT("%s: file size %zu usable space %zu mode 0%o", upath, stbuf.st_size, pmemlog_nbyte(plp), stbuf.st_mode & 0777); pmemlog_close(plp); int result = pmemlog_checkW(path); if (result < 0) UT_OUT("!%s: pmemlog_check", upath); else if (result == 0) UT_OUT("%s: pmemlog_check: not consistent", upath); } free(upath); }
int main(int argc, char *argv[]) { const char path[] = "/pmem-fs/myfile"; PMEMlogpool *plp; size_t nbyte; char *str; /* create the pmemlog pool or open it if it already exists */ plp = pmemlog_create(path, POOL_SIZE, 0666); if (plp == NULL) plp = pmemlog_open(path); if (plp == NULL) { perror(path); exit(1); } /* how many bytes does the log hold? */ nbyte = pmemlog_nbyte(plp); printf("log holds %zu bytes\n", nbyte); /* append to the log... */ str = "This is the first string appended\n"; if (pmemlog_append(plp, str, strlen(str)) < 0) { perror("pmemlog_append"); exit(1); } str = "This is the second string appended\n"; if (pmemlog_append(plp, str, strlen(str)) < 0) { perror("pmemlog_append"); exit(1); } /* print the log contents */ printf("log contains:\n"); pmemlog_walk(plp, 0, printit, NULL); pmemlog_close(plp); }
/* * do_nbyte -- call pmemlog_nbyte() & print result */ static void do_nbyte(PMEMlogpool *plp) { size_t nbyte = pmemlog_nbyte(plp); OUT("usable size: %zu", nbyte); }
int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "usage: %s [o,c] file [val...]", argv[0]); return 1; } PMEMlogpool *plp; if (strncmp(argv[1], "c", 1) == 0) { plp = pmemlog_create(argv[2], POOL_SIZE, S_IRUSR | S_IWUSR); } else if (strncmp(argv[1], "o", 1) == 0) { plp = pmemlog_open(argv[2]); } else { fprintf(stderr, "usage: %s [o,c] file [val...]", argv[0]); return 1; } if (plp == NULL) { perror("pmemlog_create/pmemlog_open"); return 1; } /* process the command line arguments */ for (int i = 3; i < argc; i++) { switch (*argv[i]) { case 'a': { printf("append: %s\n", argv[i] + 2); pmemlog_append(plp, argv[i] + 2, strlen(argv[i] + 2)); break; } case 'v': { printf("appendv: %s\n", argv[i] + 2); int count = count_iovec(argv[i] + 2); struct iovec *iov = malloc(count * sizeof (struct iovec)); fill_iovec(iov, argv[i] + 2); pmemlog_appendv(plp, iov, count); free(iov); break; } case 'r': { printf("rewind\n"); pmemlog_rewind(plp); break; } case 'w': { printf("walk\n"); pmemlog_walk(plp, 0, process_chunk, NULL); break; } case 'n': { printf("nbytes: %zu\n", pmemlog_nbyte(plp)); break; } case 't': { printf("offset: %ld\n", pmemlog_tell(plp)); break; } default: { fprintf(stderr, "unrecognized command %s\n", argv[i]); break; } }; } /* all done */ pmemlog_close(plp); return 0; }