fs/efivarfs/vars.c
Source file repositories/reference/linux-study-clean/fs/efivarfs/vars.c
File Facts
- System
- Linux kernel
- Corpus path
fs/efivarfs/vars.c- Extension
.c- Size
- 16183 bytes
- Lines
- 634
- 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.
- 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/capability.hlinux/types.hlinux/errno.hlinux/hex.hlinux/init.hlinux/mm.hlinux/module.hlinux/string.hlinux/smp.hlinux/efi.hlinux/device.hlinux/slab.hlinux/ctype.hlinux/ucs2_string.hinternal.h
Detected Declarations
struct variable_validatefunction validate_device_pathfunction validate_boot_orderfunction validate_load_optionfunction validate_uint16function validate_ascii_stringfunction variable_matchesfunction efivar_get_utf8namefunction efivar_validatefunction efivar_variable_is_removablefunction var_name_strnsizefunction dup_variable_bugfunction efivar_initfunction get_next_variablefunction set_variablefunction efivar_entry_sizefunction efivar_entry_iter_beginfunction efivar_entry_getfunction special
Annotated Snippet
struct variable_validate {
efi_guid_t vendor;
char *name;
bool (*validate)(efi_char16_t *var_name, int match, u8 *data,
unsigned long len);
};
/*
* This is the list of variables we need to validate, as well as the
* whitelist for what we think is safe not to default to immutable.
*
* If it has a validate() method that's not NULL, it'll go into the
* validation routine. If not, it is assumed valid, but still used for
* whitelisting.
*
* Note that it's sorted by {vendor,name}, but globbed names must come after
* any other name with the same prefix.
*/
static const struct variable_validate variable_validate[] = {
{ EFI_GLOBAL_VARIABLE_GUID, "BootNext", validate_uint16 },
{ EFI_GLOBAL_VARIABLE_GUID, "BootOrder", validate_boot_order },
{ EFI_GLOBAL_VARIABLE_GUID, "Boot*", validate_load_option },
{ EFI_GLOBAL_VARIABLE_GUID, "DriverOrder", validate_boot_order },
{ EFI_GLOBAL_VARIABLE_GUID, "Driver*", validate_load_option },
{ EFI_GLOBAL_VARIABLE_GUID, "ConIn", validate_device_path },
{ EFI_GLOBAL_VARIABLE_GUID, "ConInDev", validate_device_path },
{ EFI_GLOBAL_VARIABLE_GUID, "ConOut", validate_device_path },
{ EFI_GLOBAL_VARIABLE_GUID, "ConOutDev", validate_device_path },
{ EFI_GLOBAL_VARIABLE_GUID, "ErrOut", validate_device_path },
{ EFI_GLOBAL_VARIABLE_GUID, "ErrOutDev", validate_device_path },
{ EFI_GLOBAL_VARIABLE_GUID, "Lang", validate_ascii_string },
{ EFI_GLOBAL_VARIABLE_GUID, "OsIndications", NULL },
{ EFI_GLOBAL_VARIABLE_GUID, "PlatformLang", validate_ascii_string },
{ EFI_GLOBAL_VARIABLE_GUID, "Timeout", validate_uint16 },
{ LINUX_EFI_CRASH_GUID, "*", NULL },
{ NULL_GUID, "", NULL },
};
/*
* Check if @var_name matches the pattern given in @match_name.
*
* @var_name: an array of @len non-NUL characters.
* @match_name: a NUL-terminated pattern string, optionally ending in "*". A
* final "*" character matches any trailing characters @var_name,
* including the case when there are none left in @var_name.
* @match: on output, the number of non-wildcard characters in @match_name
* that @var_name matches, regardless of the return value.
* @return: whether @var_name fully matches @match_name.
*/
static bool
variable_matches(const char *var_name, size_t len, const char *match_name,
int *match)
{
for (*match = 0; ; (*match)++) {
char c = match_name[*match];
switch (c) {
case '*':
/* Wildcard in @match_name means we've matched. */
return true;
case '\0':
/* @match_name has ended. Has @var_name too? */
return (*match == len);
default:
/*
* We've reached a non-wildcard char in @match_name.
* Continue only if there's an identical character in
* @var_name.
*/
if (*match < len && c == var_name[*match])
continue;
return false;
}
}
}
char *
efivar_get_utf8name(const efi_char16_t *name16, efi_guid_t *vendor)
{
int len = ucs2_utf8size(name16);
char *name;
/* name, plus '-', plus GUID, plus NUL*/
name = kmalloc(len + 1 + EFI_VARIABLE_GUID_LEN + 1, GFP_KERNEL);
if (!name)
return NULL;
ucs2_as_utf8(name, name16, len);
Annotation
- Immediate include surface: `linux/capability.h`, `linux/types.h`, `linux/errno.h`, `linux/hex.h`, `linux/init.h`, `linux/mm.h`, `linux/module.h`, `linux/string.h`.
- Detected declarations: `struct variable_validate`, `function validate_device_path`, `function validate_boot_order`, `function validate_load_option`, `function validate_uint16`, `function validate_ascii_string`, `function variable_matches`, `function efivar_get_utf8name`, `function efivar_validate`, `function efivar_variable_is_removable`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- 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.