fs/ecryptfs/messaging.c
Source file repositories/reference/linux-study-clean/fs/ecryptfs/messaging.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ecryptfs/messaging.c- Extension
.c- Size
- 13283 bytes
- Lines
- 453
- 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.
- 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/overflow.hlinux/sched.hlinux/slab.hlinux/user_namespace.hlinux/nsproxy.hecryptfs_kernel.h
Detected Declarations
function ecryptfs_acquire_free_msg_ctxfunction ecryptfs_msg_ctx_free_to_allocfunction ecryptfs_msg_ctx_alloc_to_freefunction ecryptfs_find_daemon_by_euidfunction hlist_for_each_entryfunction ecryptfs_spawn_daemonfunction ecryptfs_exorcise_daemonfunction ecryptfs_process_responsefunction ecryptfs_send_message_lockedfunction ecryptfs_send_messagefunction ecryptfs_wait_for_responsefunction ecryptfs_init_messagingfunction ecryptfs_release_messagingfunction hlist_for_each_entry_safe
Annotated Snippet
if (mutex_trylock(&(*msg_ctx)->mux)) {
(*msg_ctx)->task = current;
rc = 0;
goto out;
}
}
rc = -ENOMEM;
out:
return rc;
}
/**
* ecryptfs_msg_ctx_free_to_alloc
* @msg_ctx: The context to move from the free list to the alloc list
*
* Must be called with ecryptfs_msg_ctx_lists_mux held.
*/
static void ecryptfs_msg_ctx_free_to_alloc(struct ecryptfs_msg_ctx *msg_ctx)
{
list_move(&msg_ctx->node, &ecryptfs_msg_ctx_alloc_list);
msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_PENDING;
msg_ctx->counter = ++ecryptfs_msg_counter;
}
/**
* ecryptfs_msg_ctx_alloc_to_free
* @msg_ctx: The context to move from the alloc list to the free list
*
* Must be called with ecryptfs_msg_ctx_lists_mux held.
*/
void ecryptfs_msg_ctx_alloc_to_free(struct ecryptfs_msg_ctx *msg_ctx)
{
list_move(&(msg_ctx->node), &ecryptfs_msg_ctx_free_list);
kfree(msg_ctx->msg);
msg_ctx->msg = NULL;
msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_FREE;
}
/**
* ecryptfs_find_daemon_by_euid
* @daemon: If return value is zero, points to the desired daemon pointer
*
* Must be called with ecryptfs_daemon_hash_mux held.
*
* Search the hash list for the current effective user id.
*
* Returns zero if the user id exists in the list; non-zero otherwise.
*/
int ecryptfs_find_daemon_by_euid(struct ecryptfs_daemon **daemon)
{
int rc;
hlist_for_each_entry(*daemon,
&ecryptfs_daemon_hash[ecryptfs_current_euid_hash()],
euid_chain) {
if (uid_eq((*daemon)->file->f_cred->euid, current_euid())) {
rc = 0;
goto out;
}
}
rc = -EINVAL;
out:
return rc;
}
/**
* ecryptfs_spawn_daemon - Create and initialize a new daemon struct
* @daemon: Pointer to set to newly allocated daemon struct
* @file: File used when opening /dev/ecryptfs
*
* Must be called ceremoniously while in possession of
* ecryptfs_sacred_daemon_hash_mux
*
* Returns zero on success; non-zero otherwise
*/
int
ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, struct file *file)
{
int rc = 0;
(*daemon) = kzalloc_obj(**daemon);
if (!(*daemon)) {
rc = -ENOMEM;
goto out;
}
(*daemon)->file = file;
mutex_init(&(*daemon)->mux);
INIT_LIST_HEAD(&(*daemon)->msg_ctx_out_queue);
init_waitqueue_head(&(*daemon)->wait);
(*daemon)->num_queued_msg_ctx = 0;
Annotation
- Immediate include surface: `linux/overflow.h`, `linux/sched.h`, `linux/slab.h`, `linux/user_namespace.h`, `linux/nsproxy.h`, `ecryptfs_kernel.h`.
- Detected declarations: `function ecryptfs_acquire_free_msg_ctx`, `function ecryptfs_msg_ctx_free_to_alloc`, `function ecryptfs_msg_ctx_alloc_to_free`, `function ecryptfs_find_daemon_by_euid`, `function hlist_for_each_entry`, `function ecryptfs_spawn_daemon`, `function ecryptfs_exorcise_daemon`, `function ecryptfs_process_response`, `function ecryptfs_send_message_locked`, `function ecryptfs_send_message`.
- 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.