fs/exfat/cache.c
Source file repositories/reference/linux-study-clean/fs/exfat/cache.c
File Facts
- System
- Linux kernel
- Corpus path
fs/exfat/cache.c- Extension
.c- Size
- 8772 bytes
- Lines
- 358
- 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/slab.hlinux/unaligned.hlinux/buffer_head.hexfat_raw.hexfat_fs.h
Detected Declarations
struct exfat_cachestruct exfat_cache_idfunction exfat_cache_init_oncefunction exfat_cache_initfunction exfat_cache_shutdownfunction exfat_cache_freefunction exfat_cache_update_lrufunction exfat_cache_lookupfunction list_for_each_entryfunction exfat_cache_addfunction __exfat_cache_inval_inodefunction exfat_cache_inval_inodefunction cache_contiguousfunction cache_initfunction exfat_get_cluster
Annotated Snippet
struct exfat_cache {
struct list_head cache_list;
unsigned int nr_contig; /* number of contiguous clusters */
unsigned int fcluster; /* cluster number in the file. */
unsigned int dcluster; /* cluster number on disk. */
};
struct exfat_cache_id {
unsigned int id;
unsigned int nr_contig;
unsigned int fcluster;
unsigned int dcluster;
};
static struct kmem_cache *exfat_cachep;
static void exfat_cache_init_once(void *c)
{
struct exfat_cache *cache = (struct exfat_cache *)c;
INIT_LIST_HEAD(&cache->cache_list);
}
int exfat_cache_init(void)
{
exfat_cachep = kmem_cache_create("exfat_cache",
sizeof(struct exfat_cache),
0, SLAB_RECLAIM_ACCOUNT,
exfat_cache_init_once);
if (!exfat_cachep)
return -ENOMEM;
return 0;
}
void exfat_cache_shutdown(void)
{
if (!exfat_cachep)
return;
kmem_cache_destroy(exfat_cachep);
}
static inline struct exfat_cache *exfat_cache_alloc(void)
{
return kmem_cache_alloc(exfat_cachep, GFP_NOFS);
}
static inline void exfat_cache_free(struct exfat_cache *cache)
{
WARN_ON(!list_empty(&cache->cache_list));
kmem_cache_free(exfat_cachep, cache);
}
static inline void exfat_cache_update_lru(struct inode *inode,
struct exfat_cache *cache)
{
struct exfat_inode_info *ei = EXFAT_I(inode);
if (ei->cache_lru.next != &cache->cache_list)
list_move(&cache->cache_list, &ei->cache_lru);
}
/*
* Find the cache that covers or precedes 'fclus' and return the last
* cluster before the next cache range.
*/
static inline unsigned int
exfat_cache_lookup(struct inode *inode, struct exfat_cache_id *cid,
unsigned int fclus, unsigned int end,
unsigned int *cached_fclus, unsigned int *cached_dclus)
{
struct exfat_inode_info *ei = EXFAT_I(inode);
static struct exfat_cache nohit = { .fcluster = 0, };
struct exfat_cache *hit = &nohit, *p;
unsigned int tail = 0; /* End boundary of hit cache */
/*
* Search range [fclus, end]. Stop early if:
* 1. Cache covers entire range, or
* 2. Next cache starts at current cache tail
*/
spin_lock(&ei->cache_lru_lock);
list_for_each_entry(p, &ei->cache_lru, cache_list) {
/* Find the cache of "fclus" or nearest cache. */
if (p->fcluster <= fclus) {
if (p->fcluster < hit->fcluster)
continue;
hit = p;
tail = hit->fcluster + hit->nr_contig;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/unaligned.h`, `linux/buffer_head.h`, `exfat_raw.h`, `exfat_fs.h`.
- Detected declarations: `struct exfat_cache`, `struct exfat_cache_id`, `function exfat_cache_init_once`, `function exfat_cache_init`, `function exfat_cache_shutdown`, `function exfat_cache_free`, `function exfat_cache_update_lru`, `function exfat_cache_lookup`, `function list_for_each_entry`, `function exfat_cache_add`.
- 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.