fs/ext2/inode.c
Source file repositories/reference/linux-study-clean/fs/ext2/inode.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext2/inode.c- Extension
.c- Size
- 47644 bytes
- Lines
- 1640
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/time.hlinux/highuid.hlinux/pagemap.hlinux/blkdev.hlinux/quotaops.hlinux/writeback.hlinux/buffer_head.hlinux/mpage.hlinux/fiemap.hlinux/iomap.hlinux/namei.hlinux/uio.hext2.hacl.hxattr.h
Detected Declarations
function ext2_inode_is_fast_symlinkfunction ext2_write_failedfunction iputfunction add_chainfunction verify_chainfunction followedfunction offunction ext2_find_nearfunction blockfunction ext2_blks_to_allocatefunction blocksfunction andfunction inodefunction linkfunction chainfunction ext2_get_blockfunction ext2_iomap_beginfunction ext2_iomap_endfunction ext2_fiemapfunction ext2_read_foliofunction ext2_readaheadfunction ext2_write_beginfunction ext2_write_endfunction ext2_bmapfunction ext2_writepagesfunction all_zeroesfunction ext2_truncatefunction arrayfunction branchesfunction __ext2_truncate_blocksfunction ext2_truncate_blocksfunction ext2_setsizefunction ext2_set_inode_flagsfunction ext2_set_file_opsfunction __ext2_write_inodefunction ext2_write_inodefunction ext2_getattrfunction ext2_setattrfunction i_gid_needs_update
Annotated Snippet
while (index < indirect_blks && count) {
new_blocks[index++] = current_block++;
count--;
}
if (count > 0)
break;
}
/* save the new block number for the first direct block */
new_blocks[index] = current_block;
/* total number of blocks allocated for direct blocks */
ret = count;
*err = 0;
return ret;
failed_out:
for (i = 0; i <index; i++)
ext2_free_blocks(inode, new_blocks[i], 1);
if (index)
mark_inode_dirty(inode);
return ret;
}
/**
* ext2_alloc_branch - allocate and set up a chain of blocks.
* @inode: owner
* @indirect_blks: depth of the chain (number of blocks to allocate)
* @blks: number of allocated direct blocks
* @goal: preferred place for allocation
* @offsets: offsets (in the blocks) to store the pointers to next.
* @branch: place to store the chain in.
*
* This function allocates @num blocks, zeroes out all but the last one,
* links them into chain and (if we are synchronous) writes them to disk.
* In other words, it prepares a branch that can be spliced onto the
* inode. It stores the information about that chain in the branch[], in
* the same format as ext2_get_branch() would do. We are calling it after
* we had read the existing part of chain and partial points to the last
* triple of that (one with zero ->key). Upon the exit we have the same
* picture as after the successful ext2_get_block(), except that in one
* place chain is disconnected - *branch->p is still zero (we did not
* set the last link), but branch->key contains the number that should
* be placed into *branch->p to fill that gap.
*
* If allocation fails we free all blocks we've allocated (and forget
* their buffer_heads) and return the error value the from failed
* ext2_alloc_block() (normally -ENOSPC). Otherwise we set the chain
* as described above and return 0.
*/
static int ext2_alloc_branch(struct inode *inode,
int indirect_blks, int *blks, ext2_fsblk_t goal,
int *offsets, Indirect *branch)
{
int blocksize = inode->i_sb->s_blocksize;
int i, n = 0;
int err = 0;
struct buffer_head *bh;
int num;
ext2_fsblk_t new_blocks[4];
ext2_fsblk_t current_block;
num = ext2_alloc_blocks(inode, goal, indirect_blks,
*blks, new_blocks, &err);
if (err)
return err;
branch[0].key = cpu_to_le32(new_blocks[0]);
/*
* metadata blocks and data blocks are allocated.
*/
for (n = 1; n <= indirect_blks; n++) {
/*
* Get buffer_head for parent block, zero it out
* and set the pointer to new one, then send
* parent to disk.
*/
bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
if (unlikely(!bh)) {
err = -ENOMEM;
goto failed;
}
branch[n].bh = bh;
lock_buffer(bh);
memset(bh->b_data, 0, blocksize);
branch[n].p = (__le32 *) bh->b_data + offsets[n];
branch[n].key = cpu_to_le32(new_blocks[n]);
*branch[n].p = branch[n].key;
if ( n == indirect_blks) {
Annotation
- Immediate include surface: `linux/time.h`, `linux/highuid.h`, `linux/pagemap.h`, `linux/blkdev.h`, `linux/quotaops.h`, `linux/writeback.h`, `linux/buffer_head.h`, `linux/mpage.h`.
- Detected declarations: `function ext2_inode_is_fast_symlink`, `function ext2_write_failed`, `function iput`, `function add_chain`, `function verify_chain`, `function followed`, `function of`, `function ext2_find_near`, `function block`, `function ext2_blks_to_allocate`.
- 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.