xref: /netbsd-src/external/gpl2/lvm2/dist/include/config.h (revision de4fa6c51a9708fc05f88b618fa6fad87c9508ec)
1 /*	$NetBSD: config.h,v 1.1.1.1 2008/12/22 00:18:47 haad Exp $	*/
2 
3 /*
4  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5  * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
6  *
7  * This file is part of LVM2.
8  *
9  * This copyrighted material is made available to anyone wishing to use,
10  * modify, copy, or redistribute it subject to the terms and conditions
11  * of the GNU Lesser General Public License v.2.1.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17 
18 #ifndef _LVM_CONFIG_H
19 #define _LVM_CONFIG_H
20 
21 #include "lvm-types.h"
22 
23 struct device;
24 struct cmd_context;
25 
26 enum {
27 	CFG_STRING,
28 	CFG_FLOAT,
29 	CFG_INT,
30 	CFG_EMPTY_ARRAY
31 };
32 
33 struct config_value {
34 	int type;
35 	union {
36 		int64_t i;
37 		float r;
38 		char *str;
39 	} v;
40 	struct config_value *next;	/* for arrays */
41 };
42 
43 struct config_node {
44 	char *key;
45 	struct config_node *sib, *child;
46 	struct config_value *v;
47 };
48 
49 struct config_tree {
50 	struct config_node *root;
51 };
52 
53 struct config_tree_list {
54 	struct dm_list list;
55 	struct config_tree *cft;
56 };
57 
58 struct config_tree *create_config_tree(const char *filename, int keep_open);
59 struct config_tree *create_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 void *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 time_t config_file_timestamp(struct config_tree *cft);
73 int config_file_changed(struct config_tree *cft);
74 int merge_config_tree(struct cmd_context *cmd, struct config_tree *cft,
75 		      struct config_tree *newdata);
76 
77 struct config_node *find_config_node(const struct config_node *cn,
78 				     const char *path);
79 const char *find_config_str(const struct config_node *cn, const char *path,
80 			    const char *fail);
81 int find_config_int(const struct config_node *cn, const char *path, int fail);
82 float find_config_float(const struct config_node *cn, const char *path,
83 			float fail);
84 
85 /*
86  * These versions check an override tree, if present, first.
87  */
88 struct config_node *find_config_tree_node(struct cmd_context *cmd,
89 					  const char *path);
90 const char *find_config_tree_str(struct cmd_context *cmd,
91 				 const char *path, const char *fail);
92 int find_config_tree_int(struct cmd_context *cmd, const char *path,
93 			 int fail);
94 float find_config_tree_float(struct cmd_context *cmd, const char *path,
95 			     float fail);
96 
97 /*
98  * Understands (0, ~0), (y, n), (yes, no), (on,
99  * off), (true, false).
100  */
101 int find_config_bool(const struct config_node *cn, const char *path, int fail);
102 int find_config_tree_bool(struct cmd_context *cmd, const char *path, int fail);
103 
104 int get_config_uint32(const struct config_node *cn, const char *path,
105 		      uint32_t *result);
106 
107 int get_config_uint64(const struct config_node *cn, const char *path,
108 		      uint64_t *result);
109 
110 int get_config_str(const struct config_node *cn, const char *path,
111 		   char **result);
112 
113 unsigned maybe_config_section(const char *str, unsigned len);
114 
115 #endif
116