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