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
impl MapData
Sourcepub fn create(
obj: Map,
name: &str,
btf_fd: Option<BorrowedFd<'_>>,
) -> Result<Self, MapError>
pub fn create( obj: Map, name: &str, btf_fd: Option<BorrowedFd<'_>>, ) -> Result<Self, MapError>
Creates a new map with the provided name
Sourcepub fn from_pin<P: AsRef<Path>>(path: P) -> Result<Self, MapError>
pub fn from_pin<P: AsRef<Path>>(path: P) -> Result<Self, MapError>
Loads a map from a pinned path in bpffs.
Sourcepub fn from_fd(fd: OwnedFd) -> Result<Self, MapError>
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.
Sourcepub fn pin<P: AsRef<Path>>(&self, path: P) -> Result<(), PinError>
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")?;