PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches

Directory entry. More...

Collaboration diagram for Dentry:

Detailed Description

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.

Mountpoints and Root Dentries

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_tdentry_new (superblock_t *superblock, dentry_t *parent, const char *name)
 Create a new dentry.
 
dentry_tdentry_get (const dentry_t *parent, const char *name)
 Get a dentry for the given name. Will NOT traverse mountpoints.
 
dentry_tdentry_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.
 

Macro Definition Documentation

◆ DENTRY_IS_ROOT

#define DENTRY_IS_ROOT (   dentry)    ((dentry)->parent == (dentry))

Macro to check if a dentry is the root entry in its filesystem.

A dentry is considered the root if its parent is itself.

Parameters
dentryThe dentry to check.
Returns
true if the dentry is the root, false otherwise.

Definition at line 65 of file dentry.h.

Typedef Documentation

◆ dentry_id_t

Dentry ID type.

Definition at line 55 of file dentry.h.

Enumeration Type Documentation

◆ dentry_flags_t

Dentry flags.

Enumerator
DENTRY_NEGATIVE 

Dentry is negative (no associated inode).

Definition at line 47 of file dentry.h.

Function Documentation

◆ dentry_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.

There is no dentry_free() instead use UNREF().

Parameters
superblockThe superblock the dentry belongs to.
parentThe parent dentry, can be NULL if this is a root dentry.
nameThe name of the dentry.
Returns
On success, the new dentry. On failure, returns NULL and errno is set.

Definition at line 114 of file dentry.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dentry_get()

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

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.

Parameters
parentThe parent path.
nameThe name of the dentry.
Returns
On success, the dentry, might be negative. On failure, returns NULL and errno is set.

Definition at line 164 of file dentry.c.

Here is the call graph for this function:

◆ dentry_lookup()

dentry_t * dentry_lookup ( const path_t parent,
const char *  name 
)

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.

Parameters
parentThe parent path.
nameThe name of the dentry.
Returns
On success, the dentry, might be negative. On failure, returns NULL and errno is set.

Definition at line 176 of file dentry.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dentry_make_positive()

void dentry_make_positive ( dentry_t dentry,
inode_t inode 
)

Make a dentry positive by associating it with an inode.

This function is expected to be protected by the parent inode's mutex.

Parameters
dentryThe dentry to make positive, or NULL for no-op.
inodeThe inode to associate with the dentry, or NULL for no-op.

Definition at line 226 of file dentry.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dentry_is_positive()

bool dentry_is_positive ( dentry_t dentry)

Check if a dentry is positive.

Parameters
dentryThe dentry to check.
Returns
true if the dentry is positive, false if it is negative.

Definition at line 243 of file dentry.c.

Here is the caller graph for this function:

◆ dentry_is_file()

bool dentry_is_file ( dentry_t dentry)

Check if the inode associated with a dentry is a file.

Parameters
dentryThe dentry to check.
Returns
true if the dentry is a file, false otherwise or if the dentry is negative.

Definition at line 253 of file dentry.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dentry_is_dir()

bool dentry_is_dir ( dentry_t dentry)

Check if the inode associated with a dentry is a directory.

Parameters
dentryThe dentry to check.
Returns
true if the dentry is a directory, false otherwise or if the dentry is negative.

Definition at line 268 of file dentry.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dentry_generic_getdents()

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.

Here is the call graph for this function: