2 * kernfs.h - pseudo filesystem decoupled from vfs locking
4 * This file is released under the GPLv2.
7 #ifndef __LINUX_KERNFS_H
8 #define __LINUX_KERNFS_H
10 #include <linux/kernel.h>
11 #include <linux/err.h>
12 #include <linux/list.h>
13 #include <linux/mutex.h>
18 struct vm_area_struct;
22 struct sysfs_open_file {
23 /* published fields */
24 struct sysfs_dirent *sd;
27 /* private fields, do not use outside kernfs proper */
30 struct list_head list;
33 const struct vm_operations_struct *vm_ops;
38 * Read is handled by either seq_file or raw_read().
40 * If seq_show() is present, seq_file path is active. Other seq
41 * operations are optional and if not implemented, the behavior is
42 * equivalent to single_open(). @sf->private points to the
43 * associated sysfs_open_file.
45 * read() is bounced through kernel buffer and a read larger than
46 * PAGE_SIZE results in partial operation of PAGE_SIZE.
48 int (*seq_show)(struct seq_file *sf, void *v);
50 void *(*seq_start)(struct seq_file *sf, loff_t *ppos);
51 void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos);
52 void (*seq_stop)(struct seq_file *sf, void *v);
54 ssize_t (*read)(struct sysfs_open_file *of, char *buf, size_t bytes,
58 * write() is bounced through kernel buffer and a write larger than
59 * PAGE_SIZE results in partial operation of PAGE_SIZE.
61 ssize_t (*write)(struct sysfs_open_file *of, char *buf, size_t bytes,
64 int (*mmap)(struct sysfs_open_file *of, struct vm_area_struct *vma);
69 struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent,
70 const char *name, void *priv,
72 struct sysfs_dirent *kernfs_create_file_ns(struct sysfs_dirent *parent,
74 umode_t mode, loff_t size,
75 const struct kernfs_ops *ops,
76 void *priv, const void *ns);
77 struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent,
79 struct sysfs_dirent *target);
80 void kernfs_remove(struct sysfs_dirent *sd);
81 int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, const char *name,
83 int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
84 const char *new_name, const void *new_ns);
85 void kernfs_enable_ns(struct sysfs_dirent *sd);
86 int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr);
87 void kernfs_notify(struct sysfs_dirent *sd);
89 #else /* CONFIG_SYSFS */
91 static inline struct sysfs_dirent *
92 kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv,
94 { return ERR_PTR(-ENOSYS); }
96 static inline struct sysfs_dirent *
97 kernfs_create_file_ns(struct sysfs_dirent *parent, const char *name,
98 umode_t mode, loff_t size, const struct kernfs_ops *ops,
99 void *priv, const void *ns)
100 { return ERR_PTR(-ENOSYS); }
102 static inline struct sysfs_dirent *
103 kernfs_create_link(struct sysfs_dirent *parent, const char *name,
104 struct sysfs_dirent *target)
105 { return ERR_PTR(-ENOSYS); }
107 static inline void kernfs_remove(struct sysfs_dirent *sd) { }
109 static inline int kernfs_remove_by_name_ns(struct sysfs_dirent *parent,
110 const char *name, const void *ns)
113 static inline int kernfs_rename_ns(struct sysfs_dirent *sd,
114 struct sysfs_dirent *new_parent,
115 const char *new_name, const void *new_ns)
118 static inline void kernfs_enable_ns(struct sysfs_dirent *sd) { }
120 static inline int kernfs_setattr(struct sysfs_dirent *sd,
121 const struct iattr *iattr)
124 static inline void kernfs_notify(struct sysfs_dirent *sd) { }
126 #endif /* CONFIG_SYSFS */
128 static inline struct sysfs_dirent *
129 kernfs_create_dir(struct sysfs_dirent *parent, const char *name, void *priv)
131 return kernfs_create_dir_ns(parent, name, priv, NULL);
134 static inline struct sysfs_dirent *
135 kernfs_create_file(struct sysfs_dirent *parent, const char *name, umode_t mode,
136 loff_t size, const struct kernfs_ops *ops, void *priv)
138 return kernfs_create_file_ns(parent, name, mode, size, ops, priv, NULL);
141 static inline int kernfs_remove_by_name(struct sysfs_dirent *parent,
144 return kernfs_remove_by_name_ns(parent, name, NULL);
147 #endif /* __LINUX_KERNFS_H */