fs/romfs/storage.c
Source file repositories/reference/linux-study-clean/fs/romfs/storage.c
File Facts
- System
- Linux kernel
- Corpus path
fs/romfs/storage.c- Extension
.c- Size
- 6271 bytes
- Lines
- 288
- 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/fs.hlinux/mtd/super.hlinux/buffer_head.hinternal.h
Detected Declarations
function Howellsfunction romfs_mtd_strnlenfunction romfs_mtd_strcmpfunction romfs_blk_readfunction romfs_blk_strnlenfunction romfs_blk_strcmpfunction romfs_dev_readfunction romfs_dev_strnlenfunction romfs_dev_strcmp
Annotated Snippet
if (matched && size == 0 && offset + segment < ROMBSIZE) {
if (!bh->b_data[offset + segment])
terminated = true;
else
matched = false;
}
brelse(bh);
if (!matched)
return 0;
}
if (!terminated) {
/* the terminating NUL must be on the first byte of the next
* block */
BUG_ON((pos & (ROMBSIZE - 1)) != 0);
bh = sb_bread(sb, pos >> ROMBSBITS);
if (!bh)
return -EIO;
matched = !bh->b_data[0];
brelse(bh);
if (!matched)
return 0;
}
return 1;
}
#endif /* CONFIG_ROMFS_ON_BLOCK */
/*
* read data from the romfs image
*/
int romfs_dev_read(struct super_block *sb, unsigned long pos,
void *buf, size_t buflen)
{
size_t limit;
limit = romfs_maxsize(sb);
if (pos >= limit || buflen > limit - pos)
return -EIO;
#ifdef CONFIG_ROMFS_ON_MTD
if (sb->s_mtd)
return romfs_mtd_read(sb, pos, buf, buflen);
#endif
#ifdef CONFIG_ROMFS_ON_BLOCK
if (sb->s_bdev)
return romfs_blk_read(sb, pos, buf, buflen);
#endif
return -EIO;
}
/*
* determine the length of a string in romfs
*/
ssize_t romfs_dev_strnlen(struct super_block *sb,
unsigned long pos, size_t maxlen)
{
size_t limit;
limit = romfs_maxsize(sb);
if (pos >= limit)
return -EIO;
if (maxlen > limit - pos)
maxlen = limit - pos;
#ifdef CONFIG_ROMFS_ON_MTD
if (sb->s_mtd)
return romfs_mtd_strnlen(sb, pos, maxlen);
#endif
#ifdef CONFIG_ROMFS_ON_BLOCK
if (sb->s_bdev)
return romfs_blk_strnlen(sb, pos, maxlen);
#endif
return -EIO;
}
/*
* compare a string to one in romfs
* - the string to be compared to, str, may not be NUL-terminated; instead the
* string is of the specified size
* - return 1 if matched, 0 if differ, -ve if error
*/
int romfs_dev_strcmp(struct super_block *sb, unsigned long pos,
const char *str, size_t size)
{
size_t limit;
limit = romfs_maxsize(sb);
if (pos >= limit)
return -EIO;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/mtd/super.h`, `linux/buffer_head.h`, `internal.h`.
- Detected declarations: `function Howells`, `function romfs_mtd_strnlen`, `function romfs_mtd_strcmp`, `function romfs_blk_read`, `function romfs_blk_strnlen`, `function romfs_blk_strcmp`, `function romfs_dev_read`, `function romfs_dev_strnlen`, `function romfs_dev_strcmp`.
- 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.