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 <sysexits.h>
37235537Sgber
38235537Sgber#include <fs/nandfs/nandfs_fs.h>
39235537Sgber#include <libnandfs.h>
40235537Sgber
41235537Sgber#include "nandfs.h"
42235537Sgber
43235537Sgberstatic void
44235537Sgbermksnap_usage(void)
45235537Sgber{
46235537Sgber
47235537Sgber	fprintf(stderr, "usage:\n");
48235537Sgber	fprintf(stderr, "\tmksnap node\n");
49235537Sgber}
50235537Sgber
51235537Sgberint
52235537Sgbernandfs_mksnap(int argc, char **argv)
53235537Sgber{
54235537Sgber	struct nandfs fs;
55235537Sgber	uint64_t cpno;
56235537Sgber	int error;
57235537Sgber
58235537Sgber	if (argc != 1) {
59235537Sgber		mksnap_usage();
60235537Sgber		return (EX_USAGE);
61235537Sgber	}
62235537Sgber
63235537Sgber	nandfs_init(&fs, argv[0]);
64235537Sgber	error = nandfs_open(&fs);
65235537Sgber	if (error == -1) {
66235537Sgber		fprintf(stderr, "nandfs_open: %s\n", nandfs_errmsg(&fs));
67235537Sgber		goto out;
68235537Sgber	}
69235537Sgber
70235537Sgber	error = nandfs_make_snap(&fs, &cpno);
71235537Sgber	if (error == -1)
72235537Sgber		fprintf(stderr, "nandfs_make_snap: %s\n", nandfs_errmsg(&fs));
73235537Sgber	else
74235537Sgber		printf("%jd\n", cpno);
75235537Sgber
76235537Sgberout:
77235537Sgber	nandfs_close(&fs);
78235537Sgber	nandfs_destroy(&fs);
79235537Sgber	return (error);
80235537Sgber}
81