1 #ifndef _LINUX_BADBLOCKS_H
2 #define _LINUX_BADBLOCKS_H
4 #include <linux/seqlock.h>
5 #include <linux/device.h>
6 #include <linux/kernel.h>
7 #include <linux/stddef.h>
8 #include <linux/types.h>
10 #define BB_LEN_MASK (0x00000000000001FFULL)
11 #define BB_OFFSET_MASK (0x7FFFFFFFFFFFFE00ULL)
12 #define BB_ACK_MASK (0x8000000000000000ULL)
13 #define BB_MAX_LEN 512
14 #define BB_OFFSET(x) (((x) & BB_OFFSET_MASK) >> 9)
15 #define BB_LEN(x) (((x) & BB_LEN_MASK) + 1)
16 #define BB_ACK(x) (!!((x) & BB_ACK_MASK))
17 #define BB_MAKE(a, l, ack) (((a)<<9) | ((l)-1) | ((u64)(!!(ack)) << 63))
19 /* Bad block numbers are stored sorted in a single page.
20 * 64bits is used for each block or extent.
21 * 54 bits are sector number, 9 bits are extent size,
22 * 1 bit is an 'acknowledged' flag.
24 #define MAX_BADBLOCKS (PAGE_SIZE/8)
27 struct device
*dev
; /* set by devm_init_badblocks */
28 int count
; /* count of bad blocks */
29 int unacked_exist
; /* there probably are unacknowledged
30 * bad blocks. This is only cleared
31 * when a read discovers none
33 int shift
; /* shift from sectors to block size
34 * a -ve shift means badblocks are
36 u64
*page
; /* badblock list */
40 sector_t size
; /* in sectors */
43 int badblocks_check(struct badblocks
*bb
, sector_t s
, int sectors
,
44 sector_t
*first_bad
, int *bad_sectors
);
45 int badblocks_set(struct badblocks
*bb
, sector_t s
, int sectors
,
47 int badblocks_clear(struct badblocks
*bb
, sector_t s
, int sectors
);
48 void ack_all_badblocks(struct badblocks
*bb
);
49 ssize_t
badblocks_show(struct badblocks
*bb
, char *page
, int unack
);
50 ssize_t
badblocks_store(struct badblocks
*bb
, const char *page
, size_t len
,
52 int badblocks_init(struct badblocks
*bb
, int enable
);
53 void badblocks_exit(struct badblocks
*bb
);
55 int devm_init_badblocks(struct device
*dev
, struct badblocks
*bb
);
56 static inline void devm_exit_badblocks(struct device
*dev
, struct badblocks
*bb
)
59 dev_WARN_ONCE(dev
, 1, "%s: badblocks instance not associated\n",