1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2019-2020, Intel Corporation */
/*
* check_is_pmem.cpp -- check if path points to a directory on pmem.
*/
#include <cstdio>
#include <iostream>
#include <libpmem.h>
/*
* return value is:
* - 0 when path points to pmem
* - 1 when path points to non-pmem
* - 2 when error occurred
*/
int
main(int argc, char *argv[])
{
if (argc != 2) {
std::cerr << "usage: " << argv[0] << " filepath\n";
return 2;
}
auto path = argv[1];
int is_pmem;
size_t size;
int flags = PMEM_FILE_CREATE;
#ifdef _WIN32
void *addr = pmem_map_fileU(path, 4096, flags, 0, &size, &is_pmem);
#else
void *addr = pmem_map_file(path, 4096, flags, 0, &size, &is_pmem);
#endif
if (addr == nullptr) {
std::perror("pmem_map_file failed");
return 2;
}
pmem_unmap(addr, size);
if (std::remove(path)) {
std::perror("cannot remove file");
return 2;
}
if (is_pmem)
return 0;
else
return 1;
}
|