block/partitions/ldm.c
Source file repositories/reference/linux-study-clean/block/partitions/ldm.c
File Facts
- System
- Linux kernel
- Corpus path
block/partitions/ldm.c- Extension
.c- Size
- 42774 bytes
- Lines
- 1488
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: implementation source
- Status
- source 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.
- 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/slab.hlinux/pagemap.hlinux/stringify.hlinux/kernel.hlinux/uuid.hlinux/msdos_partition.hldm.hcheck.h
Detected Declarations
function Copyrightfunction ldm_parse_privheadfunction TOCBLOCKfunction ldm_parse_vmdbfunction ldm_compare_privheadsfunction ldm_compare_tocblocksfunction areafunction ldm_validate_tocblocksfunction ldm_validate_vmdbfunction ldm_validate_partition_tablefunction ldm_get_disk_objidfunction list_for_eachfunction ldm_create_data_partitionsfunction ldm_relativefunction ldm_get_vnumfunction ldm_get_vstrfunction objectfunction objectfunction objectfunction objectfunction objectfunction objectfunction objectfunction ldm_parse_vblkfunction ldm_ldmdb_addfunction list_for_eachfunction ldm_frag_addfunction list_for_eachfunction ldm_frag_freefunction ldm_frag_commitfunction list_for_eachfunction ldm_get_vblksfunction ldm_free_vblksfunction ldm_partition
Annotated Snippet
sizeof (toc->bitmap1_name)) != 0) {
ldm_crit ("TOCBLOCK's first bitmap is '%s', should be '%s'.",
TOC_BITMAP1, toc->bitmap1_name);
return false;
}
strscpy_pad(toc->bitmap2_name, data + 0x46, sizeof(toc->bitmap2_name));
toc->bitmap2_start = get_unaligned_be64(data + 0x50);
toc->bitmap2_size = get_unaligned_be64(data + 0x58);
if (strncmp (toc->bitmap2_name, TOC_BITMAP2,
sizeof (toc->bitmap2_name)) != 0) {
ldm_crit ("TOCBLOCK's second bitmap is '%s', should be '%s'.",
TOC_BITMAP2, toc->bitmap2_name);
return false;
}
ldm_debug ("Parsed TOCBLOCK successfully.");
return true;
}
/**
* ldm_parse_vmdb - Read the LDM Database VMDB structure
* @data: Raw database VMDB structure loaded from the device
* @vm: In-memory vmdb structure in which to return parsed information
*
* This parses the LDM Database VMDB structure supplied in @data and sets up
* the in-memory vmdb structure @vm with the obtained information.
*
* N.B. The *_start, *_size and *_seq values will be range-checked later.
*
* Return: 'true' @vm contains VMDB info
* 'false' @vm contents are undefined
*/
static bool ldm_parse_vmdb (const u8 *data, struct vmdb *vm)
{
BUG_ON (!data || !vm);
if (MAGIC_VMDB != get_unaligned_be32(data)) {
ldm_crit ("Cannot find the VMDB, database may be corrupt.");
return false;
}
vm->ver_major = get_unaligned_be16(data + 0x12);
vm->ver_minor = get_unaligned_be16(data + 0x14);
if ((vm->ver_major != 4) || (vm->ver_minor != 10)) {
ldm_error ("Expected VMDB version %d.%d, got %d.%d. "
"Aborting.", 4, 10, vm->ver_major, vm->ver_minor);
return false;
}
vm->vblk_size = get_unaligned_be32(data + 0x08);
if (vm->vblk_size == 0) {
ldm_error ("Illegal VBLK size");
return false;
}
vm->vblk_offset = get_unaligned_be32(data + 0x0C);
vm->last_vblk_seq = get_unaligned_be32(data + 0x04);
ldm_debug ("Parsed VMDB successfully.");
return true;
}
/**
* ldm_compare_privheads - Compare two privhead objects
* @ph1: First privhead
* @ph2: Second privhead
*
* This compares the two privhead structures @ph1 and @ph2.
*
* Return: 'true' Identical
* 'false' Different
*/
static bool ldm_compare_privheads (const struct privhead *ph1,
const struct privhead *ph2)
{
BUG_ON (!ph1 || !ph2);
return ((ph1->ver_major == ph2->ver_major) &&
(ph1->ver_minor == ph2->ver_minor) &&
(ph1->logical_disk_start == ph2->logical_disk_start) &&
(ph1->logical_disk_size == ph2->logical_disk_size) &&
(ph1->config_start == ph2->config_start) &&
(ph1->config_size == ph2->config_size) &&
uuid_equal(&ph1->disk_id, &ph2->disk_id));
}
/**
* ldm_compare_tocblocks - Compare two tocblock objects
* @toc1: First toc
* @toc2: Second toc
*
Annotation
- Immediate include surface: `linux/slab.h`, `linux/pagemap.h`, `linux/stringify.h`, `linux/kernel.h`, `linux/uuid.h`, `linux/msdos_partition.h`, `ldm.h`, `check.h`.
- Detected declarations: `function Copyright`, `function ldm_parse_privhead`, `function TOCBLOCK`, `function ldm_parse_vmdb`, `function ldm_compare_privheads`, `function ldm_compare_tocblocks`, `function area`, `function ldm_validate_tocblocks`, `function ldm_validate_vmdb`, `function ldm_validate_partition_table`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: source 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.