next up previous contents
Next: 4.8 Language Syntax Up: 4.7 Filters Previous: 4.7.1 Filter Examples

   
4.7.2 Filter Functions

If the conditions of the filter are met, then a C function that implements the filter is called. The prototype of the function is as follows:

int fist_filter_filtername_attr( & attr-data-type, & attr-data-size, ... );

That is, the name of the filter function is composed from the filter name and the attribute type. The function receives at least two arguments: a pointer to the data that fits the type, and a pointer to the size of the data being passed.

Note that having the filter name and attribute type in the function's name could be easily done in C++ using methods and overloaded prototypes. This information is included in the function name because the code should be C, a requirement for portability.8

For example, for the first example in Section sec-fist-filt-ex, the prototype would be:

int fist_filter_gzip_data( page_t *, int * );

and for the third example it would be:

int fist_filter_envexpand_name( char **, int * );

Filter functions should behave like system calls, returning 0 (zero) upon success, and a non-zero integer if any failure occurred. Failure codes are assumed to be errno values.

To write a new filter, all one must do is write a simple C function that manipulates the data as needed. There is no need to worry about what vnode operations this would have to apply to, where the information is stored, when to allocate or free vnodes, most errors, and so on. All these are handled automatically by FiST.


next up previous contents
Next: 4.8 Language Syntax Up: 4.7 Filters Previous: 4.7.1 Filter Examples
Erez Zadok
1999-12-07