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