fs/xfs/libxfs/xfs_dir2_sf.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_dir2_sf.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_dir2_sf.c- Extension
.c- Size
- 36543 bytes
- Lines
- 1269
- 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_dir2.hxfs_dir2_priv.hxfs_trace.h
Detected Declarations
function xfs_dir2_sf_entsizefunction xfs_dir2_sf_nextentryfunction xfs_dir2_sf_get_inofunction xfs_dir2_sf_put_inofunction xfs_dir2_sf_get_parent_inofunction xfs_dir2_sf_put_parent_inofunction xfs_dir2_sf_get_ftypefunction xfs_dir2_sf_put_ftypefunction xfs_dir2_sf_addname_pickfunction xfs_dir2_sf_verifyfunction xfs_dir2_sf_replace_needblock
Annotated Snippet
if (!isdot && !isdotdot) {
count++;
namelen += dep->namelen + has_ftype;
} else if (isdotdot)
parent = be64_to_cpu(dep->inumber);
/*
* Calculate the new size, see if we should give up yet.
*/
size = xfs_dir2_sf_hdr_size(i8count) + /* header */
count * 3 * sizeof(u8) + /* namelen + offset */
namelen + /* name */
(i8count ? /* inumber */
count * XFS_INO64_SIZE :
count * XFS_INO32_SIZE);
if (size > xfs_inode_data_fork_size(dp))
return size; /* size value is a failure */
}
/*
* Create the output header, if it worked.
*/
sfhp->count = count;
sfhp->i8count = i8count;
xfs_dir2_sf_put_parent_ino(sfhp, parent);
return size;
}
/*
* Convert a block format directory to shortform.
* Caller has already checked that it will fit, and built us a header.
*/
int /* error */
xfs_dir2_block_to_sf(
struct xfs_da_args *args, /* operation arguments */
struct xfs_buf *bp,
int size, /* shortform directory size */
struct xfs_dir2_sf_hdr *sfhp) /* shortform directory hdr */
{
struct xfs_inode *dp = args->dp;
struct xfs_mount *mp = dp->i_mount;
int error; /* error return value */
int logflags; /* inode logging flags */
struct xfs_dir2_sf_entry *sfep; /* shortform entry */
struct xfs_dir2_sf_hdr *sfp; /* shortform directory header */
unsigned int offset = args->geo->data_entry_offset;
unsigned int end;
trace_xfs_dir2_block_to_sf(args);
/*
* Allocate a temporary destination buffer the size of the inode to
* format the data into. Once we have formatted the data, we can free
* the block and copy the formatted data into the inode literal area.
*/
sfp = kmalloc(mp->m_sb.sb_inodesize, GFP_KERNEL | __GFP_NOFAIL);
memcpy(sfp, sfhp, xfs_dir2_sf_hdr_size(sfhp->i8count));
/*
* Loop over the active and unused entries. Stop when we reach the
* leaf/tail portion of the block.
*/
end = xfs_dir3_data_end_offset(args->geo, bp->b_addr);
sfep = xfs_dir2_sf_firstentry(sfp);
while (offset < end) {
struct xfs_dir2_data_unused *dup = bp->b_addr + offset;
struct xfs_dir2_data_entry *dep = bp->b_addr + offset;
/*
* If it's unused, just skip over it.
*/
if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
offset += be16_to_cpu(dup->length);
continue;
}
/*
* Skip .
*/
if (dep->namelen == 1 && dep->name[0] == '.')
ASSERT(be64_to_cpu(dep->inumber) == I_INO(dp));
/*
* Skip .., but make sure the inode number is right.
*/
else if (dep->namelen == 2 &&
dep->name[0] == '.' && dep->name[1] == '.')
ASSERT(be64_to_cpu(dep->inumber) ==
xfs_dir2_sf_get_parent_ino(sfp));
/*
* Normal entry, copy it into shortform.
*/
else {
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_dir2_sf_entsize`, `function xfs_dir2_sf_nextentry`, `function xfs_dir2_sf_get_ino`, `function xfs_dir2_sf_put_ino`, `function xfs_dir2_sf_get_parent_ino`, `function xfs_dir2_sf_put_parent_ino`, `function xfs_dir2_sf_get_ftype`, `function xfs_dir2_sf_put_ftype`, `function xfs_dir2_sf_addname_pick`, `function xfs_dir2_sf_verify`.
- 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.