fs/ecryptfs/mmap.c
Source file repositories/reference/linux-study-clean/fs/ecryptfs/mmap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ecryptfs/mmap.c- Extension
.c- Size
- 15574 bytes
- Lines
- 535
- 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/pagemap.hlinux/writeback.hlinux/page-flags.hlinux/mount.hlinux/file.hlinux/scatterlist.hlinux/slab.hlinux/xattr.hlinux/unaligned.hecryptfs_kernel.hlinux/buffer_head.h
Detected Declarations
function Copyrightfunction strip_xattr_flagfunction ecryptfs_copy_up_encrypted_with_headerfunction ecryptfs_read_foliofunction fill_zeros_to_end_of_pagefunction ecryptfs_write_beginfunction ecryptfs_write_inode_size_to_headerfunction ecryptfs_write_inode_size_to_xattrfunction ecryptfs_write_inode_size_to_metadatafunction ecryptfs_write_endfunction ecryptfs_bmap
Annotated Snippet
if (error) {
ecryptfs_printk(KERN_WARNING,
"Error encrypting folio (index [0x%.16lx])\n",
folio->index);
folio_clear_uptodate(folio);
mapping_set_error(mapping, error);
}
folio_unlock(folio);
}
return error;
}
static void strip_xattr_flag(char *page_virt,
struct ecryptfs_crypt_stat *crypt_stat)
{
if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) {
size_t written;
crypt_stat->flags &= ~ECRYPTFS_METADATA_IN_XATTR;
ecryptfs_write_crypt_stat_flags(page_virt, crypt_stat,
&written);
crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR;
}
}
/*
* Header Extent:
* Octets 0-7: Unencrypted file size (big-endian)
* Octets 8-15: eCryptfs special marker
* Octets 16-19: Flags
* Octet 16: File format version number (between 0 and 255)
* Octets 17-18: Reserved
* Octet 19: Bit 1 (lsb): Reserved
* Bit 2: Encrypted?
* Bits 3-8: Reserved
* Octets 20-23: Header extent size (big-endian)
* Octets 24-25: Number of header extents at front of file
* (big-endian)
* Octet 26: Begin RFC 2440 authentication token packet set
*/
/**
* ecryptfs_copy_up_encrypted_with_header
* @folio: Sort of a ``virtual'' representation of the encrypted lower
* file. The actual lower file does not have the metadata in
* the header. This is locked.
* @crypt_stat: The eCryptfs inode's cryptographic context
*
* The ``view'' is the version of the file that userspace winds up
* seeing, with the header information inserted.
*/
static int
ecryptfs_copy_up_encrypted_with_header(struct folio *folio,
struct ecryptfs_crypt_stat *crypt_stat)
{
loff_t extent_num_in_page = 0;
loff_t num_extents_per_page = (PAGE_SIZE
/ crypt_stat->extent_size);
int rc = 0;
while (extent_num_in_page < num_extents_per_page) {
loff_t view_extent_num = ((loff_t)folio->index
* num_extents_per_page)
+ extent_num_in_page;
size_t num_header_extents_at_front =
(crypt_stat->metadata_size / crypt_stat->extent_size);
if (view_extent_num < num_header_extents_at_front) {
/* This is a header extent */
char *page_virt;
page_virt = kmap_local_folio(folio, 0);
memset(page_virt, 0, PAGE_SIZE);
/* TODO: Support more than one header extent */
if (view_extent_num == 0) {
size_t written;
rc = ecryptfs_read_xattr_region(
page_virt, folio->mapping->host);
strip_xattr_flag(page_virt + 16, crypt_stat);
ecryptfs_write_header_metadata(page_virt + 20,
crypt_stat,
&written);
}
kunmap_local(page_virt);
flush_dcache_folio(folio);
if (rc) {
printk(KERN_ERR "%s: Error reading xattr "
"region; rc = [%d]\n", __func__, rc);
Annotation
- Immediate include surface: `linux/pagemap.h`, `linux/writeback.h`, `linux/page-flags.h`, `linux/mount.h`, `linux/file.h`, `linux/scatterlist.h`, `linux/slab.h`, `linux/xattr.h`.
- Detected declarations: `function Copyright`, `function strip_xattr_flag`, `function ecryptfs_copy_up_encrypted_with_header`, `function ecryptfs_read_folio`, `function fill_zeros_to_end_of_page`, `function ecryptfs_write_begin`, `function ecryptfs_write_inode_size_to_header`, `function ecryptfs_write_inode_size_to_xattr`, `function ecryptfs_write_inode_size_to_metadata`, `function ecryptfs_write_end`.
- 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.