fs/btrfs/dir-item.c
Source file repositories/reference/linux-study-clean/fs/btrfs/dir-item.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/dir-item.c- Extension
.c- Size
- 12349 bytes
- Lines
- 433
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
messages.hctree.hdisk-io.htransaction.haccessors.hdir-item.hdelayed-inode.h
Detected Declarations
function Copyrightfunction btrfs_insert_xattr_itemfunction indexfunction btrfs_check_dir_item_collisionfunction criteriafunction btrfs_search_dir_index_itemfunction btrfs_for_each_slotfunction btrfs_delete_one_dir_name
Annotated Snippet
sizeof(struct btrfs_item) > BTRFS_LEAF_DATA_SIZE(root->fs_info)) {
return -EOVERFLOW;
}
/* Plenty of insertion room. */
return 0;
}
/*
* Lookup for a directory index item by name and index number.
*
* @trans: The transaction handle to use. Can be NULL if @mod is 0.
* @root: The root of the target tree.
* @path: Path to use for the search.
* @dir: The inode number (objectid) of the directory.
* @index: The index number.
* @name: The name associated to the directory entry we are looking for.
* @name_len: The length of the name.
* @mod: Used to indicate if the tree search is meant for a read only
* lookup, for a modification lookup or for a deletion lookup, so
* its value should be 0, 1 or -1, respectively.
*
* Returns: NULL if the dir index item does not exists, an error pointer if an
* error happened, or a pointer to a dir item if the dir index item exists and
* matches the criteria (name and index number).
*/
struct btrfs_dir_item *
btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path, u64 dir,
u64 index, const struct fscrypt_str *name, int mod)
{
struct btrfs_dir_item *di;
struct btrfs_key key;
key.objectid = dir;
key.type = BTRFS_DIR_INDEX_KEY;
key.offset = index;
di = btrfs_lookup_match_dir(trans, root, path, &key, name->name,
name->len, mod);
if (di == ERR_PTR(-ENOENT))
return NULL;
return di;
}
struct btrfs_dir_item *
btrfs_search_dir_index_item(struct btrfs_root *root, struct btrfs_path *path,
u64 dirid, const struct fscrypt_str *name)
{
struct btrfs_dir_item *di;
struct btrfs_key key;
int ret;
key.objectid = dirid;
key.type = BTRFS_DIR_INDEX_KEY;
key.offset = 0;
btrfs_for_each_slot(root, &key, &key, path, ret) {
if (key.objectid != dirid || key.type != BTRFS_DIR_INDEX_KEY)
break;
di = btrfs_match_dir_item_name(path, name->name, name->len);
if (di)
return di;
}
/* Adjust return code if the key was not found in the next leaf. */
if (ret >= 0)
ret = -ENOENT;
return ERR_PTR(ret);
}
struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path, u64 dir,
const char *name, u16 name_len,
int mod)
{
struct btrfs_key key;
struct btrfs_dir_item *di;
key.objectid = dir;
key.type = BTRFS_XATTR_ITEM_KEY;
key.offset = btrfs_name_hash(name, name_len);
di = btrfs_lookup_match_dir(trans, root, path, &key, name, name_len, mod);
if (IS_ERR(di) && PTR_ERR(di) == -ENOENT)
return NULL;
Annotation
- Immediate include surface: `messages.h`, `ctree.h`, `disk-io.h`, `transaction.h`, `accessors.h`, `dir-item.h`, `delayed-inode.h`.
- Detected declarations: `function Copyright`, `function btrfs_insert_xattr_item`, `function index`, `function btrfs_check_dir_item_collision`, `function criteria`, `function btrfs_search_dir_index_item`, `function btrfs_for_each_slot`, `function btrfs_delete_one_dir_name`.
- 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.