drivers/md/dm-init.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-init.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-init.c- Extension
.c- Size
- 8291 bytes
- Lines
- 329
- Domain
- Driver Families
- Bucket
- drivers/md
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/ctype.hlinux/delay.hlinux/device.hlinux/device-mapper.hlinux/init.hlinux/list.hlinux/moduleparam.h
Detected Declarations
struct dm_devicefunction dm_verify_target_typefunction dm_setup_cleanupfunction list_for_each_entry_safefunction dm_parse_tablefunction dm_parse_devicesfunction dm_init_initfunction list_for_each_entry
Annotated Snippet
struct dm_device {
struct dm_ioctl dmi;
struct dm_target_spec *table[DM_MAX_TARGETS];
char *target_args_array[DM_MAX_TARGETS];
struct list_head list;
};
static const char * const dm_allowed_targets[] __initconst = {
"crypt",
"delay",
"linear",
"snapshot-origin",
"striped",
"verity",
};
static int __init dm_verify_target_type(const char *target)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(dm_allowed_targets); i++) {
if (!strcmp(dm_allowed_targets[i], target))
return 0;
}
return -EINVAL;
}
static void __init dm_setup_cleanup(struct list_head *devices)
{
struct dm_device *dev, *tmp;
unsigned int i;
list_for_each_entry_safe(dev, tmp, devices, list) {
list_del(&dev->list);
for (i = 0; i < dev->dmi.target_count; i++) {
kfree(dev->table[i]);
kfree(dev->target_args_array[i]);
}
kfree(dev);
}
}
/**
* str_field_delimit - delimit a string based on a separator char.
* @str: the pointer to the string to delimit.
* @separator: char that delimits the field
*
* Find a @separator and replace it by '\0'.
* Remove leading and trailing spaces.
* Return the remainder string after the @separator.
*/
static char __init *str_field_delimit(char **str, char separator)
{
char *s;
/* TODO: add support for escaped characters */
*str = skip_spaces(*str);
s = strchr(*str, separator);
/* Delimit the field and remove trailing spaces */
if (s)
*s = '\0';
*str = strim(*str);
return s ? ++s : NULL;
}
/**
* dm_parse_table_entry - parse a table entry
* @dev: device to store the parsed information.
* @str: the pointer to a string with the format:
* <start_sector> <num_sectors> <target_type> <target_args>[, ...]
*
* Return the remainder string after the table entry, i.e, after the comma which
* delimits the entry or NULL if reached the end of the string.
*/
static char __init *dm_parse_table_entry(struct dm_device *dev, char *str)
{
const unsigned int n = dev->dmi.target_count - 1;
struct dm_target_spec *sp;
unsigned int i;
/* fields: */
char *field[4];
char *next;
field[0] = str;
/* Delimit first 3 fields that are separated by space */
for (i = 0; i < ARRAY_SIZE(field) - 1; i++) {
field[i + 1] = str_field_delimit(&field[i], ' ');
if (!field[i + 1])
return ERR_PTR(-EINVAL);
}
Annotation
- Immediate include surface: `linux/ctype.h`, `linux/delay.h`, `linux/device.h`, `linux/device-mapper.h`, `linux/init.h`, `linux/list.h`, `linux/moduleparam.h`.
- Detected declarations: `struct dm_device`, `function dm_verify_target_type`, `function dm_setup_cleanup`, `function list_for_each_entry_safe`, `function dm_parse_table`, `function dm_parse_devices`, `function dm_init_init`, `function list_for_each_entry`.
- Atlas domain: Driver Families / drivers/md.
- 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.