tools/usb/usbip/libsrc/names.c
Source file repositories/reference/linux-study-clean/tools/usb/usbip/libsrc/names.c
File Facts
- System
- Linux kernel
- Corpus path
tools/usb/usbip/libsrc/names.c- Extension
.c- Size
- 10679 bytes
- Lines
- 487
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- 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
sys/types.hsys/stat.hfcntl.hdirent.hstring.herrno.hstdlib.hunistd.hstdio.hctype.hnames.husbip_common.h
Detected Declarations
struct vendorstruct productstruct classstruct subclassstruct protocolstruct genericstrtablestruct poolfunction hashnumfunction names_freefunction new_vendorfunction new_productfunction new_classfunction new_subclassfunction new_protocolfunction parsefunction names_init
Annotated Snippet
struct vendor {
struct vendor *next;
u_int16_t vendorid;
char name[1];
};
struct product {
struct product *next;
u_int16_t vendorid, productid;
char name[1];
};
struct class {
struct class *next;
u_int8_t classid;
char name[1];
};
struct subclass {
struct subclass *next;
u_int8_t classid, subclassid;
char name[1];
};
struct protocol {
struct protocol *next;
u_int8_t classid, subclassid, protocolid;
char name[1];
};
struct genericstrtable {
struct genericstrtable *next;
unsigned int num;
char name[1];
};
#define HASH1 0x10
#define HASH2 0x02
#define HASHSZ 16
static unsigned int hashnum(unsigned int num)
{
unsigned int mask1 = HASH1 << 27, mask2 = HASH2 << 27;
for (; mask1 >= HASH1; mask1 >>= 1, mask2 >>= 1)
if (num & mask1)
num ^= mask2;
return num & (HASHSZ-1);
}
static struct vendor *vendors[HASHSZ] = { NULL, };
static struct product *products[HASHSZ] = { NULL, };
static struct class *classes[HASHSZ] = { NULL, };
static struct subclass *subclasses[HASHSZ] = { NULL, };
static struct protocol *protocols[HASHSZ] = { NULL, };
const char *names_vendor(u_int16_t vendorid)
{
struct vendor *v;
v = vendors[hashnum(vendorid)];
for (; v; v = v->next)
if (v->vendorid == vendorid)
return v->name;
return NULL;
}
const char *names_product(u_int16_t vendorid, u_int16_t productid)
{
struct product *p;
p = products[hashnum((vendorid << 16) | productid)];
for (; p; p = p->next)
if (p->vendorid == vendorid && p->productid == productid)
return p->name;
return NULL;
}
const char *names_class(u_int8_t classid)
{
struct class *c;
c = classes[hashnum(classid)];
for (; c; c = c->next)
if (c->classid == classid)
return c->name;
return NULL;
}
Annotation
- Immediate include surface: `sys/types.h`, `sys/stat.h`, `fcntl.h`, `dirent.h`, `string.h`, `errno.h`, `stdlib.h`, `unistd.h`.
- Detected declarations: `struct vendor`, `struct product`, `struct class`, `struct subclass`, `struct protocol`, `struct genericstrtable`, `struct pool`, `function hashnum`, `function names_free`, `function new_vendor`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.