fs/fat/dir.c
Source file repositories/reference/linux-study-clean/fs/fat/dir.c
File Facts
- System
- Linux kernel
- Corpus path
fs/fat/dir.c- Extension
.c- Size
- 36635 bytes
- Lines
- 1432
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/compat.hlinux/filelock.hlinux/hex.hlinux/uaccess.hlinux/iversion.hfat.h
Detected Declarations
struct fat_ioctl_filldir_callbackfunction fat_tolowerfunction fat_make_i_posfunction fat_dir_readaheadfunction fat__get_entryfunction fat_get_entryfunction uni16_to_x8function fat_uni_to_x8function fat_short2unifunction fat_short2lower_unifunction fat_shortname2unifunction fat_name_matchfunction fat_parse_longfunction fat_parse_shortfunction fat_search_longfunction __fat_readdirfunction fat_readdirfunction fat_ioctl_readdirfunction fat_dir_ioctlfunction fat_compat_dir_ioctlfunction fat_get_short_entryfunction fat_get_dotdot_entryfunction fat_dir_emptyfunction fat_subdirsfunction filefunction fat_scan_logstartfunction __fat_remove_entriesfunction fat_remove_entriesfunction fat_zeroed_clusterfunction fat_alloc_new_dirfunction fat_add_new_entriesfunction fat_add_entriesexport fat_search_longexport fat_get_dotdot_entryexport fat_dir_emptyexport fat_scanexport fat_remove_entriesexport fat_alloc_new_direxport fat_add_entries
Annotated Snippet
const struct file_operations fat_dir_operations = {
.llseek = generic_file_llseek,
.read = generic_read_dir,
.iterate_shared = fat_readdir,
.unlocked_ioctl = fat_dir_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = fat_compat_dir_ioctl,
#endif
.fsync = fat_file_fsync,
.setlease = generic_setlease,
};
static int fat_get_short_entry(struct inode *dir, loff_t *pos,
struct buffer_head **bh,
struct msdos_dir_entry **de)
{
while (fat_get_entry(dir, pos, bh, de) >= 0) {
/* free entry or long name entry or volume label */
if (!IS_FREE((*de)->name) && !((*de)->attr & ATTR_VOLUME))
return 0;
}
return -ENOENT;
}
/*
* The ".." entry can not provide the "struct fat_slot_info" information
* for inode, nor a usable i_pos. So, this function provides some information
* only.
*
* Since this function walks through the on-disk inodes within a directory,
* callers are responsible for taking any locks necessary to prevent the
* directory from changing.
*/
int fat_get_dotdot_entry(struct inode *dir, struct buffer_head **bh,
struct msdos_dir_entry **de)
{
loff_t offset = 0;
*de = NULL;
while (fat_get_short_entry(dir, &offset, bh, de) >= 0) {
if (!strncmp((*de)->name, MSDOS_DOTDOT, MSDOS_NAME))
return 0;
}
return -ENOENT;
}
EXPORT_SYMBOL_GPL(fat_get_dotdot_entry);
/* See if directory is empty */
int fat_dir_empty(struct inode *dir)
{
struct buffer_head *bh;
struct msdos_dir_entry *de;
loff_t cpos;
int result = 0;
bh = NULL;
cpos = 0;
while (fat_get_short_entry(dir, &cpos, &bh, &de) >= 0) {
if (strncmp(de->name, MSDOS_DOT , MSDOS_NAME) &&
strncmp(de->name, MSDOS_DOTDOT, MSDOS_NAME)) {
result = -ENOTEMPTY;
break;
}
}
brelse(bh);
return result;
}
EXPORT_SYMBOL_GPL(fat_dir_empty);
/*
* fat_subdirs counts the number of sub-directories of dir. It can be run
* on directories being created.
*/
int fat_subdirs(struct inode *dir)
{
struct buffer_head *bh;
struct msdos_dir_entry *de;
loff_t cpos;
int count = 0;
bh = NULL;
cpos = 0;
while (fat_get_short_entry(dir, &cpos, &bh, &de) >= 0) {
if (de->attr & ATTR_DIR)
count++;
}
brelse(bh);
return count;
}
Annotation
- Immediate include surface: `linux/slab.h`, `linux/compat.h`, `linux/filelock.h`, `linux/hex.h`, `linux/uaccess.h`, `linux/iversion.h`, `fat.h`.
- Detected declarations: `struct fat_ioctl_filldir_callback`, `function fat_tolower`, `function fat_make_i_pos`, `function fat_dir_readahead`, `function fat__get_entry`, `function fat_get_entry`, `function uni16_to_x8`, `function fat_uni_to_x8`, `function fat_short2uni`, `function fat_short2lower_uni`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.