fs/nls/nls_base.c
Source file repositories/reference/linux-study-clean/fs/nls/nls_base.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nls/nls_base.c- Extension
.c- Size
- 16296 bytes
- Lines
- 561
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/string.hlinux/nls.hlinux/kernel.hlinux/errno.hlinux/kmod.hlinux/spinlock.hasm/byteorder.h
Detected Declarations
struct utf8_tablefunction utf8_to_utf32function utf32_to_utf8function put_utf16function utf8s_to_utf16sfunction get_utf16function utf16s_to_utf8sfunction __register_nlsfunction unregister_nlsfunction unload_nlsfunction uni2charfunction char2uniexport utf8_to_utf32export utf32_to_utf8export utf8s_to_utf16sexport utf16s_to_utf8sexport __register_nlsexport unregister_nlsexport unload_nlsexport load_nlsexport load_nls_default
Annotated Snippet
struct utf8_table {
int cmask;
int cval;
int shift;
long lmask;
long lval;
};
static const struct utf8_table utf8_table[] =
{
{0x80, 0x00, 0*6, 0x7F, 0, /* 1 byte sequence */},
{0xE0, 0xC0, 1*6, 0x7FF, 0x80, /* 2 byte sequence */},
{0xF0, 0xE0, 2*6, 0xFFFF, 0x800, /* 3 byte sequence */},
{0xF8, 0xF0, 3*6, 0x1FFFFF, 0x10000, /* 4 byte sequence */},
{0xFC, 0xF8, 4*6, 0x3FFFFFF, 0x200000, /* 5 byte sequence */},
{0xFE, 0xFC, 5*6, 0x7FFFFFFF, 0x4000000, /* 6 byte sequence */},
{0, /* end of table */}
};
#define UNICODE_MAX 0x0010ffff
#define PLANE_SIZE 0x00010000
#define SURROGATE_MASK 0xfffff800
#define SURROGATE_PAIR 0x0000d800
#define SURROGATE_LOW 0x00000400
#define SURROGATE_BITS 0x000003ff
int utf8_to_utf32(const u8 *s, int inlen, unicode_t *pu)
{
unsigned long l;
int c0, c, nc;
const struct utf8_table *t;
nc = 0;
c0 = *s;
l = c0;
for (t = utf8_table; t->cmask; t++) {
nc++;
if ((c0 & t->cmask) == t->cval) {
l &= t->lmask;
if (l < t->lval || l > UNICODE_MAX ||
(l & SURROGATE_MASK) == SURROGATE_PAIR)
return -EILSEQ;
*pu = (unicode_t) l;
return nc;
}
if (inlen <= nc)
return -EOVERFLOW;
s++;
c = (*s ^ 0x80) & 0xFF;
if (c & 0xC0)
return -EILSEQ;
l = (l << 6) | c;
}
return -EILSEQ;
}
EXPORT_SYMBOL(utf8_to_utf32);
int utf32_to_utf8(unicode_t u, u8 *s, int maxout)
{
unsigned long l;
int c, nc;
const struct utf8_table *t;
if (!s)
return 0;
l = u;
if (l > UNICODE_MAX || (l & SURROGATE_MASK) == SURROGATE_PAIR)
return -EILSEQ;
nc = 0;
for (t = utf8_table; t->cmask && maxout; t++, maxout--) {
nc++;
if (l <= t->lmask) {
c = t->shift;
*s = (u8) (t->cval | (l >> c));
while (c > 0) {
c -= 6;
s++;
*s = (u8) (0x80 | ((l >> c) & 0x3F));
}
return nc;
}
}
return -EOVERFLOW;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/string.h`, `linux/nls.h`, `linux/kernel.h`, `linux/errno.h`, `linux/kmod.h`, `linux/spinlock.h`, `asm/byteorder.h`.
- Detected declarations: `struct utf8_table`, `function utf8_to_utf32`, `function utf32_to_utf8`, `function put_utf16`, `function utf8s_to_utf16s`, `function get_utf16`, `function utf16s_to_utf8s`, `function __register_nls`, `function unregister_nls`, `function unload_nls`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.