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_tThe 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: FsNodeStateThe security state associated with this node. Must always be acquired last
relative to other FsNode locks.
Implementations§
Source§impl FsNode
impl FsNode
Sourcepub fn new_uncached(
ino: ino_t,
ops: impl Into<Box<dyn FsNodeOps>>,
fs: &FileSystemHandle,
info: FsNodeInfo,
) -> FsNodeHandle
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.
pub fn fs(&self) -> FileSystemHandle
pub fn ops(&self) -> &dyn FsNodeOps
Sourcepub fn fail_if_locked(&self, _current_task: &CurrentTask) -> Result<(), Errno>
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.
Sourcepub fn downcast_ops<T>(&self) -> Option<&T>where
T: 'static,
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.
pub fn on_file_closed(&self, file: &FileObjectState)
pub fn record_lock( &self, locked: &mut Locked<Unlocked>, current_task: &CurrentTask, file: &FileObject, cmd: RecordLockCommand, flock: flock, ) -> Result<Option<flock>, Errno>
Sourcepub fn record_lock_release(&self, owner: RecordLockOwner)
pub fn record_lock_release(&self, owner: RecordLockOwner)
Release all record locks acquired by the given owner.
pub fn create_dir_entry_ops(&self) -> Box<dyn DirEntryOps>
pub fn create_file_ops<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
flags: OpenFlags,
) -> Result<Box<dyn FileOps>, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn open( &self, locked: &mut Locked<Unlocked>, current_task: &CurrentTask, namespace_node: &NamespaceNode, flags: OpenFlags, access_check: AccessCheck, ) -> Result<Box<dyn FileOps>, Errno>
pub fn lookup<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
) -> Result<FsNodeHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
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>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn create_symlink<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
target: &FsStr,
owner: FsCred,
) -> Result<FsNodeHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
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>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn readlink<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
) -> Result<SymlinkTarget, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn link<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
child: &FsNodeHandle,
) -> Result<FsNodeHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn unlink<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
child: &FsNodeHandle,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn truncate<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
length: u64,
) -> Result<(), Errno>where
L: LockEqualOrBefore<BeforeFsNodeAppend>,
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>
Sourcepub fn ftruncate<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
length: u64,
) -> Result<(), Errno>where
L: LockEqualOrBefore<BeforeFsNodeAppend>,
pub fn ftruncate<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
length: u64,
) -> Result<(), Errno>where
L: LockEqualOrBefore<BeforeFsNodeAppend>,
Avoid calling this method directly. You probably want to call FileObject::ftruncate()
which will also perform all file-descriptor based verifications.
Sourcepub 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 fallocate<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mode: FallocMode,
offset: u64,
length: u64,
) -> Result<(), Errno>where
L: LockBefore<BeforeFsNodeAppend>,
Avoid calling this method directly. You probably want to call FileObject::fallocate()
which will also perform additional verifications.
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>
Sourcepub fn check_o_noatime_allowed(
&self,
current_task: &CurrentTask,
) -> Result<(), Errno>
pub fn check_o_noatime_allowed( &self, current_task: &CurrentTask, ) -> Result<(), Errno>
Checks if O_NOATIME is allowed,
pub fn default_check_access_impl( &self, current_task: &CurrentTask, permission_flags: PermissionFlags, reason: CheckAccessReason, info: RwLockReadGuard<'_, FsNodeInfo>, audit_context: Auditable<'_>, ) -> Result<(), Errno>
Sourcepub 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>where
L: LockEqualOrBefore<FileOpsCore>,
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>where
L: LockEqualOrBefore<FileOpsCore>,
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.
Sourcepub fn check_sticky_bit(
&self,
current_task: &CurrentTask,
child: &FsNodeHandle,
) -> Result<(), Errno>
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.
pub fn fifo(&self, current_task: &CurrentTask) -> &PipeHandle
Sourcepub fn bound_socket(&self) -> Option<&SocketHandle>
pub fn bound_socket(&self) -> Option<&SocketHandle>
Returns the UNIX domain socket bound to this node, if any.
Sourcepub fn set_bound_socket(&self, socket: SocketHandle)
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.
pub fn update_attributes<L, F>( &self, locked: &mut Locked<L>, current_task: &CurrentTask, mutator: F, ) -> Result<(), Errno>
Sourcepub fn chmod<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
mode: FileMode,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn chmod<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
mode: FileMode,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Set the permissions on this FsNode to the given values.
Does not change the IFMT of the node.
Sourcepub fn chown<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
owner: Option<uid_t>,
group: Option<gid_t>,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn chown<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
owner: Option<uid_t>,
group: Option<gid_t>,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Sets the owner and/or group on this FsNode.
Sourcepub unsafe fn force_chown(&self, creds: FsCred)
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.
pub fn dev(&self) -> DeviceType
pub fn stat<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
) -> Result<stat, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn get_size<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
) -> Result<usize, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn statx<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
flags: StatxFlags,
mask: u32,
) -> Result<statx, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn get_xattr<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
max_size: usize,
) -> Result<ValueOrSize<FsString>, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn set_xattr<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
value: &FsStr,
op: XattrOp,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn remove_xattr<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn list_xattrs<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
max_size: usize,
) -> Result<ValueOrSize<Vec<FsString>>, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Sourcepub fn info(&self) -> RwLockReadGuard<'_, FsNodeInfo>
pub fn info(&self) -> RwLockReadGuard<'_, FsNodeInfo>
Returns current FsNodeInfo.
Sourcepub fn fetch_and_refresh_info<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
) -> Result<RwLockReadGuard<'_, FsNodeInfo>, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn fetch_and_refresh_info<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
) -> Result<RwLockReadGuard<'_, FsNodeInfo>, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Refreshes the FsNodeInfo if necessary and returns a read guard.
pub fn update_info<F, T>(&self, mutator: F) -> Twhere
F: FnOnce(&mut FsNodeInfo) -> T,
Sourcepub fn clear_suid_and_sgid_bits<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn clear_suid_and_sgid_bits<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Clear the SUID and SGID bits unless the current_task has CAP_FSETID
Sourcepub fn update_ctime_mtime(&self)
pub fn update_ctime_mtime(&self)
Update the ctime and mtime of a file to now.
Sourcepub fn update_ctime(&self)
pub fn update_ctime(&self)
Update the ctime of a file to now.
Sourcepub fn update_atime_mtime<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
atime: TimeUpdateType,
mtime: TimeUpdateType,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn update_atime_mtime<L>(
&self,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
atime: TimeUpdateType,
mtime: TimeUpdateType,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
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.
Sourcepub fn internal_name(&self) -> FsString
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:
FsNodeOps may customize this as required.
Sourcepub fn node_key(&self) -> ino_t
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.
Sourcepub fn ensure_watchers(&self) -> &InotifyWatchers
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.
Trait Implementations§
Source§impl Releasable for FsNode
impl Releasable for FsNode
type Context<'a> = (&'a mut Locked<FileOpsCore>, &'a CurrentTask)
fn release<'a>(self, context: CurrentTaskAndLocked<'a>)
Source§impl ReleaserAction<FsNode> for FsNodeReleaserAction
impl ReleaserAction<FsNode> for FsNodeReleaserAction
fn release(fs_node: ReleaseGuard<FsNode>)
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> 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