0001
0002 #ifndef __LINUX_TEXTSEARCH_H
0003 #define __LINUX_TEXTSEARCH_H
0004
0005 #include <linux/types.h>
0006 #include <linux/list.h>
0007 #include <linux/kernel.h>
0008 #include <linux/err.h>
0009 #include <linux/slab.h>
0010
0011 struct module;
0012
0013 struct ts_config;
0014
0015 #define TS_AUTOLOAD 1
0016 #define TS_IGNORECASE 2
0017
0018
0019
0020
0021
0022
0023 struct ts_state
0024 {
0025 unsigned int offset;
0026 char cb[48];
0027 };
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 struct ts_ops
0040 {
0041 const char *name;
0042 struct ts_config * (*init)(const void *, unsigned int, gfp_t, int);
0043 unsigned int (*find)(struct ts_config *,
0044 struct ts_state *);
0045 void (*destroy)(struct ts_config *);
0046 void * (*get_pattern)(struct ts_config *);
0047 unsigned int (*get_pattern_len)(struct ts_config *);
0048 struct module *owner;
0049 struct list_head list;
0050 };
0051
0052
0053
0054
0055
0056
0057
0058
0059 struct ts_config
0060 {
0061 struct ts_ops *ops;
0062 int flags;
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 unsigned int (*get_next_block)(unsigned int consumed,
0077 const u8 **dst,
0078 struct ts_config *conf,
0079 struct ts_state *state);
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 void (*finish)(struct ts_config *conf,
0090 struct ts_state *state);
0091 };
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 static inline unsigned int textsearch_next(struct ts_config *conf,
0106 struct ts_state *state)
0107 {
0108 unsigned int ret = conf->ops->find(conf, state);
0109
0110 if (conf->finish)
0111 conf->finish(conf, state);
0112
0113 return ret;
0114 }
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124 static inline unsigned int textsearch_find(struct ts_config *conf,
0125 struct ts_state *state)
0126 {
0127 state->offset = 0;
0128 return textsearch_next(conf, state);
0129 }
0130
0131
0132
0133
0134
0135 static inline void *textsearch_get_pattern(struct ts_config *conf)
0136 {
0137 return conf->ops->get_pattern(conf);
0138 }
0139
0140
0141
0142
0143
0144 static inline unsigned int textsearch_get_pattern_len(struct ts_config *conf)
0145 {
0146 return conf->ops->get_pattern_len(conf);
0147 }
0148
0149 extern int textsearch_register(struct ts_ops *);
0150 extern int textsearch_unregister(struct ts_ops *);
0151 extern struct ts_config *textsearch_prepare(const char *, const void *,
0152 unsigned int, gfp_t, int);
0153 extern void textsearch_destroy(struct ts_config *conf);
0154 extern unsigned int textsearch_find_continuous(struct ts_config *,
0155 struct ts_state *,
0156 const void *, unsigned int);
0157
0158
0159 #define TS_PRIV_ALIGNTO 8
0160 #define TS_PRIV_ALIGN(len) (((len) + TS_PRIV_ALIGNTO-1) & ~(TS_PRIV_ALIGNTO-1))
0161
0162 static inline struct ts_config *alloc_ts_config(size_t payload,
0163 gfp_t gfp_mask)
0164 {
0165 struct ts_config *conf;
0166
0167 conf = kzalloc(TS_PRIV_ALIGN(sizeof(*conf)) + payload, gfp_mask);
0168 if (conf == NULL)
0169 return ERR_PTR(-ENOMEM);
0170
0171 return conf;
0172 }
0173
0174 static inline void *ts_config_priv(struct ts_config *conf)
0175 {
0176 return ((u8 *) conf + TS_PRIV_ALIGN(sizeof(struct ts_config)));
0177 }
0178
0179 #endif