Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * The proc filesystem constants/structures |
| 4 | */ |
| 5 | #ifndef _LINUX_PROC_FS_H |
| 6 | #define _LINUX_PROC_FS_H |
| 7 | |
| 8 | #include <linux/types.h> |
| 9 | #include <linux/fs.h> |
| 10 | |
| 11 | struct proc_dir_entry; |
| 12 | struct seq_file; |
| 13 | struct seq_operations; |
| 14 | |
| 15 | #ifdef CONFIG_PROC_FS |
| 16 | |
| 17 | typedef int (*proc_write_t)(struct file *, char *, size_t); |
| 18 | |
| 19 | extern void proc_root_init(void); |
| 20 | extern void proc_flush_task(struct task_struct *); |
| 21 | |
| 22 | extern struct proc_dir_entry *proc_symlink(const char *, |
| 23 | struct proc_dir_entry *, const char *); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 24 | struct proc_dir_entry *_proc_mkdir(const char *, umode_t, struct proc_dir_entry *, void *, bool); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 25 | extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *); |
| 26 | extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t, |
| 27 | struct proc_dir_entry *, void *); |
| 28 | extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t, |
| 29 | struct proc_dir_entry *); |
| 30 | struct proc_dir_entry *proc_create_mount_point(const char *name); |
| 31 | |
| 32 | struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode, |
| 33 | struct proc_dir_entry *parent, const struct seq_operations *ops, |
| 34 | unsigned int state_size, void *data); |
| 35 | #define proc_create_seq_data(name, mode, parent, ops, data) \ |
| 36 | proc_create_seq_private(name, mode, parent, ops, 0, data) |
| 37 | #define proc_create_seq(name, mode, parent, ops) \ |
| 38 | proc_create_seq_private(name, mode, parent, ops, 0, NULL) |
| 39 | struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode, |
| 40 | struct proc_dir_entry *parent, |
| 41 | int (*show)(struct seq_file *, void *), void *data); |
| 42 | #define proc_create_single(name, mode, parent, show) \ |
| 43 | proc_create_single_data(name, mode, parent, show, NULL) |
| 44 | |
| 45 | extern struct proc_dir_entry *proc_create_data(const char *, umode_t, |
| 46 | struct proc_dir_entry *, |
| 47 | const struct file_operations *, |
| 48 | void *); |
| 49 | |
| 50 | struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops); |
| 51 | extern void proc_set_size(struct proc_dir_entry *, loff_t); |
| 52 | extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t); |
| 53 | extern void *PDE_DATA(const struct inode *); |
| 54 | extern void *proc_get_parent_data(const struct inode *); |
| 55 | extern void proc_remove(struct proc_dir_entry *); |
| 56 | extern void remove_proc_entry(const char *, struct proc_dir_entry *); |
| 57 | extern int remove_proc_subtree(const char *, struct proc_dir_entry *); |
| 58 | |
| 59 | struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode, |
| 60 | struct proc_dir_entry *parent, const struct seq_operations *ops, |
| 61 | unsigned int state_size, void *data); |
| 62 | #define proc_create_net(name, mode, parent, state_size, ops) \ |
| 63 | proc_create_net_data(name, mode, parent, state_size, ops, NULL) |
| 64 | struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode, |
| 65 | struct proc_dir_entry *parent, |
| 66 | int (*show)(struct seq_file *, void *), void *data); |
| 67 | struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode, |
| 68 | struct proc_dir_entry *parent, |
| 69 | const struct seq_operations *ops, |
| 70 | proc_write_t write, |
| 71 | unsigned int state_size, void *data); |
| 72 | struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode, |
| 73 | struct proc_dir_entry *parent, |
| 74 | int (*show)(struct seq_file *, void *), |
| 75 | proc_write_t write, |
| 76 | void *data); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 77 | extern struct pid *tgid_pidfd_to_pid(const struct file *file); |
| 78 | |
| 79 | #ifdef CONFIG_PROC_PID_ARCH_STATUS |
| 80 | /* |
| 81 | * The architecture which selects CONFIG_PROC_PID_ARCH_STATUS must |
| 82 | * provide proc_pid_arch_status() definition. |
| 83 | */ |
| 84 | int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns, |
| 85 | struct pid *pid, struct task_struct *task); |
| 86 | #endif /* CONFIG_PROC_PID_ARCH_STATUS */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 87 | |
| 88 | #else /* CONFIG_PROC_FS */ |
| 89 | |
| 90 | static inline void proc_root_init(void) |
| 91 | { |
| 92 | } |
| 93 | |
| 94 | static inline void proc_flush_task(struct task_struct *task) |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | static inline struct proc_dir_entry *proc_symlink(const char *name, |
| 99 | struct proc_dir_entry *parent,const char *dest) { return NULL;} |
| 100 | static inline struct proc_dir_entry *proc_mkdir(const char *name, |
| 101 | struct proc_dir_entry *parent) {return NULL;} |
| 102 | static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; } |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 103 | static inline struct proc_dir_entry *_proc_mkdir(const char *name, umode_t mode, |
| 104 | struct proc_dir_entry *parent, void *data, bool force_lookup) |
| 105 | { |
| 106 | return NULL; |
| 107 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 108 | static inline struct proc_dir_entry *proc_mkdir_data(const char *name, |
| 109 | umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; } |
| 110 | static inline struct proc_dir_entry *proc_mkdir_mode(const char *name, |
| 111 | umode_t mode, struct proc_dir_entry *parent) { return NULL; } |
| 112 | #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;}) |
| 113 | #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;}) |
| 114 | #define proc_create_seq(name, mode, parent, ops) ({NULL;}) |
| 115 | #define proc_create_single(name, mode, parent, show) ({NULL;}) |
| 116 | #define proc_create_single_data(name, mode, parent, show, data) ({NULL;}) |
| 117 | #define proc_create(name, mode, parent, proc_fops) ({NULL;}) |
| 118 | #define proc_create_data(name, mode, parent, proc_fops, data) ({NULL;}) |
| 119 | |
| 120 | static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {} |
| 121 | static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {} |
| 122 | static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;} |
| 123 | static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; } |
| 124 | |
| 125 | static inline void proc_remove(struct proc_dir_entry *de) {} |
| 126 | #define remove_proc_entry(name, parent) do {} while (0) |
| 127 | static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; } |
| 128 | |
| 129 | #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;}) |
| 130 | #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;}) |
| 131 | #define proc_create_net_single(name, mode, parent, show, data) ({NULL;}) |
| 132 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 133 | static inline struct pid *tgid_pidfd_to_pid(const struct file *file) |
| 134 | { |
| 135 | return ERR_PTR(-EBADF); |
| 136 | } |
| 137 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 138 | #endif /* CONFIG_PROC_FS */ |
| 139 | |
| 140 | struct net; |
| 141 | |
| 142 | static inline struct proc_dir_entry *proc_net_mkdir( |
| 143 | struct net *net, const char *name, struct proc_dir_entry *parent) |
| 144 | { |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 145 | return _proc_mkdir(name, 0, parent, net, true); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | struct ns_common; |
| 149 | int open_related_ns(struct ns_common *ns, |
| 150 | struct ns_common *(*get_ns)(struct ns_common *ns)); |
| 151 | |
| 152 | /* get the associated pid namespace for a file in procfs */ |
| 153 | static inline struct pid_namespace *proc_pid_ns(const struct inode *inode) |
| 154 | { |
| 155 | return inode->i_sb->s_fs_info; |
| 156 | } |
| 157 | |
| 158 | #endif /* _LINUX_PROC_FS_H */ |