|
PatchworkOS
966e257
A non-POSIX operating system.
|
Directory entry. More...
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.
The difference between a mountpoint dentry and a root dentry can be a bit confusing, so here is a quick explanation. When a filesystem is mounted the dentry that it gets mounted to becomes a mountpoint, any data that was there before becomes hidden and when we traverse to that dentry we "jump" to the root dentry of the mounted filesystem. The root dentry of the mounted filesystem is simply the root directory of that filesystem.
This means that the mountpoint does not "become" the root of the mounted filesystem, it simply points to it.
Finally, note that just becouse a dentry is a mountpoint does not mean that it can be traversed by the current process, a process can only traverse a mountpoint if it is visible in its namespace, if its not visible the dentry acts exactly like a normal dentry.
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_NEGATIVE = 1 << 0 } |
| Dentry flags. More... | |
Functions | |
| dentry_t * | dentry_new (superblock_t *superblock, dentry_t *parent, const char *name) |
| Create a new dentry. | |
| dentry_t * | dentry_get (const dentry_t *parent, const char *name) |
| Get a dentry for the given name. Will NOT traverse mountpoints. | |
| dentry_t * | dentry_lookup (const path_t *parent, const char *name) |
| Lookup a dentry for the given name. Will NOT traverse mountpoints. | |
| void | dentry_make_positive (dentry_t *dentry, inode_t *inode) |
| Make a dentry positive by associating it with an inode. | |
| bool | dentry_is_positive (dentry_t *dentry) |
| Check if a dentry is positive. | |
| bool | dentry_is_file (dentry_t *dentry) |
| Check if the inode associated with a dentry is a file. | |
| bool | dentry_is_dir (dentry_t *dentry) |
| Check if the inode associated with a dentry is a directory. | |
| uint64_t | dentry_generic_getdents (dentry_t *dentry, dirent_t *buffer, uint64_t count, uint64_t *offset, mode_t mode) |
| Helper function for a basic getdents. | |
| #define DENTRY_IS_ROOT | ( | dentry | ) | ((dentry)->parent == (dentry)) |
| typedef uint64_t dentry_id_t |
| enum dentry_flags_t |
| 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.
There is no dentry_free() instead use UNREF().
| 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 114 of file dentry.c.
Get a dentry for the given name. Will NOT traverse mountpoints.
Will only check the dentry cache and return a dentry if it exists there, will not call the filesystem's lookup function.
| parent | The parent path. |
| name | The name of the dentry. |
NULL and errno is set. Definition at line 164 of file dentry.c.
Lookup a dentry for the given name. Will NOT traverse mountpoints.
If the dentry is not found in the dentry cache, the filesystem's lookup function will be called to try to find it.
| parent | The parent path. |
| name | The name of the dentry. |
NULL and errno is set. Definition at line 176 of file dentry.c.
Make a dentry positive by associating it with an inode.
This function is expected to be protected by the parent inode's mutex.
| dentry | The dentry to make positive, or NULL for no-op. |
| inode | The inode to associate with the dentry, or NULL for no-op. |
Definition at line 226 of file dentry.c.
Check if the inode associated with a dentry is a file.
| dentry | The dentry to check. |
Definition at line 253 of file dentry.c.
Check if the inode associated with a dentry is a directory.
| dentry | The dentry to check. |
Definition at line 268 of file dentry.c.
| uint64_t dentry_generic_getdents | ( | dentry_t * | dentry, |
| dirent_t * | buffer, | ||
| uint64_t | count, | ||
| uint64_t * | offset, | ||
| mode_t | mode | ||
| ) |
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 345 of file dentry.c.