fs/smb/server/misc.c
Source file repositories/reference/linux-study-clean/fs/smb/server/misc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/smb/server/misc.c- Extension
.c- Size
- 7586 bytes
- Lines
- 356
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/kernel.hlinux/xattr.hlinux/fs.hlinux/unicode.hmisc.hsmb_common.hconnection.hvfs.hmgmt/share_config.h
Detected Declarations
function Copyrightfunction is_char_allowedfunction ksmbd_validate_filenamefunction ksmbd_validate_stream_namefunction parse_stream_namefunction convert_to_nt_pathnamefunction get_nlinkfunction ksmbd_conv_path_to_unixfunction ksmbd_strip_last_slashfunction ksmbd_conv_path_to_windowsfunction ksmbd_extract_sharenamefunction UTCfunction ksmbd_UnixTimeToNTfunction ksmbd_systime
Annotated Snippet
switch (*p) {
case '?':
s++;
len--;
p++;
break;
case '*':
star = true;
str = s;
if (!*++p)
return true;
pattern = p;
break;
default:
if (tolower(*s) == tolower(*p)) {
s++;
len--;
p++;
} else {
if (!star)
return false;
str++;
s = str;
p = pattern;
}
break;
}
}
if (*p == '*')
++p;
return !*p;
}
/*
* is_char_allowed() - check for valid character
* @ch: input character to be checked
*
* Return: 1 if char is allowed, otherwise 0
*/
static inline int is_char_allowed(char ch)
{
/* check for control chars, wildcards etc. */
if (!(ch & 0x80) &&
(ch <= 0x1f ||
ch == '?' || ch == '"' || ch == '<' ||
ch == '>' || ch == '|' || ch == '*'))
return 0;
return 1;
}
int ksmbd_validate_filename(char *filename)
{
while (*filename) {
char c = *filename;
filename++;
if (!is_char_allowed(c)) {
ksmbd_debug(VFS, "File name validation failed: 0x%x\n", c);
return -ENOENT;
}
}
return 0;
}
static int ksmbd_validate_stream_name(char *stream_name)
{
while (*stream_name) {
char c = *stream_name;
stream_name++;
if (c == '/' || c == ':' || c == '\\') {
pr_err("Stream name validation failed: %c\n", c);
return -ENOENT;
}
}
return 0;
}
int parse_stream_name(char *filename, char **stream_name, int *s_type)
{
char *stream_type;
char *s_name;
int rc = 0;
s_name = filename;
filename = strsep(&s_name, ":");
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/xattr.h`, `linux/fs.h`, `linux/unicode.h`, `misc.h`, `smb_common.h`, `connection.h`, `vfs.h`.
- Detected declarations: `function Copyright`, `function is_char_allowed`, `function ksmbd_validate_filename`, `function ksmbd_validate_stream_name`, `function parse_stream_name`, `function convert_to_nt_pathname`, `function get_nlink`, `function ksmbd_conv_path_to_unix`, `function ksmbd_strip_last_slash`, `function ksmbd_conv_path_to_windows`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- 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.