kernfs.h 20 KB

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