2 * Copyright (c) 2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com> and
6 * Michael Neumann <mneumann@ntecs.de>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * - volume-add: Add new volume to HAMMER filesystem
40 * - volume-del: Remove volume from HAMMER filesystem
41 * - volume-list: List volumes making up a HAMMER filesystem
42 * - volume-blkdevs: List volumes making up a HAMMER filesystem
49 * volume-add <device> <filesystem>
52 hammer_cmd_volume_add(char **av, int ac)
54 struct hammer_ioc_volume ioc;
55 struct volume_info *vol;
57 const char *device, *filesystem;
60 fprintf(stderr, "hammer volume-add <device> <filesystem>\n");
67 fd = open(filesystem, O_RDONLY);
69 fprintf(stderr, "hammer volume-add: unable to access %s: %s\n",
70 filesystem, strerror(errno));
75 * Initialize and check the device
77 vol = init_volume(-1, device, O_RDONLY);
78 assert(vol->vol_no == -1);
80 if (strcmp(vol->type, "DEVICE")) {
81 fprintf(stderr, "Not a block device: %s\n", device);
89 bzero(&ioc, sizeof(ioc));
90 strncpy(ioc.device_name, device, MAXPATHLEN);
91 ioc.vol_size = vol->size;
92 ioc.boot_area_size = init_boot_area_size(0, ioc.vol_size);
93 ioc.mem_area_size = init_mem_area_size(0, ioc.vol_size);
95 if (ioctl(fd, HAMMERIOC_ADD_VOLUME, &ioc) < 0) {
96 fprintf(stderr, "hammer volume-add ioctl: %s\n",
105 * volume-del <device> <filesystem>
108 hammer_cmd_volume_del(char **av, int ac)
110 struct hammer_ioc_volume ioc;
112 const char *device, *filesystem;
115 fprintf(stderr, "hammer volume-del <device> <filesystem>\n");
122 fd = open(filesystem, O_RDONLY);
124 fprintf(stderr, "hammer volume-del: unable to access %s: %s\n",
125 filesystem, strerror(errno));
132 bzero(&ioc, sizeof(ioc));
133 strncpy(ioc.device_name, device, MAXPATHLEN);
135 if (ioctl(fd, HAMMERIOC_DEL_VOLUME, &ioc) < 0) {
136 fprintf(stderr, "hammer volume-del ioctl: %s\n",
145 hammer_print_volumes(char **av, int ac, const char *cmd, const char sep)
147 struct hammer_ioc_volume_list ioc;
150 const char *filesystem;
153 fprintf(stderr, "hammer %s <filesystem>\n", cmd);
159 fd = open(filesystem, O_RDONLY);
162 "hammer %s: unable to access %s: %s\n",
163 cmd, filesystem, strerror(errno));
167 bzero(&ioc, sizeof(ioc));
168 ioc.vols = malloc(HAMMER_MAX_VOLUMES *
169 sizeof(struct hammer_ioc_volume));
170 if (ioc.vols == NULL) {
172 "hammer %s: unable to allocate memory: %s\n",
173 cmd, strerror(errno));
176 ioc.nvols = HAMMER_MAX_VOLUMES;
178 if (ioctl(fd, HAMMERIOC_LIST_VOLUMES, &ioc) < 0) {
179 fprintf(stderr, "hammer %s ioctl: %s\n",
180 cmd, strerror(errno));
185 for (i = 0; i < ioc.nvols; i++) {
186 printf("%s", ioc.vols[i].device_name);
187 if (i != ioc.nvols - 1)
197 * volume-list <filesystem>
200 hammer_cmd_volume_list(char **av, int ac, const char *cmd)
202 hammer_print_volumes(av, ac, cmd, '\n');
206 * volume-blkdevs <filesystem>
209 hammer_cmd_volume_blkdevs(char **av, int ac, const char *cmd)
211 hammer_print_volumes(av, ac, cmd, ':');