kernfs.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * kernfs.h - pseudo filesystem decoupled from vfs locking
  3. *
  4. * This file is released under the GPLv2.
  5. */
  6. #ifndef __LINUX_KERNFS_H
  7. #define __LINUX_KERNFS_H
  8. #include <linux/kernel.h>
  9. #include <linux/err.h>
  10. #include <linux/list.h>
  11. #include <linux/mutex.h>
  12. struct file;
  13. struct iattr;
  14. struct seq_file;
  15. struct vm_area_struct;
  16. struct sysfs_dirent;
  17. struct sysfs_open_file {
  18. /* published fields */
  19. struct sysfs_dirent *sd;
  20. struct file *file;
  21. /* private fields, do not use outside kernfs proper */
  22. struct mutex mutex;
  23. int event;
  24. struct list_head list;
  25. bool mmapped;
  26. const struct vm_operations_struct *vm_ops;
  27. };
  28. struct kernfs_ops {
  29. /*
  30. * Read is handled by either seq_file or raw_read().
  31. *
  32. * If seq_show() is present, seq_file path is active. The behavior
  33. * is equivalent to single_open(). @sf->private points to the
  34. * associated sysfs_open_file.
  35. *
  36. * read() is bounced through kernel buffer and a read larger than
  37. * PAGE_SIZE results in partial operation of PAGE_SIZE.
  38. */
  39. int (*seq_show)(struct seq_file *sf, void *v);
  40. ssize_t (*read)(struct sysfs_open_file *of, char *buf, size_t bytes,
  41. loff_t off);
  42. /*
  43. * write() is bounced through kernel buffer and a write larger than
  44. * PAGE_SIZE results in partial operation of PAGE_SIZE.
  45. */
  46. ssize_t (*write)(struct sysfs_open_file *of, char *buf, size_t bytes,
  47. loff_t off);
  48. int (*mmap)(struct sysfs_open_file *of, struct vm_area_struct *vma);
  49. };
  50. #ifdef CONFIG_SYSFS
  51. struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent,
  52. const char *name, void *priv,
  53. const void *ns);
  54. struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent,
  55. const char *name,
  56. struct sysfs_dirent *target);
  57. void kernfs_remove(struct sysfs_dirent *sd);
  58. int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, const char *name,
  59. const void *ns);
  60. int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
  61. const char *new_name, const void *new_ns);
  62. void kernfs_enable_ns(struct sysfs_dirent *sd);
  63. int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr);
  64. #else /* CONFIG_SYSFS */
  65. static inline struct sysfs_dirent *
  66. kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv,
  67. const void *ns)
  68. { return ERR_PTR(-ENOSYS); }
  69. static inline struct sysfs_dirent *
  70. kernfs_create_link(struct sysfs_dirent *parent, const char *name,
  71. struct sysfs_dirent *target)
  72. { return ERR_PTR(-ENOSYS); }
  73. static inline void kernfs_remove(struct sysfs_dirent *sd) { }
  74. static inline int kernfs_remove_by_name_ns(struct sysfs_dirent *parent,
  75. const char *name, const void *ns)
  76. { return -ENOSYS; }
  77. static inline int kernfs_rename_ns(struct sysfs_dirent *sd,
  78. struct sysfs_dirent *new_parent,
  79. const char *new_name, const void *new_ns)
  80. { return -ENOSYS; }
  81. static inline void kernfs_enable_ns(struct sysfs_dirent *sd) { }
  82. static inline int kernfs_setattr(struct sysfs_dirent *sd,
  83. const struct iattr *iattr)
  84. { return -ENOSYS; }
  85. #endif /* CONFIG_SYSFS */
  86. static inline struct sysfs_dirent *
  87. kernfs_create_dir(struct sysfs_dirent *parent, const char *name, void *priv)
  88. {
  89. return kernfs_create_dir_ns(parent, name, priv, NULL);
  90. }
  91. static inline int kernfs_remove_by_name(struct sysfs_dirent *parent,
  92. const char *name)
  93. {
  94. return kernfs_remove_by_name_ns(parent, name, NULL);
  95. }
  96. #endif /* __LINUX_KERNFS_H */