fs/btrfs/xattr.c
Source file repositories/reference/linux-study-clean/fs/btrfs/xattr.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/xattr.c- Extension
.c- Size
- 14560 bytes
- Lines
- 528
- 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/init.hlinux/fs.hlinux/slab.hlinux/rwsem.hlinux/xattr.hlinux/security.hlinux/posix_acl_xattr.hlinux/iversion.hlinux/sched/mm.hctree.hfs.hmessages.hbtrfs_inode.htransaction.hxattr.hdisk-io.hprops.hlocking.haccessors.hdir-item.h
Detected Declarations
function Copyrightfunction btrfs_setxattrfunction firstfunction btrfs_insert_xattr_itemfunction btrfs_setxattr_transfunction btrfs_listxattrfunction btrfs_xattr_handler_getfunction btrfs_xattr_handler_setfunction btrfs_xattr_handler_get_securityfunction btrfs_xattr_handler_set_securityfunction btrfs_xattr_handler_set_propfunction btrfs_initxattrsfunction btrfs_xattr_security_init
Annotated Snippet
if (!di && !(flags & XATTR_REPLACE)) {
ret = -ENOSPC;
goto out;
}
} else if (ret == -EEXIST) {
ret = 0;
di = btrfs_match_dir_item_name(path, name, name_len);
ASSERT(di); /* logic error */
} else if (ret) {
goto out;
}
if (di && (flags & XATTR_CREATE)) {
ret = -EEXIST;
goto out;
}
if (di) {
/*
* We're doing a replace, and it must be atomic, that is, at
* any point in time we have either the old or the new xattr
* value in the tree. We don't want readers (getxattr and
* listxattrs) to miss a value, this is specially important
* for ACLs.
*/
const int slot = path->slots[0];
struct extent_buffer *leaf = path->nodes[0];
const u16 old_data_len = btrfs_dir_data_len(leaf, di);
const u32 item_size = btrfs_item_size(leaf, slot);
const u32 data_size = sizeof(*di) + name_len + size;
unsigned long data_ptr;
char *ptr;
if (size > old_data_len) {
if (btrfs_leaf_free_space(leaf) <
(size - old_data_len)) {
ret = -ENOSPC;
goto out;
}
}
if (old_data_len + name_len + sizeof(*di) == item_size) {
/* No other xattrs packed in the same leaf item. */
if (size > old_data_len)
btrfs_extend_item(trans, path, size - old_data_len);
else if (size < old_data_len)
btrfs_truncate_item(trans, path, data_size, 1);
} else {
/* There are other xattrs packed in the same item. */
ret = btrfs_delete_one_dir_name(trans, root, path, di);
if (ret)
goto out;
btrfs_extend_item(trans, path, data_size);
}
ptr = btrfs_item_ptr(leaf, slot, char);
ptr += btrfs_item_size(leaf, slot) - data_size;
di = (struct btrfs_dir_item *)ptr;
btrfs_set_dir_data_len(leaf, di, size);
data_ptr = ((unsigned long)(di + 1)) + name_len;
write_extent_buffer(leaf, value, data_ptr, size);
} else {
/*
* Insert, and we had space for the xattr, so path->slots[0] is
* where our xattr dir_item is and btrfs_insert_xattr_item()
* filled it.
*/
}
out:
if (!ret) {
set_bit(BTRFS_INODE_COPY_EVERYTHING,
&BTRFS_I(inode)->runtime_flags);
clear_bit(BTRFS_INODE_NO_XATTRS, &BTRFS_I(inode)->runtime_flags);
}
return ret;
}
/*
* @value: "" makes the attribute to empty, NULL removes it
*/
int btrfs_setxattr_trans(struct inode *inode, const char *name,
const void *value, size_t size, int flags)
{
struct btrfs_root *root = BTRFS_I(inode)->root;
struct btrfs_trans_handle *trans;
const bool start_trans = (current->journal_info == NULL);
int ret;
if (start_trans) {
/*
Annotation
- Immediate include surface: `linux/init.h`, `linux/fs.h`, `linux/slab.h`, `linux/rwsem.h`, `linux/xattr.h`, `linux/security.h`, `linux/posix_acl_xattr.h`, `linux/iversion.h`.
- Detected declarations: `function Copyright`, `function btrfs_setxattr`, `function first`, `function btrfs_insert_xattr_item`, `function btrfs_setxattr_trans`, `function btrfs_listxattr`, `function btrfs_xattr_handler_get`, `function btrfs_xattr_handler_set`, `function btrfs_xattr_handler_get_security`, `function btrfs_xattr_handler_set_security`.
- 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.