]> git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/libpmem2/pmem2_utils_other.c
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / src / libpmem2 / pmem2_utils_other.c
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2014-2020, Intel Corporation */
3
4 #include <errno.h>
5 #include <sys/stat.h>
6
7 #include "libpmem2.h"
8 #include "out.h"
9 #include "pmem2_utils.h"
10
11 #ifdef _WIN32
12 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
13 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
14 #endif
15
16 int
17 pmem2_get_type_from_stat(const os_stat_t *st, enum pmem2_file_type *type)
18 {
19 if (S_ISREG(st->st_mode)) {
20 *type = PMEM2_FTYPE_REG;
21 return 0;
22 }
23
24 if (S_ISDIR(st->st_mode)) {
25 *type = PMEM2_FTYPE_DIR;
26 return 0;
27 }
28
29 ERR("file type 0%o not supported", st->st_mode & S_IFMT);
30 return PMEM2_E_INVALID_FILE_TYPE;
31 }
32
33 /*
34 * pmem2_device_dax_size -- checks the size of a given
35 * dax device from given source structure
36 */
37 int
38 pmem2_device_dax_size(const struct pmem2_source *src, size_t *size)
39 {
40 const char *err =
41 "BUG: pmem2_device_dax_size should never be called on this OS";
42 ERR("%s", err);
43 ASSERTinfo(0, err);
44 return PMEM2_E_NOSUPP;
45 }
46
47 /*
48 * pmem2_device_dax_alignment -- checks the alignment of a given
49 * dax device from given source
50 */
51 int
52 pmem2_device_dax_alignment(const struct pmem2_source *src, size_t *alignment)
53 {
54 const char *err =
55 "BUG: pmem2_device_dax_alignment should never be called on this OS";
56 ERR("%s", err);
57 ASSERTinfo(0, err);
58 return PMEM2_E_NOSUPP;
59 }