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
impl FileObject
Sourcepub fn new_anonymous<L>(
locked: &mut Locked<L>,
current_task: &CurrentTask,
ops: Box<dyn FileOps>,
node: FsNodeHandle,
flags: OpenFlags,
) -> FileHandlewhere
L: LockEqualOrBefore<FileOpsCore>,
pub fn new_anonymous<L>(
locked: &mut Locked<L>,
current_task: &CurrentTask,
ops: Box<dyn FileOps>,
node: FsNodeHandle,
flags: OpenFlags,
) -> FileHandlewhere
L: LockEqualOrBefore<FileOpsCore>,
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.
Sourcepub fn new<L>(
locked: &mut Locked<L>,
current_task: &CurrentTask,
ops: Box<dyn FileOps>,
name: NamespaceNode,
flags: OpenFlags,
) -> Result<FileHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn new<L>(
locked: &mut Locked<L>,
current_task: &CurrentTask,
ops: Box<dyn FileOps>,
name: NamespaceNode,
flags: OpenFlags,
) -> Result<FileHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Create a FileObject with an associated NamespaceNode.
This function is not typically called directly. Instead, consider calling NamespaceNode::open.
pub fn max_access_for_memory_mapping(&self) -> Access
pub fn ops(&self) -> &dyn FileOps
pub fn ops_type_name(&self) -> &'static str
pub fn is_non_blocking(&self) -> bool
Sourcepub fn blocking_op<L, T, Op>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
events: FdEvents,
deadline: Option<MonotonicInstant>,
op: Op,
) -> Result<T, Errno>
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>
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.
pub fn is_seekable(&self) -> bool
pub fn has_persistent_offsets(&self) -> bool
pub fn read<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
data: &mut dyn OutputBuffer,
) -> Result<usize, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn read_at<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
offset: usize,
data: &mut dyn OutputBuffer,
) -> Result<usize, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn write<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
data: &mut dyn InputBuffer,
) -> Result<usize, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn write_at<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
offset: usize,
data: &mut dyn InputBuffer,
) -> Result<usize, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn seek<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
target: SeekTarget,
) -> Result<off_t, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn sync(&self, current_task: &CurrentTask) -> Result<(), Errno>
pub fn data_sync(&self, current_task: &CurrentTask) -> Result<(), Errno>
pub fn get_memory<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
length: Option<usize>,
prot: ProtectionFlags,
) -> Result<Arc<MemoryObject>, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
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>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn readdir<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
sink: &mut dyn DirentSink,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn ioctl( &self, locked: &mut Locked<Unlocked>, current_task: &CurrentTask, request: u32, arg: SyscallArg, ) -> Result<SyscallResult, Errno>
pub fn fcntl( &self, current_task: &CurrentTask, cmd: u32, arg: u64, ) -> Result<SyscallResult, Errno>
pub fn ftruncate<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
length: u64,
) -> Result<(), Errno>where
L: LockBefore<BeforeFsNodeAppend>,
pub fn fallocate<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mode: FallocMode,
offset: u64,
length: u64,
) -> Result<(), Errno>where
L: LockBefore<BeforeFsNodeAppend>,
pub fn to_handle( &self, current_task: &CurrentTask, ) -> Result<Option<NullableHandle>, Errno>
pub fn as_thread_group_key(&self) -> Result<ThreadGroupKey, Errno>
pub fn update_file_flags(&self, value: OpenFlags, mask: OpenFlags)
Sourcepub fn get_async_owner(&self) -> FileAsyncOwner
pub fn get_async_owner(&self) -> FileAsyncOwner
Get the async owner of this file.
See fcntl(F_GETOWN)
Sourcepub fn set_async_owner(&self, owner: FileAsyncOwner)
pub fn set_async_owner(&self, owner: FileAsyncOwner)
Set the async owner of this file.
See fcntl(F_SETOWN)
Sourcepub fn get_lease(&self, _current_task: &CurrentTask) -> FileLeaseType
pub fn get_lease(&self, _current_task: &CurrentTask) -> FileLeaseType
See fcntl(F_GETLEASE)
Sourcepub fn set_lease(
&self,
_current_task: &CurrentTask,
lease: FileLeaseType,
) -> Result<(), Errno>
pub fn set_lease( &self, _current_task: &CurrentTask, lease: FileLeaseType, ) -> Result<(), Errno>
See fcntl(F_SETLEASE)
Sourcepub fn wait_async<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
waiter: &Waiter,
events: FdEvents,
handler: EventHandler,
) -> Option<WaitCanceler>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn wait_async<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
waiter: &Waiter,
events: FdEvents,
handler: EventHandler,
) -> Option<WaitCanceler>where
L: LockEqualOrBefore<FileOpsCore>,
Wait on the specified events and call the EventHandler when ready
Sourcepub fn query_events<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
) -> Result<FdEvents, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn query_events<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
) -> Result<FdEvents, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
The events currently active on this file.
pub fn record_lock( &self, locked: &mut Locked<Unlocked>, current_task: &CurrentTask, cmd: RecordLockCommand, flock: flock, ) -> Result<Option<flock>, Errno>
pub fn flush<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
id: FdTableId,
)where
L: LockEqualOrBefore<FileOpsCore>,
pub fn readahead( &self, current_task: &CurrentTask, offset: usize, length: usize, ) -> Result<(), Errno>
pub fn extra_fdinfo( &self, locked: &mut Locked<FileOpsCore>, current_task: &CurrentTask, ) -> Option<FsString>
Sourcepub fn register_epfd(&self, file: &FileHandle)
pub fn register_epfd(&self, file: &FileHandle)
Register the fd number of an EpollFileObject that listens to events from this
FileObject.
pub fn unregister_epfd(&self, file: &FileHandle)
Source§impl FileObject
impl FileObject
Sourcepub fn downcast_file<'a, T>(&'a self) -> Option<DowncastedFile<'a, T>>where
T: 'static,
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
impl FileObject
Sourcepub fn flock(
&self,
locked: &mut Locked<Unlocked>,
current_task: &CurrentTask,
operation: FlockOperation,
) -> Result<(), Errno>
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>§
Trait Implementations§
Source§impl Debug for FileObject
impl Debug for FileObject
Source§impl Deref for FileObject
impl Deref for FileObject
Source§impl<'a> From<&'a FileObject> for Auditable<'a>
impl<'a> From<&'a FileObject> for Auditable<'a>
Source§fn from(value: &'a FileObject) -> Self
fn from(value: &'a FileObject) -> Self
Source§impl Releasable for FileObject
impl Releasable for FileObject
type Context<'a> = (&'a mut Locked<FileOpsCore>, &'a CurrentTask)
fn release<'a>(self, context: CurrentTaskAndLocked<'a>)
Source§impl ReleaserAction<FileObject> for FileObjectReleaserAction
impl ReleaserAction<FileObject> for FileObjectReleaserAction
fn release(file_object: ReleaseGuard<FileObject>)
Auto Trait Implementations§
impl !Freeze for FileObject
impl !RefUnwindSafe for FileObject
impl Send for FileObject
impl Sync for FileObject
impl Unpin for FileObject
impl !UnwindSafe for FileObject
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
§impl<T> InstanceFromServiceTransport<T> for T
impl<T> InstanceFromServiceTransport<T> for T
§fn from_service_transport(handle: T) -> T
fn from_service_transport(handle: T) -> T
T to [Self]Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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