pub struct DirEntry {
pub node: FsNodeHandle,
/* private fields */
}Expand description
An entry in a directory.
This structure assigns a name to an FsNode in a given file system. An FsNode might have multiple directory entries, for example if there are more than one hard link to the same FsNode. In those cases, each hard link will have a different parent and a different local_name because each hard link has its own DirEntry object.
A directory cannot have more than one hard link, which means there is a single DirEntry for each Directory FsNode. That invariant lets us store the children for a directory in the DirEntry rather than in the FsNode.
Fields§
§node: FsNodeHandleThe FsNode referenced by this DirEntry.
A given FsNode can be referenced by multiple DirEntry objects, for example if there are multiple hard links to a given FsNode.
Implementations§
Source§impl DirEntry
impl DirEntry
pub fn read<'a>(self: &'a DirEntry) -> DirEntryReadGuard<'a>
pub fn write<'a>(self: &'a DirEntry) -> DirEntryWriteGuard<'a>
pub fn new_uncached( node: FsNodeHandle, parent: Option<DirEntryHandle>, local_name: FsString, ) -> DirEntryHandle
pub fn new( node: FsNodeHandle, parent: Option<DirEntryHandle>, local_name: FsString, ) -> DirEntryHandle
Sourcepub fn new_unrooted(node: FsNodeHandle) -> DirEntryHandle
pub fn new_unrooted(node: FsNodeHandle) -> DirEntryHandle
Returns a new DirEntry for the given node without parent. The entry has no local name and
is not cached.
Sourcepub fn new_deleted(
node: FsNodeHandle,
parent: Option<DirEntryHandle>,
local_name: FsString,
) -> DirEntryHandle
pub fn new_deleted( node: FsNodeHandle, parent: Option<DirEntryHandle>, local_name: FsString, ) -> DirEntryHandle
Returns a new DirEntry that is ready marked as having been deleted.
Sourcepub fn open_anonymous<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
flags: OpenFlags,
) -> Result<FileHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn open_anonymous<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
flags: OpenFlags,
) -> Result<FileHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Returns a file handle to this entry, associated with an anonymous namespace.
Sourcepub fn set_children(
self: &DirEntryHandle,
children: BTreeMap<FsString, DirEntryHandle>,
)
pub fn set_children( self: &DirEntryHandle, children: BTreeMap<FsString, DirEntryHandle>, )
Set the children of this DirEntry to the given children. This should only ever be called
when children is empty.
Sourcepub fn parent_or_self(self: &DirEntryHandle) -> DirEntryHandle
pub fn parent_or_self(self: &DirEntryHandle) -> DirEntryHandle
The parent DirEntry object or this DirEntry if this entry is the root.
Useful when traversing up the tree if you always want to find a parent (e.g., for “..”).
Be aware that the root of one file system might be mounted as a child in another file system. For that reason, consider walking the NamespaceNode tree (which understands mounts) rather than the DirEntry tree.
Sourcepub fn is_reserved_name(name: &FsStr) -> bool
pub fn is_reserved_name(name: &FsStr) -> bool
Whether the given name has special semantics as a directory entry.
Specifically, whether the name is empty (which means “self”), dot (which also means “self”), or dot dot (which means “parent”).
Sourcepub fn component_lookup<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
) -> Result<DirEntryHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn component_lookup<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
) -> Result<DirEntryHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Look up a directory entry with the given name as direct child of this entry.
Sourcepub fn create_entry<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
create_node_fn: impl FnOnce(&mut Locked<L>, &FsNodeHandle, &MountInfo, &FsStr) -> Result<FsNodeHandle, Errno>,
) -> Result<DirEntryHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn create_entry<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
create_node_fn: impl FnOnce(&mut Locked<L>, &FsNodeHandle, &MountInfo, &FsStr) -> Result<FsNodeHandle, Errno>,
) -> Result<DirEntryHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Creates a new DirEntry
The create_node_fn function is called to create the underlying FsNode for the DirEntry.
If the entry already exists, create_node_fn is not called, and EEXIST is returned.
Sourcepub fn get_or_create_entry<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
create_node_fn: impl FnOnce(&mut Locked<L>, &FsNodeHandle, &MountInfo, &FsStr) -> Result<FsNodeHandle, Errno>,
) -> Result<DirEntryHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn get_or_create_entry<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
create_node_fn: impl FnOnce(&mut Locked<L>, &FsNodeHandle, &MountInfo, &FsStr) -> Result<FsNodeHandle, Errno>,
) -> Result<DirEntryHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Creates a new DirEntry. Works just like create_entry, except if the entry already exists, it is returned.
pub fn create_dir_for_testing<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
name: &FsStr,
) -> Result<DirEntryHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Sourcepub fn create_tmpfile<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
mode: FileMode,
owner: FsCred,
flags: OpenFlags,
) -> Result<DirEntryHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn create_tmpfile<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
mode: FileMode,
owner: FsCred,
flags: OpenFlags,
) -> Result<DirEntryHandle, Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Creates an anonymous file.
The FileMode::IFMT of the FileMode is always FileMode::IFREG.
Used by O_TMPFILE.
pub fn unlink<L>(
self: &DirEntryHandle,
locked: &mut Locked<L>,
current_task: &CurrentTask,
mount: &MountInfo,
name: &FsStr,
kind: UnlinkKind,
must_be_directory: bool,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Sourcepub fn is_descendant_of(self: &DirEntryHandle, other: &DirEntryHandle) -> bool
pub fn is_descendant_of(self: &DirEntryHandle, other: &DirEntryHandle) -> bool
Returns whether this entry is a descendant of |other|.
Sourcepub fn rename<L>(
locked: &mut Locked<L>,
current_task: &CurrentTask,
old_parent: &DirEntryHandle,
old_mount: &MountInfo,
old_basename: &FsStr,
new_parent: &DirEntryHandle,
new_mount: &MountInfo,
new_basename: &FsStr,
flags: RenameFlags,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
pub fn rename<L>(
locked: &mut Locked<L>,
current_task: &CurrentTask,
old_parent: &DirEntryHandle,
old_mount: &MountInfo,
old_basename: &FsStr,
new_parent: &DirEntryHandle,
new_mount: &MountInfo,
new_basename: &FsStr,
flags: RenameFlags,
) -> Result<(), Errno>where
L: LockEqualOrBefore<FileOpsCore>,
Rename the file with old_basename in old_parent to new_basename in new_parent.
old_parent and new_parent must belong to the same file system.
pub fn get_children<F, T>(&self, callback: F) -> T
Sourcepub fn remove_child(&self, name: &FsStr, mounts: &Mounts)
pub fn remove_child(&self, name: &FsStr, mounts: &Mounts)
Remove the child with the given name from the children cache. The child must not have any mounts.
Sourcepub fn notify(&self, event_mask: InotifyMask)
pub fn notify(&self, event_mask: InotifyMask)
Notifies watchers on the current node and its parent about an event.
Sourcepub fn notify_ignoring_excl_unlink(&self, event_mask: InotifyMask)
pub fn notify_ignoring_excl_unlink(&self, event_mask: InotifyMask)
Notifies watchers on the current node and its parent about an event.
Used for FSNOTIFY_EVENT_INODE events, which ignore IN_EXCL_UNLINK.
Sourcepub fn has_mounts(&self) -> bool
pub fn has_mounts(&self) -> bool
Returns true if this entry has mounts.
Sourcepub fn set_has_mounts(&self, v: bool)
pub fn set_has_mounts(&self, v: bool)
Records whether or not the entry has mounts.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DirEntry
impl !RefUnwindSafe for DirEntry
impl Send for DirEntry
impl Sync for DirEntry
impl Unpin for DirEntry
impl !UnwindSafe for DirEntry
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