@@ -20,7 +20,6 @@ use openat_ext::OpenatDirExt;
2020use os_release:: OsRelease ;
2121use rustix:: fd:: BorrowedFd ;
2222use walkdir:: WalkDir ;
23- use widestring:: U16CString ;
2423
2524use crate :: bootupd:: RootContext ;
2625use crate :: freezethaw:: fsfreeze_thaw_cycle;
@@ -47,9 +46,9 @@ pub(crate) const SHIM: &str = "shimx64.efi";
4746#[ cfg( target_arch = "riscv64" ) ]
4847pub ( crate ) const SHIM : & str = "shimriscv64.efi" ;
4948
50- /// Systemd boot loader info EFI variable names
51- const LOADER_INFO_VAR_STR : & str = "LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f" ;
52- const STUB_INFO_VAR_STR : & str = "StubInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f" ;
49+ // // / Systemd boot loader info EFI variable names
50+ // const LOADER_INFO_VAR_STR: &str = "LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f";
51+ // const STUB_INFO_VAR_STR: &str = "StubInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f";
5352
5453/// Return `true` if the system is booted via EFI
5554pub ( crate ) fn is_efi_booted ( ) -> Result < bool > {
@@ -169,69 +168,69 @@ fn get_product_name(sysroot: &Dir) -> Result<String> {
169168 Ok ( release. name )
170169}
171170
172- /// Convert a nul-terminated UTF-16 byte array to a String.
173- fn string_from_utf16_bytes ( slice : & [ u8 ] ) -> String {
174- // For some reason, systemd appends 3 nul bytes after the string.
175- // Drop the last byte if there's an odd number.
176- let size = slice. len ( ) / 2 ;
177- let v: Vec < u16 > = ( 0 ..size)
178- . map ( |i| u16:: from_ne_bytes ( [ slice[ 2 * i] , slice[ 2 * i + 1 ] ] ) )
179- . collect ( ) ;
180- U16CString :: from_vec ( v) . unwrap ( ) . to_string_lossy ( )
181- }
182-
183- /// Read a nul-terminated UTF-16 string from an EFI variable.
184- fn read_efi_var_utf16_string ( name : & str ) -> Option < String > {
185- let efivars = Path :: new ( "/sys/firmware/efi/efivars" ) ;
186- if !efivars. exists ( ) {
187- log:: trace!( "No efivars mount at {:?}" , efivars) ;
188- return None ;
189- }
190- let path = efivars. join ( name) ;
191- if !path. exists ( ) {
192- log:: trace!( "No EFI variable {name}" ) ;
193- return None ;
194- }
195- match std:: fs:: read ( & path) {
196- Ok ( buf) => {
197- // Skip the first 4 bytes, those are the EFI variable attributes.
198- if buf. len ( ) < 4 {
199- log:: warn!( "Read less than 4 bytes from {:?}" , path) ;
200- return None ;
201- }
202- Some ( string_from_utf16_bytes ( & buf[ 4 ..] ) )
203- }
204- Err ( reason) => {
205- log:: warn!( "Failed reading {:?}: {reason}" , path) ;
206- None
207- }
208- }
209- }
210-
211- /// Read the LoaderInfo EFI variable if it exists.
212- fn get_loader_info ( ) -> Option < String > {
213- read_efi_var_utf16_string ( LOADER_INFO_VAR_STR )
214- }
215-
216- /// Read the StubInfo EFI variable if it exists.
217- fn get_stub_info ( ) -> Option < String > {
218- read_efi_var_utf16_string ( STUB_INFO_VAR_STR )
219- }
220-
221- /// Whether to skip adoption if a systemd bootloader is found.
222- fn skip_systemd_bootloaders ( ) -> bool {
223- if let Some ( loader_info) = get_loader_info ( ) {
224- if loader_info. starts_with ( "systemd" ) {
225- log:: trace!( "Skipping adoption for {:?}" , loader_info) ;
226- return true ;
227- }
228- }
229- if let Some ( stub_info) = get_stub_info ( ) {
230- log:: trace!( "Skipping adoption for {:?}" , stub_info) ;
231- return true ;
232- }
233- false
234- }
171+ // // / Convert a nul-terminated UTF-16 byte array to a String.
172+ // fn string_from_utf16_bytes(slice: &[u8]) -> String {
173+ // // For some reason, systemd appends 3 nul bytes after the string.
174+ // // Drop the last byte if there's an odd number.
175+ // let size = slice.len() / 2;
176+ // let v: Vec<u16> = (0..size)
177+ // .map(|i| u16::from_ne_bytes([slice[2 * i], slice[2 * i + 1]]))
178+ // .collect();
179+ // U16CString::from_vec(v).unwrap().to_string_lossy()
180+ // }
181+
182+ // // / Read a nul-terminated UTF-16 string from an EFI variable.
183+ // fn read_efi_var_utf16_string(name: &str) -> Option<String> {
184+ // let efivars = Path::new("/sys/firmware/efi/efivars");
185+ // if !efivars.exists() {
186+ // log::trace!("No efivars mount at {:?}", efivars);
187+ // return None;
188+ // }
189+ // let path = efivars.join(name);
190+ // if !path.exists() {
191+ // log::trace!("No EFI variable {name}");
192+ // return None;
193+ // }
194+ // match std::fs::read(&path) {
195+ // Ok(buf) => {
196+ // // Skip the first 4 bytes, those are the EFI variable attributes.
197+ // if buf.len() < 4 {
198+ // log::warn!("Read less than 4 bytes from {:?}", path);
199+ // return None;
200+ // }
201+ // Some(string_from_utf16_bytes(&buf[4..]))
202+ // }
203+ // Err(reason) => {
204+ // log::warn!("Failed reading {:?}: {reason}", path);
205+ // None
206+ // }
207+ // }
208+ // }
209+
210+ // // / Read the LoaderInfo EFI variable if it exists.
211+ // fn get_loader_info() -> Option<String> {
212+ // read_efi_var_utf16_string(LOADER_INFO_VAR_STR)
213+ // }
214+
215+ // // / Read the StubInfo EFI variable if it exists.
216+ // fn get_stub_info() -> Option<String> {
217+ // read_efi_var_utf16_string(STUB_INFO_VAR_STR)
218+ // }
219+
220+ // // / Whether to skip adoption if a systemd bootloader is found.
221+ // fn skip_systemd_bootloaders() -> bool {
222+ // if let Some(loader_info) = get_loader_info() {
223+ // if loader_info.starts_with("systemd") {
224+ // log::trace!("Skipping adoption for {:?}", loader_info);
225+ // return true;
226+ // }
227+ // }
228+ // if let Some(stub_info) = get_stub_info() {
229+ // log::trace!("Skipping adoption for {:?}", stub_info);
230+ // return true;
231+ // }
232+ // false
233+ // }
235234
236235impl Component for Efi {
237236 fn name ( & self ) -> & ' static str {
@@ -244,11 +243,11 @@ impl Component for Efi {
244243 return Ok ( None ) ;
245244 } ;
246245
247- // Don't adopt if the system is booted with systemd-boot or
248- // systemd-stub since those will be managed with bootctl.
249- if skip_systemd_bootloaders ( ) {
250- return Ok ( None ) ;
251- }
246+ // // Don't adopt if the system is booted with systemd-boot or
247+ // // systemd-stub since those will be managed with bootctl.
248+ // if skip_systemd_bootloaders() {
249+ // return Ok(None);
250+ // }
252251 crate :: component:: query_adopt_state ( )
253252 }
254253
0 commit comments