Tejun Heo | b8441ed | 2013-11-24 09:54:58 -0500 | [diff] [blame] | 1 | /* |
| 2 | * kernfs.h - pseudo filesystem decoupled from vfs locking |
| 3 | * |
| 4 | * This file is released under the GPLv2. |
| 5 | */ |
| 6 | |
| 7 | #ifndef __LINUX_KERNFS_H |
| 8 | #define __LINUX_KERNFS_H |
| 9 | |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 10 | #include <linux/kernel.h> |
Tejun Heo | 5d0e26b | 2013-11-23 17:21:50 -0500 | [diff] [blame] | 11 | #include <linux/err.h> |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame^] | 12 | #include <linux/list.h> |
| 13 | #include <linux/mutex.h> |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 14 | |
Tejun Heo | 5d60418 | 2013-11-23 17:21:52 -0500 | [diff] [blame] | 15 | struct file; |
| 16 | struct iattr; |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame^] | 17 | struct seq_file; |
| 18 | struct vm_area_struct; |
Tejun Heo | 5d60418 | 2013-11-23 17:21:52 -0500 | [diff] [blame] | 19 | |
Tejun Heo | b8441ed | 2013-11-24 09:54:58 -0500 | [diff] [blame] | 20 | struct sysfs_dirent; |
| 21 | |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame^] | 22 | struct sysfs_open_file { |
| 23 | /* published fields */ |
| 24 | struct sysfs_dirent *sd; |
| 25 | struct file *file; |
| 26 | |
| 27 | /* private fields, do not use outside kernfs proper */ |
| 28 | struct mutex mutex; |
| 29 | int event; |
| 30 | struct list_head list; |
| 31 | |
| 32 | bool mmapped; |
| 33 | const struct vm_operations_struct *vm_ops; |
| 34 | }; |
| 35 | |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 36 | #ifdef CONFIG_SYSFS |
| 37 | |
Tejun Heo | 93b2b8e | 2013-11-28 14:54:15 -0500 | [diff] [blame] | 38 | struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, |
| 39 | const char *name, void *priv, |
| 40 | const void *ns); |
Tejun Heo | 5d0e26b | 2013-11-23 17:21:50 -0500 | [diff] [blame] | 41 | struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent, |
| 42 | const char *name, |
| 43 | struct sysfs_dirent *target); |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 44 | void kernfs_remove(struct sysfs_dirent *sd); |
| 45 | int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, const char *name, |
| 46 | const void *ns); |
Tejun Heo | 890ece1 | 2013-11-23 17:21:51 -0500 | [diff] [blame] | 47 | int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent, |
| 48 | const char *new_name, const void *new_ns); |
Tejun Heo | 93b2b8e | 2013-11-28 14:54:15 -0500 | [diff] [blame] | 49 | void kernfs_enable_ns(struct sysfs_dirent *sd); |
Tejun Heo | 5d60418 | 2013-11-23 17:21:52 -0500 | [diff] [blame] | 50 | int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr); |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 51 | |
| 52 | #else /* CONFIG_SYSFS */ |
| 53 | |
Tejun Heo | 5d0e26b | 2013-11-23 17:21:50 -0500 | [diff] [blame] | 54 | static inline struct sysfs_dirent * |
Tejun Heo | 93b2b8e | 2013-11-28 14:54:15 -0500 | [diff] [blame] | 55 | kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv, |
| 56 | const void *ns) |
| 57 | { return ERR_PTR(-ENOSYS); } |
| 58 | |
| 59 | static inline struct sysfs_dirent * |
Tejun Heo | 5d0e26b | 2013-11-23 17:21:50 -0500 | [diff] [blame] | 60 | kernfs_create_link(struct sysfs_dirent *parent, const char *name, |
| 61 | struct sysfs_dirent *target) |
| 62 | { return ERR_PTR(-ENOSYS); } |
| 63 | |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 64 | static inline void kernfs_remove(struct sysfs_dirent *sd) { } |
| 65 | |
| 66 | static inline int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, |
| 67 | const char *name, const void *ns) |
| 68 | { return -ENOSYS; } |
| 69 | |
Tejun Heo | 890ece1 | 2013-11-23 17:21:51 -0500 | [diff] [blame] | 70 | static inline int kernfs_rename_ns(struct sysfs_dirent *sd, |
| 71 | struct sysfs_dirent *new_parent, |
| 72 | const char *new_name, const void *new_ns) |
| 73 | { return -ENOSYS; } |
| 74 | |
Tejun Heo | 93b2b8e | 2013-11-28 14:54:15 -0500 | [diff] [blame] | 75 | static inline void kernfs_enable_ns(struct sysfs_dirent *sd) { } |
| 76 | |
Tejun Heo | 5d60418 | 2013-11-23 17:21:52 -0500 | [diff] [blame] | 77 | static inline int kernfs_setattr(struct sysfs_dirent *sd, |
| 78 | const struct iattr *iattr) |
| 79 | { return -ENOSYS; } |
| 80 | |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 81 | #endif /* CONFIG_SYSFS */ |
| 82 | |
Tejun Heo | 93b2b8e | 2013-11-28 14:54:15 -0500 | [diff] [blame] | 83 | static inline struct sysfs_dirent * |
| 84 | kernfs_create_dir(struct sysfs_dirent *parent, const char *name, void *priv) |
| 85 | { |
| 86 | return kernfs_create_dir_ns(parent, name, priv, NULL); |
| 87 | } |
| 88 | |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 89 | static inline int kernfs_remove_by_name(struct sysfs_dirent *parent, |
| 90 | const char *name) |
| 91 | { |
| 92 | return kernfs_remove_by_name_ns(parent, name, NULL); |
| 93 | } |
| 94 | |
Tejun Heo | b8441ed | 2013-11-24 09:54:58 -0500 | [diff] [blame] | 95 | #endif /* __LINUX_KERNFS_H */ |