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