@@ -254,7 +254,7 @@ impl<'a> BootInformation<'a> {
254254 /// # use multiboot2::{BootInformation, BootInformationHeader};
255255 /// # let ptr = 0xdeadbeef as *const BootInformationHeader;
256256 /// # let boot_info = unsafe { BootInformation::load(ptr).unwrap() };
257- /// if let Some(sections) = boot_info.elf_sections( ) {
257+ /// if let Some(sections) = boot_info.elf_sections_tag().map(|tag| tag.sections() ) {
258258 /// let mut total = 0;
259259 /// for section in sections {
260260 /// println!("Section: {:?}", section);
@@ -263,14 +263,21 @@ impl<'a> BootInformation<'a> {
263263 /// }
264264 /// ```
265265 #[ must_use]
266+ #[ deprecated = "Use elf_sections_tag() instead and corresponding getters" ]
266267 pub fn elf_sections ( & self ) -> Option < ElfSectionIter > {
267268 let tag = self . get_tag :: < ElfSectionsTag > ( ) ;
268269 tag. map ( |t| {
269270 assert ! ( ( t. entry_size( ) * t. shndx( ) ) <= t. header( ) . size) ;
270- t. sections_iter ( )
271+ t. sections ( )
271272 } )
272273 }
273274
275+ /// Search for the [`ElfSectionsTag`].
276+ #[ must_use]
277+ pub fn elf_sections_tag ( & self ) -> Option < & ElfSectionsTag > {
278+ self . get_tag ( )
279+ }
280+
274281 /// Search for the [`FramebufferTag`]. The result is `Some(Err(e))`, if the
275282 /// framebuffer type is unknown, while the framebuffer tag is present.
276283 #[ must_use]
@@ -421,50 +428,42 @@ impl<'a> BootInformation<'a> {
421428
422429impl fmt:: Debug for BootInformation < ' _ > {
423430 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
424- /// Limit how many Elf-Sections should be debug-formatted.
425- /// Can be thousands of sections for a Rust binary => this is useless output.
426- /// If the user really wants this, they should debug-format the field directly.
427- const ELF_SECTIONS_LIMIT : usize = 7 ;
428-
429431 let mut debug = f. debug_struct ( "Multiboot2BootInformation" ) ;
430432 debug
431433 . field ( "start_address" , & self . start_address ( ) )
432434 . field ( "end_address" , & self . end_address ( ) )
433435 . field ( "total_size" , & self . total_size ( ) )
434436 // now tags in alphabetical order
437+ . field ( "apm" , & self . apm_tag ( ) )
435438 . field ( "basic_memory_info" , & ( self . basic_memory_info_tag ( ) ) )
436439 . field ( "boot_loader_name" , & self . boot_loader_name_tag ( ) )
437- // .field("bootdev", &self.bootdev_tag())
440+ . field ( "bootdev" , & self . bootdev_tag ( ) )
438441 . field ( "command_line" , & self . command_line_tag ( ) )
439442 . field ( "efi_bs_not_exited" , & self . efi_bs_not_exited_tag ( ) )
443+ . field ( "efi_ih32" , & self . efi_ih32_tag ( ) )
444+ . field ( "efi_ih64" , & self . efi_ih64_tag ( ) )
440445 . field ( "efi_memory_map" , & self . efi_memory_map_tag ( ) )
441446 . field ( "efi_sdt32" , & self . efi_sdt32_tag ( ) )
442447 . field ( "efi_sdt64" , & self . efi_sdt64_tag ( ) )
443- . field ( "efi_ih32" , & self . efi_ih32_tag ( ) )
444- . field ( "efi_ih64" , & self . efi_ih64_tag ( ) ) ;
445-
446- // usually this is REALLY big (thousands of tags) => skip it here
447- {
448- let elf_sections_tag_entries_count =
449- self . elf_sections ( ) . map ( |x| x. count ( ) ) . unwrap_or ( 0 ) ;
450-
451- if elf_sections_tag_entries_count > ELF_SECTIONS_LIMIT {
452- debug. field ( "elf_sections (count)" , & elf_sections_tag_entries_count) ;
453- } else {
454- debug. field ( "elf_sections" , & self . elf_sections ( ) ) ;
455- }
456- }
457-
458- debug
448+ . field ( "elf_sections" , & self . elf_sections_tag ( ) )
459449 . field ( "framebuffer" , & self . framebuffer_tag ( ) )
460450 . field ( "load_base_addr" , & self . load_base_addr_tag ( ) )
461451 . field ( "memory_map" , & self . memory_map_tag ( ) )
462452 . field ( "modules" , & self . module_tags ( ) )
463- // .field("network", &self.network_tag())
453+ . field ( "network" , & self . network_tag ( ) )
464454 . field ( "rsdp_v1" , & self . rsdp_v1_tag ( ) )
465455 . field ( "rsdp_v2" , & self . rsdp_v2_tag ( ) )
466- . field ( "smbios_tag" , & self . smbios_tag ( ) )
467- . field ( "vbe_info_tag" , & self . vbe_info_tag ( ) )
456+ . field ( "smbios" , & self . smbios_tag ( ) )
457+ . field ( "vbe_info" , & self . vbe_info_tag ( ) )
458+ // computed fields
459+ . field ( "custom_tags_count" , & {
460+ self . tags ( )
461+ . filter ( |tag| {
462+ let id: TagType = tag. header ( ) . typ . into ( ) ;
463+ matches ! ( id, TagType :: Custom ( _) )
464+ } )
465+ . count ( )
466+ } )
468467 . finish ( )
469468 }
470469}
0 commit comments