There is a d_alloc function in the kernel that allocates a dentry structure and initializes it.
/**
* D_alloc-allocate a Dcache entry
* @parent: Parent of entry to allocate
* @name: Qstr of the name
*
* Allocates a dentry. It returns%null if there is insufficient memory
* Available. On a success the Dentry is returned. The name passed in
* Copied and the copy passed in May reused the.
*/
struct Dentry *d_alloc (struct dentry * parent, const struct QSTR)
{
struct Dentry *dentry;
Char *dname;
Dentry = Kmem_cache_alloc (Dentry_cache, Gfp_kernel);
if (!dentry)
return NULL;
if (Name->len > Dname_inline_len-1) {
Dname = Kmalloc (Name->len + 1, gfp_kernel);
if (!dname) {
Kmem_cache_free (Dentry_cache, dentry);
return NULL;
}
} else {
Dname = dentry->d_iname;
}
Dentry->d_name.name = dname;
Dentry->d_name.len = name->len;
Dentry->d_name.hash = name->hash;
memcpy (Dname, Name->name, Name->len);
Dname[name->len] = 0;
Dentry->d_count.lock = 0; The newly added statement
Atomic_set (&dentry->d_count, 1);
Dentry->d_flags = dcache_unhashed;
Spin_lock_init (&dentry->d_lock);
Dentry->d_inode = NULL;
Dentry->d_parent = NULL;
DENTRY->D_SB = NULL;
Dentry->d_op = NULL;
Dentry->d_fsdata = NULL;
dentry->d_mounted = 0;
#ifdef config_profiling
Dentry->d_cookie = NULL;
#endif
Init_hlist_node (&dentry->d_hash);
Init_list_head (&DENTRY->D_LRU);
Init_list_head (&dentry->d_subdirs);
Init_list_head (&dentry->d_alias);
if (parent) {
Dentry->d_parent = Dget (parent);
DENTRY->D_SB = parent->d_sb;
} else {
Init_list_head (&dentry->d_u.d_child);
}
Spin_lock (&dcache_lock);
if (parent)
List_add (&dentry->d_u.d_child, &parent->d_subdirs);
dentry_stat.nr_dentry++;
Spin_unlock (&dcache_lock);
return dentry;
}