fs/ext4/ioctl.c
Source file repositories/reference/linux-study-clean/fs/ext4/ioctl.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext4/ioctl.c- Extension
.c- Size
- 55069 bytes
- Lines
- 2029
- 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.
- 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/fs.hlinux/capability.hlinux/time.hlinux/compat.hlinux/mount.hlinux/file.hlinux/quotaops.hlinux/random.hlinux/uaccess.hlinux/delay.hlinux/iversion.hlinux/fileattr.hlinux/uuid.hext4_jbd2.hext4.hlinux/fsmap.hfsmap.htrace/events/ext4.hlinux/fserror.h
Detected Declarations
struct getfsmap_infofunction ext4_sb_setlabelfunction ext4_sb_setuuidfunction ext4_update_primary_sbfunction ext4_update_backup_sbfunction ext4_update_superblocks_fnfunction memswapfunction swap_inode_datafunction ext4_reset_inode_seedfunction swap_inode_boot_loaderfunction ext4_ioctl_check_immutablefunction ext4_dax_dontcachefunction dax_compatiblefunction ext4_ioctl_setflagsfunction filefunction ext4_ioctl_setprojectfunction ext4_ioctl_setprojectfunction ext4_force_shutdownfunction ext4_ioctl_shutdownfunction ext4_getfsmap_formatfunction ext4_ioc_getfsmapfunction ext4_ioctl_group_addfunction ext4_fileattr_getfunction ext4_fileattr_setfunction ext4_ioctl_get_es_cachefunction ext4_ioctl_checkpointfunction ext4_ioctl_setlabelfunction ext4_ioctl_getlabelfunction ext4_ioctl_getuuidfunction ext4_ioctl_setuuidfunction ext4_ioctl_get_tune_sbfunction ext4_sb_setparamsfunction ext4_ioctl_set_tune_sbfunction __ext4_ioctlfunction ext4_ioctlfunction ext4_compat_ioctlfunction set_overheadfunction ext4_update_overhead
Annotated Snippet
struct getfsmap_info {
struct super_block *gi_sb;
struct fsmap_head __user *gi_data;
unsigned int gi_idx;
__u32 gi_last_flags;
};
static int ext4_getfsmap_format(struct ext4_fsmap *xfm, void *priv)
{
struct getfsmap_info *info = priv;
struct fsmap fm;
trace_ext4_getfsmap_mapping(info->gi_sb, xfm);
info->gi_last_flags = xfm->fmr_flags;
ext4_fsmap_from_internal(info->gi_sb, &fm, xfm);
if (copy_to_user(&info->gi_data->fmh_recs[info->gi_idx++], &fm,
sizeof(struct fsmap)))
return -EFAULT;
return 0;
}
static int ext4_ioc_getfsmap(struct super_block *sb,
struct fsmap_head __user *arg)
{
struct getfsmap_info info = { NULL };
struct ext4_fsmap_head xhead = {0};
struct fsmap_head head;
bool aborted = false;
int error;
if (copy_from_user(&head, arg, sizeof(struct fsmap_head)))
return -EFAULT;
if (memchr_inv(head.fmh_reserved, 0, sizeof(head.fmh_reserved)) ||
memchr_inv(head.fmh_keys[0].fmr_reserved, 0,
sizeof(head.fmh_keys[0].fmr_reserved)) ||
memchr_inv(head.fmh_keys[1].fmr_reserved, 0,
sizeof(head.fmh_keys[1].fmr_reserved)))
return -EINVAL;
/*
* ext4 doesn't report file extents at all, so the only valid
* file offsets are the magic ones (all zeroes or all ones).
*/
if (head.fmh_keys[0].fmr_offset ||
(head.fmh_keys[1].fmr_offset != 0 &&
head.fmh_keys[1].fmr_offset != -1ULL))
return -EINVAL;
xhead.fmh_iflags = head.fmh_iflags;
xhead.fmh_count = head.fmh_count;
ext4_fsmap_to_internal(sb, &xhead.fmh_keys[0], &head.fmh_keys[0]);
ext4_fsmap_to_internal(sb, &xhead.fmh_keys[1], &head.fmh_keys[1]);
trace_ext4_getfsmap_low_key(sb, &xhead.fmh_keys[0]);
trace_ext4_getfsmap_high_key(sb, &xhead.fmh_keys[1]);
info.gi_sb = sb;
info.gi_data = arg;
error = ext4_getfsmap(sb, &xhead, ext4_getfsmap_format, &info);
if (error == EXT4_QUERY_RANGE_ABORT)
aborted = true;
else if (error)
return error;
/* If we didn't abort, set the "last" flag in the last fmx */
if (!aborted && info.gi_idx) {
info.gi_last_flags |= FMR_OF_LAST;
if (copy_to_user(&info.gi_data->fmh_recs[info.gi_idx - 1].fmr_flags,
&info.gi_last_flags,
sizeof(info.gi_last_flags)))
return -EFAULT;
}
/* copy back header */
head.fmh_entries = xhead.fmh_entries;
head.fmh_oflags = xhead.fmh_oflags;
if (copy_to_user(arg, &head, sizeof(struct fsmap_head)))
return -EFAULT;
return 0;
}
static long ext4_ioctl_group_add(struct file *file,
struct ext4_new_group_data *input)
{
struct super_block *sb = file_inode(file)->i_sb;
int err, err2=0;
err = ext4_resize_begin(sb);
Annotation
- Immediate include surface: `linux/fs.h`, `linux/capability.h`, `linux/time.h`, `linux/compat.h`, `linux/mount.h`, `linux/file.h`, `linux/quotaops.h`, `linux/random.h`.
- Detected declarations: `struct getfsmap_info`, `function ext4_sb_setlabel`, `function ext4_sb_setuuid`, `function ext4_update_primary_sb`, `function ext4_update_backup_sb`, `function ext4_update_superblocks_fn`, `function memswap`, `function swap_inode_data`, `function ext4_reset_inode_seed`, `function swap_inode_boot_loader`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source 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.