FsNode

Struct FsNode 

Source
pub struct FsNode {
    pub ino: ino_t,
    pub append_lock: RwQueue<FsNodeAppend>,
    pub write_guard_state: Mutex<FileWriteGuardState>,
    pub fsverity: Mutex<FsVerityState>,
    pub security_state: FsNodeState,
    /* private fields */
}

Fields§

§ino: ino_t

The inode number for this FsNode.

§append_lock: RwQueue<FsNodeAppend>

A RwLock to synchronize append operations for this node.

FileObjects writing with O_APPEND should grab a write() lock on this field to ensure they operate sequentially. FileObjects writing without O_APPEND should grab read() lock so that they can operate in parallel.

§write_guard_state: Mutex<FileWriteGuardState>

Tracks lock state for this file.

§fsverity: Mutex<FsVerityState>

Cached FsVerity state associated with this node.

§security_state: FsNodeState

The security state associated with this node. Must always be acquired last relative to other FsNode locks.

Implementations§

Source§

impl FsNode

Source

pub fn new_uncached( ino: ino_t, ops: impl Into<Box<dyn FsNodeOps>>, fs: &FileSystemHandle, info: FsNodeInfo, ) -> FsNodeHandle

Create a node without inserting it into the FileSystem node cache.

This is usually not what you want! Only use if you’re also using get_or_create_node, like ext4.

Source

pub fn fs(&self) -> FileSystemHandle

Source

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

Source

pub fn fail_if_locked(&self, _current_task: &CurrentTask) -> Result<(), Errno>

Returns an error if this node is encrypted and locked. Does not require fetch_and_refresh_info because FS_IOC_SET_ENCRYPTION_POLICY updates info and once a node is encrypted, it remains encrypted forever.

Source

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

Returns the FsNode’s FsNodeOps as a &T, or None if the downcast fails.

Source

pub fn on_file_closed(&self, file: &FileObjectState)

Source

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

Source

pub fn record_lock_release(&self, owner: RecordLockOwner)

Release all record locks acquired by the given owner.

Source

pub fn create_dir_entry_ops(&self) -> Box<dyn DirEntryOps>

Source

pub fn create_file_ops<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, flags: OpenFlags, ) -> Result<Box<dyn FileOps>, Errno>

Source

pub fn open( &self, locked: &mut Locked<Unlocked>, current_task: &CurrentTask, namespace_node: &NamespaceNode, flags: OpenFlags, access_check: AccessCheck, ) -> Result<Box<dyn FileOps>, Errno>

Source

pub fn lookup<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mount: &MountInfo, name: &FsStr, ) -> Result<FsNodeHandle, Errno>

Source

pub fn create_node<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mount: &MountInfo, name: &FsStr, mode: FileMode, dev: DeviceType, owner: FsCred, ) -> Result<FsNodeHandle, Errno>

Source

pub fn create_tmpfile<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mount: &MountInfo, mode: FileMode, owner: FsCred, link_behavior: FsNodeLinkBehavior, ) -> Result<FsNodeHandle, Errno>

Source

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

Source

pub fn truncate_with_strategy<L, M>( &self, locked: &mut Locked<L>, strategy: impl AppendLockStrategy<M>, current_task: &CurrentTask, mount: &MountInfo, length: u64, ) -> Result<(), Errno>

Source

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

Avoid calling this method directly. You probably want to call FileObject::ftruncate() which will also perform all file-descriptor based verifications.

Source

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

Avoid calling this method directly. You probably want to call FileObject::fallocate() which will also perform additional verifications.

Source

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

Source

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

Checks if O_NOATIME is allowed,

Source

pub fn default_check_access_impl( &self, current_task: &CurrentTask, permission_flags: PermissionFlags, reason: CheckAccessReason, info: RwLockReadGuard<'_, FsNodeInfo>, audit_context: Auditable<'_>, ) -> Result<(), Errno>

Source

pub fn check_access<'a, L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mount: &MountInfo, access: impl Into<PermissionFlags>, reason: CheckAccessReason, audit_context: impl Into<Auditable<'a>>, ) -> Result<(), Errno>

Check whether the node can be accessed in the current context with the specified access flags (read, write, or exec). Accounts for capabilities and whether the current user is the owner or is in the file’s group.

Source

pub fn check_sticky_bit( &self, current_task: &CurrentTask, child: &FsNodeHandle, ) -> Result<(), Errno>

Check whether the stick bit, S_ISVTX, forbids the current_task from removing the given child. If this node has S_ISVTX, then either the child must be owned by the fsuid of current_task or current_task must have CAP_FOWNER.

Source

pub fn fifo(&self, current_task: &CurrentTask) -> &PipeHandle

Source

pub fn bound_socket(&self) -> Option<&SocketHandle>

Returns the UNIX domain socket bound to this node, if any.

Source

pub fn set_bound_socket(&self, socket: SocketHandle)

Register the provided socket as the UNIX domain socket bound to this node.

It is a fatal error to call this method again if it has already been called on this node.

Source

pub fn update_attributes<L, F>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mutator: F, ) -> Result<(), Errno>

Source

pub fn chmod<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mount: &MountInfo, mode: FileMode, ) -> Result<(), Errno>

Set the permissions on this FsNode to the given values.

Does not change the IFMT of the node.

Source

pub fn chown<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mount: &MountInfo, owner: Option<uid_t>, group: Option<gid_t>, ) -> Result<(), Errno>

Sets the owner and/or group on this FsNode.

Source

pub unsafe fn force_chown(&self, creds: FsCred)

Forcefully change the owner and group of this node.

§Safety

This function skips all the security checks and just updates the owner and group. Also, does not check if the filesystem is read-only and does not update the attribute change time.

This function is used to set the owner and group of /proc/pid to the credentials of the current task. Please consider carefully whether you want to use this function for another purpose.

Source

pub fn is_reg(&self) -> bool

Whether this node is a regular file.

Source

pub fn is_dir(&self) -> bool

Whether this node is a directory.

Source

pub fn is_sock(&self) -> bool

Whether this node is a socket.

Source

pub fn is_fifo(&self) -> bool

Whether this node is a FIFO.

Source

pub fn is_lnk(&self) -> bool

Whether this node is a symbolic link.

Source

pub fn dev(&self) -> DeviceType

Source

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

Source

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

Source

pub fn statx<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, flags: StatxFlags, mask: u32, ) -> Result<statx, Errno>

Source

pub fn get_xattr<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mount: &MountInfo, name: &FsStr, max_size: usize, ) -> Result<ValueOrSize<FsString>, Errno>

Source

pub fn set_xattr<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mount: &MountInfo, name: &FsStr, value: &FsStr, op: XattrOp, ) -> Result<(), Errno>

Source

pub fn remove_xattr<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mount: &MountInfo, name: &FsStr, ) -> Result<(), Errno>

Source

pub fn list_xattrs<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, max_size: usize, ) -> Result<ValueOrSize<Vec<FsString>>, Errno>

Source

pub fn info(&self) -> RwLockReadGuard<'_, FsNodeInfo>

Returns current FsNodeInfo.

Source

pub fn fetch_and_refresh_info<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, ) -> Result<RwLockReadGuard<'_, FsNodeInfo>, Errno>

Refreshes the FsNodeInfo if necessary and returns a read guard.

Source

pub fn update_info<F, T>(&self, mutator: F) -> T
where F: FnOnce(&mut FsNodeInfo) -> T,

Source

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

Clear the SUID and SGID bits unless the current_task has CAP_FSETID

Source

pub fn update_ctime_mtime(&self)

Update the ctime and mtime of a file to now.

Source

pub fn update_ctime(&self)

Update the ctime of a file to now.

Source

pub fn update_atime_mtime<L>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mount: &MountInfo, atime: TimeUpdateType, mtime: TimeUpdateType, ) -> Result<(), Errno>

Update the atime and mtime if the current_task has write access, is the file owner, or holds either the CAP_DAC_OVERRIDE or CAP_FOWNER capability.

Source

pub fn internal_name(&self) -> FsString

Returns a string describing this FsNode in the format used by “/proc/../fd” for anonymous file descriptors. By default this is in the form: :[<node_id>] though FsNodeOps may customize this as required.

Source

pub fn node_key(&self) -> ino_t

The key used to identify this node in the file system’s node cache.

For many file systems, this will be the same as the inode number. However, some file systems, such as FUSE, sometimes use different node_key and inode numbers.

Source

pub fn ensure_watchers(&self) -> &InotifyWatchers

Returns the set of watchers for this node.

Only call this function if you require this node to actually store a list of watchers. If you just wish to notify any watchers that might exist, please use notify instead.

Source

pub fn notify( &self, event_mask: InotifyMask, cookie: u32, name: &FsStr, mode: FileMode, is_dead: bool, )

Notify the watchers of the given event.

Trait Implementations§

Source§

impl Debug for FsNode

Source§

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

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

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

Source§

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

Converts to this type from the input type.
Source§

impl Releasable for FsNode

Source§

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

Source§

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

Source§

impl ReleaserAction<FsNode> for FsNodeReleaserAction

Auto Trait Implementations§

§

impl !Freeze for FsNode

§

impl !RefUnwindSafe for FsNode

§

impl Send for FsNode

§

impl Sync for FsNode

§

impl Unpin for FsNode

§

impl !UnwindSafe for FsNode

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<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>,