blob: e8b73d4a08d211590aaca4f36c13339368ae486f [file] [log] [blame]
Tejun Heob8441ed2013-11-24 09:54:58 -05001/*
2 * kernfs.h - pseudo filesystem decoupled from vfs locking
3 *
4 * This file is released under the GPLv2.
5 */
6
7#ifndef __LINUX_KERNFS_H
8#define __LINUX_KERNFS_H
9
Tejun Heo879f40d2013-11-23 17:21:49 -050010#include <linux/kernel.h>
Tejun Heo5d0e26b2013-11-23 17:21:50 -050011#include <linux/err.h>
Tejun Heo879f40d2013-11-23 17:21:49 -050012
Tejun Heo5d604182013-11-23 17:21:52 -050013struct file;
14struct iattr;
15
Tejun Heob8441ed2013-11-24 09:54:58 -050016struct sysfs_dirent;
17
Tejun Heo879f40d2013-11-23 17:21:49 -050018#ifdef CONFIG_SYSFS
19
Tejun Heo93b2b8e2013-11-28 14:54:15 -050020struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent,
21 const char *name, void *priv,
22 const void *ns);
Tejun Heo5d0e26b2013-11-23 17:21:50 -050023struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent,
24 const char *name,
25 struct sysfs_dirent *target);
Tejun Heo879f40d2013-11-23 17:21:49 -050026void kernfs_remove(struct sysfs_dirent *sd);
27int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, const char *name,
28 const void *ns);
Tejun Heo890ece12013-11-23 17:21:51 -050029int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
30 const char *new_name, const void *new_ns);
Tejun Heo93b2b8e2013-11-28 14:54:15 -050031void kernfs_enable_ns(struct sysfs_dirent *sd);
Tejun Heo5d604182013-11-23 17:21:52 -050032int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr);
Tejun Heo879f40d2013-11-23 17:21:49 -050033
34#else /* CONFIG_SYSFS */
35
Tejun Heo5d0e26b2013-11-23 17:21:50 -050036static inline struct sysfs_dirent *
Tejun Heo93b2b8e2013-11-28 14:54:15 -050037kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv,
38 const void *ns)
39{ return ERR_PTR(-ENOSYS); }
40
41static inline struct sysfs_dirent *
Tejun Heo5d0e26b2013-11-23 17:21:50 -050042kernfs_create_link(struct sysfs_dirent *parent, const char *name,
43 struct sysfs_dirent *target)
44{ return ERR_PTR(-ENOSYS); }
45
Tejun Heo879f40d2013-11-23 17:21:49 -050046static inline void kernfs_remove(struct sysfs_dirent *sd) { }
47
48static inline int kernfs_remove_by_name_ns(struct sysfs_dirent *parent,
49 const char *name, const void *ns)
50{ return -ENOSYS; }
51
Tejun Heo890ece12013-11-23 17:21:51 -050052static inline int kernfs_rename_ns(struct sysfs_dirent *sd,
53 struct sysfs_dirent *new_parent,
54 const char *new_name, const void *new_ns)
55{ return -ENOSYS; }
56
Tejun Heo93b2b8e2013-11-28 14:54:15 -050057static inline void kernfs_enable_ns(struct sysfs_dirent *sd) { }
58
Tejun Heo5d604182013-11-23 17:21:52 -050059static inline int kernfs_setattr(struct sysfs_dirent *sd,
60 const struct iattr *iattr)
61{ return -ENOSYS; }
62
Tejun Heo879f40d2013-11-23 17:21:49 -050063#endif /* CONFIG_SYSFS */
64
Tejun Heo93b2b8e2013-11-28 14:54:15 -050065static inline struct sysfs_dirent *
66kernfs_create_dir(struct sysfs_dirent *parent, const char *name, void *priv)
67{
68 return kernfs_create_dir_ns(parent, name, priv, NULL);
69}
70
Tejun Heo879f40d2013-11-23 17:21:49 -050071static inline int kernfs_remove_by_name(struct sysfs_dirent *parent,
72 const char *name)
73{
74 return kernfs_remove_by_name_ns(parent, name, NULL);
75}
76
Tejun Heob8441ed2013-11-24 09:54:58 -050077#endif /* __LINUX_KERNFS_H */