-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathbad_blocks.h
77 lines (60 loc) · 1.84 KB
/
bad_blocks.h
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
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
/* SPDX-License-Identifier: BSD-3-Clause */
/* Copyright 2017-2020, Intel Corporation */
/*
* bad_blocks.h -- bad blocks API based on the libpmem2 library
*/
#ifndef PMDK_BAD_BLOCKS_H
#define PMDK_BAD_BLOCKS_H 1
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#define B2SEC(n) ((n) >> 9) /* convert bytes to sectors */
#define SEC2B(n) ((n) << 9) /* convert sectors to bytes */
#define NO_HEALTHY_REPLICA ((int)(-1))
#define BB_NOT_SUPP \
"checking bad blocks is not supported on this OS, please switch off the CHECK_BAD_BLOCKS compat feature using 'pmempool-feature'"
/*
* 'struct badblock' is already defined in ndctl/libndctl.h,
* so we cannot use this name.
*
* libndctl returns offset relative to the beginning of the region,
* but in this structure we save offset relative to the beginning of:
* - namespace (before badblocks_get())
* and
* - file (before sync_recalc_badblocks())
* and
* - pool (after sync_recalc_badblocks())
*/
struct bad_block {
/*
* offset in bytes relative to the beginning of
* - namespace (before badblocks_get())
* and
* - file (before sync_recalc_badblocks())
* and
* - pool (after sync_recalc_badblocks())
*/
size_t offset;
/* length in bytes */
size_t length;
/* number of healthy replica to fix this bad block */
int nhealthy;
};
struct badblocks {
unsigned bb_cnt; /* number of bad blocks */
struct bad_block *bbv; /* array of bad blocks */
};
struct badblocks *badblocks_new(void);
void badblocks_delete(struct badblocks *bbs);
long badblocks_count(const char *path);
int badblocks_get(const char *file, struct badblocks *bbs);
int badblocks_clear(const char *path, struct badblocks *bbs);
int badblocks_clear_all(const char *file);
int badblocks_check_file(const char *path);
#ifdef __cplusplus
}
#endif
#endif /* PMDK_BADBLOCKS_H */