block/badblocks.c
Source file repositories/reference/linux-study-clean/block/badblocks.c
File Facts
- System
- Linux kernel
- Corpus path
block/badblocks.c- Extension
.c- Size
- 48993 bytes
- Lines
- 1551
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/badblocks.hlinux/seqlock.hlinux/device.hlinux/kernel.hlinux/module.hlinux/stddef.hlinux/types.hlinux/slab.h
Detected Declarations
function Copyrightfunction prev_badblocksfunction rangefunction front_mergefunction rangefunction front_combinefunction rangefunction rangefunction rangefunction can_front_overwritefunction insert_atfunction badblocks_update_ackedfunction rangefunction _badblocks_setfunction front_clearfunction front_splitting_clearfunction _badblocks_clearfunction _badblocks_checkfunction badblocks_checkfunction badblocks_setfunction badblocks_clearfunction ack_all_badblocksfunction badblocks_showfunction badblocks_storefunction __badblocks_initfunction badblocks_initfunction devm_init_badblocksfunction badblocks_exitexport badblocks_checkexport badblocks_setexport badblocks_clearexport ack_all_badblocksexport badblocks_showexport badblocks_storeexport badblocks_initexport devm_init_badblocksexport badblocks_exit
Annotated Snippet
if ((hint + 1) == bb->count || BB_OFFSET(p[hint + 1]) > s) {
ret = hint;
break;
}
hint++;
}
return ret;
}
/*
* Find the range starts at-or-before bad->start. If 'hint' is provided
* (hint >= 0) then search in the bad table from hint firstly. It is
* very probably the wanted bad range can be found from the hint index,
* then the unnecessary while-loop iteration can be avoided.
*/
static int prev_badblocks(struct badblocks *bb, struct badblocks_context *bad,
int hint)
{
sector_t s = bad->start;
int ret = -1;
int lo, hi;
u64 *p;
if (!bb->count)
goto out;
if (hint >= 0) {
ret = prev_by_hint(bb, s, hint);
if (ret >= 0)
goto out;
}
lo = 0;
hi = bb->count;
p = bb->page;
/* The following bisect search might be unnecessary */
if (BB_OFFSET(p[lo]) > s)
return -1;
if (BB_OFFSET(p[hi - 1]) <= s)
return hi - 1;
/* Do bisect search in bad table */
while (hi - lo > 1) {
int mid = (lo + hi)/2;
sector_t a = BB_OFFSET(p[mid]);
if (a == s) {
ret = mid;
goto out;
}
if (a < s)
lo = mid;
else
hi = mid;
}
if (BB_OFFSET(p[lo]) <= s)
ret = lo;
out:
return ret;
}
/*
* Return 'true' if the range indicated by 'bad' can be forward
* merged with the bad range (from the bad table) indexed by 'prev'.
*/
static bool can_merge_front(struct badblocks *bb, int prev,
struct badblocks_context *bad)
{
sector_t s = bad->start;
u64 *p = bb->page;
if (BB_ACK(p[prev]) == bad->ack &&
(s < BB_END(p[prev]) ||
(s == BB_END(p[prev]) && (BB_LEN(p[prev]) < BB_MAX_LEN))))
return true;
return false;
}
/*
* Do forward merge for range indicated by 'bad' and the bad range
* (from bad table) indexed by 'prev'. The return value is sectors
* merged from bad->len.
*/
static int front_merge(struct badblocks *bb, int prev, struct badblocks_context *bad)
{
sector_t sectors = bad->len;
Annotation
- Immediate include surface: `linux/badblocks.h`, `linux/seqlock.h`, `linux/device.h`, `linux/kernel.h`, `linux/module.h`, `linux/stddef.h`, `linux/types.h`, `linux/slab.h`.
- Detected declarations: `function Copyright`, `function prev_badblocks`, `function range`, `function front_merge`, `function range`, `function front_combine`, `function range`, `function range`, `function range`, `function can_front_overwrite`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.