4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * libcfs/include/libcfs/libcfs_string.h
33 * Generic string manipulation functions.
35 * Author: Nathan Rutman <nathan.rutman@sun.com>
38 #ifndef __LIBCFS_UTIL_STRING_H__
39 #define __LIBCFS_UTIL_STRING_H__
44 #include <linux/types.h>
45 #include <linux/lnet/lnet-types.h>
46 #include <libcfs/util/list.h>
49 int vscnprintf(char *buf, size_t bufsz, const char *format, va_list args)
56 ret = vsnprintf(buf, bufsz, format, args);
57 return (bufsz > ret) ? ret : bufsz - 1;
60 /* __printf from linux kernel */
62 #define __printf(a, b) __attribute__((__format__(printf, a, b)))
66 static inline int scnprintf(char *buf, size_t bufsz, const char *format, ...)
71 va_start(args, format);
72 ret = vscnprintf(buf, bufsz, format, args);
82 void (*nf_addr2str)(__u32 addr, char *str, size_t size);
83 void (*nf_addr2str_size)(const __be32 *addr, size_t asize, char *str,
85 int (*nf_str2addr)(const char *str, int nob, __u32 *addr);
86 int (*nf_str2addr_size)(const char *str, int nob,
87 __be32 *addr, size_t *asize);
88 int (*nf_parse_addrlist)(char *str, int len,
89 struct list_head *list);
90 int (*nf_print_addrlist)(char *buffer, int count,
91 struct list_head *list);
92 int (*nf_match_addr)(__u32 addr, struct list_head *list);
93 int (*nf_min_max)(struct list_head *nidlist, __u32 *min_nid,
95 int (*nf_expand_addrrange)(struct list_head *addrranges,
96 __u32 *addrs, int max_addrs);
100 * Structure to represent NULL-less strings.
108 * Structure to represent \<range_expr\> token of the syntax.
110 struct cfs_range_expr {
112 * Link to cfs_expr_list::el_exprs.
114 struct list_head re_link;
120 struct cfs_expr_list {
121 struct list_head el_link;
122 struct list_head el_exprs;
125 int cfs_expr_list_values(struct cfs_expr_list *expr_list, int max, __u32 **valpp);
126 int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res);
127 int cfs_str2num_check(char *str, int nob, unsigned *num,
128 unsigned min, unsigned max);
129 int cfs_human_readable2long(unsigned long *sizep, char *str);
130 int cfs_expr2str(struct list_head *list, char *str, size_t size);
131 int cfs_expr_list_print(char *buffer, int count,
132 struct cfs_expr_list *expr_list);
133 int cfs_expr_list_parse(char *str, int len, unsigned min, unsigned max,
134 struct cfs_expr_list **elpp);
135 void cfs_expr_list_free(struct cfs_expr_list *expr_list);
136 void cfs_expr_list_free_list(struct list_head *list);
137 int cfs_ip_addr_parse(char *str, int len, struct list_head *list);
138 int cfs_ip_addr_range_gen(__u32 *ip_list, int count,
139 struct list_head *ip_addr_expr);
140 int cfs_ip_addr_match(__u32 addr, struct list_head *list);
141 int cfs_expand_nidlist(struct list_head *nidlist, lnet_nid_t *lnet_nidlist,
143 int cfs_parse_nid_parts(char *str, struct list_head *addr,
144 struct list_head *net_num, __u32 *net_type);
145 int cfs_abs_path(const char *request_path, char **resolved_path);