fs/ubifs/sysfs.c
Source file repositories/reference/linux-study-clean/fs/ubifs/sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ubifs/sysfs.c- Extension
.c- Size
- 3296 bytes
- Lines
- 157
- 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.
- 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/fs.hubifs.h
Detected Declarations
struct ubifs_attrenum attr_id_tfunction ubifs_attr_showfunction ubifs_sb_releasefunction ubifs_sysfs_registerfunction ubifs_sysfs_unregisterfunction ubifs_sysfs_initfunction ubifs_sysfs_exit
Annotated Snippet
struct ubifs_attr {
struct attribute attr;
enum attr_id_t attr_id;
};
#define UBIFS_ATTR(_name, _mode, _id) \
static struct ubifs_attr ubifs_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \
.attr_id = attr_##_id, \
}
#define UBIFS_ATTR_FUNC(_name, _mode) UBIFS_ATTR(_name, _mode, _name)
UBIFS_ATTR_FUNC(errors_magic, 0444);
UBIFS_ATTR_FUNC(errors_crc, 0444);
UBIFS_ATTR_FUNC(errors_node, 0444);
#define ATTR_LIST(name) (&ubifs_attr_##name.attr)
static struct attribute *ubifs_attrs[] = {
ATTR_LIST(errors_magic),
ATTR_LIST(errors_node),
ATTR_LIST(errors_crc),
NULL,
};
ATTRIBUTE_GROUPS(ubifs);
static ssize_t ubifs_attr_show(struct kobject *kobj,
struct attribute *attr, char *buf)
{
struct ubifs_info *sbi = container_of(kobj, struct ubifs_info,
kobj);
struct ubifs_attr *a = container_of(attr, struct ubifs_attr, attr);
switch (a->attr_id) {
case attr_errors_magic:
return sysfs_emit(buf, "%u\n", sbi->stats->magic_errors);
case attr_errors_node:
return sysfs_emit(buf, "%u\n", sbi->stats->node_errors);
case attr_errors_crc:
return sysfs_emit(buf, "%u\n", sbi->stats->crc_errors);
}
return 0;
};
static void ubifs_sb_release(struct kobject *kobj)
{
struct ubifs_info *c = container_of(kobj, struct ubifs_info, kobj);
complete(&c->kobj_unregister);
}
static const struct sysfs_ops ubifs_attr_ops = {
.show = ubifs_attr_show,
};
static const struct kobj_type ubifs_sb_ktype = {
.default_groups = ubifs_groups,
.sysfs_ops = &ubifs_attr_ops,
.release = ubifs_sb_release,
};
static const struct kobj_type ubifs_ktype = {
.sysfs_ops = &ubifs_attr_ops,
};
static struct kset ubifs_kset = {
.kobj = {.ktype = &ubifs_ktype},
};
int ubifs_sysfs_register(struct ubifs_info *c)
{
int ret, n;
char dfs_dir_name[UBIFS_DFS_DIR_LEN];
c->stats = kzalloc_obj(struct ubifs_stats_info);
if (!c->stats) {
ret = -ENOMEM;
goto out_last;
}
n = snprintf(dfs_dir_name, UBIFS_DFS_DIR_LEN, UBIFS_DFS_DIR_NAME,
c->vi.ubi_num, c->vi.vol_id);
if (n >= UBIFS_DFS_DIR_LEN) {
/* The array size is too small */
ret = -EINVAL;
goto out_free;
}
Annotation
- Immediate include surface: `linux/fs.h`, `ubifs.h`.
- Detected declarations: `struct ubifs_attr`, `enum attr_id_t`, `function ubifs_attr_show`, `function ubifs_sb_release`, `function ubifs_sysfs_register`, `function ubifs_sysfs_unregister`, `function ubifs_sysfs_init`, `function ubifs_sysfs_exit`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
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.