2001-08-21 16:56:08 +04:00
/*
2004-03-30 23:35:44 +04:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2007-08-21 00:55:30 +04:00
* Copyright ( C ) 2004 - 2007 Red Hat , Inc . All rights reserved .
2001-08-21 16:56:08 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
2007-08-21 00:55:30 +04:00
* of the GNU Lesser General Public License v .2 .1 .
2004-03-30 23:35:44 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 23:35:44 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
2001-08-21 16:56:08 +04:00
*/
2001-09-25 16:49:28 +04:00
# ifndef _LVM_CONFIG_H
# define _LVM_CONFIG_H
2005-10-17 03:03:59 +04:00
# include "lvm-types.h"
2004-05-04 22:28:15 +04:00
struct device ;
struct cmd_context ;
2003-07-05 02:34:56 +04:00
2001-08-21 16:56:08 +04:00
enum {
2002-11-18 17:01:16 +03:00
CFG_STRING ,
CFG_FLOAT ,
CFG_INT ,
2002-08-01 16:46:52 +04:00
CFG_EMPTY_ARRAY
2001-08-21 16:56:08 +04:00
} ;
struct config_value {
2002-11-18 17:01:16 +03:00
int type ;
union {
2007-04-28 00:41:50 +04:00
int64_t i ;
2002-11-18 17:01:16 +03:00
float r ;
char * str ;
} v ;
struct config_value * next ; /* for arrays */
2001-08-21 16:56:08 +04:00
} ;
struct config_node {
2002-11-18 17:01:16 +03:00
char * key ;
2009-07-09 15:29:00 +04:00
struct config_node * parent , * sib , * child ;
2002-11-18 17:01:16 +03:00
struct config_value * v ;
2001-08-21 16:56:08 +04:00
} ;
2002-11-18 17:01:16 +03:00
struct config_tree {
struct config_node * root ;
2001-08-21 16:56:08 +04:00
} ;
2004-05-04 22:28:15 +04:00
struct config_tree_list {
2008-11-04 01:14:30 +03:00
struct dm_list list ;
2004-05-04 22:28:15 +04:00
struct config_tree * cft ;
} ;
2006-11-04 06:34:10 +03:00
struct config_tree * create_config_tree ( const char * filename , int keep_open ) ;
2006-05-16 20:48:31 +04:00
struct config_tree * create_config_tree_from_string ( struct cmd_context * cmd ,
const char * config_settings ) ;
2009-07-28 01:01:56 +04:00
int override_config_tree_from_string ( struct cmd_context * cmd ,
const char * config_settings ) ;
2004-05-04 22:28:15 +04:00
void destroy_config_tree ( struct config_tree * cft ) ;
2001-08-21 16:56:08 +04:00
2010-09-27 23:09:34 +04:00
typedef uint32_t ( * checksum_fn_t ) ( uint32_t initial , const uint8_t * buf , uint32_t size ) ;
2002-11-18 17:01:16 +03:00
2004-05-04 22:28:15 +04:00
int read_config_fd ( struct config_tree * cft , struct device * dev ,
2002-12-20 02:25:55 +03:00
off_t offset , size_t size , off_t offset2 , size_t size2 ,
2002-11-18 17:01:16 +03:00
checksum_fn_t checksum_fn , uint32_t checksum ) ;
2004-05-04 22:28:15 +04:00
int read_config_file ( struct config_tree * cft ) ;
2007-01-10 02:22:31 +03:00
int write_config_file ( struct config_tree * cft , const char * file ,
int argc , char * * argv ) ;
2009-10-16 21:41:49 +04:00
typedef int ( * putline_fn ) ( const char * line , void * baton ) ;
2009-10-22 14:38:07 +04:00
int write_config_node ( const struct config_node * cn , putline_fn putline , void * baton ) ;
2009-10-16 21:41:49 +04:00
2004-05-04 22:28:15 +04:00
time_t config_file_timestamp ( struct config_tree * cft ) ;
int config_file_changed ( struct config_tree * cft ) ;
int merge_config_tree ( struct cmd_context * cmd , struct config_tree * cft ,
struct config_tree * newdata ) ;
2001-08-21 16:56:08 +04:00
2004-05-04 22:28:15 +04:00
struct config_node * find_config_node ( const struct config_node * cn ,
2004-03-08 21:28:45 +03:00
const char * path ) ;
2004-05-04 22:28:15 +04:00
const char * find_config_str ( const struct config_node * cn , const char * path ,
2004-03-08 21:28:45 +03:00
const char * fail ) ;
2004-05-04 22:28:15 +04:00
int find_config_int ( const struct config_node * cn , const char * path , int fail ) ;
float find_config_float ( const struct config_node * cn , const char * path ,
float fail ) ;
2001-08-21 16:56:08 +04:00
2006-05-16 20:48:31 +04:00
/*
* These versions check an override tree , if present , first .
*/
struct config_node * find_config_tree_node ( struct cmd_context * cmd ,
const char * path ) ;
const char * find_config_tree_str ( struct cmd_context * cmd ,
const char * path , const char * fail ) ;
int find_config_tree_int ( struct cmd_context * cmd , const char * path ,
int fail ) ;
float find_config_tree_float ( struct cmd_context * cmd , const char * path ,
float fail ) ;
2002-01-07 13:23:52 +03:00
/*
* Understands ( 0 , ~ 0 ) , ( y , n ) , ( yes , no ) , ( on ,
* off ) , ( true , false ) .
*/
2004-05-04 22:28:15 +04:00
int find_config_bool ( const struct config_node * cn , const char * path , int fail ) ;
2006-05-16 20:48:31 +04:00
int find_config_tree_bool ( struct cmd_context * cmd , const char * path , int fail ) ;
2002-01-10 19:47:58 +03:00
2004-05-04 22:28:15 +04:00
int get_config_uint32 ( const struct config_node * cn , const char * path ,
2004-03-08 21:28:45 +03:00
uint32_t * result ) ;
2002-01-10 19:47:58 +03:00
2004-05-04 22:28:15 +04:00
int get_config_uint64 ( const struct config_node * cn , const char * path ,
2004-03-08 21:28:45 +03:00
uint64_t * result ) ;
2002-01-10 19:47:58 +03:00
2004-05-04 22:28:15 +04:00
int get_config_str ( const struct config_node * cn , const char * path ,
char * * result ) ;
2002-07-11 18:07:43 +04:00
2007-04-26 00:38:39 +04:00
unsigned maybe_config_section ( const char * str , unsigned len ) ;
2009-07-09 15:29:00 +04:00
const char * config_parent_name ( const struct config_node * n ) ;
2009-10-16 21:41:49 +04:00
struct config_node * clone_config_node ( struct dm_pool * mem , const struct config_node * cn ,
int siblings ) ;
2001-08-21 16:56:08 +04:00
# endif