]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/badblocks.h
seccomp: Move speculation migitation control to arch code
[mirror_ubuntu-artful-kernel.git] / include / linux / badblocks.h
CommitLineData
9e0e252a
VV
1#ifndef _LINUX_BADBLOCKS_H
2#define _LINUX_BADBLOCKS_H
3
4#include <linux/seqlock.h>
16263ff6 5#include <linux/device.h>
9e0e252a
VV
6#include <linux/kernel.h>
7#include <linux/stddef.h>
8#include <linux/types.h>
9
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))
18
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.
23 */
24#define MAX_BADBLOCKS (PAGE_SIZE/8)
25
26struct badblocks {
16263ff6 27 struct device *dev; /* set by devm_init_badblocks */
9e0e252a
VV
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
32 */
33 int shift; /* shift from sectors to block size
34 * a -ve shift means badblocks are
35 * disabled.*/
36 u64 *page; /* badblock list */
37 int changed;
38 seqlock_t lock;
39 sector_t sector;
40 sector_t size; /* in sectors */
41};
42
43int badblocks_check(struct badblocks *bb, sector_t s, int sectors,
44 sector_t *first_bad, int *bad_sectors);
45int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
46 int acknowledged);
47int badblocks_clear(struct badblocks *bb, sector_t s, int sectors);
48void ack_all_badblocks(struct badblocks *bb);
49ssize_t badblocks_show(struct badblocks *bb, char *page, int unack);
50ssize_t badblocks_store(struct badblocks *bb, const char *page, size_t len,
51 int unack);
52int badblocks_init(struct badblocks *bb, int enable);
d3b407fb 53void badblocks_exit(struct badblocks *bb);
16263ff6
DW
54struct device;
55int devm_init_badblocks(struct device *dev, struct badblocks *bb);
56static inline void devm_exit_badblocks(struct device *dev, struct badblocks *bb)
57{
58 if (bb->dev != dev) {
59 dev_WARN_ONCE(dev, 1, "%s: badblocks instance not associated\n",
60 __func__);
61 return;
62 }
63 badblocks_exit(bb);
64}
9e0e252a 65#endif