1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#ifndef __PARAMS_TREE_H__
41#define __PARAMS_TREE_H__
42
43#include <linux/libcfs/libcfs.h>
44
45#undef LPROCFS
46#if defined(CONFIG_PROC_FS)
47# define LPROCFS
48#endif
49
50#ifdef LPROCFS
51typedef struct file cfs_param_file_t;
52typedef struct inode cfs_inode_t;
53typedef struct proc_inode cfs_proc_inode_t;
54typedef struct seq_file cfs_seq_file_t;
55typedef struct seq_operations cfs_seq_ops_t;
56typedef struct file_operations cfs_param_file_ops_t;
57typedef module_t *cfs_param_module_t;
58typedef struct proc_dir_entry cfs_param_dentry_t;
59typedef struct poll_table_struct cfs_poll_table_t;
60#define CFS_PARAM_MODULE THIS_MODULE
61#define cfs_file_private(file) (file->private_data)
62#define cfs_dentry_data(dentry) (dentry->data)
63#define cfs_proc_inode_pde(proc_inode) (proc_inode->pde)
64#define cfs_proc_inode(proc_inode) (proc_inode->vfs_inode)
65#define cfs_seq_read_common seq_read
66#define cfs_seq_lseek_common seq_lseek
67#define cfs_seq_private(seq) (seq->private)
68#define cfs_seq_printf(seq, format, ...) seq_printf(seq, format, \
69 ## __VA_ARGS__)
70#define cfs_seq_release(inode, file) seq_release(inode, file)
71#define cfs_seq_puts(seq, s) seq_puts(seq, s)
72#define cfs_seq_putc(seq, s) seq_putc(seq, s)
73#define cfs_seq_read(file, buf, count, ppos, rc) (rc = seq_read(file, buf, \
74 count, ppos))
75#define cfs_seq_open(file, ops, rc) (rc = seq_open(file, ops))
76
77#else
78
79typedef struct cfs_params_file {
80 void *param_private;
81 loff_t param_pos;
82 unsigned int param_flags;
83} cfs_param_file_t;
84
85typedef struct cfs_param_inode {
86 void *param_private;
87} cfs_inode_t;
88
89typedef struct cfs_param_dentry {
90 void *param_data;
91} cfs_param_dentry_t;
92
93typedef struct cfs_proc_inode {
94 cfs_param_dentry_t *param_pde;
95 cfs_inode_t param_inode;
96} cfs_proc_inode_t;
97
98struct cfs_seq_operations;
99typedef struct cfs_seq_file {
100 char *buf;
101 size_t size;
102 size_t from;
103 size_t count;
104 loff_t index;
105 loff_t version;
106 struct mutex lock;
107 struct cfs_seq_operations *op;
108 void *private;
109} cfs_seq_file_t;
110
111typedef struct cfs_seq_operations {
112 void *(*start) (cfs_seq_file_t *m, loff_t *pos);
113 void (*stop) (cfs_seq_file_t *m, void *v);
114 void *(*next) (cfs_seq_file_t *m, void *v, loff_t *pos);
115 int (*show) (cfs_seq_file_t *m, void *v);
116} cfs_seq_ops_t;
117
118typedef void *cfs_param_module_t;
119typedef void *cfs_poll_table_t;
120
121typedef struct cfs_param_file_ops {
122 cfs_param_module_t owner;
123 int (*open) (cfs_inode_t *, struct file *);
124 loff_t (*llseek)(struct file *, loff_t, int);
125 int (*release) (cfs_inode_t *, cfs_param_file_t *);
126 unsigned int (*poll) (struct file *, cfs_poll_table_t *);
127 ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
128 ssize_t (*read)(struct file *, char *, size_t, loff_t *);
129} cfs_param_file_ops_t;
130typedef cfs_param_file_ops_t *cfs_lproc_filep_t;
131
132static inline cfs_proc_inode_t *FAKE_PROC_I(const cfs_inode_t *inode)
133{
134 return container_of(inode, cfs_proc_inode_t, param_inode);
135}
136
137#define CFS_PARAM_MODULE NULL
138#define cfs_file_private(file) (file->param_private)
139#define cfs_dentry_data(dentry) (dentry->param_data)
140#define cfs_proc_inode(proc_inode) (proc_inode->param_inode)
141#define cfs_proc_inode_pde(proc_inode) (proc_inode->param_pde)
142#define cfs_seq_read_common NULL
143#define cfs_seq_lseek_common NULL
144#define cfs_seq_private(seq) (seq->private)
145#define cfs_seq_read(file, buf, count, ppos, rc) do {} while(0)
146#define cfs_seq_open(file, ops, rc) \
147do { \
148 cfs_seq_file_t *p = cfs_file_private(file); \
149 if (!p) { \
150 LIBCFS_ALLOC(p, sizeof(*p)); \
151 if (!p) { \
152 rc = -ENOMEM; \
153 break; \
154 } \
155 cfs_file_private(file) = p; \
156 } \
157 memset(p, 0, sizeof(*p)); \
158 p->op = ops; \
159 rc = 0; \
160} while(0)
161
162#endif
163
164
165
166#endif
167