starnix_core/fs/
debugfs.rs1use crate::task::{CurrentTask, Kernel};
6use crate::vfs::pseudo::simple_directory::{SimpleDirectory, SimpleDirectoryMutator};
7use crate::vfs::pseudo::stub_empty_file::StubEmptyFile;
8use crate::vfs::{
9 CacheMode, FileSystem, FileSystemHandle, FileSystemOps, FileSystemOptions, FsStr,
10};
11use starnix_logging::bug_ref;
12use starnix_types::vfs::default_statfs;
13use starnix_uapi::errors::Errno;
14use starnix_uapi::file_mode::mode;
15use starnix_uapi::{DEBUGFS_MAGIC, statfs};
16
17struct DebugFs;
18
19impl FileSystemOps for DebugFs {
20 fn statfs(&self, _fs: &FileSystem, _current_task: &CurrentTask) -> Result<statfs, Errno> {
21 Ok(default_statfs(DEBUGFS_MAGIC))
22 }
23 fn name(&self) -> &'static FsStr {
24 "debugfs".into()
25 }
26}
27
28impl DebugFs {
29 fn new_fs(kernel: &Kernel, options: FileSystemOptions) -> FileSystemHandle {
30 let fs =
31 FileSystem::new(kernel, CacheMode::Cached(kernel.fs_cache_config()), DebugFs, options)
32 .expect("debugfs constructed with valid options");
33
34 let root = SimpleDirectory::new();
35 fs.create_root(fs.allocate_ino(), root.clone());
36
37 let dir = SimpleDirectoryMutator::new(fs.clone(), root);
38 let dir_mode = 0o700;
39 dir.subdir("binder", dir_mode, |dir| {
40 dir.entry(
41 "failed_transaction_log",
42 StubEmptyFile::new_node(bug_ref!("https://fxbug.dev/452096300")),
43 mode!(IFREG, 0o444),
44 );
45 dir.entry(
46 "state",
47 StubEmptyFile::new_node(bug_ref!("https://fxbug.dev/452096300")),
48 mode!(IFREG, 0o444),
49 );
50 dir.entry(
51 "stats",
52 StubEmptyFile::new_node(bug_ref!("https://fxbug.dev/452096300")),
53 mode!(IFREG, 0o444),
54 );
55 dir.entry(
56 "transaction_log",
57 StubEmptyFile::new_node(bug_ref!("https://fxbug.dev/452096300")),
58 mode!(IFREG, 0o444),
59 );
60 dir.entry(
61 "transactions",
62 StubEmptyFile::new_node(bug_ref!("https://fxbug.dev/452096300")),
63 mode!(IFREG, 0o444),
64 );
65 });
66 dir.subdir("mmc0", dir_mode, |dir| {
67 dir.subdir("mmc0:0001", dir_mode, |dir| {
68 dir.entry(
69 "ext_csd",
70 StubEmptyFile::new_node(bug_ref!("https://fxbug.dev/452096300")),
71 mode!(IFREG, 0o444),
72 );
73 });
74 });
75 dir.subdir("tracing", 0o644, |_| ());
76
77 fs
78 }
79}
80
81struct DebugFsHandle(FileSystemHandle);
82
83pub fn debug_fs(
84 current_task: &CurrentTask,
85 _options: FileSystemOptions,
86) -> Result<FileSystemHandle, Errno> {
87 Ok(get_debugfs(current_task.kernel()))
88}
89
90pub fn get_debugfs(kernel: &Kernel) -> FileSystemHandle {
91 kernel
92 .expando
93 .get_or_init(|| DebugFsHandle(DebugFs::new_fs(kernel, FileSystemOptions::default())))
94 .0
95 .clone()
96}