1- use crate :: efivarfs;
21use crate :: efi_variable_attributes:: parse_attributes;
2+ use crate :: efivarfs;
33use crate :: types:: { EfiGuid , EfiVariable } ;
44use crate :: MIN_VAR_FILE_NAME_LEN ;
55use std:: boxed:: Box ;
@@ -24,9 +24,12 @@ impl Default for EfiVariables {
2424 path : EFIVARS_PATH . into ( ) ,
2525 platform_size : 0 ,
2626 } ;
27- variables. set_firmware_platform_size (
28- EfiVariables :: get_firmware_platform_size ( EFIVARS_FW_PLATFORM_SZ_PATH . into ( ) ) . unwrap ( ) ,
29- ) ;
27+ variables
28+ . set_firmware_platform_size (
29+ EfiVariables :: get_firmware_platform_size ( EFIVARS_FW_PLATFORM_SZ_PATH . into ( ) )
30+ . unwrap ( ) ,
31+ )
32+ . unwrap ( ) ;
3033 return variables;
3134 }
3235}
@@ -142,16 +145,20 @@ impl EfiVariables {
142145 . join ( "raw_var" ) ;
143146 let efi_variable = self . parse_payload ( & full_path) ?;
144147 if * efi_variable. name != * prefix {
145- return Err :: < EfiVariable , Box < dyn Error > > ( "Corrupt variable. Reported name does not match name" . into ( ) ) ;
148+ return Err :: < EfiVariable , Box < dyn Error > > (
149+ "Corrupt variable. Reported name does not match name" . into ( ) ,
150+ ) ;
146151 }
147152 if efi_variable. guid != guid {
148- return Err :: < EfiVariable , Box < dyn Error > > ( "Corrupt variable. Reported guid does not match guid" . into ( ) ) ;
153+ return Err :: < EfiVariable , Box < dyn Error > > (
154+ "Corrupt variable. Reported guid does not match guid" . into ( ) ,
155+ ) ;
149156 }
150157 return Ok ( efi_variable) ;
151158 }
152159
153160 fn parse_payload ( & self , var_path : & Path ) -> Result < EfiVariable , Box < dyn Error > > {
154- let mut handle = fs:: File :: open ( var_path) ?;
161+ let handle = fs:: File :: open ( var_path) ?;
155162 let mut buffer: Box < dyn EfiNVariableBuffer > = match self . platform_size {
156163 64 => {
157164 Ok ( Box :: new ( Efi64VariableBuffer :: try_from ( handle) ?) as Box < dyn EfiNVariableBuffer > )
@@ -173,7 +180,8 @@ impl EfiVariables {
173180 return None ;
174181 } )
175182 . collect :: < Vec < u16 > > ( ) ,
176- ) ?. into ( ) ;
183+ ) ?
184+ . into ( ) ;
177185 let guid = EfiGuid :: try_from ( buffer. guid ( ) as & [ u8 ] ) ?;
178186 let data_size: usize = match TryInto :: < [ u8 ; 8 ] > :: try_into ( buffer. data_size ( ) ) {
179187 Ok ( v) => Ok :: < usize , Box < dyn Error > > ( usize:: from_ne_bytes ( v) ) ,
@@ -182,7 +190,9 @@ impl EfiVariables {
182190 ) ?) as usize ) ,
183191 } ?;
184192 if data_size > 1024 {
185- return Err :: < EfiVariable , Box < dyn Error > > ( "Corrupt variable. Reported data size exceeds maximum" . into ( ) ) ;
193+ return Err :: < EfiVariable , Box < dyn Error > > (
194+ "Corrupt variable. Reported data size exceeds maximum" . into ( ) ,
195+ ) ;
186196 }
187197 let data: Vec < u8 > = buffer. data ( ) [ 0 ..data_size] . into ( ) ;
188198 let status: usize = match TryInto :: < [ u8 ; 8 ] > :: try_into ( buffer. status ( ) ) {
@@ -192,9 +202,13 @@ impl EfiVariables {
192202 ) ?) as usize ) ,
193203 } ?;
194204 if status != 0 {
195- return Err :: < EfiVariable , Box < dyn Error > > ( format ! ( "Variable read error. Unexpected status code {}" , status) . into ( ) ) ;
205+ return Err :: < EfiVariable , Box < dyn Error > > (
206+ format ! ( "Variable read error. Unexpected status code {}" , status) . into ( ) ,
207+ ) ;
196208 }
197- let attributes = parse_attributes ( u32:: from_ne_bytes ( TryInto :: < [ u8 ; 4 ] > :: try_into ( buffer. attributes ( ) ) ?) ) ;
209+ let attributes = parse_attributes ( u32:: from_ne_bytes ( TryInto :: < [ u8 ; 4 ] > :: try_into (
210+ buffer. attributes ( ) ,
211+ ) ?) ) ;
198212
199213 return Ok ( EfiVariable {
200214 name,
@@ -205,12 +219,17 @@ impl EfiVariables {
205219 }
206220
207221 fn set_firmware_platform_size ( & mut self , size : usize ) -> Result < ( ) , Box < dyn Error > > {
208- match size {
209- 64 => Ok ( self . platform_size = 64 ) ,
210- 32 => Ok ( self . platform_size = 32 ) ,
211- _ => Err ( format ! ( "Unsupported platform size: {}" , size) ) ,
222+ return match size {
223+ 64 => {
224+ self . platform_size = 64 ;
225+ Ok ( ( ) )
226+ }
227+ 32 => {
228+ self . platform_size = 32 ;
229+ Ok ( ( ) )
230+ }
231+ _ => Err ( format ! ( "Unsupported platform size: {}" , size) . into ( ) ) ,
212232 } ;
213- return Ok ( ( ) ) ;
214233 }
215234
216235 fn get_firmware_platform_size ( path : & str ) -> Result < usize , Box < dyn Error > > {
@@ -219,7 +238,7 @@ impl EfiVariables {
219238 Ok ( chars) => {
220239 let ws_index = match chars. find ( char:: is_whitespace) {
221240 Some ( index) => index,
222- None => chars. len ( )
241+ None => chars. len ( ) ,
223242 } ;
224243 Ok ( usize:: from_str_radix ( & chars[ 0 ..ws_index] , 10 ) ?)
225244 }
0 commit comments