fs/smb/server/smb2misc.c
Source file repositories/reference/linux-study-clean/fs/smb/server/smb2misc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/smb/server/smb2misc.c- Extension
.c- Size
- 13875 bytes
- Lines
- 473
- 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.
- 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
glob.hsmb_common.h../common/smb2status.hmgmt/user_session.hconnection.h
Detected Declarations
function Copyrightfunction smb2_get_data_area_lenfunction smb2_calc_sizefunction smb2_query_info_req_lenfunction smb2_set_info_req_lenfunction smb2_read_req_lenfunction smb2_write_req_lenfunction smb2_query_dir_req_lenfunction smb2_ioctl_req_lenfunction smb2_ioctl_resp_lenfunction smb2_validate_credit_chargefunction ksmbd_smb2_check_messagefunction smb2_negotiate_request
Annotated Snippet
if (((struct smb2_create_req *)hdr)->CreateContextsLength) {
*off = le32_to_cpu(((struct smb2_create_req *)
hdr)->CreateContextsOffset);
*len = le32_to_cpu(((struct smb2_create_req *)
hdr)->CreateContextsLength);
if (!name_len)
break;
if (name_off + name_len < (u64)*off + *len)
break;
}
*off = name_off;
*len = name_len;
break;
}
case SMB2_QUERY_INFO:
*off = max_t(unsigned int,
le16_to_cpu(((struct smb2_query_info_req *)hdr)->InputBufferOffset),
offsetof(struct smb2_query_info_req, Buffer));
*len = le32_to_cpu(((struct smb2_query_info_req *)hdr)->InputBufferLength);
break;
case SMB2_SET_INFO:
*off = max_t(unsigned int,
le16_to_cpu(((struct smb2_set_info_req *)hdr)->BufferOffset),
offsetof(struct smb2_set_info_req, Buffer));
*len = le32_to_cpu(((struct smb2_set_info_req *)hdr)->BufferLength);
break;
case SMB2_READ:
*off = le16_to_cpu(((struct smb2_read_req *)hdr)->ReadChannelInfoOffset);
*len = le16_to_cpu(((struct smb2_read_req *)hdr)->ReadChannelInfoLength);
break;
case SMB2_WRITE:
if (((struct smb2_write_req *)hdr)->DataOffset ||
((struct smb2_write_req *)hdr)->Length) {
*off = max_t(unsigned short int,
le16_to_cpu(((struct smb2_write_req *)hdr)->DataOffset),
offsetof(struct smb2_write_req, Buffer));
*len = le32_to_cpu(((struct smb2_write_req *)hdr)->Length);
break;
}
*off = le16_to_cpu(((struct smb2_write_req *)hdr)->WriteChannelInfoOffset);
*len = le16_to_cpu(((struct smb2_write_req *)hdr)->WriteChannelInfoLength);
break;
case SMB2_QUERY_DIRECTORY:
*off = max_t(unsigned short int,
le16_to_cpu(((struct smb2_query_directory_req *)hdr)->FileNameOffset),
offsetof(struct smb2_query_directory_req, Buffer));
*len = le16_to_cpu(((struct smb2_query_directory_req *)hdr)->FileNameLength);
break;
case SMB2_LOCK:
{
unsigned short lock_count;
lock_count = le16_to_cpu(((struct smb2_lock_req *)hdr)->LockCount);
if (lock_count > 0) {
*off = offsetof(struct smb2_lock_req, locks);
*len = sizeof(struct smb2_lock_element) * lock_count;
}
break;
}
case SMB2_IOCTL:
*off = max_t(unsigned int,
le32_to_cpu(((struct smb2_ioctl_req *)hdr)->InputOffset),
offsetof(struct smb2_ioctl_req, Buffer));
*len = le32_to_cpu(((struct smb2_ioctl_req *)hdr)->InputCount);
break;
default:
ksmbd_debug(SMB, "no length check for command\n");
break;
}
if (*off > 4096) {
ksmbd_debug(SMB, "offset %d too large\n", *off);
ret = -EINVAL;
} else if ((u64)*off + *len > MAX_STREAM_PROT_LEN) {
ksmbd_debug(SMB, "Request is larger than maximum stream protocol length(%u): %llu\n",
MAX_STREAM_PROT_LEN, (u64)*off + *len);
ret = -EINVAL;
}
return ret;
}
/*
* Calculate the size of the SMB message based on the fixed header
* portion, the number of word parameters and the data portion of the message.
*/
static int smb2_calc_size(void *buf, unsigned int *len)
Annotation
- Immediate include surface: `glob.h`, `smb_common.h`, `../common/smb2status.h`, `mgmt/user_session.h`, `connection.h`.
- Detected declarations: `function Copyright`, `function smb2_get_data_area_len`, `function smb2_calc_size`, `function smb2_query_info_req_len`, `function smb2_set_info_req_len`, `function smb2_read_req_len`, `function smb2_write_req_len`, `function smb2_query_dir_req_len`, `function smb2_ioctl_req_len`, `function smb2_ioctl_resp_len`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source 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.