Whamcloud - gitweb
c8cb70b84214821e24e78ec79def1449a62dc9b8
[fs/lustre-release.git] / libcfs / include / libcfs / libcfs_string.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * libcfs/include/libcfs/libcfs_string.h
32  *
33  * Generic string manipulation functions.
34  *
35  * Author: Nathan Rutman <nathan.rutman@sun.com>
36  */
37
38 #ifndef __LIBCFS_STRING_H__
39 #define __LIBCFS_STRING_H__
40
41 /* libcfs_string.c */
42 /* Convert a text string to a bitmask */
43 int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
44                  int *oldmask, int minmask, int allmask);
45
46 /**
47  * Structure to represent NULL-less strings.
48  */
49 struct cfs_lstr {
50         char            *ls_str;
51         int             ls_len;
52 };
53
54 /*
55  * Structure to represent \<range_expr\> token of the syntax.
56  */
57 struct cfs_range_expr {
58         /*
59          * Link to cfs_expr_list::el_exprs.
60          */
61         struct list_head        re_link;
62         __u32                   re_lo;
63         __u32                   re_hi;
64         __u32                   re_stride;
65 };
66
67 struct cfs_expr_list {
68         struct list_head        el_link;
69         struct list_head        el_exprs;
70 };
71
72 int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res);
73 int cfs_str2num_check(char *str, int nob, unsigned *num,
74                       unsigned min, unsigned max);
75 int cfs_expr_list_match(__u32 value, struct cfs_expr_list *expr_list);
76 int cfs_expr_list_print(char *buffer, int count,
77                         struct cfs_expr_list *expr_list);
78 int cfs_expr_list_values(struct cfs_expr_list *expr_list,
79                          int max, __u32 **values);
80 void cfs_expr_list_values_free(__u32 *values, int num);
81 void cfs_expr_list_free(struct cfs_expr_list *expr_list);
82 int cfs_expr_list_parse(char *str, int len, unsigned min, unsigned max,
83                         struct cfs_expr_list **elpp);
84 void cfs_expr_list_free_list(struct list_head *list);
85
86 #endif