lib/bitmap-str.c
Source file repositories/reference/linux-study-clean/lib/bitmap-str.c
File Facts
- System
- Linux kernel
- Corpus path
lib/bitmap-str.c- Extension
.c- Size
- 13917 bytes
- Lines
- 479
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitmap.hlinux/ctype.hlinux/errno.hlinux/err.hlinux/export.hlinux/hex.hlinux/kernel.hlinux/mm.hlinux/string.hkstrtox.h
Detected Declarations
struct regionfunction bitmap_parse_userfunction bitmap_print_to_buffunction example_bin_attribute_showfunction bitmap_print_bitmask_to_buffunction bitmap_set_regionfunction bitmap_check_regionfunction end_of_strfunction __end_of_regionfunction end_of_regionfunction bitmap_parselistfunction bitmap_parselist_userfunction bitsexport bitmap_parse_userexport bitmap_print_bitmask_to_bufexport bitmap_print_list_to_bufexport bitmap_parselistexport bitmap_parselist_userexport bitmap_parse
Annotated Snippet
struct region {
unsigned int start;
unsigned int off;
unsigned int group_len;
unsigned int end;
unsigned int nbits;
};
static void bitmap_set_region(const struct region *r, unsigned long *bitmap)
{
unsigned int start;
for (start = r->start; start <= r->end; start += r->group_len)
bitmap_set(bitmap, start, min(r->end - start + 1, r->off));
}
static int bitmap_check_region(const struct region *r)
{
if (r->start > r->end || r->group_len == 0 || r->off > r->group_len)
return -EINVAL;
if (r->end >= r->nbits)
return -ERANGE;
return 0;
}
static const char *bitmap_getnum(const char *str, unsigned int *num,
unsigned int lastbit)
{
unsigned long long n;
unsigned int len;
if (str[0] == 'N') {
*num = lastbit;
return str + 1;
}
len = _parse_integer(str, 10, &n);
if (!len)
return ERR_PTR(-EINVAL);
if (len & KSTRTOX_OVERFLOW || n != (unsigned int)n)
return ERR_PTR(-EOVERFLOW);
*num = n;
return str + len;
}
static inline bool end_of_str(char c)
{
return c == '\0' || c == '\n';
}
static inline bool __end_of_region(char c)
{
return isspace(c) || c == ',';
}
static inline bool end_of_region(char c)
{
return __end_of_region(c) || end_of_str(c);
}
/*
* The format allows commas and whitespaces at the beginning
* of the region.
*/
static const char *bitmap_find_region(const char *str)
{
while (__end_of_region(*str))
str++;
return end_of_str(*str) ? NULL : str;
}
static const char *bitmap_find_region_reverse(const char *start, const char *end)
{
while (start <= end && __end_of_region(*end))
end--;
return end;
}
static const char *bitmap_parse_region(const char *str, struct region *r)
{
unsigned int lastbit = r->nbits - 1;
if (!strncasecmp(str, "all", 3)) {
r->start = 0;
r->end = lastbit;
Annotation
- Immediate include surface: `linux/bitmap.h`, `linux/ctype.h`, `linux/errno.h`, `linux/err.h`, `linux/export.h`, `linux/hex.h`, `linux/kernel.h`, `linux/mm.h`.
- Detected declarations: `struct region`, `function bitmap_parse_user`, `function bitmap_print_to_buf`, `function example_bin_attribute_show`, `function bitmap_print_bitmask_to_buf`, `function bitmap_set_region`, `function bitmap_check_region`, `function end_of_str`, `function __end_of_region`, `function end_of_region`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration 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.