starnix_core/power/
sync_on_suspend.rs1use crate::task::CurrentTask;
6use crate::vfs::FsNodeOps;
7use crate::vfs::pseudo::simple_file::{BytesFile, BytesFileOps, parse_i32_file};
8use starnix_uapi::error;
9use starnix_uapi::errors::Errno;
10use std::borrow::Cow;
11
12pub struct PowerSyncOnSuspendFile;
13
14impl PowerSyncOnSuspendFile {
15 pub fn new_node() -> impl FsNodeOps {
16 BytesFile::new_node(Self {})
17 }
18}
19
20impl BytesFileOps for PowerSyncOnSuspendFile {
21 fn write(&self, current_task: &CurrentTask, data: Vec<u8>) -> Result<(), Errno> {
22 let value = parse_i32_file(&data)?;
23 let enabled = match value {
24 0 => false,
25 1 => true,
26 _ => return error!(EINVAL),
27 };
28 current_task.kernel().suspend_resume_manager.set_sync_on_suspend(enabled);
29 Ok(())
30 }
31
32 fn read(&self, current_task: &CurrentTask) -> Result<Cow<'_, [u8]>, Errno> {
33 let bytes = if current_task.kernel().suspend_resume_manager.sync_on_suspend_enabled() {
34 b"1\n"
35 } else {
36 b"0\n"
37 };
38 Ok(bytes.into())
39 }
40}