![]() |
MOS Source Code
|
Directory entry. More...
Typedefs | |
| typedef void | dump_refstat_receiver_t(int depth, const dentry_t *dentry, bool mountroot, void *data) |
Enumerations | |
| enum | LastSegmentResolveFlag { RESOLVE_EXPECT_FILE = 1 << 0 , RESOLVE_EXPECT_DIR = 1 << 1 , RESOLVE_EXPECT_ANY_TYPE = RESOLVE_EXPECT_FILE | RESOLVE_EXPECT_DIR , RESOLVE_SYMLINK_NOFOLLOW = 1 << 2 , RESOLVE_EXPECT_EXIST = 1 << 3 , RESOLVE_EXPECT_NONEXIST = 1 << 4 , RESOLVE_EXPECT_ANY_EXIST = RESOLVE_EXPECT_EXIST | RESOLVE_EXPECT_NONEXIST } |
Functions | |
| MOS_ENUM_FLAGS (LastSegmentResolveFlag, LastSegmentResolveFlags) | |
| should_inline bool | path_is_absolute (mos::string_view path) |
| Check if a path is absolute. | |
| should_inline dentry_t * | dentry_parent (const dentry_t &dentry) |
| void | dentry_check_refstat (const dentry_t *dentry) |
| Check the reference count of a dentry. | |
| void | dentry_dump_refstat (const dentry_t *dentry, dump_refstat_receiver_t receiver, void *data) |
| dentry_t * | dentry_ref (dentry_t *dentry) |
| Increment the reference count of a dentry. | |
| dentry_t * | dentry_ref_up_to (dentry_t *dentry, dentry_t *root) |
| Increment the reference count of a dentry up to a given dentry. | |
| void | dentry_unref (dentry_t *dentry) |
| Decrement the reference count of a dentry. | |
| __nodiscard bool | dentry_unref_one_norelease (dentry_t *dentry) |
| Decrease the refcount of ONE SINGLE dentry, including (if it's a mountpoint) the mountpoint dentry. | |
| void | dentry_try_release (dentry_t *dentry) |
| void | dentry_attach (dentry_t *d, inode_t *inode) |
| Attach an inode to a dentry. | |
| void | dentry_detach (dentry_t *dentry) |
| Detach the inode from a dentry. | |
| PtrResult< dentry_t > | dentry_from_fd (fd_t fd) |
| Get the dentry from a file descriptor. | |
| PtrResult< dentry_t > | dentry_lookup_child (dentry_t *parent, mos::string_view name) |
| Get a child dentry from a parent dentry. | |
| PtrResult< dentry_t > | dentry_resolve (dentry_t *starting_dir, dentry_t *root_dir, mos::string_view path, LastSegmentResolveFlags flags) |
| Lookup a path in the filesystem. | |
| __nodiscard bool | dentry_mount (dentry_t *mountpoint, dentry_t *root, filesystem_t *fs) |
| Mount a filesystem at a mountpoint. | |
| __nodiscard dentry_t * | dentry_unmount (dentry_t *root) |
| Unmount a filesystem at the mountpoint. | |
| void | vfs_populate_listdir_buf (dentry_t *dir, vfs_listdir_state_t *state) |
| List the contents of a directory. | |
| std::optional< mos::string > | dentry_path (const dentry_t *dentry, dentry_t *root) |
| Get the path of a dentry. | |
Directory entry.
A dentry is a directory entry, it is a reference to an inode.
dentry cache policy: The function who references the dentry should be responsible for unrefing it.
All existing files' dentries have a reference count of 0 at the start. When a file is opened, the dentry will be referenced, and the reference count will be incremented by 1.
For all directories, the initial reference count is also 0, but when a directory is opened, the reference count will be incremented by 1.
When mounting a filesystem, the root dentry of the filesystem is inserted into the dentry cache, and will have a reference count of 1. The mountpoint itself will have its reference count incremented by 1.
For the root dentry ("/"), the reference count is 2, one for the mountpoint, and one for the dentry cache.
Definition at line 78 of file dentry.hpp.
| Enumerator | |
|---|---|
| RESOLVE_EXPECT_FILE | |
| RESOLVE_EXPECT_DIR | |
| RESOLVE_EXPECT_ANY_TYPE | |
| RESOLVE_SYMLINK_NOFOLLOW | |
| RESOLVE_EXPECT_EXIST | |
| RESOLVE_EXPECT_NONEXIST | |
| RESOLVE_EXPECT_ANY_EXIST | |
Definition at line 37 of file dentry.hpp.
| MOS_ENUM_FLAGS | ( | LastSegmentResolveFlag | , |
| LastSegmentResolveFlags | ) |
| should_inline bool path_is_absolute | ( | mos::string_view | path | ) |
Check if a path is absolute.
| path | The path to check |
Definition at line 62 of file dentry.hpp.
Referenced by dentry_resolve_to_parent(), vfs_chdirat(), vfs_fchmodat(), vfs_fstatat(), vfs_mkdir(), vfs_mount(), vfs_openat(), vfs_readlinkat(), vfs_rmdir(), vfs_symlink(), and vfs_unlinkat().
| should_inline dentry_t * dentry_parent | ( | const dentry_t & | dentry | ) |
Definition at line 67 of file dentry.hpp.
Referenced by cpio_i_iterate_dir(), dentry_mount(), dentry_path(), dentry_ref_up_to(), dentry_resolve_follow_symlink(), dentry_resolve_lastseg(), dentry_resolve_to_parent(), dentry_root_get_mountpoint(), dentry_unref(), sysfs_fops_release(), vfs_do_open(), vfs_generic_iterate_dir(), vfs_mkdir(), vfs_rmdir(), vfs_symlink(), and vfs_unlinkat().
Check the reference count of a dentry.
| dentry | The dentry to check |
Definition at line 110 of file dentry_utils.cpp.
Referenced by dentry_unref(), and vfs_unmount().
| void dentry_dump_refstat | ( | const dentry_t * | dentry, |
| dump_refstat_receiver_t | receiver, | ||
| void * | data ) |
Increment the reference count of a dentry.
| dentry | The dentry to increment the reference count of |
Definition at line 16 of file dentry_utils.cpp.
Referenced by dentry_lookup_child(), dentry_mount(), dentry_ref_up_to(), dentry_resolve_lastseg(), dentry_resolve_to_parent(), memfd_create(), and memfd_init().
Increment the reference count of a dentry up to a given dentry.
| dentry | The dentry to increment the reference count of |
| root | The dentry to stop at |
Definition at line 26 of file dentry_utils.cpp.
Referenced by dentry_resolve_to_parent(), process_do_fork(), and process_new().
Decrement the reference count of a dentry.
| dentry | The dentry to decrement the reference count of |
Definition at line 159 of file dentry_utils.cpp.
Referenced by dentry_resolve(), dentry_resolve_follow_symlink(), dentry_resolve_lastseg(), dentry_resolve_to_parent(), dentry_unref(), ipc_server_close(), FsDir::on_closed(), FsFile::on_closed(), process_exit(), vfs_chdirat(), vfs_do_open(), vfs_fchmodat(), vfs_fstatat(), vfs_mkdir(), vfs_mount(), vfs_readlinkat(), vfs_rmdir(), vfs_symlink(), vfs_unlinkat(), and vfs_unmount().
| __nodiscard bool dentry_unref_one_norelease | ( | dentry_t * | dentry | ) |
Decrease the refcount of ONE SINGLE dentry, including (if it's a mountpoint) the mountpoint dentry.
| dentry | The dentry to decrease the refcount of |
Definition at line 51 of file dentry_utils.cpp.
Referenced by dentry_resolve_lastseg(), dentry_resolve_to_parent(), dentry_unref(), and vfs_unmount().
Definition at line 147 of file dentry_utils.cpp.
Referenced by dentry_resolve_lastseg(), dentry_resolve_to_parent(), dentry_unref(), ipc_server_close(), and vfs_unlinkat().
Attach an inode to a dentry.
| d | The dentry to attach the inode to |
| inode | The inode to attach |
Definition at line 279 of file dentry.cpp.
Referenced by cpio_i_lookup(), cpio_mount(), ipc_server_close(), ipc_sysfs_create_server(), ipc_sysfs_lookup_ipc(), MOS_INIT(), sysfs_do_register(), sysfs_register_file(), tmpfs_fsop_mount(), tmpfs_i_hardlink(), tmpfs_i_rename(), tmpfs_mknod_impl(), userfs_fsop_mount(), userfs_iop_lookup(), userfs_iop_mkdir(), and userfs_iop_newfile().
Detach the inode from a dentry.
| dentry | The dentry to detach the inode from |
Definition at line 292 of file dentry.cpp.
Referenced by ipc_server_close(), memfd_file_release(), tmpfs_i_rename(), tmpfs_i_rmdir(), vfs_ipc_file_release(), and vfs_unlinkat().
Get the dentry from a file descriptor.
| fd | The file descriptor, there's a special case for AT_FDCWD, which corresponds to the process's current working directory |
Definition at line 304 of file dentry.cpp.
Referenced by vfs_chdirat(), vfs_fchmodat(), vfs_fstatat(), vfs_getcwd(), vfs_mkdir(), vfs_mount(), vfs_openat(), vfs_readlinkat(), vfs_rmdir(), vfs_symlink(), and vfs_unlinkat().
| PtrResult< dentry_t > dentry_lookup_child | ( | dentry_t * | parent, |
| mos::string_view | name ) |
Get a child dentry from a parent dentry.
| parent | The parent dentry |
| name | The name of the child dentry |
Definition at line 328 of file dentry.cpp.
Referenced by dentry_resolve_lastseg(), and dentry_resolve_to_parent().
| PtrResult< dentry_t > dentry_resolve | ( | dentry_t * | starting_dir, |
| dentry_t * | root_dir, | ||
| mos::string_view | path, | ||
| LastSegmentResolveFlags | flags ) |
Lookup a path in the filesystem.
If the path is absolute, the base is ignored and the path starts from the root_dir If the path is relative, the base is used as the starting points
| starting_dir | The starting directory when resolving a [relative] path |
| root_dir | the root directory when resolving the path, the resolved path will not go above this directory |
| path | The path to resolve, can be absolute or relative |
| flags | Flags to control the behavior of the path resolution, see lastseg_resolve_flags_t |
Definition at line 371 of file dentry.cpp.
Referenced by vfs_chdirat(), vfs_do_open(), vfs_fchmodat(), vfs_fstatat(), vfs_mkdir(), vfs_mount(), vfs_readlinkat(), vfs_rmdir(), vfs_symlink(), vfs_unlinkat(), and vfs_unmount().
| __nodiscard bool dentry_mount | ( | dentry_t * | mountpoint, |
| dentry_t * | root, | ||
| filesystem_t * | fs ) |
Mount a filesystem at a mountpoint.
| mountpoint | The mountpoint |
| root | The root directory of the filesystem |
| fs | The filesystem to mount |
Definition at line 70 of file mount.cpp.
Referenced by vfs_mount().
| __nodiscard dentry_t * dentry_unmount | ( | dentry_t * | root | ) |
Unmount a filesystem at the mountpoint.
Definition at line 100 of file mount.cpp.
Referenced by vfs_unmount().
| void vfs_populate_listdir_buf | ( | dentry_t * | dir, |
| vfs_listdir_state_t * | state ) |
List the contents of a directory.
| dir | The directory to list |
| state | The state of the directory iterator |
Definition at line 416 of file dentry.cpp.
Referenced by vfs_list_dir().
| std::optional< mos::string > dentry_path | ( | const dentry_t * | dentry, |
| dentry_t * | root ) |
Get the path of a dentry.
| dentry | The dentry to get the path of |
| root | The root directory, the path will not go above this directory |
Definition at line 171 of file dentry_utils.cpp.
Referenced by cpio_i_lookup(), FsBaseFile::name(), vfs_getcwd(), and vfs_sysfs_mountpoints().