Tizen 2.1 base
[external/device-mapper.git] / lib / misc / lvm-string.h
1 /*
2  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.  
3  * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4  *
5  * This file is part of LVM2.
6  *
7  * This copyrighted material is made available to anyone wishing to use,
8  * modify, copy, or redistribute it subject to the terms and conditions
9  * of the GNU Lesser General Public License v.2.1.
10  *
11  * You should have received a copy of the GNU Lesser General Public License
12  * along with this program; if not, write to the Free Software Foundation,
13  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14  */
15
16 #ifndef _LVM_STRING_H
17 #define _LVM_STRING_H
18
19 #include <stdio.h>
20 #include <stdarg.h>
21
22 #define NAME_LEN 128
23 #define UUID_PREFIX "LVM-"
24
25 struct pool;
26
27 int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...)
28   __attribute__ ((format(printf, 3, 4)));
29
30 char *build_dm_name(struct dm_pool *mem, const char *vg,
31                     const char *lv, const char *layer);
32 char *build_dm_uuid(struct dm_pool *mem, const char *lvid,
33                     const char *layer);
34
35 int validate_name(const char *n);
36 int validate_tag(const char *n);
37
38 int apply_lvname_restrictions(const char *name);
39 int is_reserved_lvname(const char *name);
40
41 /*
42  * Returns number of occurrences of c in first len characters of str.
43  */
44 unsigned count_chars(const char *str, size_t len, const int c);
45
46 /*
47  * Returns what length of escaped string would be including terminating NUL.
48  */
49 size_t escaped_len(const char *str);
50
51 /*
52  * Copies a string from src to out. 
53  * Double quotation marks and backslashes are quoted with a backslash.
54  * Caller must ensure *out has enough space - see escaped_len().
55  * Returns *out.
56  */
57 char *escape_double_quotes(char *out, const char *src);
58
59 /*
60  * Removes quoting of double quotation marks and backslashes in situ.
61  */
62 void unescape_double_quotes(char *src);
63
64 /*
65  * Unescape colons and at signs in situ and save the substring starting
66  * at the position of the first unescaped colon and the first unescaped
67  * "at" sign.
68  */
69 void unescape_colons_and_at_signs(char *src,
70                                   char **substr_first_unquoted_colon,
71                                   char **substr_first_unquoted_at_sign);
72
73 #endif