blob: b923052c29d0c7b419cf31b71846a468b9d109ea [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 Heodd8a5b02013-11-28 14:54:20 -050012#include <linux/list.h>
13#include <linux/mutex.h>
Tejun Heo879f40d2013-11-23 17:21:49 -050014
Tejun Heo5d604182013-11-23 17:21:52 -050015struct file;
16struct iattr;
Tejun Heodd8a5b02013-11-28 14:54:20 -050017struct seq_file;
18struct vm_area_struct;
Tejun Heo5d604182013-11-23 17:21:52 -050019
Tejun Heob8441ed2013-11-24 09:54:58 -050020struct sysfs_dirent;
21
Tejun Heodd8a5b02013-11-28 14:54:20 -050022struct sysfs_open_file {
23 /* published fields */
24 struct sysfs_dirent *sd;
25 struct file *file;
26
27 /* private fields, do not use outside kernfs proper */
28 struct mutex mutex;
29 int event;
30 struct list_head list;
31
32 bool mmapped;
33 const struct vm_operations_struct *vm_ops;
34};
35
Tejun Heo879f40d2013-11-23 17:21:49 -050036#ifdef CONFIG_SYSFS
37
Tejun Heo93b2b8e2013-11-28 14:54:15 -050038struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent,
39 const char *name, void *priv,
40 const void *ns);
Tejun Heo5d0e26b2013-11-23 17:21:50 -050041struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent,
42 const char *name,
43 struct sysfs_dirent *target);
Tejun Heo879f40d2013-11-23 17:21:49 -050044void kernfs_remove(struct sysfs_dirent *sd);
45int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, const char *name,
46 const void *ns);
Tejun Heo890ece12013-11-23 17:21:51 -050047int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
48 const char *new_name, const void *new_ns);
Tejun Heo93b2b8e2013-11-28 14:54:15 -050049void kernfs_enable_ns(struct sysfs_dirent *sd);
Tejun Heo5d604182013-11-23 17:21:52 -050050int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr);
Tejun Heo879f40d2013-11-23 17:21:49 -050051
52#else /* CONFIG_SYSFS */
53
Tejun Heo5d0e26b2013-11-23 17:21:50 -050054static inline struct sysfs_dirent *
Tejun Heo93b2b8e2013-11-28 14:54:15 -050055kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv,
56 const void *ns)
57{ return ERR_PTR(-ENOSYS); }
58
59static inline struct sysfs_dirent *
Tejun Heo5d0e26b2013-11-23 17:21:50 -050060kernfs_create_link(struct sysfs_dirent *parent, const char *name,
61 struct sysfs_dirent *target)
62{ return ERR_PTR(-ENOSYS); }
63
Tejun Heo879f40d2013-11-23 17:21:49 -050064static inline void kernfs_remove(struct sysfs_dirent *sd) { }
65
66static inline int kernfs_remove_by_name_ns(struct sysfs_dirent *parent,
67 const char *name, const void *ns)
68{ return -ENOSYS; }
69
Tejun Heo890ece12013-11-23 17:21:51 -050070static inline int kernfs_rename_ns(struct sysfs_dirent *sd,
71 struct sysfs_dirent *new_parent,
72 const char *new_name, const void *new_ns)
73{ return -ENOSYS; }
74
Tejun Heo93b2b8e2013-11-28 14:54:15 -050075static inline void kernfs_enable_ns(struct sysfs_dirent *sd) { }
76
Tejun Heo5d604182013-11-23 17:21:52 -050077static inline int kernfs_setattr(struct sysfs_dirent *sd,
78 const struct iattr *iattr)
79{ return -ENOSYS; }
80
Tejun Heo879f40d2013-11-23 17:21:49 -050081#endif /* CONFIG_SYSFS */
82
Tejun Heo93b2b8e2013-11-28 14:54:15 -050083static inline struct sysfs_dirent *
84kernfs_create_dir(struct sysfs_dirent *parent, const char *name, void *priv)
85{
86 return kernfs_create_dir_ns(parent, name, priv, NULL);
87}
88
Tejun Heo879f40d2013-11-23 17:21:49 -050089static inline int kernfs_remove_by_name(struct sysfs_dirent *parent,
90 const char *name)
91{
92 return kernfs_remove_by_name_ns(parent, name, NULL);
93}
94
Tejun Heob8441ed2013-11-24 09:54:58 -050095#endif /* __LINUX_KERNFS_H */