1 #ifndef _LINUX_BADBLOCKS_H 2 #define _LINUX_BADBLOCKS_H 3 4 #include <linux/seqlock.h> 5 #include <linux/kernel.h> 6 #include <linux/stddef.h> 7 #include <linux/types.h> 8 9 #define BB_LEN_MASK (0x00000000000001FFULL) 10 #define BB_OFFSET_MASK (0x7FFFFFFFFFFFFE00ULL) 11 #define BB_ACK_MASK (0x8000000000000000ULL) 12 #define BB_MAX_LEN 512 13 #define BB_OFFSET(x) (((x) & BB_OFFSET_MASK) >> 9) 14 #define BB_LEN(x) (((x) & BB_LEN_MASK) + 1) 15 #define BB_ACK(x) (!!((x) & BB_ACK_MASK)) 16 #define BB_MAKE(a, l, ack) (((a)<<9) | ((l)-1) | ((u64)(!!(ack)) << 63)) 17 18 /* Bad block numbers are stored sorted in a single page. 19 * 64bits is used for each block or extent. 20 * 54 bits are sector number, 9 bits are extent size, 21 * 1 bit is an 'acknowledged' flag. 22 */ 23 #define MAX_BADBLOCKS (PAGE_SIZE/8) 24 25 struct badblocks { 26 int count; /* count of bad blocks */ 27 int unacked_exist; /* there probably are unacknowledged 28 * bad blocks. This is only cleared 29 * when a read discovers none 30 */ 31 int shift; /* shift from sectors to block size 32 * a -ve shift means badblocks are 33 * disabled.*/ 34 u64 *page; /* badblock list */ 35 int changed; 36 seqlock_t lock; 37 sector_t sector; 38 sector_t size; /* in sectors */ 39 }; 40 41 int badblocks_check(struct badblocks *bb, sector_t s, int sectors, 42 sector_t *first_bad, int *bad_sectors); 43 int badblocks_set(struct badblocks *bb, sector_t s, int sectors, 44 int acknowledged); 45 int badblocks_clear(struct badblocks *bb, sector_t s, int sectors); 46 void ack_all_badblocks(struct badblocks *bb); 47 ssize_t badblocks_show(struct badblocks *bb, char *page, int unack); 48 ssize_t badblocks_store(struct badblocks *bb, const char *page, size_t len, 49 int unack); 50 int badblocks_init(struct badblocks *bb, int enable); 51 void badblocks_exit(struct badblocks *bb); 52 53 #endif 54