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