badblocks_check(9)
π badblocks_check β check a given range for bad sectors
okay bestie so this is from the Kernel API Manual β badblocks_check(9), the little function that looks at a chunk of your disk and goes "hmm, is any of this cursed?" π¦
β¨ NAME β¨
badblocks_check β check a given range for bad sectors π
πΈ SYNOPSIS πΈ
int badblocks_check (struct badblocks *bb , sector_t s , sector_t
sectors , sector_t *first_bad , sector_t *bad_sectors );
π ARGUMENTS π
bbβ thebadblocksstructure that holds all the badblock information. it's giving main character energy, everything lives here πsβ sector (start) at which to check for badblockssectorsβ number of sectors to check for badblocksfirst_badβ pointer to store location of the first badblockbad_sectorsβ pointer to store number of badblocks afterfirst_bad
π DESCRIPTION π
okay so the whole vibe here: we can record which blocks on each device are 'bad' and so just fail those blocks, or that stripe, rather than the whole device. like, we're not gonna nuke the entire disk because one little corner is sus π
Entries in the bad-block table are 64 bits wide. This comprises:
- Length of bad-range, in sectors:
0-511for lengths1-512 - Start of bad-range, sector offset,
54 bits(allows8 exbibytes) - A
'shift'can be set so that larger blocks are tracked and consequently larger devices can be covered β¨
Locking of the bad-block table uses a seqlock so badblocks_check might need to retry if it is very unlucky π no cap, it just happens sometimes. We will sometimes want to check for bad blocks in a bi_end_io function, so we use the write_seqlock_irq variant π«Ά
When looking for a bad block we specify a range and want to know if any block in the range is bad. So we binary-search to the last range that starts at-or-before the given endpoint, (or "before the sector after the target range") then see if it ends after the given start. iconic algorithm behaviour, honestly π
π₯ RETURN π₯
0β there are no known bad blocks in the range π1β there are known bad block which are all acknowledged-1β there are bad blocks which have not yet been acknowledged in metadata π
plus the start/length of the first bad section we overlap π
fr fr, that -1 is the one that means somebody hasn't done their homework yet β the badness is real but nobody's written it down in metadata.
π SEE ALSO π
- Kernel file
./block/badblocks.c badblocks_set(9)badblocks_clear(9)ack_all_badblocks(9)badblocks_show(9)badblocks_store(9)badblocks_init(9)badblocks_exit(9)
that's the whole page bestie, go check those blocks π§ββοΈ
mwah π β this one's from ./block, dated October 2026, and it's the badblocks_check(9) page, so you know exactly where it came from. no cap, that's the whole sign-off π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms