/* SPDX-License-Identifier: GPL-2.0 */ #ifndef __LINUX_TEXTSEARCH_H #define __LINUX_TEXTSEARCH_H #include <linux/types.h> #include <linux/list.h> #include <linux/kernel.h> #include <linux/err.h> #include <linux/slab.h> struct module; struct ts_config; #define TS_AUTOLOAD … #define TS_IGNORECASE … /** * struct ts_state - search state * @offset: offset for next match * @cb: control buffer, for persistent variables of get_next_block() */ struct ts_state { … }; /** * struct ts_ops - search module operations * @name: name of search algorithm * @init: initialization function to prepare a search * @find: find the next occurrence of the pattern * @destroy: destroy algorithm specific parts of a search configuration * @get_pattern: return head of pattern * @get_pattern_len: return length of pattern * @owner: module reference to algorithm */ struct ts_ops { … }; /** * struct ts_config - search configuration * @ops: operations of chosen algorithm * @flags: flags * @get_next_block: callback to fetch the next block to search in * @finish: callback to finalize a search */ struct ts_config { … }; /** * textsearch_next - continue searching for a pattern * @conf: search configuration * @state: search state * * Continues a search looking for more occurrences of the pattern. * textsearch_find() must be called to find the first occurrence * in order to reset the state. * * Returns the position of the next occurrence of the pattern or * UINT_MAX if not match was found. */ static inline unsigned int textsearch_next(struct ts_config *conf, struct ts_state *state) { … } /** * textsearch_find - start searching for a pattern * @conf: search configuration * @state: search state * * Returns the position of first occurrence of the pattern or * UINT_MAX if no match was found. */ static inline unsigned int textsearch_find(struct ts_config *conf, struct ts_state *state) { … } /** * textsearch_get_pattern - return head of the pattern * @conf: search configuration */ static inline void *textsearch_get_pattern(struct ts_config *conf) { … } /** * textsearch_get_pattern_len - return length of the pattern * @conf: search configuration */ static inline unsigned int textsearch_get_pattern_len(struct ts_config *conf) { … } extern int textsearch_register(struct ts_ops *); extern int textsearch_unregister(struct ts_ops *); extern struct ts_config *textsearch_prepare(const char *, const void *, unsigned int, gfp_t, int); extern void textsearch_destroy(struct ts_config *conf); extern unsigned int textsearch_find_continuous(struct ts_config *, struct ts_state *, const void *, unsigned int); #define TS_PRIV_ALIGNTO … #define TS_PRIV_ALIGN(len) … static inline struct ts_config *alloc_ts_config(size_t payload, gfp_t gfp_mask) { … } static inline void *ts_config_priv(struct ts_config *conf) { … } #endif