fs/ocfs2/dir.c
Source file repositories/reference/linux-study-clean/fs/ocfs2/dir.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ocfs2/dir.c- Extension
.c- Size
- 117949 bytes
- Lines
- 4520
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/fs.hlinux/types.hlinux/slab.hlinux/highmem.hlinux/quotaops.hlinux/sort.hlinux/iversion.hcluster/masklog.hocfs2.halloc.hblockcheck.hdir.hdlmglue.hextent_map.hfile.hinode.hjournal.hnamei.hsuballoc.hsuper.hsysfile.huptodate.hocfs2_trace.hbuffer_head_io.h
Detected Declarations
struct ocfs2_empty_dir_privfunction ocfs2_supports_dir_trailerfunction ocfs2_new_dir_wants_trailerfunction ocfs2_dir_trailer_blk_offfunction ocfs2_skip_dir_trailerfunction ocfs2_init_dir_trailerfunction ocfs2_dx_dir_link_trailerfunction ocfs2_free_list_at_rootfunction ocfs2_free_dir_lookup_resultfunction ocfs2_dir_indexedfunction ocfs2_dx_root_inlinefunction TEA_transformfunction str2hashbuffunction ocfs2_dx_dir_name_hashfunction ocfs2_check_dir_entryfunction ocfs2_matchfunction ocfs2_search_dirblockfunction ocfs2_validate_dir_blockfunction ocfs2_validate_dir_blockfunction OCFS2_Ifunction mlog_errnofunction ocfs2_read_dir_block_directfunction ocfs2_validate_dx_rootfunction ocfs2_read_dx_rootfunction ocfs2_validate_dx_leaffunction ocfs2_read_dx_leaffunction ocfs2_read_dx_leavesfunction ocfs2_dx_dir_lookup_recfunction __ocfs2_dx_dir_hash_idxfunction ocfs2_dx_dir_hash_idxfunction ocfs2_dx_dir_lookupfunction ocfs2_dx_dir_searchfunction ocfs2_find_entry_dxfunction functionsfunction ocfs2_update_entryfunction __ocfs2_delete_entryfunction ocfs2_figure_dirent_holefunction ocfs2_find_max_rec_lenfunction ocfs2_dx_list_remove_entryfunction ocfs2_delete_entry_dxfunction ocfs2_delete_entry_idfunction ocfs2_delete_entry_elfunction ocfs2_delete_entryfunction ocfs2_dirent_would_fitfunction ocfs2_dx_dir_leaf_insert_tailfunction ocfs2_dx_entry_list_insertfunction __ocfs2_dx_dir_leaf_insertfunction ocfs2_dx_inline_root_insert
Annotated Snippet
struct ocfs2_empty_dir_priv {
struct dir_context ctx;
unsigned seen_dot;
unsigned seen_dot_dot;
unsigned seen_other;
unsigned dx_dir;
};
static bool ocfs2_empty_dir_filldir(struct dir_context *ctx, const char *name,
int name_len, loff_t pos, u64 ino,
unsigned type)
{
struct ocfs2_empty_dir_priv *p =
container_of(ctx, struct ocfs2_empty_dir_priv, ctx);
/*
* Check the positions of "." and ".." records to be sure
* they're in the correct place.
*
* Indexed directories don't need to proceed past the first
* two entries, so we end the scan after seeing '..'. Despite
* that, we allow the scan to proceed In the event that we
* have a corrupted indexed directory (no dot or dot dot
* entries). This allows us to double check for existing
* entries which might not have been found in the index.
*/
if (name_len == 1 && !strncmp(".", name, 1) && pos == 0) {
p->seen_dot = 1;
return true;
}
if (name_len == 2 && !strncmp("..", name, 2) &&
pos == OCFS2_DIR_REC_LEN(1)) {
p->seen_dot_dot = 1;
if (p->dx_dir && p->seen_dot)
return false;
return true;
}
p->seen_other = 1;
return false;
}
static int ocfs2_empty_dir_dx(struct inode *inode,
struct ocfs2_empty_dir_priv *priv)
{
int ret;
struct buffer_head *di_bh = NULL;
struct buffer_head *dx_root_bh = NULL;
struct ocfs2_dinode *di;
struct ocfs2_dx_root_block *dx_root;
priv->dx_dir = 1;
ret = ocfs2_read_inode_block(inode, &di_bh);
if (ret) {
mlog_errno(ret);
goto out;
}
di = (struct ocfs2_dinode *)di_bh->b_data;
ret = ocfs2_read_dx_root(inode, di, &dx_root_bh);
if (ret) {
mlog_errno(ret);
goto out;
}
dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data;
if (le32_to_cpu(dx_root->dr_num_entries) != 2)
priv->seen_other = 1;
out:
brelse(di_bh);
brelse(dx_root_bh);
return ret;
}
/*
* routine to check that the specified directory is empty (for rmdir)
*
* Returns 1 if dir is empty, zero otherwise.
*
* XXX: This is a performance problem for unindexed directories.
*/
int ocfs2_empty_dir(struct inode *inode)
{
int ret;
struct ocfs2_empty_dir_priv priv = {
.ctx.actor = ocfs2_empty_dir_filldir,
Annotation
- Immediate include surface: `linux/fs.h`, `linux/types.h`, `linux/slab.h`, `linux/highmem.h`, `linux/quotaops.h`, `linux/sort.h`, `linux/iversion.h`, `cluster/masklog.h`.
- Detected declarations: `struct ocfs2_empty_dir_priv`, `function ocfs2_supports_dir_trailer`, `function ocfs2_new_dir_wants_trailer`, `function ocfs2_dir_trailer_blk_off`, `function ocfs2_skip_dir_trailer`, `function ocfs2_init_dir_trailer`, `function ocfs2_dx_dir_link_trailer`, `function ocfs2_free_list_at_root`, `function ocfs2_free_dir_lookup_result`, `function ocfs2_dir_indexed`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.