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