1#ifndef __LINUX_TEXTSEARCH_H
2#define __LINUX_TEXTSEARCH_H
3
4#ifdef __KERNEL__
5
6#include <linux/types.h>
7#include <linux/list.h>
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/err.h>
11#include <linux/slab.h>
12
13struct ts_config;
14
15
16
17
18#define TS_AUTOLOAD 1
19
20
21
22
23
24
25struct ts_state
26{
27 unsigned int offset;
28 char cb[40];
29};
30
31
32
33
34
35
36
37
38
39
40
41struct ts_ops
42{
43 const char *name;
44 struct ts_config * (*init)(const void *, unsigned int, gfp_t);
45 unsigned int (*find)(struct ts_config *,
46 struct ts_state *);
47 void (*destroy)(struct ts_config *);
48 void * (*get_pattern)(struct ts_config *);
49 unsigned int (*get_pattern_len)(struct ts_config *);
50 struct module *owner;
51 struct list_head list;
52};
53
54
55
56
57
58
59
60struct ts_config
61{
62 struct ts_ops *ops;
63
64
65
66
67
68
69
70
71
72
73
74
75
76 unsigned int (*get_next_block)(unsigned int consumed,
77 const u8 **dst,
78 struct ts_config *conf,
79 struct ts_state *state);
80
81
82
83
84
85
86
87
88
89 void (*finish)(struct ts_config *conf,
90 struct ts_state *state);
91};
92
93
94
95
96
97
98
99
100
101
102
103
104
105static inline unsigned int textsearch_next(struct ts_config *conf,
106 struct ts_state *state)
107{
108 unsigned int ret = conf->ops->find(conf, state);
109
110 if (conf->finish)
111 conf->finish(conf, state);
112
113 return ret;
114}
115
116
117
118
119
120
121
122
123
124static inline unsigned int textsearch_find(struct ts_config *conf,
125 struct ts_state *state)
126{
127 state->offset = 0;
128 return textsearch_next(conf, state);
129}
130
131
132
133
134
135static inline void *textsearch_get_pattern(struct ts_config *conf)
136{
137 return conf->ops->get_pattern(conf);
138}
139
140
141
142
143
144static inline unsigned int textsearch_get_pattern_len(struct ts_config *conf)
145{
146 return conf->ops->get_pattern_len(conf);
147}
148
149extern int textsearch_register(struct ts_ops *);
150extern int textsearch_unregister(struct ts_ops *);
151extern struct ts_config *textsearch_prepare(const char *, const void *,
152 unsigned int, gfp_t, int);
153extern void textsearch_destroy(struct ts_config *conf);
154extern unsigned int textsearch_find_continuous(struct ts_config *,
155 struct ts_state *,
156 const void *, unsigned int);
157
158
159#define TS_PRIV_ALIGNTO 8
160#define TS_PRIV_ALIGN(len) (((len) + TS_PRIV_ALIGNTO-1) & ~(TS_PRIV_ALIGNTO-1))
161
162static inline struct ts_config *alloc_ts_config(size_t payload,
163 gfp_t gfp_mask)
164{
165 struct ts_config *conf;
166
167 conf = kmalloc(TS_PRIV_ALIGN(sizeof(*conf)) + payload, gfp_mask);
168 if (conf == NULL)
169 return ERR_PTR(-ENOMEM);
170
171 memset(conf, 0, TS_PRIV_ALIGN(sizeof(*conf)) + payload);
172 return conf;
173}
174
175static inline void *ts_config_priv(struct ts_config *conf)
176{
177 return ((u8 *) conf + TS_PRIV_ALIGN(sizeof(struct ts_config)));
178}
179
180#endif
181
182#endif
183