os/uapi/
sysinfo.rs

1use core::ffi::{c_uint, c_ulong};
2
3/// 系统信息结构体
4/// 对应 Linux 的 `struct sysinfo`
5#[repr(C)]
6#[derive(Debug, Clone, Copy)]
7pub struct SysInfo {
8    /// 系统启动后经过的时间,单位为秒
9    pub uptime: c_ulong,
10    /// 1 分钟、5 分钟和 15 分钟的平均负载
11    pub loads: [c_ulong; 3],
12    /// 总内存大小,单位为字节
13    pub totalram: c_ulong,
14    /// 可用内存大小,单位为字节
15    pub freeram: c_ulong,
16    /// 缓存大小,单位为字节
17    pub sharedram: c_ulong,
18    /// 用作文件缓存的内存大小,单位为字节
19    pub bufferram: c_ulong,
20    /// 总交换空间大小,单位为字节
21    pub totalswap: c_ulong,
22    /// 可用交换空间大小,单位为字节
23    pub freeswap: c_ulong,
24    /// 当前进程数
25    pub procs: u16,
26    /// 高端内存总大小,单位为字节
27    pub totalhigh: c_ulong,
28    /// 高端可用内存大小,单位为字节
29    pub freehigh: c_ulong,
30    /// 内存单位大小,单位为字节
31    pub mem_unit: c_uint,
32    /// 保留字段,供未来使用
33    pub _reserved: [u8; 256],
34}
35
36impl SysInfo {
37    /// 创建一个新的 SysInfo 实例,所有字段初始化为零
38    pub fn new() -> Self {
39        Self {
40            uptime: 0,
41            loads: [0; 3],
42            totalram: 0,
43            freeram: 0,
44            sharedram: 0,
45            bufferram: 0,
46            totalswap: 0,
47            freeswap: 0,
48            procs: 0,
49            totalhigh: 0,
50            freehigh: 0,
51            mem_unit: 0,
52            _reserved: [0; 256],
53        }
54    }
55}