fs/nilfs2/direct.c
Source file repositories/reference/linux-study-clean/fs/nilfs2/direct.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nilfs2/direct.c- Extension
.c- Size
- 9151 bytes
- Lines
- 388
- 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
linux/errno.hnilfs.hpage.hdirect.halloc.hdat.h
Detected Declarations
function Copyrightfunction nilfs_direct_get_ptrfunction nilfs_direct_set_ptrfunction nilfs_direct_lookupfunction nilfs_direct_lookup_contigfunction nilfs_direct_find_target_vfunction nilfs_direct_insertfunction nilfs_direct_deletefunction nilfs_direct_seek_keyfunction nilfs_direct_last_keyfunction nilfs_direct_check_insertfunction nilfs_direct_gather_datafunction nilfs_direct_delete_and_convertfunction nilfs_direct_propagatefunction nilfs_direct_assign_vfunction nilfs_direct_assign_pfunction nilfs_direct_assignfunction nilfs_direct_init
Annotated Snippet
if (dat) {
ret = nilfs_dat_translate(dat, ptr2, &blocknr);
if (ret < 0)
goto dat_error;
ptr2 = blocknr;
}
if (ptr2 != ptr + cnt)
break;
}
*ptrp = ptr;
return cnt;
dat_error:
if (ret == -ENOENT)
ret = -EINVAL; /* Notify bmap layer of metadata corruption */
return ret;
}
static __u64
nilfs_direct_find_target_v(const struct nilfs_bmap *direct, __u64 key)
{
__u64 ptr;
ptr = nilfs_bmap_find_target_seq(direct, key);
if (ptr != NILFS_BMAP_INVALID_PTR)
/* sequential access */
return ptr;
/* block group */
return nilfs_bmap_find_target_in_group(direct);
}
static int nilfs_direct_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr)
{
union nilfs_bmap_ptr_req req;
struct inode *dat = NULL;
struct buffer_head *bh;
int ret;
if (key > NILFS_DIRECT_KEY_MAX)
return -ENOENT;
if (nilfs_direct_get_ptr(bmap, key) != NILFS_BMAP_INVALID_PTR)
return -EEXIST;
if (NILFS_BMAP_USE_VBN(bmap)) {
req.bpr_ptr = nilfs_direct_find_target_v(bmap, key);
dat = nilfs_bmap_get_dat(bmap);
}
ret = nilfs_bmap_prepare_alloc_ptr(bmap, &req, dat);
if (!ret) {
/* ptr must be a pointer to a buffer head. */
bh = (struct buffer_head *)((unsigned long)ptr);
set_buffer_nilfs_volatile(bh);
nilfs_bmap_commit_alloc_ptr(bmap, &req, dat);
nilfs_direct_set_ptr(bmap, key, req.bpr_ptr);
if (!nilfs_bmap_dirty(bmap))
nilfs_bmap_set_dirty(bmap);
if (NILFS_BMAP_USE_VBN(bmap))
nilfs_bmap_set_target_v(bmap, key, req.bpr_ptr);
nilfs_inode_add_blocks(bmap->b_inode, 1);
}
return ret;
}
static int nilfs_direct_delete(struct nilfs_bmap *bmap, __u64 key)
{
union nilfs_bmap_ptr_req req;
struct inode *dat;
int ret;
if (key > NILFS_DIRECT_KEY_MAX ||
nilfs_direct_get_ptr(bmap, key) == NILFS_BMAP_INVALID_PTR)
return -ENOENT;
dat = NILFS_BMAP_USE_VBN(bmap) ? nilfs_bmap_get_dat(bmap) : NULL;
req.bpr_ptr = nilfs_direct_get_ptr(bmap, key);
ret = nilfs_bmap_prepare_end_ptr(bmap, &req, dat);
if (!ret) {
nilfs_bmap_commit_end_ptr(bmap, &req, dat);
nilfs_direct_set_ptr(bmap, key, NILFS_BMAP_INVALID_PTR);
nilfs_inode_sub_blocks(bmap->b_inode, 1);
}
return ret;
}
Annotation
- Immediate include surface: `linux/errno.h`, `nilfs.h`, `page.h`, `direct.h`, `alloc.h`, `dat.h`.
- Detected declarations: `function Copyright`, `function nilfs_direct_get_ptr`, `function nilfs_direct_set_ptr`, `function nilfs_direct_lookup`, `function nilfs_direct_lookup_contig`, `function nilfs_direct_find_target_v`, `function nilfs_direct_insert`, `function nilfs_direct_delete`, `function nilfs_direct_seek_key`, `function nilfs_direct_last_key`.
- 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.