2004-05-11 20:01:58 +04:00
/*
* Copyright ( C ) 2004 Red Hat , Inc . All rights reserved .
*
* 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
* of the GNU General Public License v .2 .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
# include "lib.h"
# include "toolcontext.h"
2004-09-16 22:40:56 +04:00
# include "segtype.h"
2004-05-11 20:01:58 +04:00
# include "display.h"
# include "text_export.h"
# include "text_import.h"
# include "config.h"
# include "str_list.h"
# include "targets.h"
# include "lvm-string.h"
# include "activate.h"
static const char * _name ( const struct lv_segment * seg )
{
return seg - > segtype - > name ;
}
static int _merge_segments ( struct lv_segment * seg1 , struct lv_segment * seg2 )
{
seg1 - > len + = seg2 - > len ;
seg1 - > area_len + = seg2 - > area_len ;
return 1 ;
}
# ifdef DEVMAPPER_SUPPORT
2005-11-09 01:52:26 +03:00
static int _add_target_line ( struct dev_manager * dm , struct dm_pool * mem ,
struct config_tree * cft , void * * target_state ,
struct lv_segment * seg ,
2005-11-09 16:08:41 +03:00
struct dm_tree_node * node , uint64_t len ,
2005-11-09 01:52:26 +03:00
uint32_t * pvmove_mirror_count )
2004-05-11 20:01:58 +04:00
{
2005-11-09 16:08:41 +03:00
return dm_tree_node_add_zero_target ( node , len ) ;
2004-05-11 20:01:58 +04:00
}
static int _target_present ( void )
{
static int checked = 0 ;
static int present = 0 ;
if ( ! checked )
2005-11-09 01:52:26 +03:00
present = target_present ( " zero " , 0 ) ;
2004-05-11 20:01:58 +04:00
checked = 1 ;
return present ;
}
# endif
static void _destroy ( const struct segment_type * segtype )
{
2005-10-17 03:03:59 +04:00
dm_free ( ( void * ) segtype ) ;
2004-05-11 20:01:58 +04:00
}
static struct segtype_handler _zero_ops = {
name : _name ,
merge_segments : _merge_segments ,
# ifdef DEVMAPPER_SUPPORT
2005-11-09 01:52:26 +03:00
add_target_line : _add_target_line ,
2004-05-11 20:01:58 +04:00
target_present : _target_present ,
# endif
destroy : _destroy ,
} ;
struct segment_type * init_zero_segtype ( struct cmd_context * cmd )
{
2005-10-17 03:03:59 +04:00
struct segment_type * segtype = dm_malloc ( sizeof ( * segtype ) ) ;
2004-05-11 20:01:58 +04:00
if ( ! segtype ) {
stack ;
return NULL ;
}
segtype - > cmd = cmd ;
segtype - > ops = & _zero_ops ;
segtype - > name = " zero " ;
segtype - > private = NULL ;
2005-11-09 01:52:26 +03:00
segtype - > flags = SEG_CAN_SPLIT | SEG_VIRTUAL | SEG_CANNOT_BE_ZEROED ;
2004-05-11 20:01:58 +04:00
2004-09-14 21:37:51 +04:00
log_very_verbose ( " Initialised segtype: %s " , segtype - > name ) ;
2004-05-11 20:01:58 +04:00
return segtype ;
}