starnix_core/power/
wakeup_count.rs1use crate::task::CurrentTask;
6use crate::vfs::FsNodeOps;
7use crate::vfs::pseudo::simple_file::{
8 BytesFile, BytesFileOps, parse_unsigned_file, serialize_for_file,
9};
10use starnix_uapi::error;
11use starnix_uapi::errors::Errno;
12use std::borrow::Cow;
13
14pub struct PowerWakeupCountFile;
22
23impl PowerWakeupCountFile {
24 pub fn new_node() -> impl FsNodeOps {
25 BytesFile::new_node(Self {})
26 }
27}
28
29impl BytesFileOps for PowerWakeupCountFile {
30 fn write(&self, current_task: &CurrentTask, data: Vec<u8>) -> Result<(), Errno> {
31 let expected_count: u64 = parse_unsigned_file(&data)?;
32 let real_count = current_task.kernel().suspend_resume_manager.suspend_stats().wakeup_count;
33 if expected_count != real_count {
34 return error!(EINVAL);
35 }
36 Ok(())
37 }
38
39 fn read(&self, current_task: &CurrentTask) -> Result<Cow<'_, [u8]>, Errno> {
40 let wakeup_count =
41 current_task.kernel().suspend_resume_manager.suspend_stats().wakeup_count;
42 Ok(serialize_for_file(wakeup_count).into())
43 }
44}