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 #include <linux/android_kabi.h>
23
24 struct file;
25 struct dentry;
26 struct iattr;
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 /* type-specific structures for kernfs_node union members */
154 struct kernfs_elem_dir {
155 unsigned long subdirs;
156 /* children rbtree starts here and goes through kn->rb */
157 struct rb_root children;
158
159 /*
160 * The kernfs hierarchy this directory belongs to. This fits
161 * better directly in kernfs_node but is here to save space.
162 */
163 struct kernfs_root *root;
164 /*
165 * Monotonic revision counter, used to identify if a directory
166 * node has changed during negative dentry revalidation.
167 */
168 unsigned long rev;
169 };
170
171 struct kernfs_elem_symlink {
172 struct kernfs_node *target_kn;
173 };
174
175 struct kernfs_elem_attr {
176 const struct kernfs_ops *ops;
177 struct kernfs_open_node __rcu *open;
178 loff_t size;
179 struct kernfs_node *notify_next; /* for kernfs_notify() */
180 };
181
182 /*
183 * kernfs_node - the building block of kernfs hierarchy. Each and every
184 * kernfs node is represented by single kernfs_node. Most fields are
185 * private to kernfs and shouldn't be accessed directly by kernfs users.
186 *
187 * As long as count reference is held, the kernfs_node itself is
188 * accessible. Dereferencing elem or any other outer entity requires
189 * active reference.
190 */
191 struct kernfs_node {
192 atomic_t count;
193 atomic_t active;
194 #ifdef CONFIG_DEBUG_LOCK_ALLOC
195 struct lockdep_map dep_map;
196 #endif
197 /*
198 * Use kernfs_get_parent() and kernfs_name/path() instead of
199 * accessing the following two fields directly. If the node is
200 * never moved to a different parent, it is safe to access the
201 * parent directly.
202 */
203 struct kernfs_node *parent;
204 const char *name;
205
206 struct rb_node rb;
207
208 const void *ns; /* namespace tag */
209 unsigned int hash; /* ns + name hash */
210 unsigned short flags;
211 umode_t mode;
212
213 union {
214 struct kernfs_elem_dir dir;
215 struct kernfs_elem_symlink symlink;
216 struct kernfs_elem_attr attr;
217 };
218
219 /*
220 * 64bit unique ID. On 64bit ino setups, id is the ino. On 32bit,
221 * the low 32bits are ino and upper generation.
222 */
223 u64 id;
224
225 void *priv;
226 struct kernfs_iattrs *iattr;
227
228 struct rcu_head rcu;
229 ANDROID_KABI_RESERVE(1);
230 };
231
232 /*
233 * kernfs_syscall_ops may be specified on kernfs_create_root() to support
234 * syscalls. These optional callbacks are invoked on the matching syscalls
235 * and can perform any kernfs operations which don't necessarily have to be
236 * the exact operation requested. An active reference is held for each
237 * kernfs_node parameter.
238 */
239 struct kernfs_syscall_ops {
240 int (*show_options)(struct seq_file *sf, struct kernfs_root *root);
241
242 int (*mkdir)(struct kernfs_node *parent, const char *name,
243 umode_t mode);
244 int (*rmdir)(struct kernfs_node *kn);
245 int (*rename)(struct kernfs_node *kn, struct kernfs_node *new_parent,
246 const char *new_name);
247 int (*show_path)(struct seq_file *sf, struct kernfs_node *kn,
248 struct kernfs_root *root);
249
250 ANDROID_KABI_RESERVE(1);
251 ANDROID_KABI_RESERVE(2);
252 ANDROID_KABI_RESERVE(3);
253 ANDROID_KABI_RESERVE(4);
254 };
255
256 struct kernfs_node *kernfs_root_to_node(struct kernfs_root *root);
257
258 struct kernfs_open_file {
259 /* published fields */
260 struct kernfs_node *kn;
261 struct file *file;
262 struct seq_file *seq_file;
263 void *priv;
264
265 /* private fields, do not use outside kernfs proper */
266 struct mutex mutex;
267 struct mutex prealloc_mutex;
268 int event;
269 struct list_head list;
270 char *prealloc_buf;
271
272 size_t atomic_write_len;
273 bool mmapped:1;
274 bool released:1;
275 const struct vm_operations_struct *vm_ops;
276
277 ANDROID_KABI_RESERVE(1);
278 };
279
280 struct kernfs_ops {
281 /*
282 * Optional open/release methods. Both are called with
283 * @of->seq_file populated.
284 */
285 int (*open)(struct kernfs_open_file *of);
286 void (*release)(struct kernfs_open_file *of);
287
288 /*
289 * Read is handled by either seq_file or raw_read().
290 *
291 * If seq_show() is present, seq_file path is active. Other seq
292 * operations are optional and if not implemented, the behavior is
293 * equivalent to single_open(). @sf->private points to the
294 * associated kernfs_open_file.
295 *
296 * read() is bounced through kernel buffer and a read larger than
297 * PAGE_SIZE results in partial operation of PAGE_SIZE.
298 */
299 int (*seq_show)(struct seq_file *sf, void *v);
300
301 void *(*seq_start)(struct seq_file *sf, loff_t *ppos);
302 void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos);
303 void (*seq_stop)(struct seq_file *sf, void *v);
304
305 ssize_t (*read)(struct kernfs_open_file *of, char *buf, size_t bytes,
306 loff_t off);
307
308 /*
309 * write() is bounced through kernel buffer. If atomic_write_len
310 * is not set, a write larger than PAGE_SIZE results in partial
311 * operations of PAGE_SIZE chunks. If atomic_write_len is set,
312 * writes upto the specified size are executed atomically but
313 * larger ones are rejected with -E2BIG.
314 */
315 size_t atomic_write_len;
316 /*
317 * "prealloc" causes a buffer to be allocated at open for
318 * all read/write requests. As ->seq_show uses seq_read()
319 * which does its own allocation, it is incompatible with
320 * ->prealloc. Provide ->read and ->write with ->prealloc.
321 */
322 bool prealloc;
323 ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t bytes,
324 loff_t off);
325
326 __poll_t (*poll)(struct kernfs_open_file *of,
327 struct poll_table_struct *pt);
328
329 int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma);
330 loff_t (*llseek)(struct kernfs_open_file *of, loff_t offset, int whence);
331
332 ANDROID_KABI_RESERVE(1);
333 ANDROID_KABI_RESERVE(2);
334 };
335
336 /*
337 * The kernfs superblock creation/mount parameter context.
338 */
339 struct kernfs_fs_context {
340 struct kernfs_root *root; /* Root of the hierarchy being mounted */
341 void *ns_tag; /* Namespace tag of the mount (or NULL) */
342 unsigned long magic; /* File system specific magic number */
343
344 /* The following are set/used by kernfs_mount() */
345 bool new_sb_created; /* Set to T if we allocated a new sb */
346 };
347
348 #ifdef CONFIG_KERNFS
349
kernfs_type(struct kernfs_node * kn)350 static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn)
351 {
352 return kn->flags & KERNFS_TYPE_MASK;
353 }
354
kernfs_id_ino(u64 id)355 static inline ino_t kernfs_id_ino(u64 id)
356 {
357 /* id is ino if ino_t is 64bit; otherwise, low 32bits */
358 if (sizeof(ino_t) >= sizeof(u64))
359 return id;
360 else
361 return (u32)id;
362 }
363
kernfs_id_gen(u64 id)364 static inline u32 kernfs_id_gen(u64 id)
365 {
366 /* gen is fixed at 1 if ino_t is 64bit; otherwise, high 32bits */
367 if (sizeof(ino_t) >= sizeof(u64))
368 return 1;
369 else
370 return id >> 32;
371 }
372
kernfs_ino(struct kernfs_node * kn)373 static inline ino_t kernfs_ino(struct kernfs_node *kn)
374 {
375 return kernfs_id_ino(kn->id);
376 }
377
kernfs_gen(struct kernfs_node * kn)378 static inline ino_t kernfs_gen(struct kernfs_node *kn)
379 {
380 return kernfs_id_gen(kn->id);
381 }
382
383 /**
384 * kernfs_enable_ns - enable namespace under a directory
385 * @kn: directory of interest, should be empty
386 *
387 * This is to be called right after @kn is created to enable namespace
388 * under it. All children of @kn must have non-NULL namespace tags and
389 * only the ones which match the super_block's tag will be visible.
390 */
kernfs_enable_ns(struct kernfs_node * kn)391 static inline void kernfs_enable_ns(struct kernfs_node *kn)
392 {
393 WARN_ON_ONCE(kernfs_type(kn) != KERNFS_DIR);
394 WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->dir.children));
395 kn->flags |= KERNFS_NS;
396 }
397
398 /**
399 * kernfs_ns_enabled - test whether namespace is enabled
400 * @kn: the node to test
401 *
402 * Test whether namespace filtering is enabled for the children of @ns.
403 */
kernfs_ns_enabled(struct kernfs_node * kn)404 static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
405 {
406 return kn->flags & KERNFS_NS;
407 }
408
409 int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen);
410 int kernfs_path_from_node(struct kernfs_node *root_kn, struct kernfs_node *kn,
411 char *buf, size_t buflen);
412 void pr_cont_kernfs_name(struct kernfs_node *kn);
413 void pr_cont_kernfs_path(struct kernfs_node *kn);
414 struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn);
415 struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
416 const char *name, const void *ns);
417 struct kernfs_node *kernfs_walk_and_get_ns(struct kernfs_node *parent,
418 const char *path, const void *ns);
419 void kernfs_get(struct kernfs_node *kn);
420 void kernfs_put(struct kernfs_node *kn);
421
422 struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry);
423 struct kernfs_root *kernfs_root_from_sb(struct super_block *sb);
424 struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn);
425
426 struct dentry *kernfs_node_dentry(struct kernfs_node *kn,
427 struct super_block *sb);
428 struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops,
429 unsigned int flags, void *priv);
430 void kernfs_destroy_root(struct kernfs_root *root);
431
432 struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
433 const char *name, umode_t mode,
434 kuid_t uid, kgid_t gid,
435 void *priv, const void *ns);
436 struct kernfs_node *kernfs_create_empty_dir(struct kernfs_node *parent,
437 const char *name);
438 struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
439 const char *name, umode_t mode,
440 kuid_t uid, kgid_t gid,
441 loff_t size,
442 const struct kernfs_ops *ops,
443 void *priv, const void *ns,
444 struct lock_class_key *key);
445 struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
446 const char *name,
447 struct kernfs_node *target);
448 void kernfs_activate(struct kernfs_node *kn);
449 void kernfs_show(struct kernfs_node *kn, bool show);
450 void kernfs_remove(struct kernfs_node *kn);
451 void kernfs_break_active_protection(struct kernfs_node *kn);
452 void kernfs_unbreak_active_protection(struct kernfs_node *kn);
453 bool kernfs_remove_self(struct kernfs_node *kn);
454 int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name,
455 const void *ns);
456 int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
457 const char *new_name, const void *new_ns);
458 int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);
459 __poll_t kernfs_generic_poll(struct kernfs_open_file *of,
460 struct poll_table_struct *pt);
461 void kernfs_notify(struct kernfs_node *kn);
462
463 int kernfs_xattr_get(struct kernfs_node *kn, const char *name,
464 void *value, size_t size);
465 int kernfs_xattr_set(struct kernfs_node *kn, const char *name,
466 const void *value, size_t size, int flags);
467
468 const void *kernfs_super_ns(struct super_block *sb);
469 int kernfs_get_tree(struct fs_context *fc);
470 void kernfs_free_fs_context(struct fs_context *fc);
471 void kernfs_kill_sb(struct super_block *sb);
472
473 void kernfs_init(void);
474
475 struct kernfs_node *kernfs_find_and_get_node_by_id(struct kernfs_root *root,
476 u64 id);
477 #else /* CONFIG_KERNFS */
478
kernfs_type(struct kernfs_node * kn)479 static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn)
480 { return 0; } /* whatever */
481
kernfs_enable_ns(struct kernfs_node * kn)482 static inline void kernfs_enable_ns(struct kernfs_node *kn) { }
483
kernfs_ns_enabled(struct kernfs_node * kn)484 static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
485 { return false; }
486
kernfs_name(struct kernfs_node * kn,char * buf,size_t buflen)487 static inline int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen)
488 { return -ENOSYS; }
489
kernfs_path_from_node(struct kernfs_node * root_kn,struct kernfs_node * kn,char * buf,size_t buflen)490 static inline int kernfs_path_from_node(struct kernfs_node *root_kn,
491 struct kernfs_node *kn,
492 char *buf, size_t buflen)
493 { return -ENOSYS; }
494
pr_cont_kernfs_name(struct kernfs_node * kn)495 static inline void pr_cont_kernfs_name(struct kernfs_node *kn) { }
pr_cont_kernfs_path(struct kernfs_node * kn)496 static inline void pr_cont_kernfs_path(struct kernfs_node *kn) { }
497
kernfs_get_parent(struct kernfs_node * kn)498 static inline struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
499 { return NULL; }
500
501 static inline struct kernfs_node *
kernfs_find_and_get_ns(struct kernfs_node * parent,const char * name,const void * ns)502 kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name,
503 const void *ns)
504 { return NULL; }
505 static inline struct kernfs_node *
kernfs_walk_and_get_ns(struct kernfs_node * parent,const char * path,const void * ns)506 kernfs_walk_and_get_ns(struct kernfs_node *parent, const char *path,
507 const void *ns)
508 { return NULL; }
509
kernfs_get(struct kernfs_node * kn)510 static inline void kernfs_get(struct kernfs_node *kn) { }
kernfs_put(struct kernfs_node * kn)511 static inline void kernfs_put(struct kernfs_node *kn) { }
512
kernfs_node_from_dentry(struct dentry * dentry)513 static inline struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry)
514 { return NULL; }
515
kernfs_root_from_sb(struct super_block * sb)516 static inline struct kernfs_root *kernfs_root_from_sb(struct super_block *sb)
517 { return NULL; }
518
519 static inline struct inode *
kernfs_get_inode(struct super_block * sb,struct kernfs_node * kn)520 kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
521 { return NULL; }
522
523 static inline struct kernfs_root *
kernfs_create_root(struct kernfs_syscall_ops * scops,unsigned int flags,void * priv)524 kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags,
525 void *priv)
526 { return ERR_PTR(-ENOSYS); }
527
kernfs_destroy_root(struct kernfs_root * root)528 static inline void kernfs_destroy_root(struct kernfs_root *root) { }
529
530 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 void * ns)531 kernfs_create_dir_ns(struct kernfs_node *parent, const char *name,
532 umode_t mode, kuid_t uid, kgid_t gid,
533 void *priv, const void *ns)
534 { return ERR_PTR(-ENOSYS); }
535
536 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 void * ns,struct lock_class_key * key)537 __kernfs_create_file(struct kernfs_node *parent, const char *name,
538 umode_t mode, kuid_t uid, kgid_t gid,
539 loff_t size, const struct kernfs_ops *ops,
540 void *priv, const void *ns, struct lock_class_key *key)
541 { return ERR_PTR(-ENOSYS); }
542
543 static inline struct kernfs_node *
kernfs_create_link(struct kernfs_node * parent,const char * name,struct kernfs_node * target)544 kernfs_create_link(struct kernfs_node *parent, const char *name,
545 struct kernfs_node *target)
546 { return ERR_PTR(-ENOSYS); }
547
kernfs_activate(struct kernfs_node * kn)548 static inline void kernfs_activate(struct kernfs_node *kn) { }
549
kernfs_remove(struct kernfs_node * kn)550 static inline void kernfs_remove(struct kernfs_node *kn) { }
551
kernfs_remove_self(struct kernfs_node * kn)552 static inline bool kernfs_remove_self(struct kernfs_node *kn)
553 { return false; }
554
kernfs_remove_by_name_ns(struct kernfs_node * kn,const char * name,const void * ns)555 static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn,
556 const char *name, const void *ns)
557 { return -ENOSYS; }
558
kernfs_rename_ns(struct kernfs_node * kn,struct kernfs_node * new_parent,const char * new_name,const void * new_ns)559 static inline int kernfs_rename_ns(struct kernfs_node *kn,
560 struct kernfs_node *new_parent,
561 const char *new_name, const void *new_ns)
562 { return -ENOSYS; }
563
kernfs_setattr(struct kernfs_node * kn,const struct iattr * iattr)564 static inline int kernfs_setattr(struct kernfs_node *kn,
565 const struct iattr *iattr)
566 { return -ENOSYS; }
567
kernfs_generic_poll(struct kernfs_open_file * of,struct poll_table_struct * pt)568 static inline __poll_t kernfs_generic_poll(struct kernfs_open_file *of,
569 struct poll_table_struct *pt)
570 { return -ENOSYS; }
571
kernfs_notify(struct kernfs_node * kn)572 static inline void kernfs_notify(struct kernfs_node *kn) { }
573
kernfs_xattr_get(struct kernfs_node * kn,const char * name,void * value,size_t size)574 static inline int kernfs_xattr_get(struct kernfs_node *kn, const char *name,
575 void *value, size_t size)
576 { return -ENOSYS; }
577
kernfs_xattr_set(struct kernfs_node * kn,const char * name,const void * value,size_t size,int flags)578 static inline int kernfs_xattr_set(struct kernfs_node *kn, const char *name,
579 const void *value, size_t size, int flags)
580 { return -ENOSYS; }
581
kernfs_super_ns(struct super_block * sb)582 static inline const void *kernfs_super_ns(struct super_block *sb)
583 { return NULL; }
584
kernfs_get_tree(struct fs_context * fc)585 static inline int kernfs_get_tree(struct fs_context *fc)
586 { return -ENOSYS; }
587
kernfs_free_fs_context(struct fs_context * fc)588 static inline void kernfs_free_fs_context(struct fs_context *fc) { }
589
kernfs_kill_sb(struct super_block * sb)590 static inline void kernfs_kill_sb(struct super_block *sb) { }
591
kernfs_init(void)592 static inline void kernfs_init(void) { }
593
594 #endif /* CONFIG_KERNFS */
595
596 /**
597 * kernfs_path - build full path of a given node
598 * @kn: kernfs_node of interest
599 * @buf: buffer to copy @kn's name into
600 * @buflen: size of @buf
601 *
602 * If @kn is NULL result will be "(null)".
603 *
604 * Returns the length of the full path. If the full length is equal to or
605 * greater than @buflen, @buf contains the truncated path with the trailing
606 * '\0'. On error, -errno is returned.
607 */
kernfs_path(struct kernfs_node * kn,char * buf,size_t buflen)608 static inline int kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen)
609 {
610 return kernfs_path_from_node(kn, NULL, buf, buflen);
611 }
612
613 static inline struct kernfs_node *
kernfs_find_and_get(struct kernfs_node * kn,const char * name)614 kernfs_find_and_get(struct kernfs_node *kn, const char *name)
615 {
616 return kernfs_find_and_get_ns(kn, name, NULL);
617 }
618
619 static inline struct kernfs_node *
kernfs_walk_and_get(struct kernfs_node * kn,const char * path)620 kernfs_walk_and_get(struct kernfs_node *kn, const char *path)
621 {
622 return kernfs_walk_and_get_ns(kn, path, NULL);
623 }
624
625 static inline struct kernfs_node *
kernfs_create_dir(struct kernfs_node * parent,const char * name,umode_t mode,void * priv)626 kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode,
627 void *priv)
628 {
629 return kernfs_create_dir_ns(parent, name, mode,
630 GLOBAL_ROOT_UID, GLOBAL_ROOT_GID,
631 priv, NULL);
632 }
633
kernfs_remove_by_name(struct kernfs_node * parent,const char * name)634 static inline int kernfs_remove_by_name(struct kernfs_node *parent,
635 const char *name)
636 {
637 return kernfs_remove_by_name_ns(parent, name, NULL);
638 }
639
kernfs_rename(struct kernfs_node * kn,struct kernfs_node * new_parent,const char * new_name)640 static inline int kernfs_rename(struct kernfs_node *kn,
641 struct kernfs_node *new_parent,
642 const char *new_name)
643 {
644 return kernfs_rename_ns(kn, new_parent, new_name, NULL);
645 }
646
647 #endif /* __LINUX_KERNFS_H */
648