pub struct Cmdline { /* private fields */ }
Expand description

A builder for a kernel command line string that validates the string as it’s being built. A CString can be constructed from this directly using CString::new.

Examples

let cl = Cmdline::new(100);
let cl_cstring = CString::new(cl).unwrap();
assert_eq!(cl_cstring.to_str().unwrap(), "");

Implementations

Constructs an empty Cmdline with the given capacity, including the nul terminator.

Arguments
  • capacity - Command line capacity. Must be greater than 0.
Examples
let cl = Cmdline::new(100);

Validates and inserts a key-value pair into this command line.

Arguments
  • key - Key to be inserted in the command line string.
  • val - Value corresponding to key.
Examples
let mut cl = Cmdline::new(100);
cl.insert("foo", "bar");
assert_eq!(cl.as_cstring().unwrap().as_bytes_with_nul(), b"foo=bar\0");

Validates and inserts a key-value1,…,valueN pair into this command line.

Arguments
  • key - Key to be inserted in the command line string.
  • vals - Values corresponding to key.
Examples
let mut cl = Cmdline::new(100);
cl.insert_multiple("foo", &["bar", "baz"]);
let cl_cstring = CString::new(cl).unwrap();
assert_eq!(cl_cstring.to_str().unwrap(), "foo=bar,baz");

Validates and inserts a string to the end of the current command line.

Arguments
  • slug - String to be appended to the command line.
Examples
let mut cl = Cmdline::new(100);
cl.insert_str("foobar");
let cl_cstring = CString::new(cl).unwrap();
assert_eq!(cl_cstring.to_str().unwrap(), "foobar");

Returns a C compatible representation of the command line The Linux kernel expects a null terminated cmdline according to the source: https://elixir.bootlin.com/linux/v5.10.139/source/kernel/params.c#L179

To get bytes of the cmdline to be written in guest’s memory (including the null terminator) from this representation, use CString::as_bytes_with_nul()

Examples
let mut cl = Cmdline::new(10);
cl.insert_str("foobar");
assert_eq!(cl.as_cstring().unwrap().as_bytes_with_nul(), b"foobar\0");

Adds a virtio MMIO device to the kernel command line.

Multiple devices can be specified, with multiple virtio_mmio.device= options. This function must be called once per device. The function appends a string of the following format to the kernel command line: <size>@<baseaddr>:<irq>[:<id>]. For more details see the documentation (section virtio_mmio.device=).

Arguments
  • size - size of the slot the device occupies on the MMIO bus.
  • baseaddr - physical base address of the device.
  • irq - interrupt number to be used by the device.
  • id - optional platform device ID.
Examples
let mut cl = Cmdline::new(100);
cl.add_virtio_mmio_device(1 << 12, GuestAddress(0x1000), 5, Some(42))
    .unwrap();
let cl_cstring = CString::new(cl).unwrap();
assert_eq!(
    cl_cstring.to_str().unwrap(),
    "virtio_mmio.device=4K@0x1000:5:42"
);

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.