include/linux/badblocks.h

Source file repositories/reference/linux-study-clean/include/linux/badblocks.h

File Facts

System
Linux kernel
Corpus path
include/linux/badblocks.h
Extension
.h
Size
2720 bytes
Lines
97
Domain
Core OS
Bucket
Core Kernel Interface
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct badblocks {
	struct device *dev;	/* set by devm_init_badblocks */
	int count;		/* count of bad blocks */
	int unacked_exist;	/* there probably are unacknowledged
				 * bad blocks.  This is only cleared
				 * when a read discovers none
				 */
	int shift;		/* shift from sectors to block size
				 * a -ve shift means badblocks are
				 * disabled.*/
	u64 *page;		/* badblock list */
	int changed;
	seqlock_t lock;
	sector_t sector;
	sector_t size;		/* in sectors */
};

struct badblocks_context {
	sector_t	start;
	sector_t	len;
	int		ack;
};

int badblocks_check(struct badblocks *bb, sector_t s, sector_t sectors,
		    sector_t *first_bad, sector_t *bad_sectors);
bool badblocks_set(struct badblocks *bb, sector_t s, sector_t sectors,
		   int acknowledged);
bool badblocks_clear(struct badblocks *bb, sector_t s, sector_t sectors);
void ack_all_badblocks(struct badblocks *bb);
ssize_t badblocks_show(struct badblocks *bb, char *page, int unack);
ssize_t badblocks_store(struct badblocks *bb, const char *page, size_t len,
			int unack);
int badblocks_init(struct badblocks *bb, int enable);
void badblocks_exit(struct badblocks *bb);
struct device;
int devm_init_badblocks(struct device *dev, struct badblocks *bb);
static inline void devm_exit_badblocks(struct device *dev, struct badblocks *bb)
{
	if (bb->dev != dev) {
		dev_WARN_ONCE(dev, 1, "%s: badblocks instance not associated\n",
				__func__);
		return;
	}
	badblocks_exit(bb);
}

static inline int badblocks_full(struct badblocks *bb)
{
	return (bb->count >= MAX_BADBLOCKS);
}

static inline int badblocks_empty(struct badblocks *bb)
{
	return (bb->count == 0);
}

static inline void set_changed(struct badblocks *bb)
{
	if (bb->changed != 1)
		bb->changed = 1;
}

static inline void clear_changed(struct badblocks *bb)
{
	if (bb->changed != 0)
		bb->changed = 0;
}

#endif

Annotation

Implementation Notes