fs/ceph/crypto.c
Source file repositories/reference/linux-study-clean/fs/ceph/crypto.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ceph/crypto.c- Extension
.c- Size
- 16736 bytes
- Lines
- 606
- 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/ceph/ceph_debug.hlinux/xattr.hlinux/fscrypt.hlinux/ceph/striper.hsuper.hmds_client.hcrypto.h
Detected Declarations
function Copyrightfunction ceph_crypt_set_contextfunction ceph_crypt_empty_dirfunction ceph_fscrypt_set_opsfunction ceph_fscrypt_free_dummy_policyfunction ceph_fscrypt_prepare_contextfunction ceph_fscrypt_as_ctx_to_reqfunction specialfunction ceph_encode_encrypted_dnamefunction filenamefunction __fscrypt_prepare_readdirfunction ceph_fscrypt_decrypt_block_inplacefunction ceph_fscrypt_encrypt_block_inplacefunction ignoredfunction ceph_fscrypt_decrypt_extentsfunction ceph_fscrypt_encrypt_pages
Annotated Snippet
if (!tname) {
ret = fscrypt_fname_alloc_buffer(NAME_MAX, &_tname);
if (ret)
goto out_inode;
tname = &_tname;
}
declen = base64_decode(name, name_len,
tname->name, false, BASE64_IMAP);
if (declen <= 0) {
ret = -EIO;
goto out;
}
iname.name = tname->name;
iname.len = declen;
} else {
iname.name = fname->ctext;
iname.len = fname->ctext_len;
}
ret = fscrypt_fname_disk_to_usr(dir, 0, 0, &iname, oname);
if (!ret && (dir != fname->dir)) {
char tmp_buf[BASE64_CHARS(NAME_MAX)];
name_len = snprintf(tmp_buf, sizeof(tmp_buf), "_%.*s_%llu",
oname->len, oname->name, dir->i_ino);
memcpy(oname->name, tmp_buf, name_len);
oname->len = name_len;
}
out:
fscrypt_fname_free_buffer(&_tname);
out_inode:
if (dir != fname->dir) {
if ((inode_state_read_once(dir) & I_NEW))
discard_new_inode(dir);
else
iput(dir);
}
return ret;
}
/**
* ceph_fscrypt_prepare_readdir - simple __fscrypt_prepare_readdir() wrapper
* @dir: directory inode for readdir prep
*
* Simple wrapper around __fscrypt_prepare_readdir() that will mark directory as
* non-complete if this call results in having the directory unlocked.
*
* Returns:
* 1 - if directory was locked and key is now loaded (i.e. dir is unlocked)
* 0 - if directory is still locked
* < 0 - if __fscrypt_prepare_readdir() fails
*/
int ceph_fscrypt_prepare_readdir(struct inode *dir)
{
bool had_key = fscrypt_has_encryption_key(dir);
int err;
if (!IS_ENCRYPTED(dir))
return 0;
err = __fscrypt_prepare_readdir(dir);
if (err)
return err;
if (!had_key && fscrypt_has_encryption_key(dir)) {
/* directory just got unlocked, mark it as not complete */
ceph_dir_clear_complete(dir);
return 1;
}
return 0;
}
int ceph_fscrypt_decrypt_block_inplace(const struct inode *inode,
struct page *page, unsigned int len,
unsigned int offs, u64 lblk_num)
{
struct ceph_client *cl = ceph_inode_to_client(inode);
doutc(cl, "%p %llx.%llx len %u offs %u blk %llu\n", inode,
ceph_vinop(inode), len, offs, lblk_num);
return fscrypt_decrypt_block_inplace(inode, page, len, offs, lblk_num);
}
int ceph_fscrypt_encrypt_block_inplace(const struct inode *inode,
struct page *page, unsigned int len,
unsigned int offs, u64 lblk_num)
{
struct ceph_client *cl = ceph_inode_to_client(inode);
Annotation
- Immediate include surface: `linux/ceph/ceph_debug.h`, `linux/xattr.h`, `linux/fscrypt.h`, `linux/ceph/striper.h`, `super.h`, `mds_client.h`, `crypto.h`.
- Detected declarations: `function Copyright`, `function ceph_crypt_set_context`, `function ceph_crypt_empty_dir`, `function ceph_fscrypt_set_ops`, `function ceph_fscrypt_free_dummy_policy`, `function ceph_fscrypt_prepare_context`, `function ceph_fscrypt_as_ctx_to_req`, `function special`, `function ceph_encode_encrypted_dname`, `function filename`.
- 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.