|
PatchworkOS
|
Directory entry. More...
Data Structures | |
| struct | dentry_ops_t |
| Dentry operations structure. More... | |
| struct | dentry_t |
| Directory entry structure. More... | |
Macros | |
| #define | DENTRY_IS_ROOT(dentry) (dentry->parent == dentry) |
| Macro to check if a dentry is the root entry in its filesystem. | |
Typedefs | |
| typedef uint64_t | dentry_id_t |
| Dentry ID type. | |
Enumerations | |
| enum | dentry_flags_t { DENTRY_NONE = 0 , DENTRY_NEGATIVE = 1 << 1 } |
| Flags for a dentry. More... | |
Functions | |
| dentry_t * | dentry_new (superblock_t *superblock, dentry_t *parent, const char *name) |
| Create a new dentry. | |
| uint64_t | dentry_make_positive (dentry_t *dentry, inode_t *inode) |
| Make a dentry positive by associating it with an inode. | |
| void | dentry_inc_mount_count (dentry_t *dentry) |
| Increments the mount count of a dentry. | |
| void | dentry_dec_mount_count (dentry_t *dentry) |
| Decrements the mount count of a dentry. | |
| uint64_t | dentry_generic_getdents (dentry_t *dentry, dirent_t *buffer, uint64_t count, uint64_t *offset, path_flags_t flags) |
| Helper function for a basic getdents. | |
Directory entry.
A dentry represents the actual name in the filesystem hierarchy. It can be either positive, meaning it has an associated inode, or negative, meaning it does not have an associated inode. When traversing a filesystem this is the thing you actually walk through.
| #define DENTRY_IS_ROOT | ( | dentry | ) | (dentry->parent == dentry) |
| typedef uint64_t dentry_id_t |
| enum dentry_flags_t |
Flags for a dentry.
| void dentry_dec_mount_count | ( | dentry_t * | dentry | ) |
Decrements the mount count of a dentry.
| dentry | The dentry to decrement the mount count of. |
Definition at line 133 of file dentry.c.
References atomic_fetch_sub, and dentry_t::mountCount.
Referenced by mount_free().
| uint64_t dentry_generic_getdents | ( | dentry_t * | dentry, |
| dirent_t * | buffer, | ||
| uint64_t | count, | ||
| uint64_t * | offset, | ||
| path_flags_t | flags | ||
| ) |
Helper function for a basic getdents.
This function can be used by filesystems that do not have any special requirements for getdents.
In practice this is only useful for in-memory filesystems.
Used by setting the dentry ops getdents to this function.
Definition at line 195 of file dentry.c.
References getdents_ctx_t::basePath, buffer, dentry_t::children, dentry_t::childrenMutex, count, getdents_recursive_traversal(), getdents_write(), getdents_ctx_t::index, dentry_t::inode, INODE_DIR, LIST_FOR_EACH, MAX_PATH, MIN, MUTEX_SCOPE, dentry_t::name, inode_t::number, dentry_t::parent, PATH_RECURSIVE, snprintf(), start(), and inode_t::type.
| void dentry_inc_mount_count | ( | dentry_t * | dentry | ) |
Increments the mount count of a dentry.
| dentry | The dentry to increment the mount count of. |
Definition at line 128 of file dentry.c.
References atomic_fetch_add, and dentry_t::mountCount.
Referenced by mount_new().
Make a dentry positive by associating it with an inode.
This will also add the dentry to its parent's list of children, set the dentrys inode and its flags to positive.
| dentry | The dentry to make positive. |
| inode | The inode to associate with the dentry. |
Definition at line 101 of file dentry.c.
References assert, atomic_fetch_and, atomic_load, dentry_t::children, dentry_t::childrenMutex, DENTRY_IS_ROOT, DENTRY_NEGATIVE, EINVAL, ERR, errno, dentry_t::inode, list_push(), MUTEX_SCOPE, NULL, dentry_t::parent, REF, and dentry_t::siblingEntry.
Referenced by ramfs_create(), ramfs_link(), ramfs_load_dir(), ramfs_load_file(), sysfs_dir_new(), sysfs_file_new(), sysfs_mount(), and sysfs_mount_new().
| dentry_t * dentry_new | ( | superblock_t * | superblock, |
| dentry_t * | parent, | ||
| const char * | name | ||
| ) |
Create a new dentry.
Will not add the dentry to its parent's list of children but it will appear in the dentry cache as a negative dentry until dentry_make_positive() is called making it positive. This is needed to solve some race conditions when creating new files. While the dentry is negative it is not possible to create another dentry of the same name in the same parent, and any lookup to the dentry will fail until it is made positive.
Note that this function will set errno == EEXIST if a dentry with the same name and parent already exists in the dentry cache, this is very useful for solving race conditions when looking up dentries.
There is no dentry_free() instead use DEREF().
| superblock | The superblock the dentry belongs to. |
| parent | The parent dentry, can be NULL if this is a root dentry. |
| name | The name of the dentry. |
NULL and errno is set. Definition at line 51 of file dentry.c.
References assert, atomic_init, dentry_t::children, dentry_t::childrenMutex, dentry_free(), DENTRY_NEGATIVE, superblock_t::dentryOps, DEREF, EINVAL, ERR, errno, dentry_t::id, dentry_t::inode, list_entry_init(), list_init(), malloc(), map_entry_init(), dentry_t::mapEntry, MAX_NAME, dentry_t::mountCount, mutex_init(), dentry_t::name, NULL, dentry_t::ops, dentry_t::parent, dentry_t::private, dentry_t::ref, REF, ref_init(), dentry_t::siblingEntry, strncpy(), strnlen_s(), dentry_t::superblock, vfs_add_dentry(), and vfs_get_new_id().
Referenced by ramfs_load_dir(), ramfs_load_file(), sysfs_dir_new(), sysfs_file_new(), sysfs_mount(), sysfs_mount_new(), and vfs_get_or_lookup_dentry().