@@ -25,6 +25,19 @@ fn push_string_if_some(map: &mut serde_json::Value, key: &str, value: Option<Str
25
25
}
26
26
}
27
27
28
+ fn get_cmdline_cached ( ) -> & ' static str {
29
+ static CACHED : Once < String > = Once :: new ( ) ;
30
+
31
+ CACHED . call_once ( || {
32
+ use serde_json:: * ;
33
+
34
+ json ! ( {
35
+ "cmdline" : crate :: cmdline:: get_raw_cmdline( ) ,
36
+ } )
37
+ . to_string ( )
38
+ } )
39
+ }
40
+
28
41
fn get_cpuinfo_cached ( ) -> & ' static str {
29
42
static CACHED : Once < String > = Once :: new ( ) ;
30
43
@@ -78,6 +91,8 @@ struct ProcINode {
78
91
79
92
enum FileContents {
80
93
CpuInfo ,
94
+ CmdLine ,
95
+
81
96
None ,
82
97
}
83
98
@@ -90,7 +105,6 @@ impl Default for FileContents {
90
105
struct LockedProcINode ( RwLock < ProcINode > ) ;
91
106
92
107
impl LockedProcINode {
93
- #[ inline]
94
108
fn new ( node : ProcINode ) -> Self {
95
109
Self ( RwLock :: new ( node) )
96
110
}
@@ -123,16 +137,13 @@ impl LockedProcINode {
123
137
return Err ( FileSystemError :: EntryExists ) ;
124
138
}
125
139
126
- let filesystem = this
127
- . filesystem
128
- . upgrade ( )
129
- . expect ( "Failed to upgrade to strong filesystem" ) ;
140
+ let filesystem = this. filesystem . upgrade ( ) . unwrap ( ) ;
130
141
131
142
let inode = filesystem. allocate_inode ( file_type, contents) ;
132
143
let inode_cached = icache. make_item_no_cache ( CachedINode :: new ( inode) ) ;
133
144
134
145
downcast :: < dyn INodeInterface , LockedProcINode > ( & inode_cached. inner ( ) )
135
- . expect ( "Failed to downcast cached inode on creation" )
146
+ . unwrap ( )
136
147
. init (
137
148
& this. node ,
138
149
& inode_cached. downgrade ( ) ,
@@ -151,18 +162,17 @@ impl INodeInterface for LockedProcINode {
151
162
fn read_at ( & self , offset : usize , buffer : & mut [ u8 ] ) -> Result < usize > {
152
163
let this = self . 0 . read ( ) ;
153
164
154
- match & this. contents {
155
- FileContents :: CpuInfo => {
156
- let data = get_cpuinfo_cached ( ) ;
165
+ let data = match & this. contents {
166
+ FileContents :: CpuInfo => Ok ( get_cpuinfo_cached ( ) ) ,
167
+ FileContents :: CmdLine => Ok ( get_cmdline_cached ( ) ) ,
157
168
158
- let count = core :: cmp :: min ( buffer . len ( ) , data . len ( ) - offset ) ;
159
- buffer [ ..count ] . copy_from_slice ( & data . as_bytes ( ) [ offset.. ] ) ;
169
+ _ => Err ( FileSystemError :: NotSupported ) ,
170
+ } ? ;
160
171
161
- Ok ( count )
162
- }
172
+ let count = core :: cmp :: min ( buffer . len ( ) , data . len ( ) - offset ) ;
173
+ buffer [ ..count ] . copy_from_slice ( & data . as_bytes ( ) [ offset..offset + count ] ) ;
163
174
164
- _ => Err ( FileSystemError :: NotSupported ) ,
165
- }
175
+ Ok ( count)
166
176
}
167
177
168
178
fn lookup ( & self , dir : DirCacheItem , name : & str ) -> Result < DirCacheItem > {
@@ -253,8 +263,7 @@ impl ProcFs {
253
263
254
264
root_dir. filesystem . call_once ( || Arc :: downgrade ( & copy) ) ;
255
265
256
- let down = downcast :: < dyn INodeInterface , LockedProcINode > ( root_cached. inner ( ) )
257
- . expect ( "cannot downcast inode to ram inode" ) ;
266
+ let down = downcast :: < dyn INodeInterface , LockedProcINode > ( root_cached. inner ( ) ) . unwrap ( ) ;
258
267
259
268
down. init (
260
269
& ramfs. root_inode . downgrade ( ) ,
@@ -264,6 +273,8 @@ impl ProcFs {
264
273
) ;
265
274
266
275
down. make_inode ( "cpuinfo" , FileType :: File , FileContents :: CpuInfo ) ?;
276
+ down. make_inode ( "cmdline" , FileType :: File , FileContents :: CmdLine ) ?;
277
+
267
278
Ok ( ramfs)
268
279
}
269
280
0 commit comments