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 | lastseg_resolve_flags_t { 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 | |
should_inline bool | path_is_absolute (const char *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. | |
dentry_t * | dentry_from_fd (fd_t fd) |
Get the dentry from a file descriptor. | |
dentry_t * | dentry_lookup_child (dentry_t *parent, const char *name) |
Get a child dentry from a parent dentry. | |
dentry_t * | dentry_resolve (dentry_t *starting_dir, dentry_t *root_dir, const char *path, lastseg_resolve_flags_t 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. | |
ssize_t | dentry_path (dentry_t *dentry, dentry_t *root, char *buf, size_t size) |
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.
should_inline bool path_is_absolute | ( | const char * | path | ) |
Check if a path is absolute.
path | The path to check |
Definition at line 60 of file dentry.h.
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 65 of file dentry.h.
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 107 of file dentry_utils.c.
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 14 of file dentry_utils.c.
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 24 of file dentry_utils.c.
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 158 of file dentry_utils.c.
Referenced by dentry_resolve(), dentry_resolve_follow_symlink(), dentry_resolve_lastseg(), dentry_resolve_to_parent(), dentry_unref(), process_exit(), vfs_chdirat(), vfs_do_open(), vfs_fchmodat(), vfs_fstatat(), vfs_io_ops_close(), 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 49 of file dentry_utils.c.
Referenced by dentry_resolve_lastseg(), dentry_resolve_to_parent(), dentry_unref(), and vfs_unmount().
Definition at line 144 of file dentry_utils.c.
Referenced by dentry_resolve_lastseg(), dentry_resolve_to_parent(), dentry_unref(), 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 305 of file dentry.c.
Referenced by cpio_i_lookup(), cpio_mount(), 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 318 of file dentry.c.
Referenced by 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 330 of file dentry.c.
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().
Get a child dentry from a parent dentry.
parent | The parent dentry |
name | The name of the child dentry |
Definition at line 354 of file dentry.c.
Referenced by dentry_resolve_lastseg(), and dentry_resolve_to_parent().
dentry_t * dentry_resolve | ( | dentry_t * | starting_dir, |
dentry_t * | root_dir, | ||
const char * | path, | ||
lastseg_resolve_flags_t | 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 397 of file dentry.c.
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 76 of file mount.c.
Referenced by vfs_mount().
__nodiscard dentry_t * dentry_unmount | ( | dentry_t * | root | ) |
Unmount a filesystem at the mountpoint.
Definition at line 107 of file mount.c.
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 446 of file dentry.c.
Referenced by vfs_list_dir().
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 |
buf | The buffer to write the path to |
size | The size of the buffer |
Definition at line 170 of file dentry_utils.c.
Referenced by cpio_i_lookup(), vfs_getcwd(), vfs_io_ops_getname(), and vfs_sysfs_mountpoints().