1#![recursion_limit = "256"]
7
8use starnix_core::bpf::fs::BpfFs;
9use starnix_core::device::kobject::DeviceMetadata;
10use starnix_core::device::mem::{DevRandom, mem_device_init};
11use starnix_core::device::{DeviceMode, simple_device_ops};
12use starnix_core::fs::debugfs::debug_fs;
13use starnix_core::fs::devpts::{dev_pts_fs, tty_device_init};
14use starnix_core::fs::devtmpfs::dev_tmp_fs;
15use starnix_core::fs::fuchsia::{RemoteBundle, new_remote_fs, new_remote_vol};
16use starnix_core::fs::sysfs::sys_fs;
17use starnix_core::fs::tmpfs::tmp_fs;
18use starnix_core::task::Kernel;
19use starnix_core::vfs::fs_registry::FsRegistry;
20use starnix_core::vfs::pipe::register_pipe_fs;
21use starnix_modules_binderfs::BinderFs;
22use starnix_modules_cgroupfs::{CgroupV1Fs, cgroup2_fs};
23use starnix_modules_device_mapper::{create_device_mapper, device_mapper_init};
24use starnix_modules_ext4::ExtFilesystem;
25use starnix_modules_functionfs::FunctionFs;
26use starnix_modules_fuse::{new_fuse_fs, new_fusectl_fs, open_fuse_device};
27use starnix_modules_inotify::inotify::inotify_init;
28use starnix_modules_loop::{create_loop_control_device, loop_device_init};
29use starnix_modules_overlayfs::new_overlay_fs;
30use starnix_modules_procfs::proc_fs;
31use starnix_modules_pstore::pstore_fs;
32use starnix_modules_selinuxfs::selinux_fs;
33use starnix_modules_tracefs::trace_fs;
34use starnix_modules_tun::DevTun;
35use starnix_modules_zram::zram_device_init;
36use starnix_uapi::device_id::DeviceId;
37use starnix_uapi::errors::Errno;
38
39fn misc_device_init(kernel: &Kernel) -> Result<(), Errno> {
40 let registry = &kernel.device_registry;
41 let misc_class = registry.objects.misc_class();
42 registry.register_device(
43 kernel,
44 "hw_random".into(),
46 DeviceMetadata::new("hwrng".into(), DeviceId::HW_RANDOM, DeviceMode::Char),
47 misc_class.clone(),
48 simple_device_ops::<DevRandom>,
49 )?;
50 registry.register_device(
51 kernel,
52 "fuse".into(),
53 DeviceMetadata::new("fuse".into(), DeviceId::FUSE, DeviceMode::Char),
54 misc_class.clone(),
55 open_fuse_device,
56 )?;
57 registry.register_device(
58 kernel,
59 "device-mapper".into(),
60 DeviceMetadata::new("mapper/control".into(), DeviceId::DEVICE_MAPPER, DeviceMode::Char),
61 misc_class.clone(),
62 create_device_mapper,
63 )?;
64 registry.register_device(
65 kernel,
66 "loop-control".into(),
67 DeviceMetadata::new("loop-control".into(), DeviceId::LOOP_CONTROL, DeviceMode::Char),
68 misc_class.clone(),
69 create_loop_control_device,
70 )?;
71 registry.register_device(
72 kernel,
73 "tun".into(),
74 DeviceMetadata::new("tun".into(), DeviceId::TUN, DeviceMode::Char),
75 misc_class,
76 simple_device_ops::<DevTun>,
77 )?;
78 Ok(())
79}
80
81pub fn init_common_devices(kernel: &Kernel) -> Result<(), Errno> {
87 misc_device_init(kernel)?;
88 mem_device_init(kernel)?;
89 tty_device_init(kernel)?;
90 loop_device_init(kernel)?;
91 device_mapper_init(kernel)?;
92 zram_device_init(kernel)?;
93 Ok(())
94}
95
96pub fn register_common_file_systems(kernel: &Kernel) {
97 let registry = kernel.expando.get::<FsRegistry>();
98 registry.register(b"binder".into(), BinderFs::new_fs);
99 registry.register(b"bpf".into(), BpfFs::new_fs);
100 registry.register(b"cgroup".into(), CgroupV1Fs::new_fs);
101 registry.register(b"cgroup2".into(), cgroup2_fs);
102 registry.register(b"cpuset".into(), CgroupV1Fs::new_fs_cpuset);
105 registry.register(b"debugfs".into(), debug_fs);
106 registry.register(b"devpts".into(), dev_pts_fs);
107 registry.register(b"devtmpfs".into(), dev_tmp_fs);
108 registry.register(b"ext4".into(), ExtFilesystem::new_fs);
109 registry.register(b"functionfs".into(), FunctionFs::new_fs);
110 registry.register(b"fuse".into(), new_fuse_fs);
111 registry.register(b"fusectl".into(), new_fusectl_fs);
112 registry.register(b"overlay".into(), new_overlay_fs);
113 register_pipe_fs(registry.as_ref());
114 registry.register(b"proc".into(), proc_fs);
115 registry.register(b"pstore".into(), pstore_fs);
116 registry.register(b"remotefs".into(), new_remote_fs);
117 registry.register(b"remotevol".into(), new_remote_vol);
118 registry.register(b"remote_bundle".into(), RemoteBundle::new_fs);
119 registry.register(b"selinuxfs".into(), selinux_fs);
120 registry.register(b"sysfs".into(), sys_fs);
121 registry.register(b"tmpfs".into(), tmp_fs);
122 registry.register(b"tracefs".into(), trace_fs);
123}
124
125pub fn register_common_syscalls(kernel: &Kernel) {
126 inotify_init(kernel);
127}