fs/ext4/sysfs.c
Source file repositories/reference/linux-study-clean/fs/ext4/sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext4/sysfs.c- Extension
.c- Size
- 19636 bytes
- Lines
- 699
- 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/time.hlinux/fs.hlinux/seq_file.hlinux/slab.hlinux/proc_fs.hlinux/part_stat.hext4.hext4_jbd2.h
Detected Declarations
struct ext4_attrfunction session_write_kbytes_showfunction lifetime_write_kbytes_showfunction inode_readahead_blks_storefunction reserved_clusters_storefunction trigger_test_errorfunction err_report_sec_storefunction journal_task_showfunction __print_tstampfunction ext4_generic_attr_showfunction ext4_attr_showfunction ext4_generic_attr_storefunction ext4_attr_storefunction ext4_sb_releasefunction ext4_feat_releasefunction ext4_notify_error_sysfsfunction ext4_register_sysfsfunction ext4_unregister_sysfsfunction ext4_init_sysfsfunction ext4_exit_sysfs
Annotated Snippet
struct ext4_attr {
struct attribute attr;
short attr_id;
short attr_ptr;
unsigned short attr_size;
union {
int offset;
void *explicit_ptr;
} u;
};
static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
{
struct super_block *sb = sbi->s_buddy_cache->i_sb;
return sysfs_emit(buf, "%lu\n",
(part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
sbi->s_sectors_written_start) >> 1);
}
static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
{
struct super_block *sb = sbi->s_buddy_cache->i_sb;
return sysfs_emit(buf, "%llu\n",
(unsigned long long)(sbi->s_kbytes_written +
((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
EXT4_SB(sb)->s_sectors_written_start) >> 1)));
}
static ssize_t inode_readahead_blks_store(struct ext4_sb_info *sbi,
const char *buf, size_t count)
{
unsigned long t;
int ret;
ret = kstrtoul(skip_spaces(buf), 0, &t);
if (ret)
return ret;
if (t && (!is_power_of_2(t) || t > 0x40000000))
return -EINVAL;
sbi->s_inode_readahead_blks = t;
return count;
}
static ssize_t reserved_clusters_store(struct ext4_sb_info *sbi,
const char *buf, size_t count)
{
unsigned long long val;
ext4_fsblk_t clusters = (ext4_blocks_count(sbi->s_es) >>
sbi->s_cluster_bits);
int ret;
ret = kstrtoull(skip_spaces(buf), 0, &val);
if (ret || val >= clusters || (s64)val < 0)
return -EINVAL;
atomic64_set(&sbi->s_resv_clusters, val);
return count;
}
static ssize_t trigger_test_error(struct ext4_sb_info *sbi,
const char *buf, size_t count)
{
int len = count;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
if (len && buf[len-1] == '\n')
len--;
if (len)
ext4_error(sbi->s_sb, "%.*s", len, buf);
return count;
}
static ssize_t err_report_sec_store(struct ext4_sb_info *sbi,
const char *buf, size_t count)
{
unsigned long t;
int ret;
ret = kstrtoul(skip_spaces(buf), 0, &t);
if (ret)
return ret;
/*the maximum time interval must not exceed one year.*/
Annotation
- Immediate include surface: `linux/time.h`, `linux/fs.h`, `linux/seq_file.h`, `linux/slab.h`, `linux/proc_fs.h`, `linux/part_stat.h`, `ext4.h`, `ext4_jbd2.h`.
- Detected declarations: `struct ext4_attr`, `function session_write_kbytes_show`, `function lifetime_write_kbytes_show`, `function inode_readahead_blks_store`, `function reserved_clusters_store`, `function trigger_test_error`, `function err_report_sec_store`, `function journal_task_show`, `function __print_tstamp`, `function ext4_generic_attr_show`.
- 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.