4 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
6 * This file is part of LVM2.
8 * This copyrighted material is made available to anyone wishing to use,
9 * modify, copy, or redistribute it subject to the terms and conditions
10 * of the GNU Lesser General Public License v.2.1.
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include "toolcontext.h"
21 #include "text_export.h"
22 #include "text_import.h"
26 #include "lvm-string.h"
30 static const char *_zero_name(const struct lv_segment
*seg
)
32 return seg
->segtype
->name
;
35 static int _zero_merge_segments(struct lv_segment
*seg1
, struct lv_segment
*seg2
)
37 seg1
->len
+= seg2
->len
;
38 seg1
->area_len
+= seg2
->area_len
;
43 #ifdef DEVMAPPER_SUPPORT
44 static int _zero_add_target_line(struct dev_manager
*dm
__attribute((unused
)),
45 struct dm_pool
*mem
__attribute((unused
)),
46 struct cmd_context
*cmd
__attribute((unused
)),
47 void **target_state
__attribute((unused
)),
48 struct lv_segment
*seg
__attribute((unused
)),
49 struct dm_tree_node
*node
,uint64_t len
,
50 uint32_t *pvmove_mirror_count
__attribute((unused
)))
52 return dm_tree_node_add_zero_target(node
, len
);
55 static int _zero_target_present(struct cmd_context
*cmd
,
56 const struct lv_segment
*seg
__attribute((unused
)),
57 unsigned *attributes
__attribute((unused
)))
59 static int _zero_checked
= 0;
60 static int _zero_present
= 0;
63 _zero_present
= target_present(cmd
, "zero", 1);
71 static int _zero_modules_needed(struct dm_pool
*mem
,
72 const struct lv_segment
*seg
__attribute((unused
)),
73 struct dm_list
*modules
)
75 if (!str_list_add(mem
, modules
, "zero")) {
76 log_error("zero module string list allocation failed");
83 static void _zero_destroy(const struct segment_type
*segtype
)
85 dm_free((void *) segtype
);
88 static struct segtype_handler _zero_ops
= {
90 .merge_segments
= _zero_merge_segments
,
91 #ifdef DEVMAPPER_SUPPORT
92 .add_target_line
= _zero_add_target_line
,
93 .target_present
= _zero_target_present
,
95 .modules_needed
= _zero_modules_needed
,
96 .destroy
= _zero_destroy
,
99 struct segment_type
*init_zero_segtype(struct cmd_context
*cmd
)
101 struct segment_type
*segtype
= dm_malloc(sizeof(*segtype
));
107 segtype
->ops
= &_zero_ops
;
108 segtype
->name
= "zero";
109 segtype
->private = NULL
;
110 segtype
->flags
= SEG_CAN_SPLIT
| SEG_VIRTUAL
| SEG_CANNOT_BE_ZEROED
;
112 log_very_verbose("Initialised segtype: %s", segtype
->name
);