]>
Commit | Line | Data |
---|---|---|
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> |
cf9e5a73 TH |
16 | #include <linux/rbtree.h> |
17 | #include <linux/atomic.h> | |
488dee96 | 18 | #include <linux/uidgid.h> |
abd54f02 | 19 | #include <linux/wait.h> |
879f40d1 | 20 | |
5d60418e | 21 | struct file; |
917f56ca | 22 | struct dentry; |
5d60418e | 23 | struct iattr; |
dd8a5b03 TH |
24 | struct seq_file; |
25 | struct vm_area_struct; | |
4b93dc9b TH |
26 | struct super_block; |
27 | struct file_system_type; | |
147e1a97 | 28 | struct poll_table_struct; |
23bf1b6b | 29 | struct fs_context; |
5d60418e | 30 | |
23bf1b6b | 31 | struct kernfs_fs_context; |
c525aadd TH |
32 | struct kernfs_open_node; |
33 | struct kernfs_iattrs; | |
cf9e5a73 TH |
34 | |
35 | enum kernfs_node_type { | |
df23fc39 TH |
36 | KERNFS_DIR = 0x0001, |
37 | KERNFS_FILE = 0x0002, | |
38 | KERNFS_LINK = 0x0004, | |
cf9e5a73 TH |
39 | }; |
40 | ||
df23fc39 | 41 | #define KERNFS_TYPE_MASK 0x000f |
df23fc39 | 42 | #define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK |
cf9e5a73 TH |
43 | |
44 | enum kernfs_node_flag { | |
d35258ef | 45 | KERNFS_ACTIVATED = 0x0010, |
df23fc39 TH |
46 | KERNFS_NS = 0x0020, |
47 | KERNFS_HAS_SEQ_SHOW = 0x0040, | |
48 | KERNFS_HAS_MMAP = 0x0080, | |
49 | KERNFS_LOCKDEP = 0x0100, | |
6b0afc2a TH |
50 | KERNFS_SUICIDAL = 0x0400, |
51 | KERNFS_SUICIDED = 0x0800, | |
ea015218 | 52 | KERNFS_EMPTY_DIR = 0x1000, |
0e67db2f | 53 | KERNFS_HAS_RELEASE = 0x2000, |
cf9e5a73 TH |
54 | }; |
55 | ||
d35258ef TH |
56 | /* @flags for kernfs_create_root() */ |
57 | enum kernfs_root_flag { | |
555724a8 TH |
58 | /* |
59 | * kernfs_nodes are created in the deactivated state and invisible. | |
60 | * They require explicit kernfs_activate() to become visible. This | |
61 | * can be used to make related nodes become visible atomically | |
62 | * after all nodes are created successfully. | |
63 | */ | |
64 | KERNFS_ROOT_CREATE_DEACTIVATED = 0x0001, | |
65 | ||
66 | /* | |
0d1a393d | 67 | * For regular files, if the opener has CAP_DAC_OVERRIDE, open(2) |
555724a8 TH |
68 | * succeeds regardless of the RW permissions. sysfs had an extra |
69 | * layer of enforcement where open(2) fails with -EACCES regardless | |
70 | * of CAP_DAC_OVERRIDE if the permission doesn't have the | |
71 | * respective read or write access at all (none of S_IRUGO or | |
72 | * S_IWUGO) or the respective operation isn't implemented. The | |
73 | * following flag enables that behavior. | |
74 | */ | |
75 | KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK = 0x0002, | |
aa818825 SL |
76 | |
77 | /* | |
78 | * The filesystem supports exportfs operation, so userspace can use | |
79 | * fhandle to access nodes of the fs. | |
80 | */ | |
81 | KERNFS_ROOT_SUPPORT_EXPORTOP = 0x0004, | |
d35258ef TH |
82 | }; |
83 | ||
324a56e1 TH |
84 | /* type-specific structures for kernfs_node union members */ |
85 | struct kernfs_elem_dir { | |
cf9e5a73 | 86 | unsigned long subdirs; |
adc5e8b5 | 87 | /* children rbtree starts here and goes through kn->rb */ |
cf9e5a73 TH |
88 | struct rb_root children; |
89 | ||
90 | /* | |
91 | * The kernfs hierarchy this directory belongs to. This fits | |
324a56e1 | 92 | * better directly in kernfs_node but is here to save space. |
cf9e5a73 TH |
93 | */ |
94 | struct kernfs_root *root; | |
95 | }; | |
96 | ||
324a56e1 TH |
97 | struct kernfs_elem_symlink { |
98 | struct kernfs_node *target_kn; | |
cf9e5a73 TH |
99 | }; |
100 | ||
324a56e1 | 101 | struct kernfs_elem_attr { |
cf9e5a73 | 102 | const struct kernfs_ops *ops; |
c525aadd | 103 | struct kernfs_open_node *open; |
cf9e5a73 | 104 | loff_t size; |
ecca47ce | 105 | struct kernfs_node *notify_next; /* for kernfs_notify() */ |
cf9e5a73 TH |
106 | }; |
107 | ||
c53cd490 SL |
108 | /* represent a kernfs node */ |
109 | union kernfs_node_id { | |
110 | struct { | |
aa818825 SL |
111 | /* |
112 | * blktrace will export this struct as a simplified 'struct | |
113 | * fid' (which is a big data struction), so userspace can use | |
114 | * it to find kernfs node. The layout must match the first two | |
115 | * fields of 'struct fid' exactly. | |
116 | */ | |
c53cd490 SL |
117 | u32 ino; |
118 | u32 generation; | |
119 | }; | |
120 | u64 id; | |
121 | }; | |
122 | ||
cf9e5a73 | 123 | /* |
324a56e1 TH |
124 | * kernfs_node - the building block of kernfs hierarchy. Each and every |
125 | * kernfs node is represented by single kernfs_node. Most fields are | |
cf9e5a73 TH |
126 | * private to kernfs and shouldn't be accessed directly by kernfs users. |
127 | * | |
324a56e1 TH |
128 | * As long as s_count reference is held, the kernfs_node itself is |
129 | * accessible. Dereferencing elem or any other outer entity requires | |
130 | * active reference. | |
cf9e5a73 | 131 | */ |
324a56e1 | 132 | struct kernfs_node { |
adc5e8b5 TH |
133 | atomic_t count; |
134 | atomic_t active; | |
cf9e5a73 TH |
135 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
136 | struct lockdep_map dep_map; | |
137 | #endif | |
3eef34ad TH |
138 | /* |
139 | * Use kernfs_get_parent() and kernfs_name/path() instead of | |
140 | * accessing the following two fields directly. If the node is | |
141 | * never moved to a different parent, it is safe to access the | |
142 | * parent directly. | |
143 | */ | |
adc5e8b5 TH |
144 | struct kernfs_node *parent; |
145 | const char *name; | |
cf9e5a73 | 146 | |
adc5e8b5 | 147 | struct rb_node rb; |
cf9e5a73 | 148 | |
adc5e8b5 | 149 | const void *ns; /* namespace tag */ |
9b0925a6 | 150 | unsigned int hash; /* ns + name hash */ |
cf9e5a73 | 151 | union { |
adc5e8b5 TH |
152 | struct kernfs_elem_dir dir; |
153 | struct kernfs_elem_symlink symlink; | |
154 | struct kernfs_elem_attr attr; | |
cf9e5a73 TH |
155 | }; |
156 | ||
157 | void *priv; | |
158 | ||
c53cd490 | 159 | union kernfs_node_id id; |
adc5e8b5 TH |
160 | unsigned short flags; |
161 | umode_t mode; | |
c525aadd | 162 | struct kernfs_iattrs *iattr; |
cf9e5a73 | 163 | }; |
b8441ed2 | 164 | |
80b9bbef | 165 | /* |
90c07c89 TH |
166 | * kernfs_syscall_ops may be specified on kernfs_create_root() to support |
167 | * syscalls. These optional callbacks are invoked on the matching syscalls | |
168 | * and can perform any kernfs operations which don't necessarily have to be | |
169 | * the exact operation requested. An active reference is held for each | |
170 | * kernfs_node parameter. | |
80b9bbef | 171 | */ |
90c07c89 | 172 | struct kernfs_syscall_ops { |
6a7fed4e TH |
173 | int (*show_options)(struct seq_file *sf, struct kernfs_root *root); |
174 | ||
80b9bbef TH |
175 | int (*mkdir)(struct kernfs_node *parent, const char *name, |
176 | umode_t mode); | |
177 | int (*rmdir)(struct kernfs_node *kn); | |
178 | int (*rename)(struct kernfs_node *kn, struct kernfs_node *new_parent, | |
179 | const char *new_name); | |
4f41fc59 SH |
180 | int (*show_path)(struct seq_file *sf, struct kernfs_node *kn, |
181 | struct kernfs_root *root); | |
80b9bbef TH |
182 | }; |
183 | ||
ba7443bc TH |
184 | struct kernfs_root { |
185 | /* published fields */ | |
324a56e1 | 186 | struct kernfs_node *kn; |
d35258ef | 187 | unsigned int flags; /* KERNFS_ROOT_* flags */ |
bc755553 TH |
188 | |
189 | /* private fields, do not use outside kernfs proper */ | |
7d35079f | 190 | struct idr ino_idr; |
4a3ef68a | 191 | u32 next_generation; |
90c07c89 | 192 | struct kernfs_syscall_ops *syscall_ops; |
7d568a83 TH |
193 | |
194 | /* list of kernfs_super_info of this root, protected by kernfs_mutex */ | |
195 | struct list_head supers; | |
196 | ||
abd54f02 | 197 | wait_queue_head_t deactivate_waitq; |
ba7443bc TH |
198 | }; |
199 | ||
c525aadd | 200 | struct kernfs_open_file { |
dd8a5b03 | 201 | /* published fields */ |
324a56e1 | 202 | struct kernfs_node *kn; |
dd8a5b03 | 203 | struct file *file; |
0e67db2f | 204 | struct seq_file *seq_file; |
2536390d | 205 | void *priv; |
dd8a5b03 TH |
206 | |
207 | /* private fields, do not use outside kernfs proper */ | |
208 | struct mutex mutex; | |
e4234a1f | 209 | struct mutex prealloc_mutex; |
dd8a5b03 TH |
210 | int event; |
211 | struct list_head list; | |
2b75869b | 212 | char *prealloc_buf; |
dd8a5b03 | 213 | |
b7ce40cf | 214 | size_t atomic_write_len; |
a1d82aff | 215 | bool mmapped:1; |
0e67db2f | 216 | bool released:1; |
dd8a5b03 TH |
217 | const struct vm_operations_struct *vm_ops; |
218 | }; | |
219 | ||
f6acf8bb | 220 | struct kernfs_ops { |
0e67db2f TH |
221 | /* |
222 | * Optional open/release methods. Both are called with | |
223 | * @of->seq_file populated. | |
224 | */ | |
225 | int (*open)(struct kernfs_open_file *of); | |
226 | void (*release)(struct kernfs_open_file *of); | |
227 | ||
f6acf8bb TH |
228 | /* |
229 | * Read is handled by either seq_file or raw_read(). | |
230 | * | |
d19b9846 TH |
231 | * If seq_show() is present, seq_file path is active. Other seq |
232 | * operations are optional and if not implemented, the behavior is | |
233 | * equivalent to single_open(). @sf->private points to the | |
c525aadd | 234 | * associated kernfs_open_file. |
f6acf8bb TH |
235 | * |
236 | * read() is bounced through kernel buffer and a read larger than | |
237 | * PAGE_SIZE results in partial operation of PAGE_SIZE. | |
238 | */ | |
239 | int (*seq_show)(struct seq_file *sf, void *v); | |
d19b9846 TH |
240 | |
241 | void *(*seq_start)(struct seq_file *sf, loff_t *ppos); | |
242 | void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos); | |
243 | void (*seq_stop)(struct seq_file *sf, void *v); | |
f6acf8bb | 244 | |
c525aadd | 245 | ssize_t (*read)(struct kernfs_open_file *of, char *buf, size_t bytes, |
f6acf8bb TH |
246 | loff_t off); |
247 | ||
248 | /* | |
4d3773c4 TH |
249 | * write() is bounced through kernel buffer. If atomic_write_len |
250 | * is not set, a write larger than PAGE_SIZE results in partial | |
251 | * operations of PAGE_SIZE chunks. If atomic_write_len is set, | |
252 | * writes upto the specified size are executed atomically but | |
253 | * larger ones are rejected with -E2BIG. | |
f6acf8bb | 254 | */ |
4d3773c4 | 255 | size_t atomic_write_len; |
2b75869b N |
256 | /* |
257 | * "prealloc" causes a buffer to be allocated at open for | |
258 | * all read/write requests. As ->seq_show uses seq_read() | |
259 | * which does its own allocation, it is incompatible with | |
260 | * ->prealloc. Provide ->read and ->write with ->prealloc. | |
261 | */ | |
262 | bool prealloc; | |
c525aadd | 263 | ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t bytes, |
f6acf8bb TH |
264 | loff_t off); |
265 | ||
147e1a97 JW |
266 | __poll_t (*poll)(struct kernfs_open_file *of, |
267 | struct poll_table_struct *pt); | |
268 | ||
c525aadd | 269 | int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma); |
517e64f5 TH |
270 | |
271 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | |
272 | struct lock_class_key lockdep_key; | |
273 | #endif | |
f6acf8bb TH |
274 | }; |
275 | ||
23bf1b6b DH |
276 | /* |
277 | * The kernfs superblock creation/mount parameter context. | |
278 | */ | |
279 | struct kernfs_fs_context { | |
280 | struct kernfs_root *root; /* Root of the hierarchy being mounted */ | |
281 | void *ns_tag; /* Namespace tag of the mount (or NULL) */ | |
282 | unsigned long magic; /* File system specific magic number */ | |
283 | ||
284 | /* The following are set/used by kernfs_mount() */ | |
285 | bool new_sb_created; /* Set to T if we allocated a new sb */ | |
286 | }; | |
287 | ||
ba341d55 | 288 | #ifdef CONFIG_KERNFS |
879f40d1 | 289 | |
df23fc39 | 290 | static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn) |
cf9e5a73 | 291 | { |
df23fc39 | 292 | return kn->flags & KERNFS_TYPE_MASK; |
cf9e5a73 TH |
293 | } |
294 | ||
295 | /** | |
296 | * kernfs_enable_ns - enable namespace under a directory | |
324a56e1 | 297 | * @kn: directory of interest, should be empty |
cf9e5a73 | 298 | * |
324a56e1 TH |
299 | * This is to be called right after @kn is created to enable namespace |
300 | * under it. All children of @kn must have non-NULL namespace tags and | |
cf9e5a73 TH |
301 | * only the ones which match the super_block's tag will be visible. |
302 | */ | |
324a56e1 | 303 | static inline void kernfs_enable_ns(struct kernfs_node *kn) |
cf9e5a73 | 304 | { |
df23fc39 | 305 | WARN_ON_ONCE(kernfs_type(kn) != KERNFS_DIR); |
adc5e8b5 | 306 | WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->dir.children)); |
df23fc39 | 307 | kn->flags |= KERNFS_NS; |
cf9e5a73 TH |
308 | } |
309 | ||
ac9bba03 TH |
310 | /** |
311 | * kernfs_ns_enabled - test whether namespace is enabled | |
324a56e1 | 312 | * @kn: the node to test |
ac9bba03 TH |
313 | * |
314 | * Test whether namespace filtering is enabled for the children of @ns. | |
315 | */ | |
324a56e1 | 316 | static inline bool kernfs_ns_enabled(struct kernfs_node *kn) |
ac9bba03 | 317 | { |
df23fc39 | 318 | return kn->flags & KERNFS_NS; |
ac9bba03 TH |
319 | } |
320 | ||
3eef34ad | 321 | int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen); |
9f6df573 AK |
322 | int kernfs_path_from_node(struct kernfs_node *root_kn, struct kernfs_node *kn, |
323 | char *buf, size_t buflen); | |
3eef34ad TH |
324 | void pr_cont_kernfs_name(struct kernfs_node *kn); |
325 | void pr_cont_kernfs_path(struct kernfs_node *kn); | |
326 | struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn); | |
324a56e1 TH |
327 | struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent, |
328 | const char *name, const void *ns); | |
bd96f76a TH |
329 | struct kernfs_node *kernfs_walk_and_get_ns(struct kernfs_node *parent, |
330 | const char *path, const void *ns); | |
324a56e1 TH |
331 | void kernfs_get(struct kernfs_node *kn); |
332 | void kernfs_put(struct kernfs_node *kn); | |
ccf73cf3 | 333 | |
0c23b225 TH |
334 | struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry); |
335 | struct kernfs_root *kernfs_root_from_sb(struct super_block *sb); | |
fb02915f | 336 | struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn); |
0c23b225 | 337 | |
fb3c8315 AK |
338 | struct dentry *kernfs_node_dentry(struct kernfs_node *kn, |
339 | struct super_block *sb); | |
90c07c89 | 340 | struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops, |
d35258ef | 341 | unsigned int flags, void *priv); |
ba7443bc TH |
342 | void kernfs_destroy_root(struct kernfs_root *root); |
343 | ||
324a56e1 | 344 | struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent, |
bb8b9d09 | 345 | const char *name, umode_t mode, |
488dee96 | 346 | kuid_t uid, kgid_t gid, |
bb8b9d09 | 347 | void *priv, const void *ns); |
ea015218 EB |
348 | struct kernfs_node *kernfs_create_empty_dir(struct kernfs_node *parent, |
349 | const char *name); | |
2063d608 | 350 | struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent, |
488dee96 DT |
351 | const char *name, umode_t mode, |
352 | kuid_t uid, kgid_t gid, | |
353 | loff_t size, | |
2063d608 TH |
354 | const struct kernfs_ops *ops, |
355 | void *priv, const void *ns, | |
2063d608 | 356 | struct lock_class_key *key); |
324a56e1 TH |
357 | struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, |
358 | const char *name, | |
359 | struct kernfs_node *target); | |
d35258ef | 360 | void kernfs_activate(struct kernfs_node *kn); |
324a56e1 | 361 | void kernfs_remove(struct kernfs_node *kn); |
6b0afc2a TH |
362 | void kernfs_break_active_protection(struct kernfs_node *kn); |
363 | void kernfs_unbreak_active_protection(struct kernfs_node *kn); | |
364 | bool kernfs_remove_self(struct kernfs_node *kn); | |
324a56e1 | 365 | int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name, |
879f40d1 | 366 | const void *ns); |
324a56e1 | 367 | int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, |
890ece16 | 368 | const char *new_name, const void *new_ns); |
324a56e1 | 369 | int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr); |
147e1a97 JW |
370 | __poll_t kernfs_generic_poll(struct kernfs_open_file *of, |
371 | struct poll_table_struct *pt); | |
324a56e1 | 372 | void kernfs_notify(struct kernfs_node *kn); |
879f40d1 | 373 | |
1537ad15 OM |
374 | int kernfs_xattr_get(struct kernfs_node *kn, const char *name, |
375 | void *value, size_t size); | |
376 | int kernfs_xattr_set(struct kernfs_node *kn, const char *name, | |
377 | const void *value, size_t size, int flags); | |
b230d5ab | 378 | |
4b93dc9b | 379 | const void *kernfs_super_ns(struct super_block *sb); |
23bf1b6b DH |
380 | int kernfs_get_tree(struct fs_context *fc); |
381 | void kernfs_free_fs_context(struct fs_context *fc); | |
4b93dc9b TH |
382 | void kernfs_kill_sb(struct super_block *sb); |
383 | ||
384 | void kernfs_init(void); | |
385 | ||
69fd5c39 SL |
386 | struct kernfs_node *kernfs_get_node_by_id(struct kernfs_root *root, |
387 | const union kernfs_node_id *id); | |
ba341d55 | 388 | #else /* CONFIG_KERNFS */ |
879f40d1 | 389 | |
df23fc39 | 390 | static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn) |
cf9e5a73 TH |
391 | { return 0; } /* whatever */ |
392 | ||
324a56e1 | 393 | static inline void kernfs_enable_ns(struct kernfs_node *kn) { } |
cf9e5a73 | 394 | |
324a56e1 | 395 | static inline bool kernfs_ns_enabled(struct kernfs_node *kn) |
ac9bba03 TH |
396 | { return false; } |
397 | ||
3eef34ad TH |
398 | static inline int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen) |
399 | { return -ENOSYS; } | |
400 | ||
0e0b2afd TH |
401 | static inline int kernfs_path_from_node(struct kernfs_node *root_kn, |
402 | struct kernfs_node *kn, | |
403 | char *buf, size_t buflen) | |
404 | { return -ENOSYS; } | |
405 | ||
3eef34ad TH |
406 | static inline void pr_cont_kernfs_name(struct kernfs_node *kn) { } |
407 | static inline void pr_cont_kernfs_path(struct kernfs_node *kn) { } | |
408 | ||
409 | static inline struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn) | |
410 | { return NULL; } | |
411 | ||
324a56e1 TH |
412 | static inline struct kernfs_node * |
413 | kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name, | |
ccf73cf3 TH |
414 | const void *ns) |
415 | { return NULL; } | |
bd96f76a TH |
416 | static inline struct kernfs_node * |
417 | kernfs_walk_and_get_ns(struct kernfs_node *parent, const char *path, | |
418 | const void *ns) | |
419 | { return NULL; } | |
ccf73cf3 | 420 | |
324a56e1 TH |
421 | static inline void kernfs_get(struct kernfs_node *kn) { } |
422 | static inline void kernfs_put(struct kernfs_node *kn) { } | |
ccf73cf3 | 423 | |
0c23b225 TH |
424 | static inline struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry) |
425 | { return NULL; } | |
426 | ||
427 | static inline struct kernfs_root *kernfs_root_from_sb(struct super_block *sb) | |
428 | { return NULL; } | |
429 | ||
fb02915f TH |
430 | static inline struct inode * |
431 | kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn) | |
432 | { return NULL; } | |
433 | ||
80b9bbef | 434 | static inline struct kernfs_root * |
d35258ef TH |
435 | kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags, |
436 | void *priv) | |
ba7443bc TH |
437 | { return ERR_PTR(-ENOSYS); } |
438 | ||
439 | static inline void kernfs_destroy_root(struct kernfs_root *root) { } | |
440 | ||
324a56e1 | 441 | static inline struct kernfs_node * |
bb8b9d09 | 442 | kernfs_create_dir_ns(struct kernfs_node *parent, const char *name, |
488dee96 DT |
443 | umode_t mode, kuid_t uid, kgid_t gid, |
444 | void *priv, const void *ns) | |
93b2b8e4 TH |
445 | { return ERR_PTR(-ENOSYS); } |
446 | ||
324a56e1 | 447 | static inline struct kernfs_node * |
2063d608 | 448 | __kernfs_create_file(struct kernfs_node *parent, const char *name, |
488dee96 DT |
449 | umode_t mode, kuid_t uid, kgid_t gid, |
450 | loff_t size, const struct kernfs_ops *ops, | |
dfeb0750 | 451 | void *priv, const void *ns, struct lock_class_key *key) |
496f7394 TH |
452 | { return ERR_PTR(-ENOSYS); } |
453 | ||
324a56e1 TH |
454 | static inline struct kernfs_node * |
455 | kernfs_create_link(struct kernfs_node *parent, const char *name, | |
456 | struct kernfs_node *target) | |
5d0e26bb TH |
457 | { return ERR_PTR(-ENOSYS); } |
458 | ||
d35258ef TH |
459 | static inline void kernfs_activate(struct kernfs_node *kn) { } |
460 | ||
324a56e1 | 461 | static inline void kernfs_remove(struct kernfs_node *kn) { } |
879f40d1 | 462 | |
6b0afc2a TH |
463 | static inline bool kernfs_remove_self(struct kernfs_node *kn) |
464 | { return false; } | |
465 | ||
324a56e1 | 466 | static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn, |
879f40d1 TH |
467 | const char *name, const void *ns) |
468 | { return -ENOSYS; } | |
469 | ||
324a56e1 TH |
470 | static inline int kernfs_rename_ns(struct kernfs_node *kn, |
471 | struct kernfs_node *new_parent, | |
890ece16 TH |
472 | const char *new_name, const void *new_ns) |
473 | { return -ENOSYS; } | |
474 | ||
324a56e1 | 475 | static inline int kernfs_setattr(struct kernfs_node *kn, |
5d60418e TH |
476 | const struct iattr *iattr) |
477 | { return -ENOSYS; } | |
478 | ||
324a56e1 | 479 | static inline void kernfs_notify(struct kernfs_node *kn) { } |
024f6471 | 480 | |
1537ad15 OM |
481 | static inline int kernfs_xattr_get(struct kernfs_node *kn, const char *name, |
482 | void *value, size_t size) | |
b230d5ab OM |
483 | { return -ENOSYS; } |
484 | ||
1537ad15 OM |
485 | static inline int kernfs_xattr_set(struct kernfs_node *kn, const char *name, |
486 | const void *value, size_t size, int flags) | |
b230d5ab OM |
487 | { return -ENOSYS; } |
488 | ||
4b93dc9b TH |
489 | static inline const void *kernfs_super_ns(struct super_block *sb) |
490 | { return NULL; } | |
491 | ||
23bf1b6b DH |
492 | static inline int kernfs_get_tree(struct fs_context *fc) |
493 | { return -ENOSYS; } | |
494 | ||
495 | static inline void kernfs_free_fs_context(struct fs_context *fc) { } | |
4b93dc9b TH |
496 | |
497 | static inline void kernfs_kill_sb(struct super_block *sb) { } | |
498 | ||
499 | static inline void kernfs_init(void) { } | |
500 | ||
ba341d55 | 501 | #endif /* CONFIG_KERNFS */ |
879f40d1 | 502 | |
3abb1d90 TH |
503 | /** |
504 | * kernfs_path - build full path of a given node | |
505 | * @kn: kernfs_node of interest | |
506 | * @buf: buffer to copy @kn's name into | |
507 | * @buflen: size of @buf | |
508 | * | |
8f5be0ec KK |
509 | * If @kn is NULL result will be "(null)". |
510 | * | |
511 | * Returns the length of the full path. If the full length is equal to or | |
512 | * greater than @buflen, @buf contains the truncated path with the trailing | |
513 | * '\0'. On error, -errno is returned. | |
3abb1d90 TH |
514 | */ |
515 | static inline int kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen) | |
516 | { | |
517 | return kernfs_path_from_node(kn, NULL, buf, buflen); | |
518 | } | |
519 | ||
324a56e1 TH |
520 | static inline struct kernfs_node * |
521 | kernfs_find_and_get(struct kernfs_node *kn, const char *name) | |
ccf73cf3 | 522 | { |
324a56e1 | 523 | return kernfs_find_and_get_ns(kn, name, NULL); |
ccf73cf3 TH |
524 | } |
525 | ||
bd96f76a TH |
526 | static inline struct kernfs_node * |
527 | kernfs_walk_and_get(struct kernfs_node *kn, const char *path) | |
528 | { | |
529 | return kernfs_walk_and_get_ns(kn, path, NULL); | |
530 | } | |
531 | ||
324a56e1 | 532 | static inline struct kernfs_node * |
bb8b9d09 TH |
533 | kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode, |
534 | void *priv) | |
93b2b8e4 | 535 | { |
488dee96 DT |
536 | return kernfs_create_dir_ns(parent, name, mode, |
537 | GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, | |
538 | priv, NULL); | |
93b2b8e4 TH |
539 | } |
540 | ||
324a56e1 TH |
541 | static inline struct kernfs_node * |
542 | kernfs_create_file_ns(struct kernfs_node *parent, const char *name, | |
488dee96 DT |
543 | umode_t mode, kuid_t uid, kgid_t gid, |
544 | loff_t size, const struct kernfs_ops *ops, | |
517e64f5 TH |
545 | void *priv, const void *ns) |
546 | { | |
547 | struct lock_class_key *key = NULL; | |
548 | ||
549 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | |
550 | key = (struct lock_class_key *)&ops->lockdep_key; | |
551 | #endif | |
488dee96 DT |
552 | return __kernfs_create_file(parent, name, mode, uid, gid, |
553 | size, ops, priv, ns, key); | |
517e64f5 TH |
554 | } |
555 | ||
324a56e1 TH |
556 | static inline struct kernfs_node * |
557 | kernfs_create_file(struct kernfs_node *parent, const char *name, umode_t mode, | |
496f7394 TH |
558 | loff_t size, const struct kernfs_ops *ops, void *priv) |
559 | { | |
488dee96 DT |
560 | return kernfs_create_file_ns(parent, name, mode, |
561 | GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, | |
562 | size, ops, priv, NULL); | |
496f7394 TH |
563 | } |
564 | ||
324a56e1 | 565 | static inline int kernfs_remove_by_name(struct kernfs_node *parent, |
879f40d1 TH |
566 | const char *name) |
567 | { | |
568 | return kernfs_remove_by_name_ns(parent, name, NULL); | |
569 | } | |
570 | ||
0c23b225 TH |
571 | static inline int kernfs_rename(struct kernfs_node *kn, |
572 | struct kernfs_node *new_parent, | |
573 | const char *new_name) | |
574 | { | |
575 | return kernfs_rename_ns(kn, new_parent, new_name, NULL); | |
576 | } | |
577 | ||
b8441ed2 | 578 | #endif /* __LINUX_KERNFS_H */ |