MOS Source Code
Loading...
Searching...
No Matches
Directory Entry

Directory entry. More...

+ Collaboration diagram for Directory Entry:

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_tdentry_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_tdentry_ref (dentry_t *dentry)
 Increment the reference count of a dentry.
 
dentry_tdentry_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_detach_inode (dentry_t *dentry)
 Detach the inode from a dentry.
 
dentry_tdentry_from_fd (fd_t fd)
 Get the dentry from a file descriptor.
 
dentry_tdentry_get_child (dentry_t *parent, const char *name)
 Get a child dentry from a parent dentry.
 
dentry_tdentry_get (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_tdentry_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.
 

Detailed Description

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.

Typedef Documentation

◆ dump_refstat_receiver_t

typedef void dump_refstat_receiver_t(int depth, const dentry_t *dentry, bool mountroot, void *data)

Definition at line 76 of file dentry.h.

Enumeration Type Documentation

◆ lastseg_resolve_flags_t

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.h.

Function Documentation

◆ path_is_absolute()

should_inline bool path_is_absolute ( const char * path)

Check if a path is absolute.

Parameters
pathThe path to check
Returns
true if the path is absolute (starts with a '/'), false otherwise

Definition at line 60 of file dentry.h.

Referenced by dentry_lookup_parent(), vfs_chdir(), vfs_fchmodat(), vfs_fstatat(), vfs_mkdir(), vfs_mount(), vfs_openat(), vfs_readlinkat(), vfs_rmdir(), and vfs_symlink().

◆ dentry_parent()

◆ dentry_check_refstat()

void dentry_check_refstat ( const dentry_t * dentry)

Check the reference count of a dentry.

Parameters
dentryThe dentry to check

Definition at line 95 of file dentry_utils.c.

Referenced by dentry_unref(), and vfs_unmount().

◆ dentry_dump_refstat()

void dentry_dump_refstat ( const dentry_t * dentry,
dump_refstat_receiver_t receiver,
void * data )

◆ dentry_ref()

dentry_t * dentry_ref ( dentry_t * dentry)

Increment the reference count of a dentry.

Parameters
dentryThe dentry to increment the reference count of
Returns
the dentry itself

Definition at line 13 of file dentry_utils.c.

Referenced by dentry_get_child(), dentry_lookup_parent(), dentry_mount(), dentry_ref_up_to(), and dentry_resolve_handle_last_segment().

◆ dentry_ref_up_to()

dentry_t * dentry_ref_up_to ( dentry_t * dentry,
dentry_t * root )

Increment the reference count of a dentry up to a given dentry.

Parameters
dentryThe dentry to increment the reference count of
rootThe dentry to stop at
Returns
dentry_t* The dentry itself

Definition at line 22 of file dentry_utils.c.

Referenced by dentry_lookup_parent(), process_do_fork(), and process_new().

+ Here is the call graph for this function:

◆ dentry_unref()

void dentry_unref ( dentry_t * dentry)

Decrement the reference count of a dentry.

Parameters
dentryThe dentry to decrement the reference count of

Definition at line 146 of file dentry_utils.c.

Referenced by dentry_get(), dentry_lookup_parent(), dentry_resolve_follow_symlink(), dentry_resolve_handle_last_segment(), dentry_unref(), process_handle_exit(), vfs_chdir(), vfs_do_open(), vfs_fchmodat(), vfs_fstatat(), vfs_io_ops_close(), vfs_mkdir(), vfs_mount(), vfs_readlinkat(), vfs_rmdir(), vfs_symlink(), and vfs_unmount().

+ Here is the call graph for this function:

◆ dentry_unref_one_norelease()

__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.

Parameters
dentryThe dentry to decrease the refcount of
Returns
true if the refcount was decreased, false if the refcount was already 0

Definition at line 47 of file dentry_utils.c.

Referenced by dentry_lookup_parent(), dentry_resolve_handle_last_segment(), dentry_unref(), and vfs_unmount().

+ Here is the call graph for this function:

◆ dentry_try_release()

void dentry_try_release ( dentry_t * dentry)

Definition at line 132 of file dentry_utils.c.

Referenced by dentry_lookup_parent(), dentry_resolve_handle_last_segment(), and dentry_unref().

+ Here is the call graph for this function:

◆ dentry_detach_inode()

void dentry_detach_inode ( dentry_t * dentry)

Detach the inode from a dentry.

Parameters
dentryThe dentry to detach the inode from

Definition at line 303 of file dentry.c.

Referenced by vfs_ipc_file_release().

+ Here is the call graph for this function:

◆ dentry_from_fd()

dentry_t * dentry_from_fd ( fd_t fd)

Get the dentry from a file descriptor.

Parameters
fdThe file descriptor, there's a special case for FD_CWD, which corresponds to the process's current working directory
Returns
The dentry associated with the file descriptor, or NULL if the file descriptor is invalid

Definition at line 314 of file dentry.c.

Referenced by vfs_chdir(), vfs_fchmodat(), vfs_fstatat(), vfs_getcwd(), vfs_mkdir(), vfs_mount(), vfs_openat(), vfs_readlinkat(), vfs_rmdir(), and vfs_symlink().

+ Here is the call graph for this function:

◆ dentry_get_child()

dentry_t * dentry_get_child ( dentry_t * parent,
const char * name )

Get a child dentry from a parent dentry.

Parameters
parentThe parent dentry
nameThe name of the child dentry
Returns
The child dentry, always non-NULL, even if the child dentry does not exist in the filesystem
Note
The returned dentry will have its reference count incremented, even if it does not exist.

Definition at line 335 of file dentry.c.

Referenced by dentry_lookup_parent(), and dentry_resolve_handle_last_segment().

+ Here is the call graph for this function:

◆ dentry_get()

dentry_t * dentry_get ( 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

Parameters
starting_dirThe starting directory when resolving a [relative] path
root_dirthe root directory when resolving the path, the resolved path will not go above this directory
pathThe path to resolve, can be absolute or relative
flagsFlags to control the behavior of the path resolution, see lastseg_resolve_flags_t
Returns
The parent directory (if such a parent exists) containing (or to contain) the last segment of the path, or NULL if any intermediate directory in the path does not exist.

Definition at line 388 of file dentry.c.

Referenced by vfs_chdir(), vfs_do_open(), vfs_fchmodat(), vfs_fstatat(), vfs_mkdir(), vfs_mount(), vfs_readlinkat(), vfs_rmdir(), vfs_symlink(), and vfs_unmount().

+ Here is the call graph for this function:

◆ dentry_mount()

__nodiscard bool dentry_mount ( dentry_t * mountpoint,
dentry_t * root,
filesystem_t * fs )

Mount a filesystem at a mountpoint.

Parameters
mountpointThe mountpoint
rootThe root directory of the filesystem
fsThe filesystem to mount
Returns
true if the filesystem was mounted successfully, false otherwise

Definition at line 72 of file mount.c.

Referenced by vfs_mount().

+ Here is the call graph for this function:

◆ dentry_unmount()

__nodiscard dentry_t * dentry_unmount ( dentry_t * root)

Unmount a filesystem at the mountpoint.

Returns
__nodiscard

Definition at line 103 of file mount.c.

Referenced by vfs_unmount().

+ Here is the call graph for this function:

◆ vfs_populate_listdir_buf()

void vfs_populate_listdir_buf ( dentry_t * dir,
vfs_listdir_state_t * state )

List the contents of a directory.

Parameters
dirThe directory to list
stateThe state of the directory iterator

Definition at line 437 of file dentry.c.

Referenced by vfs_list_dir().

+ Here is the call graph for this function:

◆ dentry_path()

ssize_t dentry_path ( dentry_t * dentry,
dentry_t * root,
char * buf,
size_t size )

Get the path of a dentry.

Parameters
dentryThe dentry to get the path of
rootThe root directory, the path will not go above this directory
bufThe buffer to write the path to
sizeThe size of the buffer
Returns
ssize_t

Definition at line 158 of file dentry_utils.c.

Referenced by cpio_i_lookup(), vfs_getcwd(), vfs_op_ops_getname(), and vfs_sysfs_mountpoints().

+ Here is the call graph for this function: