Skip to main content

FixedFdTable

Struct FixedFdTable 

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

Table de descripteurs de fichiers fixes (REGISTER_FILES2, 13).

Possède les [OwnedFd] des slots remplis ; sparse par défaut (slots vides à remplir plus tard). Les opérations sur FD fixe (FixedSlot) évitent au kernel la résolution du FD à chaque op (IOSQE_FIXED_FILE).

Implementations§

Source§

impl FixedFdTable

Source

pub fn register(ring: &mut IoUring, capacity: NonZeroU32) -> Result<Self, Errno>

REGISTER_FILES2 (13) : table sparse de capacity slots vides.

§Errors

Erreurs de io_uring_register : [Errno::EINVAL] (capacité trop grande, déjà enregistré), [Errno::EMFILE]/[Errno::ENOMEM].

Source

pub fn register_with( ring: &mut IoUring, fds: Vec<OwnedFd>, ) -> Result<Self, Errno>

REGISTER_FILES2 (13) avec un jeu initial de FD (slots remplis dans l’ordre, à partir de l’indice 0). Les FD sont possédés par la table.

§Errors

[Errno::EINVAL] si fds est vide ou déborde un u32 ; erreurs de io_uring_register.

Source

pub fn set( &mut self, ring: &mut IoUring, slot: u32, fd: OwnedFd, ) -> Result<(), Errno>

REGISTER_FILES_UPDATE2 (14) : place/remplace le FD du slot slot.

Consomme tout FD précédemment présent dans ce slot (fermé) — transfert d’ownership voulu, gravé dans la signature (ADR-032 : consommation explicite ≠ discard).

§Errors

[Errno::EINVAL] si slot est hors borne ; erreurs de io_uring_register.

Source

pub fn clear( &mut self, ring: &mut IoUring, slot: u32, ) -> Result<Option<OwnedFd>, Errno>

REGISTER_FILES_UPDATE2 (14) avec fd = -1 : vide le slot. Rend le FD qu’il contenait (zéro discard), ou None s’il était déjà vide.

§Errors

[Errno::EINVAL] si slot est hors borne ; erreurs de io_uring_register.

Source

pub fn set_alloc_range( &mut self, ring: &mut IoUring, range: Range<u32>, ) -> Result<(), Errno>

REGISTER_FILE_ALLOC_RANGE (25) : borne la plage [start, end) des slots éligibles à l’auto-allocation (FixedSlotTarget::Alloc).

§Errors

[Errno::EINVAL] si range est inversé ou déborde la capacité ; erreurs de io_uring_register.

Source

pub fn unregister(self, ring: &mut IoUring) -> Result<Vec<OwnedFd>, Errno>

UNREGISTER_FILES (3) : désenregistre toute la table et rend les FD restants (restitution intégrale, ADR-032).

Sûreté par construction : un FixedSlot emprunté à la table ne peut pas survivre à ce désenregistrement (qui consomme self) — le code suivant ne compile pas :

let table = FixedFdTable::register(ring, NonZeroU32::new(4).unwrap()).unwrap();
let slot = table.slot(0).unwrap();         // emprunte `table`
let _fds = table.unregister(ring).unwrap(); // déplace `table`…
let _ = slot.index();                       // …emprunt encore vivant ⇒ ERREUR
§Errors

Erreurs de io_uring_register ([Errno::EINVAL] si rien n’est enregistré, [Errno::EBUSY]). En cas d’erreur, les FD possédés sont fermés (la table est consommée).

Source

pub fn slot(&self, slot: u32) -> Option<FixedSlot<'_>>

Référence empruntée au slot slot pour usage en opération (IOSQE_FIXED_FILE), si l’indice est dans la capacité de la table. None si hors borne.

La référence est bornée par l’indice, pas par le suivi d’ownership : un slot peut avoir été rempli par une variante « direct » (côté kernel, sans OwnedFd côté Air). Référencer un slot vide est sûr — l’op échoue alors proprement à la complétion (EBADF), jamais d’UB.

Trait Implementations§

Source§

impl Debug for FixedFdTable

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.