fs/ocfs2/blockcheck.c
Source file repositories/reference/linux-study-clean/fs/ocfs2/blockcheck.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ocfs2/blockcheck.c- Extension
.c- Size
- 15535 bytes
- Lines
- 606
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- 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.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/types.hlinux/crc32.hlinux/buffer_head.hlinux/bitops.hlinux/debugfs.hlinux/module.hlinux/fs.hasm/byteorder.hcluster/masklog.hocfs2.hblockcheck.h
Detected Declarations
function Copyrightfunction ocfs2_hamming_encodefunction ocfs2_hamming_encode_blockfunction ocfs2_hamming_encodefunction ocfs2_hamming_fix_blockfunction blockcheck_u64_getfunction ocfs2_blockcheck_debug_removefunction ocfs2_blockcheck_debug_installfunction ocfs2_blockcheck_debug_installfunction ocfs2_blockcheck_stats_debugfs_removefunction ocfs2_blockcheck_inc_checkfunction ocfs2_blockcheck_inc_failurefunction ocfs2_blockcheck_inc_recoverfunction ocfs2_block_check_computefunction ocfs2_block_check_validatefunction ocfs2_block_check_compute_bhsfunction ocfs2_block_check_validate_bhsfunction bufferfunction ocfs2_validate_meta_eccfunction ocfs2_compute_meta_ecc_bhsfunction ocfs2_validate_meta_ecc_bhs
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* blockcheck.c
*
* Checksum and ECC codes for the OCFS2 userspace library.
*
* Copyright (C) 2006, 2008 Oracle. All rights reserved.
*/
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/crc32.h>
#include <linux/buffer_head.h>
#include <linux/bitops.h>
#include <linux/debugfs.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <asm/byteorder.h>
#include <cluster/masklog.h>
#include "ocfs2.h"
#include "blockcheck.h"
/*
* We use the following conventions:
*
* d = # data bits
* p = # parity bits
* c = # total code bits (d + p)
*/
/*
* Calculate the bit offset in the hamming code buffer based on the bit's
* offset in the data buffer. Since the hamming code reserves all
* power-of-two bits for parity, the data bit number and the code bit
* number are offset by all the parity bits beforehand.
*
* Recall that bit numbers in hamming code are 1-based. This function
* takes the 0-based data bit from the caller.
*
* An example. Take bit 1 of the data buffer. 1 is a power of two (2^0),
* so it's a parity bit. 2 is a power of two (2^1), so it's a parity bit.
* 3 is not a power of two. So bit 1 of the data buffer ends up as bit 3
* in the code buffer.
*
* The caller can pass in *p if it wants to keep track of the most recent
* number of parity bits added. This allows the function to start the
* calculation at the last place.
*/
static unsigned int calc_code_bit(unsigned int i, unsigned int *p_cache)
{
unsigned int b, p = 0;
/*
* Data bits are 0-based, but we're talking code bits, which
* are 1-based.
*/
b = i + 1;
/* Use the cache if it is there */
if (p_cache)
p = *p_cache;
b += p;
/*
* For every power of two below our bit number, bump our bit.
*
* We compare with (b + 1) because we have to compare with what b
* would be _if_ it were bumped up by the parity bit. Capice?
*
* p is set above.
*/
for (; (1 << p) < (b + 1); p++)
b++;
if (p_cache)
*p_cache = p;
return b;
}
/*
* This is the low level encoder function. It can be called across
* multiple hunks just like the crc32 code. 'd' is the number of bits
* _in_this_hunk_. nr is the bit offset of this hunk. So, if you had
* two 512B buffers, you would do it like so:
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/crc32.h`, `linux/buffer_head.h`, `linux/bitops.h`, `linux/debugfs.h`, `linux/module.h`, `linux/fs.h`.
- Detected declarations: `function Copyright`, `function ocfs2_hamming_encode`, `function ocfs2_hamming_encode_block`, `function ocfs2_hamming_encode`, `function ocfs2_hamming_fix_block`, `function blockcheck_u64_get`, `function ocfs2_blockcheck_debug_remove`, `function ocfs2_blockcheck_debug_install`, `function ocfs2_blockcheck_debug_install`, `function ocfs2_blockcheck_stats_debugfs_remove`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.