fs/xfs/libxfs/xfs_dir2.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_dir2.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_dir2.c- Extension
.c- Size
- 35531 bytes
- Lines
- 1412
- 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
xfs_platform.hxfs_fs.hxfs_shared.hxfs_format.hxfs_log_format.hxfs_trans_resv.hxfs_mount.hxfs_inode.hxfs_trans.hxfs_bmap.hxfs_dir2.hxfs_dir2_priv.hxfs_errortag.hxfs_error.hxfs_trace.hxfs_health.hxfs_bmap_btree.hxfs_trans_space.hxfs_parent.hxfs_ag.hxfs_ialloc.h
Detected Declarations
function xfs_mode_to_ftypefunction xfs_ascii_ci_hashnamefunction xfs_ascii_ci_compnamefunction xfs_da_mountfunction xfs_da_unmountfunction xfs_dir_isemptyfunction xfs_dir_ino_validatefunction xfs_dir_initfunction xfs_dir2_formatfunction xfs_dir_createname_argsfunction xfs_dir_cilookup_resultfunction xfs_dir_lookup_argsfunction xfs_dir_removename_argsfunction xfs_dir_replace_argsfunction xfs_dir2_shrink_inodefunction xfs_dir2_namecheckfunction xfs_dir2_hashnamefunction xfs_dir2_compnamefunction xfs_dir_hook_disablefunction xfs_dir_hook_enablefunction xfs_dir_update_hookfunction xfs_dir_hook_addfunction xfs_dir_hook_delfunction xfs_dir_hook_setupfunction xfs_dir_create_childfunction xfs_dir_add_childfunction xfs_dir_remove_childfunction entryfunction entry
Annotated Snippet
XFS_TEST_ERROR(mp, XFS_ERRTAG_DIR_INO_VALIDATE)) {
xfs_warn(mp, "Invalid inode number 0x%Lx",
(unsigned long long) ino);
return -EFSCORRUPTED;
}
return 0;
}
/*
* Initialize a directory with its "." and ".." entries.
*/
int
xfs_dir_init(
xfs_trans_t *tp,
xfs_inode_t *dp,
xfs_inode_t *pdp)
{
struct xfs_da_args *args;
int error;
ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
error = xfs_dir_ino_validate(tp->t_mountp, I_INO(pdp));
if (error)
return error;
args = kzalloc_obj(*args, GFP_KERNEL | __GFP_NOFAIL);
if (!args)
return -ENOMEM;
args->geo = dp->i_mount->m_dir_geo;
args->dp = dp;
args->trans = tp;
args->owner = I_INO(dp);
error = xfs_dir2_sf_create(args, I_INO(pdp));
kfree(args);
return error;
}
enum xfs_dir2_fmt
xfs_dir2_format(
struct xfs_da_args *args,
int *error)
{
struct xfs_inode *dp = args->dp;
struct xfs_mount *mp = dp->i_mount;
struct xfs_da_geometry *geo = mp->m_dir_geo;
xfs_fileoff_t eof;
xfs_assert_ilocked(dp, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL);
*error = 0;
if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
return XFS_DIR2_FMT_SF;
*error = xfs_bmap_last_offset(dp, &eof, XFS_DATA_FORK);
if (*error)
return XFS_DIR2_FMT_ERROR;
if (eof == XFS_B_TO_FSB(mp, geo->blksize)) {
if (XFS_IS_CORRUPT(mp, dp->i_disk_size != geo->blksize)) {
xfs_da_mark_sick(args);
*error = -EFSCORRUPTED;
return XFS_DIR2_FMT_ERROR;
}
return XFS_DIR2_FMT_BLOCK;
}
if (eof == geo->leafblk + geo->fsbcount)
return XFS_DIR2_FMT_LEAF;
return XFS_DIR2_FMT_NODE;
}
int
xfs_dir_createname_args(
struct xfs_da_args *args)
{
int error;
if (!args->inumber)
args->op_flags |= XFS_DA_OP_JUSTCHECK;
switch (xfs_dir2_format(args, &error)) {
case XFS_DIR2_FMT_SF:
return xfs_dir2_sf_addname(args);
case XFS_DIR2_FMT_BLOCK:
return xfs_dir2_block_addname(args);
case XFS_DIR2_FMT_LEAF:
return xfs_dir2_leaf_addname(args);
case XFS_DIR2_FMT_NODE:
return xfs_dir2_node_addname(args);
default:
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_inode.h`.
- Detected declarations: `function xfs_mode_to_ftype`, `function xfs_ascii_ci_hashname`, `function xfs_ascii_ci_compname`, `function xfs_da_mount`, `function xfs_da_unmount`, `function xfs_dir_isempty`, `function xfs_dir_ino_validate`, `function xfs_dir_init`, `function xfs_dir2_format`, `function xfs_dir_createname_args`.
- 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.