fs/jffs2/scan.c
Source file repositories/reference/linux-study-clean/fs/jffs2/scan.c
File Facts
- System
- Linux kernel
- Corpus path
fs/jffs2/scan.c- Extension
.c- Size
- 36199 bytes
- Lines
- 1185
- 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/kernel.hlinux/sched.hlinux/slab.hlinux/mtd/mtd.hlinux/pagemap.hlinux/crc32.hlinux/compiler.hnodelist.hsummary.hdebug.h
Detected Declarations
function min_freefunction EMPTY_SCAN_SIZEfunction file_dirtyfunction jffs2_scan_mediumfunction jffs2_fill_scan_buffunction jffs2_scan_classify_jebfunction jffs2_scan_xattr_nodefunction jffs2_scan_xref_nodefunction jffs2_scan_eraseblockfunction jffs2_scan_inode_nodefunction jffs2_scan_dirent_nodefunction count_listfunction list_for_eachfunction rotate_listfunction jffs2_rotate_lists
Annotated Snippet
static inline uint32_t EMPTY_SCAN_SIZE(uint32_t sector_size) {
if (sector_size < DEFAULT_EMPTY_SCAN_SIZE)
return sector_size;
else
return DEFAULT_EMPTY_SCAN_SIZE;
}
static int file_dirty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
{
int ret;
if ((ret = jffs2_prealloc_raw_node_refs(c, jeb, 1)))
return ret;
if ((ret = jffs2_scan_dirty_space(c, jeb, jeb->free_size)))
return ret;
/* Turned wasted size into dirty, since we apparently
think it's recoverable now. */
jeb->dirty_size += jeb->wasted_size;
c->dirty_size += jeb->wasted_size;
c->wasted_size -= jeb->wasted_size;
jeb->wasted_size = 0;
if (VERYDIRTY(c, jeb->dirty_size)) {
list_add(&jeb->list, &c->very_dirty_list);
} else {
list_add(&jeb->list, &c->dirty_list);
}
return 0;
}
int jffs2_scan_medium(struct jffs2_sb_info *c)
{
int i, ret;
uint32_t empty_blocks = 0, bad_blocks = 0;
unsigned char *flashbuf = NULL;
uint32_t buf_size = 0;
struct jffs2_summary *s = NULL; /* summary info collected by the scan process */
#ifndef __ECOS
size_t pointlen, try_size;
ret = mtd_point(c->mtd, 0, c->mtd->size, &pointlen,
(void **)&flashbuf, NULL);
if (!ret && pointlen < c->mtd->size) {
/* Don't muck about if it won't let us point to the whole flash */
jffs2_dbg(1, "MTD point returned len too short: 0x%zx\n",
pointlen);
mtd_unpoint(c->mtd, 0, pointlen);
flashbuf = NULL;
}
if (ret && ret != -EOPNOTSUPP)
jffs2_dbg(1, "MTD point failed %d\n", ret);
#endif
if (!flashbuf) {
/* For NAND it's quicker to read a whole eraseblock at a time,
apparently */
if (jffs2_cleanmarker_oob(c))
try_size = c->sector_size;
else
try_size = PAGE_SIZE;
jffs2_dbg(1, "Trying to allocate readbuf of %zu "
"bytes\n", try_size);
flashbuf = mtd_kmalloc_up_to(c->mtd, &try_size);
if (!flashbuf)
return -ENOMEM;
jffs2_dbg(1, "Allocated readbuf of %zu bytes\n",
try_size);
buf_size = (uint32_t)try_size;
}
if (jffs2_sum_active()) {
s = kzalloc_obj(struct jffs2_summary);
if (!s) {
JFFS2_WARNING("Can't allocate memory for summary\n");
ret = -ENOMEM;
goto out_buf;
}
}
for (i=0; i<c->nr_blocks; i++) {
struct jffs2_eraseblock *jeb = &c->blocks[i];
cond_resched();
/* reset summary info for next eraseblock scan */
jffs2_sum_reset_collected(s);
ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/sched.h`, `linux/slab.h`, `linux/mtd/mtd.h`, `linux/pagemap.h`, `linux/crc32.h`, `linux/compiler.h`, `nodelist.h`.
- Detected declarations: `function min_free`, `function EMPTY_SCAN_SIZE`, `function file_dirty`, `function jffs2_scan_medium`, `function jffs2_fill_scan_buf`, `function jffs2_scan_classify_jeb`, `function jffs2_scan_xattr_node`, `function jffs2_scan_xref_node`, `function jffs2_scan_eraseblock`, `function jffs2_scan_inode_node`.
- 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.