Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


Some helper functions are more complicated, so it’s best to inspect their prototypes.^12

<dcache.h>
extern void d_instantiate(struct dentry *, struct inode *);

struct dentry * d_alloc(struct dentry *, const struct qstr *);
struct dentry * d_alloc_anon(struct inode *);

struct dentry * d_splice_alias(struct inode *, struct dentry *);

static inline void d_add(struct dentry *entry, struct inode *inode);
struct dentry * d_lookup(struct dentry *, struct qstr *);

❑ d_instantiateassociates adentryinstance with an inode. This means setting thed_inodefield
and adding the dentry to the list headed byinode->i_dentry.
❑ d_addinstantiates a dentry object by usingd_instantiate. Additionally, the object is added to
the global inode hash tabledentry_hashtable.
❑ d_allocallocates memory for a new instance ofstruct dentryas the name does suggest. The
fields are initialized, and if a parent dentry is given, the superblock pointer for the new dentry
is taken from the parent. Additionally, the new dentry is added to the subdirectory list of the
parent headed byparent->d_subdirs.
❑ d_alloc_anonallocates memory for an instance ofstruct dentrybut does not set up any
connections with a parent dentry — this is why no such parameter is required in contrast to
d_alloc. The new dentry is added to two lists: the superblock-specific list of anonymous dentry
objects headed bysuper_block->s_anonand the list of all dentry instances associated with the
inode, which is headed byinode->i_dentry.
Note that if the inode already contains a disconnected dentry as allocated by a previous call to
d_alloc_anon, this copy is used instead of creating a new instance.
❑ d_splice_aliassplices a disconnected dentry into the dentry tree. Theinodeparameter
required by the function denotes the inode to which thedentryis supposed to be associated.
For inodes that represent any filesystem object other than directories, it suffices to calld_add.For
directories, the function ensures that only a single dentry alias is present, which requires some
more administrative work that I won’t bother to discuss in detail.
❑ d_lookuptakes thedentryinstance of a directory and searches for a dentry object that represents
afilewithname.

8.4 Working with VFS Objects


The data structures described above act as a basis for working with the VFS layer. We examine this layer
in the following sections. Let us first focus on mounting and unmounting filesystems (and filesystem

(^12) More auxiliary functions are defined in<dentry.h>and implemented infs/dcache.c. Since they are not so frequently used,
I will not discuss them here, but refer to the documentation associated with them for more information.

Free download pdf