block/partitions/efi.c
Source file repositories/reference/linux-study-clean/block/partitions/efi.c
File Facts
- System
- Linux kernel
- Corpus path
block/partitions/efi.c- Extension
.c- Size
- 23524 bytes
- Lines
- 757
- 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/kernel.hlinux/crc32.hlinux/ctype.hlinux/math64.hlinux/slab.hcheck.hefi.h
Detected Declarations
function force_gpt_fnfunction efi_crc32function last_lbafunction pmbr_part_validfunction is_pmbr_validfunction TiBfunction read_lbafunction alloc_read_gpt_entriesfunction alloc_read_gpt_headerfunction is_gpt_validfunction queue_logical_block_sizefunction is_pte_validfunction compare_gptsfunction le64_to_cpufunction le64_to_cpufunction le32_to_cpufunction le32_to_cpufunction le32_to_cpufunction find_valid_gptfunction utf16_le_to_7bitfunction msdos_partition
Annotated Snippet
if (ret == GPT_MBR_PROTECTIVE) {
part = i;
/*
* Ok, we at least know that there's a protective MBR,
* now check if there are other partition types for
* hybrid MBR.
*/
goto check_hybrid;
}
}
if (ret != GPT_MBR_PROTECTIVE)
goto done;
check_hybrid:
for (i = 0; i < 4; i++)
if ((mbr->partition_record[i].os_type !=
EFI_PMBR_OSTYPE_EFI_GPT) &&
(mbr->partition_record[i].os_type != 0x00))
ret = GPT_MBR_HYBRID;
/*
* Protective MBRs take up the lesser of the whole disk
* or 2 TiB (32bit LBA), ignoring the rest of the disk.
* Some partitioning programs, nonetheless, choose to set
* the size to the maximum 32-bit limitation, disregarding
* the disk size.
*
* Hybrid MBRs do not necessarily comply with this.
*
* Consider a bad value here to be a warning to support dd'ing
* an image from a smaller disk to a larger disk.
*/
if (ret == GPT_MBR_PROTECTIVE) {
sz = le32_to_cpu(mbr->partition_record[part].size_in_lba);
if (sz != (uint32_t) total_sectors - 1 && sz != 0xFFFFFFFF)
pr_debug("GPT: mbr size in lba (%u) different than whole disk (%u).\n",
sz, (uint32_t)min(total_sectors - 1, 0xFFFFFFFF));
}
done:
return ret;
}
/**
* read_lba(): Read bytes from disk, starting at given LBA
* @state: disk parsed partitions
* @lba: the Logical Block Address of the partition table
* @buffer: destination buffer
* @count: bytes to read
*
* Description: Reads @count bytes from @state->disk into @buffer.
* Returns number of bytes read on success, 0 on error.
*/
static size_t read_lba(struct parsed_partitions *state,
u64 lba, u8 *buffer, size_t count)
{
size_t totalreadcount = 0;
sector_t n = lba *
(queue_logical_block_size(state->disk->queue) / 512);
if (!buffer || lba > last_lba(state->disk))
return 0;
while (count) {
int copied = 512;
Sector sect;
unsigned char *data = read_part_sector(state, n++, §);
if (!data)
break;
if (copied > count)
copied = count;
memcpy(buffer, data, copied);
put_dev_sector(sect);
buffer += copied;
totalreadcount +=copied;
count -= copied;
}
return totalreadcount;
}
/**
* alloc_read_gpt_entries(): reads partition entries from disk
* @state: disk parsed partitions
* @gpt: GPT header
*
* Description: Returns ptes on success, NULL on error.
* Allocates space for PTEs based on information found in @gpt.
* Notes: remember to free pte when you're done!
*/
static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
gpt_header *gpt)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/crc32.h`, `linux/ctype.h`, `linux/math64.h`, `linux/slab.h`, `check.h`, `efi.h`.
- Detected declarations: `function force_gpt_fn`, `function efi_crc32`, `function last_lba`, `function pmbr_part_valid`, `function is_pmbr_valid`, `function TiB`, `function read_lba`, `function alloc_read_gpt_entries`, `function alloc_read_gpt_header`, `function is_gpt_valid`.
- 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.