Tizen 2.1 base
[external/device-mapper.git] / lib / config / config.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_CONFIG_H
17 #define _LVM_CONFIG_H
18
19 #include "lvm-types.h"
20
21 struct device;
22 struct cmd_context;
23
24 enum {
25         CFG_STRING,
26         CFG_FLOAT,
27         CFG_INT,
28         CFG_EMPTY_ARRAY
29 };
30
31 struct config_value {
32         int type;
33         union {
34                 int64_t i;
35                 float r;
36                 const char *str;
37         } v;
38         struct config_value *next;      /* for arrays */
39 };
40
41 struct config_node {
42         const char *key;
43         struct config_node *parent, *sib, *child;
44         struct config_value *v;
45 };
46
47 struct config_tree {
48         struct config_node *root;
49 };
50
51 struct config_tree_list {
52         struct dm_list list;
53         struct config_tree *cft;
54 };
55
56 struct config_tree *create_config_tree(const char *filename, int keep_open);
57 struct config_tree *create_config_tree_from_string(struct cmd_context *cmd,
58                                                    const char *config_settings);
59 int override_config_tree_from_string(struct cmd_context *cmd,
60                                      const char *config_settings);
61 void destroy_config_tree(struct config_tree *cft);
62
63 typedef uint32_t (*checksum_fn_t) (uint32_t initial, const uint8_t *buf, uint32_t size);
64
65 int read_config_fd(struct config_tree *cft, struct device *dev,
66                    off_t offset, size_t size, off_t offset2, size_t size2,
67                    checksum_fn_t checksum_fn, uint32_t checksum);
68
69 int read_config_file(struct config_tree *cft);
70 int write_config_file(struct config_tree *cft, const char *file,
71                       int argc, char **argv);
72
73 typedef int (*putline_fn)(const char *line, void *baton);
74 int write_config_node(const struct config_node *cn, putline_fn putline, void *baton);
75
76 time_t config_file_timestamp(struct config_tree *cft);
77 int config_file_changed(struct config_tree *cft);
78 int merge_config_tree(struct cmd_context *cmd, struct config_tree *cft,
79                       struct config_tree *newdata);
80
81 const struct config_node *find_config_node(const struct config_node *cn,
82                                            const char *path);
83 const char *find_config_str(const struct config_node *cn, const char *path,
84                             const char *fail);
85 int find_config_int(const struct config_node *cn, const char *path, int fail);
86 float find_config_float(const struct config_node *cn, const char *path,
87                         float fail);
88
89 /*
90  * These versions check an override tree, if present, first.
91  */
92 const struct config_node *find_config_tree_node(struct cmd_context *cmd,
93                                                 const char *path);
94 const char *find_config_tree_str(struct cmd_context *cmd,
95                                  const char *path, const char *fail);
96 int find_config_tree_int(struct cmd_context *cmd, const char *path,
97                          int fail);
98 float find_config_tree_float(struct cmd_context *cmd, const char *path,
99                              float fail);
100
101 /*
102  * Understands (0, ~0), (y, n), (yes, no), (on,
103  * off), (true, false).
104  */
105 int find_config_bool(const struct config_node *cn, const char *path, int fail);
106 int find_config_tree_bool(struct cmd_context *cmd, const char *path, int fail);
107
108 int get_config_uint32(const struct config_node *cn, const char *path,
109                       uint32_t *result);
110
111 int get_config_uint64(const struct config_node *cn, const char *path,
112                       uint64_t *result);
113
114 int get_config_str(const struct config_node *cn, const char *path,
115                    const char **result);
116
117 unsigned maybe_config_section(const char *str, unsigned len);
118
119 const char *config_parent_name(const struct config_node *n);
120
121 struct config_node *clone_config_node(struct dm_pool *mem, const struct config_node *cn,
122                                       int siblings);
123 #endif