Skip to content

Commit adc0e91

Browse files
author
Al Viro
committed
vfs: new helper - d_make_root()
d_alloc_root() with iput() in case of allocation failure... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent b48f03b commit adc0e91

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎fs/dcache.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,23 @@ struct dentry * d_alloc_root(struct inode * root_inode)
14401440
}
14411441
EXPORT_SYMBOL(d_alloc_root);
14421442

1443+
struct dentry *d_make_root(struct inode *root_inode)
1444+
{
1445+
struct dentry *res = NULL;
1446+
1447+
if (root_inode) {
1448+
static const struct qstr name = { .name = "/", .len = 1 };
1449+
1450+
res = __d_alloc(root_inode->i_sb, &name);
1451+
if (res)
1452+
d_instantiate(res, root_inode);
1453+
else
1454+
iput(root_inode);
1455+
}
1456+
return res;
1457+
}
1458+
EXPORT_SYMBOL(d_make_root);
1459+
14431460
static struct dentry * __d_find_any_alias(struct inode *inode)
14441461
{
14451462
struct dentry *alias;

‎include/linux/dcache.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ extern int d_invalidate(struct dentry *);
249249

250250
/* only used at mount-time */
251251
extern struct dentry * d_alloc_root(struct inode *);
252+
extern struct dentry * d_make_root(struct inode *);
252253

253254
/* <clickety>-<click> the ramfs-type tree */
254255
extern void d_genocide(struct dentry *);

0 commit comments

Comments
 (0)