scripts/mod/file2alias.c
Source file repositories/reference/linux-study-clean/scripts/mod/file2alias.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/mod/file2alias.c- Extension
.c- Size
- 46912 bytes
- Lines
- 1585
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdarg.hstdio.hlist.hxalloc.hmodpost.hdevicetable-offsets.hinttypes.hstdint.hctype.hstdbool.h../../include/linux/mod_devicetable.h
Detected Declarations
struct devtablefunction __attribute__function add_uuidfunction add_guidfunction do_usb_entryfunction incbcdfunction do_usb_entry_multifunction do_of_entryfunction do_hid_entryfunction do_ieee1394_entryfunction do_pci_entryfunction do_ccw_entryfunction do_ap_entryfunction do_css_entryfunction do_serio_entryfunction do_acpi_entryfunction do_pnp_device_entryfunction do_pnp_card_entryfunction do_pcmcia_entryfunction do_vio_entryfunction __attribute__function do_inputfunction do_input_entryfunction do_eisa_entryfunction do_parisc_entryfunction do_sdio_entryfunction do_ssb_entryfunction do_bcma_entryfunction do_virtio_entryfunction do_vmbus_entryfunction do_rpmsg_entryfunction do_i2c_entryfunction do_i3c_entryfunction do_slim_entryfunction do_spi_entryfunction dmi_ascii_filterfunction do_dmi_entryfunction do_platform_entryfunction do_mdio_entryfunction do_zorro_entryfunction do_isapnp_entryfunction do_ipack_entryfunction append_nibble_maskfunction do_amba_entryfunction do_mips_cdmm_entryfunction do_x86cpu_entryfunction do_cpu_entryfunction do_mcb_entry
Annotated Snippet
struct devtable {
const char *device_id;
unsigned long id_size;
void (*do_entry)(struct module *mod, void *symval);
};
/* Define a variable f that holds the value of field f of struct devid
* based at address m.
*/
#define DEF_FIELD(m, devid, f) \
typeof(((struct devid *)0)->f) f = \
get_unaligned_native((typeof(f) *)((m) + OFF_##devid##_##f))
/* Define a variable f that holds the address of field f of struct devid
* based at address m. Due to the way typeof works, for a field of type
* T[N] the variable has type T(*)[N], _not_ T*.
*/
#define DEF_FIELD_ADDR(m, devid, f) \
typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f)
#define ADD(str, sep, cond, field) \
do { \
strcat(str, sep); \
if (cond) \
sprintf(str + strlen(str), \
sizeof(field) == 1 ? "%02X" : \
sizeof(field) == 2 ? "%04X" : \
sizeof(field) == 4 ? "%08X" : "", \
field); \
else \
sprintf(str + strlen(str), "*"); \
} while(0)
static inline void add_uuid(char *str, uuid_le uuid)
{
int len = strlen(str);
sprintf(str + len, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
uuid.b[3], uuid.b[2], uuid.b[1], uuid.b[0],
uuid.b[5], uuid.b[4], uuid.b[7], uuid.b[6],
uuid.b[8], uuid.b[9], uuid.b[10], uuid.b[11],
uuid.b[12], uuid.b[13], uuid.b[14], uuid.b[15]);
}
static inline void add_guid(char *str, guid_t guid)
{
int len = strlen(str);
sprintf(str + len, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
guid.b[3], guid.b[2], guid.b[1], guid.b[0],
guid.b[5], guid.b[4], guid.b[7], guid.b[6],
guid.b[8], guid.b[9], guid.b[10], guid.b[11],
guid.b[12], guid.b[13], guid.b[14], guid.b[15]);
}
/* USB is special because the bcdDevice can be matched against a numeric range */
/* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
static void do_usb_entry(void *symval,
unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
unsigned char range_lo, unsigned char range_hi,
unsigned char max, struct module *mod)
{
char alias[500];
DEF_FIELD(symval, usb_device_id, match_flags);
DEF_FIELD(symval, usb_device_id, idVendor);
DEF_FIELD(symval, usb_device_id, idProduct);
DEF_FIELD(symval, usb_device_id, bcdDevice_lo);
DEF_FIELD(symval, usb_device_id, bDeviceClass);
DEF_FIELD(symval, usb_device_id, bDeviceSubClass);
DEF_FIELD(symval, usb_device_id, bDeviceProtocol);
DEF_FIELD(symval, usb_device_id, bInterfaceClass);
DEF_FIELD(symval, usb_device_id, bInterfaceSubClass);
DEF_FIELD(symval, usb_device_id, bInterfaceProtocol);
DEF_FIELD(symval, usb_device_id, bInterfaceNumber);
strcpy(alias, "usb:");
ADD(alias, "v", match_flags&USB_DEVICE_ID_MATCH_VENDOR,
idVendor);
ADD(alias, "p", match_flags&USB_DEVICE_ID_MATCH_PRODUCT,
idProduct);
strcat(alias, "d");
if (bcdDevice_initial_digits)
sprintf(alias + strlen(alias), "%0*X",
bcdDevice_initial_digits, bcdDevice_initial);
if (range_lo == range_hi)
sprintf(alias + strlen(alias), "%X", range_lo);
else if (range_lo > 0 || range_hi < max) {
if (range_lo > 0x9 || range_hi < 0xA)
sprintf(alias + strlen(alias),
Annotation
- Immediate include surface: `stdarg.h`, `stdio.h`, `list.h`, `xalloc.h`, `modpost.h`, `devicetable-offsets.h`, `inttypes.h`, `stdint.h`.
- Detected declarations: `struct devtable`, `function __attribute__`, `function add_uuid`, `function add_guid`, `function do_usb_entry`, `function incbcd`, `function do_usb_entry_multi`, `function do_of_entry`, `function do_hid_entry`, `function do_ieee1394_entry`.
- Atlas domain: Support Tooling And Documentation / scripts.
- 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.