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