sysfs, kernfs: move mount core code to fs/kernfs/mount.c
[linux-2.6-block.git] / include / linux / kernfs.h
CommitLineData
b8441ed2
TH
1/*
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
879f40d1 10#include <linux/kernel.h>
5d0e26bb 11#include <linux/err.h>
dd8a5b03
TH
12#include <linux/list.h>
13#include <linux/mutex.h>
bc755553 14#include <linux/idr.h>
517e64f5 15#include <linux/lockdep.h>
879f40d1 16
5d60418e
TH
17struct file;
18struct iattr;
dd8a5b03
TH
19struct seq_file;
20struct vm_area_struct;
4b93dc9b
TH
21struct super_block;
22struct file_system_type;
5d60418e 23
b8441ed2
TH
24struct sysfs_dirent;
25
ba7443bc
TH
26struct kernfs_root {
27 /* published fields */
28 struct sysfs_dirent *sd;
bc755553
TH
29
30 /* private fields, do not use outside kernfs proper */
31 struct ida ino_ida;
ba7443bc
TH
32};
33
dd8a5b03
TH
34struct sysfs_open_file {
35 /* published fields */
36 struct sysfs_dirent *sd;
37 struct file *file;
38
39 /* private fields, do not use outside kernfs proper */
40 struct mutex mutex;
41 int event;
42 struct list_head list;
43
44 bool mmapped;
45 const struct vm_operations_struct *vm_ops;
46};
47
f6acf8bb
TH
48struct kernfs_ops {
49 /*
50 * Read is handled by either seq_file or raw_read().
51 *
d19b9846
TH
52 * If seq_show() is present, seq_file path is active. Other seq
53 * operations are optional and if not implemented, the behavior is
54 * equivalent to single_open(). @sf->private points to the
f6acf8bb
TH
55 * associated sysfs_open_file.
56 *
57 * read() is bounced through kernel buffer and a read larger than
58 * PAGE_SIZE results in partial operation of PAGE_SIZE.
59 */
60 int (*seq_show)(struct seq_file *sf, void *v);
d19b9846
TH
61
62 void *(*seq_start)(struct seq_file *sf, loff_t *ppos);
63 void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos);
64 void (*seq_stop)(struct seq_file *sf, void *v);
f6acf8bb
TH
65
66 ssize_t (*read)(struct sysfs_open_file *of, char *buf, size_t bytes,
67 loff_t off);
68
69 /*
70 * write() is bounced through kernel buffer and a write larger than
71 * PAGE_SIZE results in partial operation of PAGE_SIZE.
72 */
73 ssize_t (*write)(struct sysfs_open_file *of, char *buf, size_t bytes,
74 loff_t off);
75
76 int (*mmap)(struct sysfs_open_file *of, struct vm_area_struct *vma);
517e64f5
TH
77
78#ifdef CONFIG_DEBUG_LOCK_ALLOC
79 struct lock_class_key lockdep_key;
80#endif
f6acf8bb
TH
81};
82
879f40d1
TH
83#ifdef CONFIG_SYSFS
84
ccf73cf3
TH
85struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent,
86 const char *name, const void *ns);
87void kernfs_get(struct sysfs_dirent *sd);
88void kernfs_put(struct sysfs_dirent *sd);
89
ba7443bc
TH
90struct kernfs_root *kernfs_create_root(void *priv);
91void kernfs_destroy_root(struct kernfs_root *root);
92
93b2b8e4
TH
93struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent,
94 const char *name, void *priv,
95 const void *ns);
517e64f5
TH
96struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent,
97 const char *name,
98 umode_t mode, loff_t size,
99 const struct kernfs_ops *ops,
100 void *priv, const void *ns,
101 struct lock_class_key *key);
5d0e26bb
TH
102struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent,
103 const char *name,
104 struct sysfs_dirent *target);
879f40d1
TH
105void kernfs_remove(struct sysfs_dirent *sd);
106int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, const char *name,
107 const void *ns);
890ece16
TH
108int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
109 const char *new_name, const void *new_ns);
93b2b8e4 110void kernfs_enable_ns(struct sysfs_dirent *sd);
5d60418e 111int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr);
024f6471 112void kernfs_notify(struct sysfs_dirent *sd);
879f40d1 113
4b93dc9b
TH
114const void *kernfs_super_ns(struct super_block *sb);
115struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
116 struct kernfs_root *root, const void *ns);
117void kernfs_kill_sb(struct super_block *sb);
118
119void kernfs_init(void);
120
879f40d1
TH
121#else /* CONFIG_SYSFS */
122
ccf73cf3
TH
123static inline struct sysfs_dirent *
124kernfs_find_and_get_ns(struct sysfs_dirent *parent, const char *name,
125 const void *ns)
126{ return NULL; }
127
128static inline void kernfs_get(struct sysfs_dirent *sd) { }
129static inline void kernfs_put(struct sysfs_dirent *sd) { }
130
ba7443bc
TH
131static inline struct kernfs_root *kernfs_create_root(void *priv)
132{ return ERR_PTR(-ENOSYS); }
133
134static inline void kernfs_destroy_root(struct kernfs_root *root) { }
135
93b2b8e4
TH
136static inline struct sysfs_dirent *
137kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv,
138 const void *ns)
139{ return ERR_PTR(-ENOSYS); }
140
496f7394 141static inline struct sysfs_dirent *
517e64f5
TH
142kernfs_create_file_ns_key(struct sysfs_dirent *parent, const char *name,
143 umode_t mode, loff_t size,
144 const struct kernfs_ops *ops, void *priv,
145 const void *ns, struct lock_class_key *key)
496f7394
TH
146{ return ERR_PTR(-ENOSYS); }
147
5d0e26bb
TH
148static inline struct sysfs_dirent *
149kernfs_create_link(struct sysfs_dirent *parent, const char *name,
150 struct sysfs_dirent *target)
151{ return ERR_PTR(-ENOSYS); }
152
879f40d1
TH
153static inline void kernfs_remove(struct sysfs_dirent *sd) { }
154
155static inline int kernfs_remove_by_name_ns(struct sysfs_dirent *parent,
156 const char *name, const void *ns)
157{ return -ENOSYS; }
158
890ece16
TH
159static inline int kernfs_rename_ns(struct sysfs_dirent *sd,
160 struct sysfs_dirent *new_parent,
161 const char *new_name, const void *new_ns)
162{ return -ENOSYS; }
163
93b2b8e4
TH
164static inline void kernfs_enable_ns(struct sysfs_dirent *sd) { }
165
5d60418e
TH
166static inline int kernfs_setattr(struct sysfs_dirent *sd,
167 const struct iattr *iattr)
168{ return -ENOSYS; }
169
024f6471
TH
170static inline void kernfs_notify(struct sysfs_dirent *sd) { }
171
4b93dc9b
TH
172static inline const void *kernfs_super_ns(struct super_block *sb)
173{ return NULL; }
174
175static inline struct dentry *
176kernfs_mount_ns(struct file_system_type *fs_type, int flags,
177 struct kernfs_root *root, const void *ns)
178{ return ERR_PTR(-ENOSYS); }
179
180static inline void kernfs_kill_sb(struct super_block *sb) { }
181
182static inline void kernfs_init(void) { }
183
879f40d1
TH
184#endif /* CONFIG_SYSFS */
185
93b2b8e4 186static inline struct sysfs_dirent *
ccf73cf3
TH
187kernfs_find_and_get(struct sysfs_dirent *sd, const char *name)
188{
189 return kernfs_find_and_get_ns(sd, name, NULL);
190}
191
192static inline struct sysfs_dirent *
93b2b8e4
TH
193kernfs_create_dir(struct sysfs_dirent *parent, const char *name, void *priv)
194{
195 return kernfs_create_dir_ns(parent, name, priv, NULL);
196}
197
517e64f5
TH
198static inline struct sysfs_dirent *
199kernfs_create_file_ns(struct sysfs_dirent *parent, const char *name,
200 umode_t mode, loff_t size, const struct kernfs_ops *ops,
201 void *priv, const void *ns)
202{
203 struct lock_class_key *key = NULL;
204
205#ifdef CONFIG_DEBUG_LOCK_ALLOC
206 key = (struct lock_class_key *)&ops->lockdep_key;
207#endif
208 return kernfs_create_file_ns_key(parent, name, mode, size, ops, priv,
209 ns, key);
210}
211
496f7394
TH
212static inline struct sysfs_dirent *
213kernfs_create_file(struct sysfs_dirent *parent, const char *name, umode_t mode,
214 loff_t size, const struct kernfs_ops *ops, void *priv)
215{
216 return kernfs_create_file_ns(parent, name, mode, size, ops, priv, NULL);
217}
218
879f40d1
TH
219static inline int kernfs_remove_by_name(struct sysfs_dirent *parent,
220 const char *name)
221{
222 return kernfs_remove_by_name_ns(parent, name, NULL);
223}
224
4b93dc9b
TH
225static inline struct dentry *
226kernfs_mount(struct file_system_type *fs_type, int flags,
227 struct kernfs_root *root)
228{
229 return kernfs_mount_ns(fs_type, flags, root, NULL);
230}
231
b8441ed2 232#endif /* __LINUX_KERNFS_H */