Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / lib / zero / zero.c
blobd100fa487fc27bc0c30035a204566b0b0025ff0a
1 /* $NetBSD$ */
3 /*
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
17 #include "lib.h"
18 #include "toolcontext.h"
19 #include "segtype.h"
20 #include "display.h"
21 #include "text_export.h"
22 #include "text_import.h"
23 #include "config.h"
24 #include "str_list.h"
25 #include "targets.h"
26 #include "lvm-string.h"
27 #include "activate.h"
28 #include "metadata.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;
40 return 1;
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;
62 if (!_zero_checked)
63 _zero_present = target_present(cmd, "zero", 1);
65 _zero_checked = 1;
67 return _zero_present;
69 #endif
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");
77 return 0;
80 return 1;
83 static void _zero_destroy(const struct segment_type *segtype)
85 dm_free((void *) segtype);
88 static struct segtype_handler _zero_ops = {
89 .name = _zero_name,
90 .merge_segments = _zero_merge_segments,
91 #ifdef DEVMAPPER_SUPPORT
92 .add_target_line = _zero_add_target_line,
93 .target_present = _zero_target_present,
94 #endif
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));
103 if (!segtype)
104 return_NULL;
106 segtype->cmd = cmd;
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);
114 return segtype;