Lucas De Marchi | 8f923be | 2011-12-03 04:28:49 -0200 | [diff] [blame] | 1 | /* |
| 2 | * libkmod - interface to kernel module operations |
| 3 | * |
Lucas De Marchi | e6b0e49 | 2013-01-16 11:27:21 -0200 | [diff] [blame] | 4 | * Copyright (C) 2011-2013 ProFUSION embedded systems |
Lucas De Marchi | 8f923be | 2011-12-03 04:28:49 -0200 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
Lucas De Marchi | cb451f3 | 2011-12-12 18:24:35 -0200 | [diff] [blame] | 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
Lucas De Marchi | 8f923be | 2011-12-03 04:28:49 -0200 | [diff] [blame] | 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
Lucas De Marchi | dea2dfe | 2014-12-25 23:32:03 -0200 | [diff] [blame] | 17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
Lucas De Marchi | 8f923be | 2011-12-03 04:28:49 -0200 | [diff] [blame] | 18 | */ |
Lucas De Marchi | e8847fd | 2011-11-30 15:23:28 -0200 | [diff] [blame] | 19 | |
Lucas De Marchi | e8fd8fe | 2012-07-18 10:19:48 -0300 | [diff] [blame] | 20 | #pragma once |
Lucas De Marchi | e8847fd | 2011-11-30 15:23:28 -0200 | [diff] [blame] | 21 | |
Lucas De Marchi | b18979b | 2014-10-03 02:03:55 -0300 | [diff] [blame] | 22 | #include <inttypes.h> |
Lucas De Marchi | e8847fd | 2011-11-30 15:23:28 -0200 | [diff] [blame] | 23 | |
Lucas De Marchi | e8847fd | 2011-11-30 15:23:28 -0200 | [diff] [blame] | 24 | struct index_value { |
| 25 | struct index_value *next; |
| 26 | unsigned int priority; |
Gustavo Sverzut Barbieri | 1433ba9 | 2011-12-08 14:50:29 -0200 | [diff] [blame] | 27 | unsigned int len; |
Lucas De Marchi | e8847fd | 2011-11-30 15:23:28 -0200 | [diff] [blame] | 28 | char value[0]; |
| 29 | }; |
| 30 | |
| 31 | /* In-memory index (depmod only) */ |
Lucas De Marchi | e8847fd | 2011-11-30 15:23:28 -0200 | [diff] [blame] | 32 | struct index_file; |
Lucas De Marchi | e8847fd | 2011-11-30 15:23:28 -0200 | [diff] [blame] | 33 | struct index_file *index_file_open(const char *filename); |
Lucas De Marchi | 4a4876d | 2011-12-02 17:48:14 -0200 | [diff] [blame] | 34 | void index_file_close(struct index_file *idx); |
| 35 | char *index_search(struct index_file *idx, const char *key); |
Lucas De Marchi | 758428a | 2012-01-16 15:56:17 -0200 | [diff] [blame] | 36 | void index_dump(struct index_file *in, int fd, const char *prefix); |
Lucas De Marchi | 4a4876d | 2011-12-02 17:48:14 -0200 | [diff] [blame] | 37 | struct index_value *index_searchwild(struct index_file *idx, const char *key); |
Lucas De Marchi | e8847fd | 2011-11-30 15:23:28 -0200 | [diff] [blame] | 38 | |
| 39 | void index_values_free(struct index_value *values); |
| 40 | |
Lucas De Marchi | b471a6b | 2011-12-01 23:14:20 -0200 | [diff] [blame] | 41 | /* Implementation using mmap */ |
| 42 | struct index_mm; |
Lucas De Marchi | 5109f2b | 2011-12-08 15:10:55 -0200 | [diff] [blame] | 43 | struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, |
Lucas De Marchi | 2e2e252 | 2012-03-02 20:33:26 -0300 | [diff] [blame] | 44 | unsigned long long *stamp); |
Lucas De Marchi | b471a6b | 2011-12-01 23:14:20 -0200 | [diff] [blame] | 45 | void index_mm_close(struct index_mm *index); |
Lucas De Marchi | b797b79 | 2011-12-02 17:49:03 -0200 | [diff] [blame] | 46 | char *index_mm_search(struct index_mm *idx, const char *key); |
Lucas De Marchi | bf89f70 | 2011-12-02 18:23:36 -0200 | [diff] [blame] | 47 | struct index_value *index_mm_searchwild(struct index_mm *idx, const char *key); |
Lucas De Marchi | 758428a | 2012-01-16 15:56:17 -0200 | [diff] [blame] | 48 | void index_mm_dump(struct index_mm *idx, int fd, const char *prefix); |