Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
textsearch.h
Go to the documentation of this file.
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/err.h>
8 #include <linux/slab.h>
9 
10 struct module;
11 
12 struct ts_config;
13 
14 #define TS_AUTOLOAD 1 /* Automatically load textsearch modules when needed */
15 #define TS_IGNORECASE 2 /* Searches string case insensitively */
16 
22 struct ts_state
23 {
24  unsigned int offset;
25  char cb[40];
26 };
27 
38 struct ts_ops
39 {
40  const char *name;
41  struct ts_config * (*init)(const void *, unsigned int, gfp_t, int);
42  unsigned int (*find)(struct ts_config *,
43  struct ts_state *);
44  void (*destroy)(struct ts_config *);
45  void * (*get_pattern)(struct ts_config *);
46  unsigned int (*get_pattern_len)(struct ts_config *);
47  struct module *owner;
48  struct list_head list;
49 };
50 
58 struct ts_config
59 {
60  struct ts_ops *ops;
61  int flags;
62 
75  unsigned int (*get_next_block)(unsigned int consumed,
76  const u8 **dst,
77  struct ts_config *conf,
78  struct ts_state *state);
79 
88  void (*finish)(struct ts_config *conf,
89  struct ts_state *state);
90 };
91 
104 static inline unsigned int textsearch_next(struct ts_config *conf,
105  struct ts_state *state)
106 {
107  unsigned int ret = conf->ops->find(conf, state);
108 
109  if (conf->finish)
110  conf->finish(conf, state);
111 
112  return ret;
113 }
114 
123 static inline unsigned int textsearch_find(struct ts_config *conf,
124  struct ts_state *state)
125 {
126  state->offset = 0;
127  return textsearch_next(conf, state);
128 }
129 
134 static inline void *textsearch_get_pattern(struct ts_config *conf)
135 {
136  return conf->ops->get_pattern(conf);
137 }
138 
143 static inline unsigned int textsearch_get_pattern_len(struct ts_config *conf)
144 {
145  return conf->ops->get_pattern_len(conf);
146 }
147 
148 extern int textsearch_register(struct ts_ops *);
149 extern int textsearch_unregister(struct ts_ops *);
150 extern struct ts_config *textsearch_prepare(const char *, const void *,
151  unsigned int, gfp_t, int);
152 extern void textsearch_destroy(struct ts_config *conf);
153 extern unsigned int textsearch_find_continuous(struct ts_config *,
154  struct ts_state *,
155  const void *, unsigned int);
156 
157 
158 #define TS_PRIV_ALIGNTO 8
159 #define TS_PRIV_ALIGN(len) (((len) + TS_PRIV_ALIGNTO-1) & ~(TS_PRIV_ALIGNTO-1))
160 
161 static inline struct ts_config *alloc_ts_config(size_t payload,
162  gfp_t gfp_mask)
163 {
164  struct ts_config *conf;
165 
166  conf = kzalloc(TS_PRIV_ALIGN(sizeof(*conf)) + payload, gfp_mask);
167  if (conf == NULL)
168  return ERR_PTR(-ENOMEM);
169 
170  return conf;
171 }
172 
173 static inline void *ts_config_priv(struct ts_config *conf)
174 {
175  return ((u8 *) conf + TS_PRIV_ALIGN(sizeof(struct ts_config)));
176 }
177 
178 #endif