1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * kernfs.h - pseudo filesystem decoupled from vfs locking
4 */
5
6 #ifndef __LINUX_KERNFS_H
7 #define __LINUX_KERNFS_H
8
9 #include <linux/err.h>
10 #include <linux/list.h>
11 #include <linux/mutex.h>
12 #include <linux/idr.h>
13 #include <linux/lockdep.h>
14 #include <linux/rbtree.h>
15 #include <linux/atomic.h>
16 #include <linux/bug.h>
17 #include <linux/types.h>
18 #include <linux/uidgid.h>
19 #include <linux/wait.h>
20 #include <linux/rwsem.h>
21 #include <linux/cache.h>
22
23 struct file;
24 struct dentry;
25 struct iattr;
26 struct ns_common;
27 struct seq_file;
28 struct vm_area_struct;
29 struct vm_operations_struct;
30 struct super_block;
31 struct file_system_type;
32 struct poll_table_struct;
33 struct fs_context;
34
35 struct kernfs_fs_context;
36 struct kernfs_open_node;
37 struct kernfs_iattrs;
38
39 /*
40 * NR_KERNFS_LOCK_BITS determines size (NR_KERNFS_LOCKS) of hash
41 * table of locks.
42 * Having a small hash table would impact scalability, since
43 * more and more kernfs_node objects will end up using same lock
44 * and having a very large hash table would waste memory.
45 *
46 * At the moment size of hash table of locks is being set based on
47 * the number of CPUs as follows:
48 *
49 * NR_CPU NR_KERNFS_LOCK_BITS NR_KERNFS_LOCKS
50 * 1 1 2
51 * 2-3 2 4
52 * 4-7 4 16
53 * 8-15 6 64
54 * 16-31 8 256
55 * 32 and more 10 1024
56 *
57 * The above relation between NR_CPU and number of locks is based
58 * on some internal experimentation which involved booting qemu
59 * with different values of smp, performing some sysfs operations
60 * on all CPUs and observing how increase in number of locks impacts
61 * completion time of these sysfs operations on each CPU.
62 */
63 #ifdef CONFIG_SMP
64 #define NR_KERNFS_LOCK_BITS (2 * (ilog2(NR_CPUS < 32 ? NR_CPUS : 32)))
65 #else
66 #define NR_KERNFS_LOCK_BITS 1
67 #endif
68
69 #define NR_KERNFS_LOCKS (1 << NR_KERNFS_LOCK_BITS)
70
71 /*
72 * There's one kernfs_open_file for each open file and one kernfs_open_node
73 * for each kernfs_node with one or more open files.
74 *
75 * filp->private_data points to seq_file whose ->private points to
76 * kernfs_open_file.
77 *
78 * kernfs_open_files are chained at kernfs_open_node->files, which is
79 * protected by kernfs_global_locks.open_file_mutex[i].
80 *
81 * To reduce possible contention in sysfs access, arising due to single
82 * locks, use an array of locks (e.g. open_file_mutex) and use kernfs_node
83 * object address as hash keys to get the index of these locks.
84 *
85 * Hashed mutexes are safe to use here because operations using these don't
86 * rely on global exclusion.
87 *
88 * In future we intend to replace other global locks with hashed ones as well.
89 * kernfs_global_locks acts as a holder for all such hash tables.
90 */
91 struct kernfs_global_locks {
92 struct mutex open_file_mutex[NR_KERNFS_LOCKS];
93 };
94
95 enum kernfs_node_type {
96 KERNFS_DIR = 0x0001,
97 KERNFS_FILE = 0x0002,
98 KERNFS_LINK = 0x0004,
99 };
100
101 #define KERNFS_TYPE_MASK 0x000f
102 #define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK
103 #define KERNFS_MAX_USER_XATTRS 128
104 #define KERNFS_USER_XATTR_SIZE_LIMIT (128 << 10)
105
106 enum kernfs_node_flag {
107 KERNFS_ACTIVATED = 0x0010,
108 KERNFS_NS = 0x0020,
109 KERNFS_HAS_SEQ_SHOW = 0x0040,
110 KERNFS_HAS_MMAP = 0x0080,
111 KERNFS_LOCKDEP = 0x0100,
112 KERNFS_HIDDEN = 0x0200,
113 KERNFS_SUICIDAL = 0x0400,
114 KERNFS_SUICIDED = 0x0800,
115 KERNFS_EMPTY_DIR = 0x1000,
116 KERNFS_HAS_RELEASE = 0x2000,
117 KERNFS_REMOVING = 0x4000,
118 };
119
120 /* @flags for kernfs_create_root() */
121 enum kernfs_root_flag {
122 /*
123 * kernfs_nodes are created in the deactivated state and invisible.
124 * They require explicit kernfs_activate() to become visible. This
125 * can be used to make related nodes become visible atomically
126 * after all nodes are created successfully.
127 */
128 KERNFS_ROOT_CREATE_DEACTIVATED = 0x0001,
129
130 /*
131 * For regular files, if the opener has CAP_DAC_OVERRIDE, open(2)
132 * succeeds regardless of the RW permissions. sysfs had an extra
133 * layer of enforcement where open(2) fails with -EACCES regardless
134 * of CAP_DAC_OVERRIDE if the permission doesn't have the
135 * respective read or write access at all (none of S_IRUGO or
136 * S_IWUGO) or the respective operation isn't implemented. The
137 * following flag enables that behavior.
138 */
139 KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK = 0x0002,
140
141 /*
142 * The filesystem supports exportfs operation, so userspace can use
143 * fhandle to access nodes of the fs.
144 */
145 KERNFS_ROOT_SUPPORT_EXPORTOP = 0x0004,
146
147 /*
148 * Support user xattrs to be written to nodes rooted at this root.
149 */
150 KERNFS_ROOT_SUPPORT_USER_XATTR = 0x0008,
151
152 /*
153 * Renames must not change the parent node.
154 */
155 KERNFS_ROOT_INVARIANT_PARENT = 0x0010,
156 };
157
158 /* type-specific structures for kernfs_node union members */
159 struct kernfs_elem_dir {
160 unsigned long subdirs;
161 /* children rbtree starts here and goes through kn->rb */
162 struct rb_root children;
163
164 /*
165 * The kernfs hierarchy this directory belongs to. This fits
166 * better directly in kernfs_node but is here to save space.
167 */
168 struct kernfs_root *root;
169 /*
170 * Monotonic revision counter, used to identify if a directory
171 * node has changed during negative dentry revalidation.
172 */
173 unsigned long rev;
174 };
175
176 struct kernfs_elem_symlink {
177 struct kernfs_node *target_kn;
178 };
179
180 struct kernfs_elem_attr {
181 const struct kernfs_ops *ops;
182 struct kernfs_open_node __rcu *open;
183 loff_t size;
184 struct kernfs_node *notify_next; /* for kernfs_notify() */
185 };
186
187 /*
188 * kernfs_node - the building block of kernfs hierarchy. Each and every
189 * kernfs node is represented by single kernfs_node. Most fields are
190 * private to kernfs and shouldn't be accessed directly by kernfs users.
191 *
192 * As long as count reference is held, the kernfs_node itself is
193 * accessible. Dereferencing elem or any other outer entity requires
194 * active reference.
195 */
196 struct kernfs_node {
197 atomic_t count;
198 atomic_t active;
199 #ifdef CONFIG_DEBUG_LOCK_ALLOC
200 struct lockdep_map dep_map;
201 #endif
202 /*
203 * Use kernfs_get_parent() and kernfs_name/path() instead of
204 * accessing the following two fields directly. If the node is
205 * never moved to a different parent, it is safe to access the
206 * parent directly.
207 */
208 struct kernfs_node __rcu *__parent;
209 const char __rcu *name;
210
211 struct rb_node rb;
212
213 const struct ns_common *ns; /* namespace tag */
214 unsigned int hash; /* ns + name hash */
215 unsigned short flags;
216 umode_t mode;
217
218 union {
219 struct kernfs_elem_dir dir;
220 struct kernfs_elem_symlink symlink;
221 struct kernfs_elem_attr attr;
222 };
223
224 /*
225 * 64bit unique ID. On 64bit ino setups, id is the ino. On 32bit,
226 * the low 32bits are ino and upper generation.
227 */
228 u64 id;
229
230 void *priv;
231 struct kernfs_iattrs *iattr;
232
233 struct rcu_head rcu;
234 };
235
236 /*
237 * kernfs_syscall_ops may be specified on kernfs_create_root() to support
238 * syscalls. These optional callbacks are invoked on the matching syscalls
239 * and can perform any kernfs operations which don't necessarily have to be
240 * the exact operation requested. An active reference is held for each
241 * kernfs_node parameter.
242 */
243 struct kernfs_syscall_ops {
244 int (*show_options)(struct seq_file *sf, struct kernfs_root *root);
245
246 int (*mkdir)(struct kernfs_node *parent, const char *name,
247 umode_t mode);
248 int (*rmdir)(struct kernfs_node *kn);
249 int (*rename)(struct kernfs_node *kn, struct kernfs_node *new_parent,
250 const char *new_name);
251 int (*show_path)(struct seq_file *sf, struct kernfs_node *kn,
252 struct kernfs_root *root);
253 };
254
255 struct kernfs_node *kernfs_root_to_node(struct kernfs_root *root);
256
257 struct kernfs_open_file {
258 /* published fields */
259 struct kernfs_node *kn;
260 struct file *file;
261 struct seq_file *seq_file;
262 void *priv;
263
264 /* private fields, do not use outside kernfs proper */
265 struct mutex mutex;
266 struct mutex prealloc_mutex;
267 int event;
268 struct list_head list;
269 char *prealloc_buf;
270
271 size_t atomic_write_len;
272 bool mmapped:1;
273 bool released:1;
274 const struct vm_operations_struct *vm_ops;
275 };
276
277 struct kernfs_ops {
278 /*
279 * Optional open/release methods. Both are called with
280 * @of->seq_file populated.
281 */
282 int (*open)(struct kernfs_open_file *of);
283 void (*release)(struct kernfs_open_file *of);
284
285 /*
286 * Read is handled by either seq_file or raw_read().
287 *
288 * If seq_show() is present, seq_file path is active. Other seq
289 * operations are optional and if not implemented, the behavior is
290 * equivalent to single_open(). @sf->private points to the
291 * associated kernfs_open_file.
292 *
293 * read() is bounced through kernel buffer and a read larger than
294 * PAGE_SIZE results in partial operation of PAGE_SIZE.
295 */
296 int (*seq_show)(struct seq_file *sf, void *v);
297
298 void *(*seq_start)(struct seq_file *sf, loff_t *ppos);
299 void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos);
300 void (*seq_stop)(struct seq_file *sf, void *v);
301
302 ssize_t (*read)(struct kernfs_open_file *of, char *buf, size_t bytes,
303 loff_t off);
304
305 /*
306 * write() is bounced through kernel buffer. If atomic_write_len
307 * is not set, a write larger than PAGE_SIZE results in partial
308 * operations of PAGE_SIZE chunks. If atomic_write_len is set,
309 * writes upto the specified size are executed atomically but
310 * larger ones are rejected with -E2BIG.
311 */
312 size_t atomic_write_len;
313 /*
314 * "prealloc" causes a buffer to be allocated at open for
315 * all read/write requests. As ->seq_show uses seq_read()
316 * which does its own allocation, it is incompatible with
317 * ->prealloc. Provide ->read and ->write with ->prealloc.
318 */
319 bool prealloc;
320 ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t bytes,
321 loff_t off);
322
323 __poll_t (*poll)(struct kernfs_open_file *of,
324 struct poll_table_struct *pt);
325
326 int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma);
327 loff_t (*llseek)(struct kernfs_open_file *of, loff_t offset, int whence);
328 };
329
330 /*
331 * The kernfs superblock creation/mount parameter context.
332 */
333 struct kernfs_fs_context {
334 struct kernfs_root *root; /* Root of the hierarchy being mounted */
335 struct ns_common *ns_tag; /* Namespace tag of the mount (or NULL) */
336 unsigned long magic; /* File system specific magic number */
337
338 /* The following are set/used by kernfs_mount() */
339 bool new_sb_created; /* Set to T if we allocated a new sb */
340 };
341
342 #ifdef CONFIG_KERNFS
343
kernfs_type(struct kernfs_node * kn)344 static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn)
345 {
346 return kn->flags & KERNFS_TYPE_MASK;
347 }
348
kernfs_id_ino(u64 id)349 static inline ino_t kernfs_id_ino(u64 id)
350 {
351 /* id is ino if ino_t is 64bit; otherwise, low 32bits */
352 if (sizeof(ino_t) >= sizeof(u64))
353 return id;
354 else
355 return (u32)id;
356 }
357
kernfs_id_gen(u64 id)358 static inline u32 kernfs_id_gen(u64 id)
359 {
360 /* gen is fixed at 1 if ino_t is 64bit; otherwise, high 32bits */
361 if (sizeof(ino_t) >= sizeof(u64))
362 return 1;
363 else
364 return id >> 32;
365 }
366
kernfs_ino(struct kernfs_node * kn)367 static inline ino_t kernfs_ino(struct kernfs_node *kn)
368 {
369 return kernfs_id_ino(kn->id);
370 }
371
kernfs_gen(struct kernfs_node * kn)372 static inline ino_t kernfs_gen(struct kernfs_node *kn)
373 {
374 return kernfs_id_gen(kn->id);
375 }
376
377 /**
378 * kernfs_enable_ns - enable namespace under a directory
379 * @kn: directory of interest, should be empty
380 *
381 * This is to be called right after @kn is created to enable namespace
382 * under it. All children of @kn must have non-NULL namespace tags and
383 * only the ones which match the super_block's tag will be visible.
384 */
kernfs_enable_ns(struct kernfs_node * kn)385 static inline void kernfs_enable_ns(struct kernfs_node *kn)
386 {
387 WARN_ON_ONCE(kernfs_type(kn) != KERNFS_DIR);
388 WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->dir.children));
389 kn->flags |= KERNFS_NS;
390 }
391
392 /**
393 * kernfs_ns_enabled - test whether namespace is enabled
394 * @kn: the node to test
395 *
396 * Test whether namespace filtering is enabled for the children of @ns.
397 */
kernfs_ns_enabled(struct kernfs_node * kn)398 static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
399 {
400 return kn->flags & KERNFS_NS;
401 }
402
403 int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen);
404 int kernfs_path_from_node(struct kernfs_node *kn_to, struct kernfs_node *kn_from,
405 char *buf, size_t buflen);
406 void pr_cont_kernfs_name(struct kernfs_node *kn);
407 void pr_cont_kernfs_path(struct kernfs_node *kn);
408 struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn);
409 struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
410 const char *name,
411 const struct ns_common *ns);
412 struct kernfs_node *kernfs_walk_and_get_ns(struct kernfs_node *parent,
413 const char *path,
414 const struct ns_common *ns);
415 void kernfs_get(struct kernfs_node *kn);
416 void kernfs_put(struct kernfs_node *kn);
417
418 struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry);
419 struct kernfs_root *kernfs_root_from_sb(struct super_block *sb);
420 struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn);
421
422 struct dentry *kernfs_node_dentry(struct kernfs_node *kn,
423 struct super_block *sb);
424 struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops,
425 unsigned int flags, void *priv);
426 void kernfs_destroy_root(struct kernfs_root *root);
427 unsigned int kernfs_root_flags(struct kernfs_node *kn);
428
429 struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
430 const char *name, umode_t mode,
431 kuid_t uid, kgid_t gid,
432 void *priv,
433 const struct ns_common *ns);
434 struct kernfs_node *kernfs_create_empty_dir(struct kernfs_node *parent,
435 const char *name);
436 struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
437 const char *name, umode_t mode,
438 kuid_t uid, kgid_t gid,
439 loff_t size,
440 const struct kernfs_ops *ops,
441 void *priv,
442 const struct ns_common *ns,
443 struct lock_class_key *key);
444 struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
445 const char *name,
446 struct kernfs_node *target);
447 void kernfs_activate(struct kernfs_node *kn);
448 void kernfs_show(struct kernfs_node *kn, bool show);
449 void kernfs_remove(struct kernfs_node *kn);
450 void kernfs_break_active_protection(struct kernfs_node *kn);
451 void kernfs_unbreak_active_protection(struct kernfs_node *kn);
452 bool kernfs_remove_self(struct kernfs_node *kn);
453 int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name,
454 const struct ns_common *ns);
455 int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
456 const char *new_name, const struct ns_common *new_ns);
457 int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);
458 __poll_t kernfs_generic_poll(struct kernfs_open_file *of,
459 struct poll_table_struct *pt);
460 void kernfs_notify(struct kernfs_node *kn);
461
462 int kernfs_xattr_get(struct kernfs_node *kn, const char *name,
463 void *value, size_t size);
464 int kernfs_xattr_set(struct kernfs_node *kn, const char *name,
465 const void *value, size_t size, int flags);
466
467 const struct ns_common *kernfs_super_ns(struct super_block *sb);
468 int kernfs_get_tree(struct fs_context *fc);
469 void kernfs_free_fs_context(struct fs_context *fc);
470 void kernfs_kill_sb(struct super_block *sb);
471
472 void kernfs_init(void);
473
474 struct kernfs_node *kernfs_find_and_get_node_by_id(struct kernfs_root *root,
475 u64 id);
476 #else /* CONFIG_KERNFS */
477
kernfs_type(struct kernfs_node * kn)478 static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn)
479 { return 0; } /* whatever */
480
kernfs_enable_ns(struct kernfs_node * kn)481 static inline void kernfs_enable_ns(struct kernfs_node *kn) { }
482
kernfs_ns_enabled(struct kernfs_node * kn)483 static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
484 { return false; }
485
kernfs_name(struct kernfs_node * kn,char * buf,size_t buflen)486 static inline int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen)
487 { return -ENOSYS; }
488
kernfs_path_from_node(struct kernfs_node * root_kn,struct kernfs_node * kn,char * buf,size_t buflen)489 static inline int kernfs_path_from_node(struct kernfs_node *root_kn,
490 struct kernfs_node *kn,
491 char *buf, size_t buflen)
492 { return -ENOSYS; }
493
pr_cont_kernfs_name(struct kernfs_node * kn)494 static inline void pr_cont_kernfs_name(struct kernfs_node *kn) { }
pr_cont_kernfs_path(struct kernfs_node * kn)495 static inline void pr_cont_kernfs_path(struct kernfs_node *kn) { }
496
kernfs_get_parent(struct kernfs_node * kn)497 static inline struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
498 { return NULL; }
499
500 static inline struct kernfs_node *
kernfs_find_and_get_ns(struct kernfs_node * parent,const char * name,const struct ns_common * ns)501 kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name,
502 const struct ns_common *ns)
503 { return NULL; }
504 static inline struct kernfs_node *
kernfs_walk_and_get_ns(struct kernfs_node * parent,const char * path,const struct ns_common * ns)505 kernfs_walk_and_get_ns(struct kernfs_node *parent, const char *path,
506 const struct ns_common *ns)
507 { return NULL; }
508
kernfs_get(struct kernfs_node * kn)509 static inline void kernfs_get(struct kernfs_node *kn) { }
kernfs_put(struct kernfs_node * kn)510 static inline void kernfs_put(struct kernfs_node *kn) { }
511
kernfs_node_from_dentry(struct dentry * dentry)512 static inline struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry)
513 { return NULL; }
514
kernfs_root_from_sb(struct super_block * sb)515 static inline struct kernfs_root *kernfs_root_from_sb(struct super_block *sb)
516 { return NULL; }
517
518 static inline struct inode *
kernfs_get_inode(struct super_block * sb,struct kernfs_node * kn)519 kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
520 { return NULL; }
521
522 static inline struct kernfs_root *
kernfs_create_root(struct kernfs_syscall_ops * scops,unsigned int flags,void * priv)523 kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags,
524 void *priv)
525 { return ERR_PTR(-ENOSYS); }
526
kernfs_destroy_root(struct kernfs_root * root)527 static inline void kernfs_destroy_root(struct kernfs_root *root) { }
kernfs_root_flags(struct kernfs_node * kn)528 static inline unsigned int kernfs_root_flags(struct kernfs_node *kn)
529 { return 0; }
530
531 static inline struct kernfs_node *
kernfs_create_dir_ns(struct kernfs_node * parent,const char * name,umode_t mode,kuid_t uid,kgid_t gid,void * priv,const struct ns_common * ns)532 kernfs_create_dir_ns(struct kernfs_node *parent, const char *name,
533 umode_t mode, kuid_t uid, kgid_t gid,
534 void *priv, const struct ns_common *ns)
535 { return ERR_PTR(-ENOSYS); }
536
537 static inline struct kernfs_node *
__kernfs_create_file(struct kernfs_node * parent,const char * name,umode_t mode,kuid_t uid,kgid_t gid,loff_t size,const struct kernfs_ops * ops,void * priv,const struct ns_common * ns,struct lock_class_key * key)538 __kernfs_create_file(struct kernfs_node *parent, const char *name,
539 umode_t mode, kuid_t uid, kgid_t gid,
540 loff_t size, const struct kernfs_ops *ops,
541 void *priv, const struct ns_common *ns,
542 struct lock_class_key *key)
543 { return ERR_PTR(-ENOSYS); }
544
545 static inline struct kernfs_node *
kernfs_create_link(struct kernfs_node * parent,const char * name,struct kernfs_node * target)546 kernfs_create_link(struct kernfs_node *parent, const char *name,
547 struct kernfs_node *target)
548 { return ERR_PTR(-ENOSYS); }
549
kernfs_activate(struct kernfs_node * kn)550 static inline void kernfs_activate(struct kernfs_node *kn) { }
551
kernfs_remove(struct kernfs_node * kn)552 static inline void kernfs_remove(struct kernfs_node *kn) { }
553
kernfs_remove_self(struct kernfs_node * kn)554 static inline bool kernfs_remove_self(struct kernfs_node *kn)
555 { return false; }
556
kernfs_remove_by_name_ns(struct kernfs_node * kn,const char * name,const struct ns_common * ns)557 static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn,
558 const char *name,
559 const struct ns_common *ns)
560 { return -ENOSYS; }
561
kernfs_rename_ns(struct kernfs_node * kn,struct kernfs_node * new_parent,const char * new_name,const struct ns_common * new_ns)562 static inline int kernfs_rename_ns(struct kernfs_node *kn,
563 struct kernfs_node *new_parent,
564 const char *new_name,
565 const struct ns_common *new_ns)
566 { return -ENOSYS; }
567
kernfs_setattr(struct kernfs_node * kn,const struct iattr * iattr)568 static inline int kernfs_setattr(struct kernfs_node *kn,
569 const struct iattr *iattr)
570 { return -ENOSYS; }
571
kernfs_generic_poll(struct kernfs_open_file * of,struct poll_table_struct * pt)572 static inline __poll_t kernfs_generic_poll(struct kernfs_open_file *of,
573 struct poll_table_struct *pt)
574 { return -ENOSYS; }
575
kernfs_notify(struct kernfs_node * kn)576 static inline void kernfs_notify(struct kernfs_node *kn) { }
577
kernfs_xattr_get(struct kernfs_node * kn,const char * name,void * value,size_t size)578 static inline int kernfs_xattr_get(struct kernfs_node *kn, const char *name,
579 void *value, size_t size)
580 { return -ENOSYS; }
581
kernfs_xattr_set(struct kernfs_node * kn,const char * name,const void * value,size_t size,int flags)582 static inline int kernfs_xattr_set(struct kernfs_node *kn, const char *name,
583 const void *value, size_t size, int flags)
584 { return -ENOSYS; }
585
kernfs_super_ns(struct super_block * sb)586 static inline const struct ns_common *kernfs_super_ns(struct super_block *sb)
587 { return NULL; }
588
kernfs_get_tree(struct fs_context * fc)589 static inline int kernfs_get_tree(struct fs_context *fc)
590 { return -ENOSYS; }
591
kernfs_free_fs_context(struct fs_context * fc)592 static inline void kernfs_free_fs_context(struct fs_context *fc) { }
593
kernfs_kill_sb(struct super_block * sb)594 static inline void kernfs_kill_sb(struct super_block *sb) { }
595
kernfs_init(void)596 static inline void kernfs_init(void) { }
597
598 #endif /* CONFIG_KERNFS */
599
600 /**
601 * kernfs_path - build full path of a given node
602 * @kn: kernfs_node of interest
603 * @buf: buffer to copy @kn's name into
604 * @buflen: size of @buf
605 *
606 * If @kn is NULL result will be "(null)".
607 *
608 * Returns the length of the full path. If the full length is equal to or
609 * greater than @buflen, @buf contains the truncated path with the trailing
610 * '\0'. On error, -errno is returned.
611 */
kernfs_path(struct kernfs_node * kn,char * buf,size_t buflen)612 static inline int kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen)
613 {
614 return kernfs_path_from_node(kn, NULL, buf, buflen);
615 }
616
617 static inline struct kernfs_node *
kernfs_find_and_get(struct kernfs_node * kn,const char * name)618 kernfs_find_and_get(struct kernfs_node *kn, const char *name)
619 {
620 return kernfs_find_and_get_ns(kn, name, NULL);
621 }
622
623 static inline struct kernfs_node *
kernfs_walk_and_get(struct kernfs_node * kn,const char * path)624 kernfs_walk_and_get(struct kernfs_node *kn, const char *path)
625 {
626 return kernfs_walk_and_get_ns(kn, path, NULL);
627 }
628
629 static inline struct kernfs_node *
kernfs_create_dir(struct kernfs_node * parent,const char * name,umode_t mode,void * priv)630 kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode,
631 void *priv)
632 {
633 return kernfs_create_dir_ns(parent, name, mode,
634 GLOBAL_ROOT_UID, GLOBAL_ROOT_GID,
635 priv, NULL);
636 }
637
kernfs_remove_by_name(struct kernfs_node * parent,const char * name)638 static inline int kernfs_remove_by_name(struct kernfs_node *parent,
639 const char *name)
640 {
641 return kernfs_remove_by_name_ns(parent, name, NULL);
642 }
643
kernfs_rename(struct kernfs_node * kn,struct kernfs_node * new_parent,const char * new_name)644 static inline int kernfs_rename(struct kernfs_node *kn,
645 struct kernfs_node *new_parent,
646 const char *new_name)
647 {
648 return kernfs_rename_ns(kn, new_parent, new_name, NULL);
649 }
650
651 #endif /* __LINUX_KERNFS_H */
652