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>
* kernfs_create_dir_ns - create a directory
* @parent: parent in which to create a new directory
* @name: name of the new directory
* kernfs_create_dir_ns - create a directory
* @parent: parent in which to create a new directory
* @name: name of the new directory
+ * @mode: mode of the new directory
* @priv: opaque data associated with the new directory
* @ns: optional namespace tag of the directory
*
* Returns the created node on success, ERR_PTR() value on failure.
*/
struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
* @priv: opaque data associated with the new directory
* @ns: optional namespace tag of the directory
*
* Returns the created node on success, ERR_PTR() value on failure.
*/
struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
- const char *name, void *priv,
- const void *ns)
+ const char *name, umode_t mode,
+ void *priv, const void *ns)
- umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
struct kernfs_addrm_cxt acxt;
struct kernfs_node *kn;
int rc;
/* allocate */
struct kernfs_addrm_cxt acxt;
struct kernfs_node *kn;
int rc;
/* allocate */
- kn = kernfs_new_node(kernfs_root(parent), name, mode, KERNFS_DIR);
+ kn = kernfs_new_node(kernfs_root(parent), name, mode | S_IFDIR,
+ KERNFS_DIR);
if (!kn)
return ERR_PTR(-ENOMEM);
if (!kn)
return ERR_PTR(-ENOMEM);
if (!parent)
return -ENOENT;
if (!parent)
return -ENOENT;
- kn = kernfs_create_dir_ns(parent, kobject_name(kobj), kobj, ns);
+ kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
+ S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
if (IS_ERR(kn)) {
if (PTR_ERR(kn) == -EEXIST)
sysfs_warn_dup(parent, kobject_name(kobj));
if (IS_ERR(kn)) {
if (PTR_ERR(kn) == -EEXIST)
sysfs_warn_dup(parent, kobject_name(kobj));
return -EINVAL;
}
if (grp->name) {
return -EINVAL;
}
if (grp->name) {
- kn = kernfs_create_dir(kobj->sd, grp->name, kobj);
+ kn = kernfs_create_dir(kobj->sd, grp->name,
+ S_IRWXU | S_IRUGO | S_IXUGO, kobj);
if (IS_ERR(kn)) {
if (PTR_ERR(kn) == -EEXIST)
sysfs_warn_dup(kobj->sd, grp->name);
if (IS_ERR(kn)) {
if (PTR_ERR(kn) == -EEXIST)
sysfs_warn_dup(kobj->sd, grp->name);
void kernfs_destroy_root(struct kernfs_root *root);
struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
void kernfs_destroy_root(struct kernfs_root *root);
struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
- const char *name, void *priv,
- const void *ns);
+ const char *name, umode_t mode,
+ void *priv, const void *ns);
struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent,
const char *name,
umode_t mode, loff_t size,
struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent,
const char *name,
umode_t mode, loff_t size,
static inline void kernfs_destroy_root(struct kernfs_root *root) { }
static inline struct kernfs_node *
static inline void kernfs_destroy_root(struct kernfs_root *root) { }
static inline struct kernfs_node *
-kernfs_create_dir_ns(struct kernfs_node *parent, const char *name, void *priv,
- const void *ns)
+kernfs_create_dir_ns(struct kernfs_node *parent, const char *name,
+ umode_t mode, void *priv, const void *ns)
{ return ERR_PTR(-ENOSYS); }
static inline struct kernfs_node *
{ return ERR_PTR(-ENOSYS); }
static inline struct kernfs_node *
}
static inline struct kernfs_node *
}
static inline struct kernfs_node *
-kernfs_create_dir(struct kernfs_node *parent, const char *name, void *priv)
+kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode,
+ void *priv)
- return kernfs_create_dir_ns(parent, name, priv, NULL);
+ return kernfs_create_dir_ns(parent, name, mode, priv, NULL);
}
static inline struct kernfs_node *
}
static inline struct kernfs_node *