Struct MapData

Source
pub struct MapData { /* private fields */ }
Expand description

A generic handle to a BPF map.

You should never need to use this unless you’re implementing a new map type.

Implementations§

Source§

impl MapData

Source

pub fn create( obj: Map, name: &str, btf_fd: Option<BorrowedFd<'_>>, ) -> Result<Self, MapError>

Creates a new map with the provided name

Source

pub fn from_pin<P: AsRef<Path>>(path: P) -> Result<Self, MapError>

Loads a map from a pinned path in bpffs.

Source

pub fn from_id(id: u32) -> Result<Self, MapError>

Loads a map from a map id.

Source

pub fn from_fd(fd: OwnedFd) -> Result<Self, MapError>

Loads a map from a file descriptor.

If loading from a BPF Filesystem (bpffs) you should use Map::from_pin. This API is intended for cases where you have received a valid BPF FD from some other means. For example, you received an FD over Unix Domain Socket.

Source

pub fn pin<P: AsRef<Path>>(&self, path: P) -> Result<(), PinError>

Allows the map to be pinned to the provided path.

Any directories in the the path provided should have been created by the caller. The path must be on a BPF filesystem.

§Errors

Returns a PinError::SyscallError if the underlying syscall fails. This may also happen if the path already exists, in which case the wrapped std::io::Error kind will be std::io::ErrorKind::AlreadyExists. Returns a PinError::InvalidPinPath if the path provided cannot be converted to a CString.

§Example

let mut map = MapData::from_pin("/sys/fs/bpf/my_map")?;
map.pin("/sys/fs/bpf/my_map2")?;
Source

pub fn fd(&self) -> &MapFd

Returns the file descriptor of the map.

Source

pub fn info(&self) -> Result<MapInfo, MapError>

Returns the kernel’s information about the loaded map.

Trait Implementations§

Source§

impl Debug for MapData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.