Skip to content

Commit bb8b9d0

Browse files
htejungregkh
authored andcommitted
kernfs: add @mode to kernfs_create_dir[_ns]()
sysfs assumed 0755 for all newly created directories and kernfs inherited it. This assumption is unnecessarily restrictive and inconsistent with kernfs_create_file[_ns](). This patch adds @mode parameter to kernfs_create_dir[_ns]() and update uses in sysfs accordingly. Among others, this will be useful for implementations of the planned ->mkdir() method. This patch doesn't introduce any behavior differences. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c637b8a commit bb8b9d0

4 files changed

Lines changed: 16 additions & 12 deletions

File tree

‎fs/kernfs/dir.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,22 +639,23 @@ void kernfs_destroy_root(struct kernfs_root *root)
639639
* kernfs_create_dir_ns - create a directory
640640
* @parent: parent in which to create a new directory
641641
* @name: name of the new directory
642+
* @mode: mode of the new directory
642643
* @priv: opaque data associated with the new directory
643644
* @ns: optional namespace tag of the directory
644645
*
645646
* Returns the created node on success, ERR_PTR() value on failure.
646647
*/
647648
struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
648-
const char *name, void *priv,
649-
const void *ns)
649+
const char *name, umode_t mode,
650+
void *priv, const void *ns)
650651
{
651-
umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
652652
struct kernfs_addrm_cxt acxt;
653653
struct kernfs_node *kn;
654654
int rc;
655655

656656
/* allocate */
657-
kn = kernfs_new_node(kernfs_root(parent), name, mode, KERNFS_DIR);
657+
kn = kernfs_new_node(kernfs_root(parent), name, mode | S_IFDIR,
658+
KERNFS_DIR);
658659
if (!kn)
659660
return ERR_PTR(-ENOMEM);
660661

‎fs/sysfs/dir.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
7373
if (!parent)
7474
return -ENOENT;
7575

76-
kn = kernfs_create_dir_ns(parent, kobject_name(kobj), kobj, ns);
76+
kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
77+
S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
7778
if (IS_ERR(kn)) {
7879
if (PTR_ERR(kn) == -EEXIST)
7980
sysfs_warn_dup(parent, kobject_name(kobj));

‎fs/sysfs/group.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ static int internal_create_group(struct kobject *kobj, int update,
100100
return -EINVAL;
101101
}
102102
if (grp->name) {
103-
kn = kernfs_create_dir(kobj->sd, grp->name, kobj);
103+
kn = kernfs_create_dir(kobj->sd, grp->name,
104+
S_IRWXU | S_IRUGO | S_IXUGO, kobj);
104105
if (IS_ERR(kn)) {
105106
if (PTR_ERR(kn) == -EEXIST)
106107
sysfs_warn_dup(kobj->sd, grp->name);

‎include/linux/kernfs.h‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ struct kernfs_root *kernfs_create_root(void *priv);
210210
void kernfs_destroy_root(struct kernfs_root *root);
211211

212212
struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
213-
const char *name, void *priv,
214-
const void *ns);
213+
const char *name, umode_t mode,
214+
void *priv, const void *ns);
215215
struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent,
216216
const char *name,
217217
umode_t mode, loff_t size,
@@ -260,8 +260,8 @@ static inline struct kernfs_root *kernfs_create_root(void *priv)
260260
static inline void kernfs_destroy_root(struct kernfs_root *root) { }
261261

262262
static inline struct kernfs_node *
263-
kernfs_create_dir_ns(struct kernfs_node *parent, const char *name, void *priv,
264-
const void *ns)
263+
kernfs_create_dir_ns(struct kernfs_node *parent, const char *name,
264+
umode_t mode, void *priv, const void *ns)
265265
{ return ERR_PTR(-ENOSYS); }
266266

267267
static inline struct kernfs_node *
@@ -314,9 +314,10 @@ kernfs_find_and_get(struct kernfs_node *kn, const char *name)
314314
}
315315

316316
static inline struct kernfs_node *
317-
kernfs_create_dir(struct kernfs_node *parent, const char *name, void *priv)
317+
kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode,
318+
void *priv)
318319
{
319-
return kernfs_create_dir_ns(parent, name, priv, NULL);
320+
return kernfs_create_dir_ns(parent, name, mode, priv, NULL);
320321
}
321322

322323
static inline struct kernfs_node *

0 commit comments

Comments
 (0)