FileObject

Struct FileObject 

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

A session with a file object.

Each time a client calls open(), we create a new FileObject from the underlying FsNode that receives the open(). This object contains the state that is specific to this sessions whereas the underlying FsNode contains the state that is shared between all the sessions.

Implementations§

Source§

impl FileObject

Source

pub fn new_anonymous<L>( locked: &mut Locked<L>, current_task: &CurrentTask, ops: Box<dyn FileOps>, node: FsNodeHandle, flags: OpenFlags, ) -> FileHandle

Create a FileObject that is not mounted in a namespace.

In particular, this will create a new unrooted entries. This should not be used on file system with persistent entries, as the created entry will be out of sync with the one from the file system.

The returned FileObject does not have a name.

Source

pub fn new<L>( locked: &mut Locked<L>, current_task: &CurrentTask, ops: Box<dyn FileOps>, name: NamespaceNode, flags: OpenFlags, ) -> Result<FileHandle, Errno>

Create a FileObject with an associated NamespaceNode.

This function is not typically called directly. Instead, consider calling NamespaceNode::open.

Source

pub fn max_access_for_memory_mapping(&self) -> Access

Source

pub fn ops(&self) -> &dyn FileOps

Source

pub fn ops_type_name(&self) -> &'static str

Source

pub fn is_non_blocking(&self) -> bool

Source

pub fn blocking_op<L, T, Op>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, events: FdEvents, deadline: Option<MonotonicInstant>, op: Op, ) -> Result<T, Errno>
where L: LockEqualOrBefore<FileOpsCore>, Op: FnMut(&mut Locked<L>) -> Result<T, Errno>,

Common implementation for blocking operations.

This function is used to implement the blocking operations for file objects. FileOps implementations should call this function to handle the blocking logic.

The op parameter is a function that implements the non-blocking version of the operation. The function is called once without registering a waiter in case no wait is needed. If the operation returns EAGAIN and the file object is non-blocking, the function returns EAGAIN.

If the operation returns EAGAIN and the file object is blocking, the function will block until the given events are triggered. At that time, the operation is retried. Notice that the op function can be called multiple times before the operation completes.

The deadline parameter is the deadline for the operation. If the operation does not complete before the deadline, the function will return ETIMEDOUT.

Source

pub fn is_seekable(&self) -> bool

Source

pub fn has_persistent_offsets(&self) -> bool

Source

pub fn read<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, data: &mut dyn OutputBuffer, ) -> Result<usize, Errno>

Source

pub fn read_at<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, offset: usize, data: &mut dyn OutputBuffer, ) -> Result<usize, Errno>

Source

pub fn write<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, data: &mut dyn InputBuffer, ) -> Result<usize, Errno>

Source

pub fn write_at<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, offset: usize, data: &mut dyn InputBuffer, ) -> Result<usize, Errno>

Source

pub fn seek<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, target: SeekTarget, ) -> Result<off_t, Errno>

Source

pub fn sync(&self, current_task: &CurrentTask) -> Result<(), Errno>

Source

pub fn data_sync(&self, current_task: &CurrentTask) -> Result<(), Errno>

Source

pub fn get_memory<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, length: Option<usize>, prot: ProtectionFlags, ) -> Result<Arc<MemoryObject>, Errno>

Source

pub fn mmap<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, addr: DesiredAddress, memory_offset: u64, length: usize, prot_flags: ProtectionFlags, options: MappingOptions, filename: NamespaceNode, ) -> Result<UserAddress, Errno>

Source

pub fn readdir<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, sink: &mut dyn DirentSink, ) -> Result<(), Errno>

Source

pub fn ioctl( &self, locked: &mut Locked<Unlocked>, current_task: &CurrentTask, request: u32, arg: SyscallArg, ) -> Result<SyscallResult, Errno>

Source

pub fn fcntl( &self, current_task: &CurrentTask, cmd: u32, arg: u64, ) -> Result<SyscallResult, Errno>

Source

pub fn ftruncate<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, length: u64, ) -> Result<(), Errno>

Source

pub fn fallocate<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mode: FallocMode, offset: u64, length: u64, ) -> Result<(), Errno>

Source

pub fn to_handle( &self, current_task: &CurrentTask, ) -> Result<Option<NullableHandle>, Errno>

Source

pub fn as_thread_group_key(&self) -> Result<ThreadGroupKey, Errno>

Source

pub fn update_file_flags(&self, value: OpenFlags, mask: OpenFlags)

Source

pub fn get_async_owner(&self) -> FileAsyncOwner

Get the async owner of this file.

See fcntl(F_GETOWN)

Source

pub fn set_async_owner(&self, owner: FileAsyncOwner)

Set the async owner of this file.

See fcntl(F_SETOWN)

Source

pub fn get_lease(&self, _current_task: &CurrentTask) -> FileLeaseType

See fcntl(F_GETLEASE)

Source

pub fn set_lease( &self, _current_task: &CurrentTask, lease: FileLeaseType, ) -> Result<(), Errno>

See fcntl(F_SETLEASE)

Source

pub fn wait_async<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, waiter: &Waiter, events: FdEvents, handler: EventHandler, ) -> Option<WaitCanceler>

Wait on the specified events and call the EventHandler when ready

Source

pub fn query_events<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, ) -> Result<FdEvents, Errno>

The events currently active on this file.

Source

pub fn record_lock( &self, locked: &mut Locked<Unlocked>, current_task: &CurrentTask, cmd: RecordLockCommand, flock: flock, ) -> Result<Option<flock>, Errno>

Source

pub fn flush<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, id: FdTableId, )

Source

pub fn readahead( &self, current_task: &CurrentTask, offset: usize, length: usize, ) -> Result<(), Errno>

Source

pub fn extra_fdinfo( &self, locked: &mut Locked<FileOpsCore>, current_task: &CurrentTask, ) -> Option<FsString>

Source

pub fn register_epfd(&self, file: &FileHandle)

Register the fd number of an EpollFileObject that listens to events from this FileObject.

Source

pub fn unregister_epfd(&self, file: &FileHandle)

Source§

impl FileObject

Source

pub fn downcast_file<'a, T>(&'a self) -> Option<DowncastedFile<'a, T>>
where T: 'static,

Returns the FileObject’s FileOps as a DowncastedFile<T>, or None if the downcast fails.

This is useful for syscalls that only operate on a certain type of file.

Source§

impl FileObject

Source

pub fn flock( &self, locked: &mut Locked<Unlocked>, current_task: &CurrentTask, operation: FlockOperation, ) -> Result<(), Errno>

Advisory locking.

See flock(2).

Methods from Deref<Target = FileObjectState>§

Source

pub fn node(&self) -> &FsNodeHandle

The FsNode from which this FileObject was created.

Source

pub fn flags(&self) -> OpenFlags

Source

pub fn can_read(&self) -> bool

Source

pub fn can_write(&self) -> bool

Source

pub fn can_exec(&self) -> bool

Returns false if the file is not allowed to be executed.

Source

pub fn notify(&self, event_mask: InotifyMask)

Trait Implementations§

Source§

impl Debug for FileObject

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Deref for FileObject

Source§

type Target = FileObjectState

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a> From<&'a FileObject> for Auditable<'a>

Source§

fn from(value: &'a FileObject) -> Self

Converts to this type from the input type.
Source§

impl Releasable for FileObject

Source§

type Context<'a> = (&'a mut Locked<FileOpsCore>, &'a CurrentTask)

Source§

fn release<'a>(self, context: CurrentTaskAndLocked<'a>)

Source§

impl ReleaserAction<FileObject> for FileObjectReleaserAction

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn type_name(&self) -> &'static str

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, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> InstanceFromServiceTransport<T> for T

§

fn from_service_transport(handle: T) -> T

Converts the given service transport handle of type T to [Self]
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> Into32<U> for T
where U: MultiArchFrom<T>,

Source§

fn into_32(self) -> U

Source§

impl<T, U> Into64<U> for T
where U: MultiArchFrom<T>,

Source§

fn into_64(self) -> U

Source§

impl<T> IntoAny for T
where T: 'static + Send + Sync,

Source§

fn into_any(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Cast the given object into a dyn std::any::Any.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T, U> IntoExt<U> for T
where U: FromExt<T>,

§

fn into_ext(self) -> U

Performs the conversion.
Source§

impl<T, U> IntoFidl<U> for T
where U: FromFidl<T>,

Source§

fn into_fidl(self) -> U

Source§

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

Source§

fn from_64(value: T) -> U

Source§

fn from_32(value: T) -> U

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T, U> TryIntoExt<U> for T
where U: TryFromExt<T>,

§

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

§

fn try_into_ext(self) -> Result<U, <T as TryIntoExt<U>>::Error>

Tries to perform the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<St> WithTag for St

§

fn tagged<T>(self, tag: T) -> Tagged<T, St>

Produce a new stream from this one which yields item tupled with a constant tag
Source§

impl<B, A> LockBefore<B> for A
where B: LockAfter<A>,

Source§

impl<B, A> LockEqualOrBefore<B> for A
where A: LockBefore<B>,

§

impl<E> RunsTransport<Mpsc> for E

§

impl<E> RunsTransport<Mpsc> for E
where E: RunsTransport<Mpsc>,