fs/romfs/super.c
Source file repositories/reference/linux-study-clean/fs/romfs/super.c
File Facts
- System
- Linux kernel
- Corpus path
fs/romfs/super.c- Extension
.c- Size
- 15503 bytes
- Lines
- 665
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/module.hlinux/string.hlinux/fs.hlinux/time.hlinux/slab.hlinux/init.hlinux/blkdev.hlinux/fs_context.hlinux/mount.hlinux/namei.hlinux/statfs.hlinux/mtd/super.hlinux/ctype.hlinux/highmem.hlinux/pagemap.hlinux/uaccess.hlinux/major.hinternal.h
Detected Declarations
function romfs_read_foliofunction romfs_readdirfunction imagefunction romfs_free_inodefunction romfs_statfsfunction romfs_reconfigurefunction romfs_checksumfunction romfs_fill_superfunction romfs_get_treefunction romfs_init_fs_contextfunction romfs_kill_sbfunction romfs_i_init_oncefunction init_romfs_fsfunction exit_romfs_fsmodule init init_romfs_fs
Annotated Snippet
static const struct file_operations romfs_dir_operations = {
.read = generic_read_dir,
.iterate_shared = romfs_readdir,
.llseek = generic_file_llseek,
};
static const struct inode_operations romfs_dir_inode_operations = {
.lookup = romfs_lookup,
};
/*
* get a romfs inode based on its position in the image (which doubles as the
* inode number)
*/
static struct inode *romfs_iget(struct super_block *sb, unsigned long pos)
{
struct romfs_inode_info *inode;
struct romfs_inode ri;
struct inode *i;
unsigned long nlen;
unsigned nextfh;
int ret;
umode_t mode;
/* we might have to traverse a chain of "hard link" file entries to get
* to the actual file */
for (;;) {
ret = romfs_dev_read(sb, pos, &ri, sizeof(ri));
if (ret < 0)
goto error;
/* XXX: do romfs_checksum here too (with name) */
nextfh = be32_to_cpu(ri.next);
if ((nextfh & ROMFH_TYPE) != ROMFH_HRD)
break;
pos = be32_to_cpu(ri.spec) & ROMFH_MASK;
}
/* determine the length of the filename */
nlen = romfs_dev_strnlen(sb, pos + ROMFH_SIZE, ROMFS_MAXFN);
if (IS_ERR_VALUE(nlen))
goto eio;
/* get an inode for this image position */
i = iget_locked(sb, pos);
if (!i)
return ERR_PTR(-ENOMEM);
if (!(inode_state_read_once(i) & I_NEW))
return i;
/* precalculate the data offset */
inode = ROMFS_I(i);
inode->i_metasize = (ROMFH_SIZE + nlen + 1 + ROMFH_PAD) & ROMFH_MASK;
inode->i_dataoffset = pos + inode->i_metasize;
set_nlink(i, 1); /* Hard to decide.. */
i->i_size = be32_to_cpu(ri.size);
inode_set_mtime_to_ts(i,
inode_set_atime_to_ts(i, inode_set_ctime(i, 0, 0)));
/* set up mode and ops */
mode = romfs_modemap[nextfh & ROMFH_TYPE];
switch (nextfh & ROMFH_TYPE) {
case ROMFH_DIR:
i->i_size = ROMFS_I(i)->i_metasize;
i->i_op = &romfs_dir_inode_operations;
i->i_fop = &romfs_dir_operations;
if (nextfh & ROMFH_EXEC)
mode |= S_IXUGO;
break;
case ROMFH_REG:
i->i_fop = &romfs_ro_fops;
i->i_data.a_ops = &romfs_aops;
if (nextfh & ROMFH_EXEC)
mode |= S_IXUGO;
break;
case ROMFH_SYM:
i->i_op = &page_symlink_inode_operations;
inode_nohighmem(i);
i->i_data.a_ops = &romfs_aops;
mode |= S_IRWXUGO;
break;
default:
/* depending on MBZ for sock/fifos */
nextfh = be32_to_cpu(ri.spec);
init_special_inode(i, mode, MKDEV(nextfh >> 16,
Annotation
- Immediate include surface: `linux/module.h`, `linux/string.h`, `linux/fs.h`, `linux/time.h`, `linux/slab.h`, `linux/init.h`, `linux/blkdev.h`, `linux/fs_context.h`.
- Detected declarations: `function romfs_read_folio`, `function romfs_readdir`, `function image`, `function romfs_free_inode`, `function romfs_statfs`, `function romfs_reconfigure`, `function romfs_checksum`, `function romfs_fill_super`, `function romfs_get_tree`, `function romfs_init_fs_context`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern 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.