command_line.rs 1002 B

1234567891011121314151617181920212223242526272829303132
  1. /// This Tag contains the command line string.
  2. ///
  3. /// The string is a normal C-style UTF-8 zero-terminated string that can be
  4. /// obtained via the `command_line` method.
  5. #[derive(Clone, Copy, Debug)]
  6. #[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
  7. pub struct CommandLineTag {
  8. typ: u32,
  9. size: u32,
  10. string: u8,
  11. }
  12. impl CommandLineTag {
  13. /// Read the command line string that is being passed to the booting kernel.
  14. ///
  15. /// # Examples
  16. ///
  17. /// ```ignore
  18. /// if let Some(tag) = boot_info.command_line_tag() {
  19. /// let command_line = tag.command_line();
  20. /// assert_eq!("/bootarg", command_line);
  21. /// }
  22. /// ```
  23. pub fn command_line(&self) -> &str {
  24. use core::{mem,str,slice};
  25. unsafe {
  26. let strlen = self.size as usize - mem::size_of::<CommandLineTag>();
  27. str::from_utf8_unchecked(
  28. slice::from_raw_parts((&self.string) as *const u8, strlen))
  29. }
  30. }
  31. }