fs/ufs/inode.c
Source file repositories/reference/linux-study-clean/fs/ufs/inode.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ufs/inode.c- Extension
.c- Size
- 33315 bytes
- Lines
- 1223
- 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/uaccess.hlinux/errno.hlinux/fs.hlinux/time.hlinux/stat.hlinux/string.hlinux/mm.hlinux/buffer_head.hlinux/mpage.hlinux/writeback.hlinux/iversion.hufs_fs.hufs.hswab.hutil.h
Detected Declarations
struct to_freefunction Copyrightfunction grow_chain32function grow_chain64function ufs_frag_mapfunction ufs_extend_tailfunction ufs_inode_getfragfunction ufs_inode_getblockfunction ufs_getfrag_blockfunction ufs_writepagesfunction ufs_read_foliofunction ufs_prepare_chunkfunction ufs_write_failedfunction ufs_write_beginfunction ufs_write_endfunction ufs_bmapfunction ufs_set_inode_opsfunction ufs1_read_inodefunction ufs2_read_inodefunction ufs1_update_inodefunction ufs2_update_inodefunction ufs_update_inodefunction ufs_write_inodefunction ufs_sync_inodefunction ufs_evict_inodefunction free_datafunction ufs_trunc_directfunction free_full_branchfunction free_branch_tailfunction ufs_alloc_lastblockfunction ufs_truncate_blocksfunction ufs_truncatefunction ufs_setattr
Annotated Snippet
struct to_free {
struct inode *inode;
u64 to;
unsigned count;
};
static inline void free_data(struct to_free *ctx, u64 from, unsigned count)
{
if (ctx->count && ctx->to != from) {
ufs_free_blocks(ctx->inode, ctx->to - ctx->count, ctx->count);
ctx->count = 0;
}
ctx->count += count;
ctx->to = from + count;
}
#define DIRECT_FRAGMENT ((inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift)
/*
* used only for truncation down to direct blocks.
*/
static void ufs_trunc_direct(struct inode *inode)
{
struct ufs_inode_info *ufsi = UFS_I(inode);
struct super_block *sb = inode->i_sb;
struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
unsigned int new_frags, old_frags;
unsigned int old_slot, new_slot;
unsigned int old_tail, new_tail;
struct to_free ctx = {.inode = inode};
UFSD("ENTER: ino %llu\n", inode->i_ino);
new_frags = DIRECT_FRAGMENT;
// new_frags = first fragment past the new EOF
old_frags = min_t(u64, UFS_NDIR_FRAGMENT, ufsi->i_lastfrag);
// old_frags = first fragment past the old EOF or covered by indirects
if (new_frags >= old_frags) // expanding - nothing to free
goto done;
old_tail = ufs_fragnum(old_frags);
old_slot = ufs_fragstoblks(old_frags);
new_tail = ufs_fragnum(new_frags);
new_slot = ufs_fragstoblks(new_frags);
if (old_slot == new_slot) { // old_tail > 0
void *p = ufs_get_direct_data_ptr(uspi, ufsi, old_slot);
u64 tmp = ufs_data_ptr_to_cpu(sb, p);
if (!tmp)
ufs_panic(sb, __func__, "internal error");
if (!new_tail) {
write_seqlock(&ufsi->meta_lock);
ufs_data_ptr_clear(uspi, p);
write_sequnlock(&ufsi->meta_lock);
}
ufs_free_fragments(inode, tmp + new_tail, old_tail - new_tail);
} else {
unsigned int slot = new_slot;
if (new_tail) {
void *p = ufs_get_direct_data_ptr(uspi, ufsi, slot++);
u64 tmp = ufs_data_ptr_to_cpu(sb, p);
if (!tmp)
ufs_panic(sb, __func__, "internal error");
ufs_free_fragments(inode, tmp + new_tail,
uspi->s_fpb - new_tail);
}
while (slot < old_slot) {
void *p = ufs_get_direct_data_ptr(uspi, ufsi, slot++);
u64 tmp = ufs_data_ptr_to_cpu(sb, p);
if (!tmp)
continue;
write_seqlock(&ufsi->meta_lock);
ufs_data_ptr_clear(uspi, p);
write_sequnlock(&ufsi->meta_lock);
free_data(&ctx, tmp, uspi->s_fpb);
}
free_data(&ctx, 0, 0);
if (old_tail) {
void *p = ufs_get_direct_data_ptr(uspi, ufsi, slot);
u64 tmp = ufs_data_ptr_to_cpu(sb, p);
if (!tmp)
ufs_panic(sb, __func__, "internal error");
write_seqlock(&ufsi->meta_lock);
ufs_data_ptr_clear(uspi, p);
Annotation
- Immediate include surface: `linux/uaccess.h`, `linux/errno.h`, `linux/fs.h`, `linux/time.h`, `linux/stat.h`, `linux/string.h`, `linux/mm.h`, `linux/buffer_head.h`.
- Detected declarations: `struct to_free`, `function Copyright`, `function grow_chain32`, `function grow_chain64`, `function ufs_frag_map`, `function ufs_extend_tail`, `function ufs_inode_getfrag`, `function ufs_inode_getblock`, `function ufs_getfrag_block`, `function ufs_writepages`.
- 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.