fs/fat/file.c
Source file repositories/reference/linux-study-clean/fs/fat/file.c
File Facts
- System
- Linux kernel
- Corpus path
fs/fat/file.c- Extension
.c- Size
- 16181 bytes
- Lines
- 616
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/capability.hlinux/module.hlinux/compat.hlinux/mount.hlinux/blkdev.hlinux/backing-dev.hlinux/filelock.hlinux/fsnotify.hlinux/security.hlinux/falloc.hlinux/fileattr.hfat.h
Detected Declarations
function fat_ioctl_get_attributesfunction fat_ioctl_set_attributesfunction fat_ioctl_get_volume_idfunction fat_ioctl_fitrimfunction fat_generic_ioctlfunction fat_file_releasefunction fat_file_fsyncfunction fat_cont_expandfunction fat_fallocatefunction fat_freefunction fat_truncate_blocksfunction fat_fileattr_getfunction fat_getattrfunction fat_sanitize_modefunction fat_allow_set_timefunction fat_setattrexport fat_fileattr_getexport fat_getattrexport fat_setattr
Annotated Snippet
const struct file_operations fat_file_operations = {
.llseek = generic_file_llseek,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
.mmap_prepare = generic_file_mmap_prepare,
.release = fat_file_release,
.unlocked_ioctl = fat_generic_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.fsync = fat_file_fsync,
.splice_read = filemap_splice_read,
.splice_write = iter_file_splice_write,
.fallocate = fat_fallocate,
.setlease = generic_setlease,
};
static int fat_cont_expand(struct inode *inode, loff_t size)
{
struct address_space *mapping = inode->i_mapping;
loff_t start = inode->i_size, count = size - inode->i_size;
int err;
err = generic_cont_expand_simple(inode, size);
if (err)
goto out;
fat_truncate_time(inode, NULL, FAT_UPDATE_CMTIME);
mark_inode_dirty(inode);
if (IS_SYNC(inode)) {
int err2;
/*
* Opencode syncing since we don't have a file open to use
* standard fsync path.
*/
err = filemap_fdatawrite_range(mapping, start,
start + count - 1);
err2 = mmb_sync(&MSDOS_I(inode)->i_metadata_bhs);
if (!err)
err = err2;
err2 = write_inode_now(inode, 1);
if (!err)
err = err2;
if (!err) {
err = filemap_fdatawait_range(mapping, start,
start + count - 1);
}
}
out:
return err;
}
/*
* Preallocate space for a file. This implements fat's fallocate file
* operation, which gets called from sys_fallocate system call. User
* space requests len bytes at offset. If FALLOC_FL_KEEP_SIZE is set
* we just allocate clusters without zeroing them out. Otherwise we
* allocate and zero out clusters via an expanding truncate.
*/
static long fat_fallocate(struct file *file, int mode,
loff_t offset, loff_t len)
{
int nr_cluster; /* Number of clusters to be allocated */
loff_t mm_bytes; /* Number of bytes to be allocated for file */
loff_t ondisksize; /* block aligned on-disk size in bytes*/
struct inode *inode = file->f_mapping->host;
struct super_block *sb = inode->i_sb;
struct msdos_sb_info *sbi = MSDOS_SB(sb);
int err = 0;
/* No support for hole punch or other fallocate flags. */
if (mode & ~FALLOC_FL_KEEP_SIZE)
return -EOPNOTSUPP;
/* No support for dir */
if (!S_ISREG(inode->i_mode))
return -EOPNOTSUPP;
inode_lock(inode);
if (mode & FALLOC_FL_KEEP_SIZE) {
ondisksize = inode->i_blocks << 9;
if ((offset + len) <= ondisksize)
goto error;
/* First compute the number of clusters to be allocated */
mm_bytes = offset + len - ondisksize;
nr_cluster = (mm_bytes + (sbi->cluster_size - 1)) >>
sbi->cluster_bits;
/* Start the allocation.We are not zeroing out the clusters */
while (nr_cluster-- > 0) {
Annotation
- Immediate include surface: `linux/capability.h`, `linux/module.h`, `linux/compat.h`, `linux/mount.h`, `linux/blkdev.h`, `linux/backing-dev.h`, `linux/filelock.h`, `linux/fsnotify.h`.
- Detected declarations: `function fat_ioctl_get_attributes`, `function fat_ioctl_set_attributes`, `function fat_ioctl_get_volume_id`, `function fat_ioctl_fitrim`, `function fat_generic_ioctl`, `function fat_file_release`, `function fat_file_fsync`, `function fat_cont_expand`, `function fat_fallocate`, `function fat_free`.
- 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.
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.