1235537Sgber/*-
2235537Sgber * Copyright (c) 2012 The FreeBSD Foundation
3235537Sgber * All rights reserved.
4235537Sgber *
5235537Sgber * This software was developed by Semihalf under sponsorship
6235537Sgber * from the FreeBSD Foundation.
7235537Sgber *
8235537Sgber * Redistribution and use in source and binary forms, with or without
9235537Sgber * modification, are permitted provided that the following conditions
10235537Sgber * are met:
11235537Sgber *
12235537Sgber * 1. Redistributions of source code must retain the above copyright
13235537Sgber *    notice, this list of conditions and the following disclaimer.
14235537Sgber * 2. Redistributions in binary form must reproduce the above copyright
15235537Sgber *    notice, this list of conditions and the following disclaimer in the
16235537Sgber *    documentation and/or other materials provided with the distribution.
17235537Sgber *
18235537Sgber * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19235537Sgber * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20235537Sgber * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21235537Sgber * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22235537Sgber * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23235537Sgber * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24235537Sgber * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25235537Sgber * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26235537Sgber * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27235537Sgber * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28235537Sgber * SUCH DAMAGE.
29235537Sgber */
30235537Sgber
31235537Sgber#include <sys/cdefs.h>
32235537Sgber__FBSDID("$FreeBSD$");
33235537Sgber#include <sys/types.h>
34235537Sgber
35235537Sgber#include <stdio.h>
36235537Sgber#include <stdlib.h>
37235537Sgber#include <limits.h>
38235537Sgber#include <sysexits.h>
39235537Sgber
40235537Sgber#include <fs/nandfs/nandfs_fs.h>
41235537Sgber#include <libnandfs.h>
42235537Sgber
43235537Sgber#include "nandfs.h"
44235537Sgber
45235537Sgberstatic void
46235537Sgberrmsnap_usage(void)
47235537Sgber{
48235537Sgber
49235537Sgber	fprintf(stderr, "usage:\n");
50235537Sgber	fprintf(stderr, "\trmsnap snap node\n");
51235537Sgber}
52235537Sgber
53235537Sgberint
54235537Sgbernandfs_rmsnap(int argc, char **argv)
55235537Sgber{
56235537Sgber	struct nandfs fs;
57235537Sgber	uint64_t cpno;
58235537Sgber	int error;
59235537Sgber
60235537Sgber	if (argc != 2) {
61235537Sgber		rmsnap_usage();
62235537Sgber		return (EX_USAGE);
63235537Sgber	}
64235537Sgber
65235537Sgber	cpno = strtoll(argv[0], (char **)NULL, 10);
66235537Sgber	if (cpno == 0) {
67235537Sgber		fprintf(stderr, "%s must be a number greater than 0\n",
68235537Sgber		    argv[0]);
69235537Sgber		return (EX_USAGE);
70235537Sgber	}
71235537Sgber
72235537Sgber	nandfs_init(&fs, argv[1]);
73235537Sgber	error = nandfs_open(&fs);
74235537Sgber	if (error == -1) {
75235537Sgber		fprintf(stderr, "nandfs_open: %s\n", nandfs_errmsg(&fs));
76235537Sgber		goto out;
77235537Sgber	}
78235537Sgber
79235537Sgber	error = nandfs_delete_snap(&fs, cpno);
80235537Sgber	if (error == -1)
81235537Sgber		fprintf(stderr, "nandfs_delete_snap: %s\n", nandfs_errmsg(&fs));
82235537Sgber
83235537Sgberout:
84235537Sgber	nandfs_close(&fs);
85235537Sgber	nandfs_destroy(&fs);
86235537Sgber	return (error);
87235537Sgber}
88