svn commit: r233069 - in projects/nand/sbin: . mount mount_nandfs
nandfs newfs_nandfs
Grzegorz Bernacki
gber at FreeBSD.org
Sat Mar 17 02:52:17 UTC 2012
Author: gber
Date: Sat Mar 17 02:52:16 2012
New Revision: 233069
URL: http://svn.freebsd.org/changeset/base/233069
Log:
Add tools required by NANDFS to mount/umount, create/remove/list
snapshots.
Obtained from: Semihalf
Supported by: FreeBSD Foundation, Juniper Networks
Added:
projects/nand/sbin/mount_nandfs/
projects/nand/sbin/mount_nandfs/Makefile
projects/nand/sbin/mount_nandfs/mount_nandfs.8
projects/nand/sbin/mount_nandfs/mount_nandfs.c
projects/nand/sbin/nandfs/
projects/nand/sbin/nandfs/Makefile
projects/nand/sbin/nandfs/lssnap.c
projects/nand/sbin/nandfs/mksnap.c
projects/nand/sbin/nandfs/nandfs.8
projects/nand/sbin/nandfs/nandfs.c
projects/nand/sbin/nandfs/nandfs.h
projects/nand/sbin/nandfs/rmsnap.c
projects/nand/sbin/newfs_nandfs/
projects/nand/sbin/newfs_nandfs/Makefile
projects/nand/sbin/newfs_nandfs/newfs_nandfs.8
projects/nand/sbin/newfs_nandfs/newfs_nandfs.c
Modified:
projects/nand/sbin/Makefile
projects/nand/sbin/mount/mntopts.h
projects/nand/sbin/mount/mount.c
Modified: projects/nand/sbin/Makefile
==============================================================================
--- projects/nand/sbin/Makefile Sat Mar 17 02:39:20 2012 (r233068)
+++ projects/nand/sbin/Makefile Sat Mar 17 02:52:16 2012 (r233069)
@@ -91,6 +91,12 @@ SUBDIR+= ipfw
SUBDIR+= natd
.endif
+.if ${MK_NAND} != "no"
+SUBDIR+= mount_nandfs
+SUBDIR+= nandfs
+SUBDIR+= newfs_nandfs
+.endif
+
.if ${MK_PF} != "no"
SUBDIR+= pfctl
SUBDIR+= pflogd
Modified: projects/nand/sbin/mount/mntopts.h
==============================================================================
--- projects/nand/sbin/mount/mntopts.h Sat Mar 17 02:39:20 2012 (r233068)
+++ projects/nand/sbin/mount/mntopts.h Sat Mar 17 02:52:16 2012 (r233069)
@@ -62,6 +62,10 @@ struct mntopt {
#define MOPT_RO { "ro", 0, MNT_RDONLY, 0 }
#define MOPT_RW { "rw", 1, MNT_RDONLY, 0 }
+
+/* Cleaner daemon flags */
+#define MOPT_NOCLEANER { "nocleaner", 0, 0, 0 }
+
/* This is parsed by mount(8), but is ignored by specific mount_*(8)s. */
#define MOPT_AUTO { "auto", 0, 0, 0 }
Modified: projects/nand/sbin/mount/mount.c
==============================================================================
--- projects/nand/sbin/mount/mount.c Sat Mar 17 02:39:20 2012 (r233068)
+++ projects/nand/sbin/mount/mount.c Sat Mar 17 02:52:16 2012 (r233069)
@@ -142,7 +142,7 @@ use_mountprog(const char *vfstype)
*/
unsigned int i;
const char *fs[] = {
- "cd9660", "mfs", "msdosfs", "nfs", "ntfs",
+ "cd9660", "mfs", "msdosfs", "nandfs", "nfs", "ntfs",
"nwfs", "nullfs", "oldnfs", "portalfs", "smbfs", "udf", "unionfs",
NULL
};
Added: projects/nand/sbin/mount_nandfs/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/nand/sbin/mount_nandfs/Makefile Sat Mar 17 02:52:16 2012 (r233069)
@@ -0,0 +1,15 @@
+PROG = mount_nandfs
+SRCS = mount_nandfs.c getmntopts.c
+MAN = mount_nandfs.8
+
+LDADD = -lutil
+DPADD = ${LIBUTIL}
+
+# mount_nandfs needs mntopts.h and getmntopts.c from src/sbin/mount/
+MOUNT ?= ${.CURDIR}/../mount
+CFLAGS += -I${MOUNT}
+WARNS ?= 6
+
+.PATH: ${MOUNT}
+
+.include <bsd.prog.mk>
Added: projects/nand/sbin/mount_nandfs/mount_nandfs.8
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/nand/sbin/mount_nandfs/mount_nandfs.8 Sat Mar 17 02:52:16 2012 (r233069)
@@ -0,0 +1,93 @@
+.\"
+.\" Copyright (c) 1993,1994 Christopher G. Demetriou
+.\" Copyright (c) 1999 Semen Ustimenko
+.\" Copyright (c) 2005 Jean-Sébastien Pédron
+.\" Copyright (c) 2010 Semihalf
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgment:
+.\" This product includes software developed by Christopher G. Demetriou.
+.\" 3. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 28, 2012
+.Dt MOUNT_NANDFS 8
+.Os
+.Sh NAME
+.Nm mount_nandfs
+.Nd "mount a NandFS file system"
+.Sh SYNOPSIS
+.Nm
+.Op Fl n
+.Op Fl f Ar cleanerd_config
+.Op Fl c Ar snapshot
+.Op Fl o Ar options
+.Ar special
+.Ar node
+.Sh DESCRIPTION
+The
+.Nm
+utility attaches the NandFS file system residing on the device
+.Ar special
+to the global file system namespace at the location
+indicated by
+.Ar node .
+.Pp
+This command is normally executed by
+.Xr mount 8
+at boot time, but can be used by any user to mount a
+NandFS file system on any directory that they own (provided,
+of course, that they have appropriate access to the device that
+contains the file system).
+.Pp
+The options are as follow:
+.Bl -tag -width indent
+.It Fl n
+Don't run
+.Xr cleanerd 8 .
+.It Fl f Ar cleanerd_config
+Run
+.Xr cleanerd 8
+with config
+.Ar cleanerd_config .
+.It Fl c Ar snapshot
+Mount specified snapshot.
+.It Fl o Ar options
+Options are specified by a comma separated string of options.
+See the mount(8) man page for possible options and their meanings.
+.El
+.Sh EXAMPLES
+To mount a NandFS volume located in
+.Pa /dev/md0 :
+.Pp
+.Dl "mount_nandfs /dev/md0 /mnt"
+.Sh SEE ALSO
+.Xr mount 2 ,
+.Xr unmount 2 ,
+.Xr fstab 5 ,
+.Xr mount 8
+.Sh AUTHORS
+.An Grzegorz Bernacki
+.An Jakub Klama
Added: projects/nand/sbin/mount_nandfs/mount_nandfs.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/nand/sbin/mount_nandfs/mount_nandfs.c Sat Mar 17 02:52:16 2012 (r233069)
@@ -0,0 +1,353 @@
+/*-
+ * Copyright (c) 2005 Jean-Sébastien Pédron
+ * Copyright (c) 2010 Semihalf
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * From FreeBSD: src/sbin/mount_reiserfs/mount_reiserfs.c,v 1.4.10.1 2009/08/03 08:13:06 kensmith Exp
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/uio.h>
+#include <sys/fcntl.h>
+#include <sys/stat.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+#include <sys/sysctl.h>
+#include <fs/nandfs/nandfs_fs.h>
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <errno.h>
+#include <sysexits.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <libutil.h>
+
+#include "mntopts.h"
+
+#define CLEANERD_PATH "/usr/sbin/cleanerd"
+#define CLEANERD_CONFIG "/etc/nandfs_cleanerd.conf"
+
+struct mntopt mopts[] = {
+ MOPT_STDOPTS,
+ MOPT_UPDATE,
+ MOPT_END
+};
+
+void usage(void);
+
+static int
+nandfs_lookup_pid_mib(const char *dev, int *mibp, size_t *miblen)
+{
+ char *mibname;
+ char readpath[MAXPATHLEN+1];
+ size_t readlen;
+ int i;
+
+ *miblen = 5;
+
+ for (i = 0; i < NANDFS_MAX_MOUNTS; i++) {
+ asprintf(&mibname, "vfs.nandfs.mount.%d.dev", i);
+ readlen = MAXPATHLEN;
+
+ if (sysctlbyname(mibname, readpath, &readlen, NULL, 0)) {
+ free(mibname);
+
+ if (errno == ENOENT)
+ continue;
+
+ return (-1);
+ }
+
+ free(mibname);
+
+ if (strncmp(dev, readpath, readlen) != 0)
+ continue;
+
+ asprintf(&mibname, "vfs.nandfs.mount.%d.cleanerd_pid", i);
+
+ if (sysctlnametomib(mibname, mibp, miblen)) {
+ free(mibname);
+ return (-1);
+ }
+
+ free(mibname);
+ return (0);
+ }
+
+ errno = ENOENT;
+ return (-1);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ struct iovec *iov;
+ struct sembuf sbuf;
+ struct statfs sfs;
+ int ch, mntflags, iovlen, nocleanerd = 0;
+ int update_start_cleanerd = 0;
+ size_t miblen, pidlen;
+ int mib[5];
+ int64_t cpno = 0;
+ uint64_t oldmntflags;
+ char *dev, *dir, mntpath[MAXPATHLEN];
+ char *cleanerd_config = NULL;
+#if 0
+ char *cleanerd_args[6];
+#endif
+ char fstype[] = "nandfs";
+ time_t start;
+ pid_t cleanerd_pid;
+ key_t semkey;
+ int semid;
+ char *p, *val;
+
+ iov = NULL;
+ iovlen = 0;
+ mntflags = 0;
+ while ((ch = getopt(argc, argv, "o:c:f:n")) != -1) {
+ switch(ch) {
+ case 'c':
+ cpno = strtoll(optarg, NULL, 10);
+ if (cpno == 0 && errno == EINVAL)
+ usage();
+ break;
+ case 'f':
+ cleanerd_config = strdup(optarg);
+ break;
+ case 'n':
+ nocleanerd = 1;
+ break;
+ case 'o':
+ getmntopts(optarg, mopts, &mntflags, 0);
+ p = strchr(optarg, '=');
+ val = NULL;
+ if (p != NULL) {
+ *p = '\0';
+ val = p + 1;
+ }
+ build_iovec(&iov, &iovlen, optarg, val, (size_t)-1);
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 2)
+ usage();
+
+ dev = argv[0];
+ dir = argv[1];
+
+ /*
+ * Resolve the mountpoint with realpath(3) and remove unnecessary
+ * slashes from the devicename if there are any.
+ */
+ (void)checkpath(dir, mntpath);
+ (void)rmslashes(dev, dev);
+
+ /* Prepare the options vector for nmount(). build_iovec() is declared
+ * in mntopts.h. */
+ build_iovec(&iov, &iovlen, "fstype", fstype, (size_t)-1);
+ build_iovec(&iov, &iovlen, "fspath", mntpath, (size_t)-1);
+ build_iovec(&iov, &iovlen, "from", dev, (size_t)-1);
+ build_iovec(&iov, &iovlen, "cpno", &cpno, sizeof(int64_t));
+
+ if (mntflags & MNT_UPDATE) {
+ if (statfs(dir, &sfs) < 0) {
+ fprintf(stderr, "Cannot statfs(): %s\n",
+ strerror(errno));
+ return (EXIT_FAILURE);
+ }
+
+ oldmntflags = sfs.f_flags;
+
+ /* Read cleanerd PID */
+ if (nandfs_lookup_pid_mib(dev, mib, &miblen)) {
+ fprintf(stderr, "Cannot lookup cleanerd PID: %s\n", strerror(errno));
+ }
+
+ pidlen = sizeof(pid_t);
+ if (sysctl(mib, miblen, &cleanerd_pid, &pidlen, NULL, 0) < 0) {
+ fprintf(stderr, "Cannot lookup cleanerd PID: %s\n",
+ strerror(errno));
+ }
+
+ /* RW -> RO update, so kill cleanerd */
+ if (((oldmntflags & MNT_RDONLY) == 0) && (mntflags & MNT_RDONLY) &&
+ (cleanerd_pid != -1)) {
+ semkey = ftok(dev, 'c');
+ semid = semget(semkey, 1, 0666 | IPC_CREAT);
+
+ if (semid < 0) {
+ fprintf(stderr, "Cannot obtain cleanerd semaphore: %s\n",
+ strerror(errno));
+ } else {
+ sbuf.sem_num = 0;
+ sbuf.sem_op = 1;
+ sbuf.sem_flg = 0;
+
+ if (semop(semid, &sbuf, 1) < 0) {
+ fprintf(stderr, "Cannot access semaphore: %s\n",
+ strerror(errno));
+ }
+ }
+
+ /* Kill cleanerd */
+ if (kill(cleanerd_pid, SIGTERM) < 0) {
+ fprintf(stderr, "Cannot kill cleanerd (pid %d): %s\n",
+ cleanerd_pid, strerror(errno));
+ } else {
+ /* Make sure that cleanerd is killed. */
+ start = time(NULL);
+ do {
+ sbuf.sem_num = 0;
+ sbuf.sem_op = 0;
+ sbuf.sem_flg = IPC_NOWAIT;
+
+ if (semop(semid, &sbuf, 1) < 0) {
+ if (errno == EAGAIN)
+ continue;
+
+ fprintf(stderr, "Cannot access semaphore: %s\n",
+ strerror(errno));
+ }
+
+ break;
+ } while (time(NULL) < (start + 5));
+ }
+
+ /* Destroy semaphore */
+ if (semctl(semid, 0, IPC_RMID, NULL) < 0) {
+ if (errno != EINVAL)
+ fprintf(stderr, "Cannot remove semaphore: %s\n",
+ strerror(errno));
+ }
+ }
+
+ /* RO -> RW update, start cleanerd */
+ if ((oldmntflags & MNT_RDONLY) && ((mntflags & MNT_RDONLY) == 0)) {
+ update_start_cleanerd = 1;
+ }
+ }
+
+
+ if (nmount(iov, iovlen, mntflags) < 0)
+ err(EX_OSERR, "%s", dev);
+
+ return (0);
+#if 0
+
+ if (nocleanerd || (mntflags & MNT_RDONLY))
+ exit(0);
+
+ if ((mntflags & MNT_UPDATE) && (update_start_cleanerd == 0)) {
+ exit(0);
+ }
+
+ /* Create cleaner semaphore */
+ semkey = ftok(dev, 'c');
+ semid = semget(semkey, 1, 0666 | IPC_CREAT);
+
+ if (semid < 0) {
+ fprintf(stderr, "Cannot obtain semaphore: %s\n",
+ strerror(errno));
+ } else {
+ sbuf.sem_num = 0;
+ sbuf.sem_op = 1;
+ sbuf.sem_flg = 0;
+
+ if (semop(semid, &sbuf, 1) < 0) {
+ fprintf(stderr, "Cannot access semaphore: %s\n",
+ strerror(errno));
+ }
+ }
+
+ /* Start cleaner daemon */
+ cleanerd_pid = fork();
+ switch (cleanerd_pid) {
+ case 0:
+ if (cleanerd_config == NULL)
+ cleanerd_config = strdup(CLEANERD_CONFIG);
+
+ cleanerd_args[0] = strdup("cleanerd");
+ cleanerd_args[1] = strdup("-c");
+ cleanerd_args[2] = cleanerd_config;
+ cleanerd_args[3] = dir;
+ cleanerd_args[4] = NULL;
+ execv(CLEANERD_PATH, cleanerd_args);
+ break;
+ case -1:
+ fprintf(stderr, "Cannot spawn cleaner daemon: %s\n",
+ strerror(errno));
+ exit(EXIT_FAILURE);
+ default:
+ start = time(NULL);
+ do {
+ sbuf.sem_num = 0;
+ sbuf.sem_op = 0;
+ sbuf.sem_flg = IPC_NOWAIT;
+
+ if (semop(semid, &sbuf, 1) < 0) {
+ if (errno == EAGAIN)
+ continue;
+
+ fprintf(stderr, "Cannot access semaphore: %s\n",
+ strerror(errno));
+
+ }
+
+ break;
+ } while (time(NULL) < (start + 5));
+
+ /* Destroy semaphore */
+ if (semctl(semid, 0, IPC_RMID, NULL) < 0) {
+ fprintf(stderr, "Cannot remove semaphore: %s\n",
+ strerror(errno));
+ }
+ }
+
+ exit(0);
+#endif
+}
+
+void
+usage(void)
+{
+ fprintf(stderr,
+ "usage: mount_nandfs [-c cpno] [-f cleanerd_config] [-n] [-o options]"
+ " special node\n");
+ exit(EX_USAGE);
+}
Added: projects/nand/sbin/nandfs/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/nand/sbin/nandfs/Makefile Sat Mar 17 02:52:16 2012 (r233069)
@@ -0,0 +1,8 @@
+PROG= nandfs
+SRCS= nandfs.c lssnap.c mksnap.c rmsnap.c
+MAN= nandfs.8
+
+DPADD= ${LIBNANDFS}
+LDADD= -lnandfs
+
+.include <bsd.prog.mk>
Added: projects/nand/sbin/nandfs/lssnap.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/nand/sbin/nandfs/lssnap.c Sat Mar 17 02:52:16 2012 (r233069)
@@ -0,0 +1,112 @@
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Semihalf under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sysexits.h>
+#include <time.h>
+
+#include <fs/nandfs/nandfs_fs.h>
+#include <libnandfs.h>
+
+#include "nandfs.h"
+
+#define NCPINFO 512
+
+static void
+lssnap_usage(void)
+{
+
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, "\tlssnap node\n");
+}
+
+static void
+print_cpinfo(struct nandfs_cpinfo *cpinfo)
+{
+ struct tm tm;
+ time_t t;
+ char timebuf[128];
+
+ if (!(cpinfo->nci_nblk_inc) && !(cpinfo->nci_inodes_count))
+ return;
+
+ t = (time_t)cpinfo->nci_create;
+ localtime_r(&t, &tm);
+ strftime(timebuf, sizeof(timebuf), "%F %T", &tm);
+
+ printf("%20llu %s\n", (unsigned long long)cpinfo->nci_cno, timebuf);
+}
+
+int
+nandfs_lssnap(int argc, char **argv)
+{
+ struct nandfs_cpinfo *cpinfos;
+ struct nandfs fs;
+ int nsnap, i;
+ int error;
+
+ if (argc != 1) {
+ lssnap_usage();
+ return (EX_USAGE);
+ }
+
+ cpinfos = malloc(sizeof(*cpinfos) * NCPINFO);
+ if (cpinfos == NULL) {
+ fprintf(stderr, "cannot allocate memory\n");
+ return (-1);
+ }
+
+ nandfs_init(&fs, argv[0]);
+ error = nandfs_open(&fs);
+ if (error == -1) {
+ fprintf(stderr, "nandfs_open: %s\n", nandfs_errmsg(&fs));
+ goto out;
+ }
+
+ nsnap = nandfs_get_snap(&fs, 1, cpinfos, NCPINFO);
+ if (nsnap == -1) {
+ fprintf(stderr, "nandfs_get_snap: %s\n", nandfs_errmsg(&fs));
+ goto out;
+ }
+
+ for (i = 0; i < nsnap; i++)
+ print_cpinfo(&cpinfos[i]);
+
+out:
+ nandfs_close(&fs);
+ nandfs_destroy(&fs);
+ free(cpinfos);
+ return (error);
+}
Added: projects/nand/sbin/nandfs/mksnap.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/nand/sbin/nandfs/mksnap.c Sat Mar 17 02:52:16 2012 (r233069)
@@ -0,0 +1,91 @@
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Semihalf under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <sysexits.h>
+
+#include <fs/nandfs/nandfs_fs.h>
+#include <libnandfs.h>
+
+#include "nandfs.h"
+
+static void
+mksnap_usage(void)
+{
+
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, "\tmksnap node\n");
+}
+
+int
+nandfs_mksnap(int argc, char **argv)
+{
+ struct nandfs fs;
+ uint64_t cpno;
+ int error;
+
+ if (argc != 1) {
+ mksnap_usage();
+ return (EX_USAGE);
+ }
+
+ nandfs_init(&fs, argv[0]);
+ error = nandfs_open_rw(&fs);
+ if (error == -1) {
+ fprintf(stderr, "nandfs_open: %s\n", nandfs_errmsg(&fs));
+ goto out;
+ }
+
+ error = nandfs_lock(&fs, 1);
+ if (error == -1) {
+ fprintf(stderr, "nandfs_lock: %s\n", nandfs_errmsg(&fs));
+ goto out;
+ }
+
+ error = nandfs_make_snap(&fs, &cpno);
+ if (error == -1)
+ fprintf(stderr, "nandfs_make_snap: %s\n", nandfs_errmsg(&fs));
+ else
+ printf("%jd\n", cpno);
+
+ error = nandfs_unlock(&fs);
+ if (error == -1) {
+ fprintf(stderr, "nandfs_unlock: %s\n", nandfs_errmsg(&fs));
+ goto out;
+ }
+out:
+ nandfs_close(&fs);
+ nandfs_destroy(&fs);
+ return (error);
+}
Added: projects/nand/sbin/nandfs/nandfs.8
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/nand/sbin/nandfs/nandfs.8 Sat Mar 17 02:52:16 2012 (r233069)
@@ -0,0 +1,75 @@
+.\"
+.\" Copyright (c) 2012 The FreeBSD Foundation
+.\" All rights reserved.
+.\"
+.\" This software was developed by Semihalf under sponsorship
+.\" from the FreeBSD Foundation.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\"
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 28, 2012
+.Dt NANDFS 8
+.Os
+.Sh NAME
+.Nm nandfs
+.Nd manage mounted NAND FS
+.Sh SYNOPSIS
+.Nm
+.Cm lssnap
+.Ar node
+.Nm
+.Cm mksnap
+.Ar node
+.Nm
+.Cm rmsnap
+.Ar snapshot node
+.Sh DESCRIPTION
+The
+.Nm
+utility allows to manage snapshots of a mounted NAND FS.
+.Sh EXAMPLES
+.Pp
+Create a snapshot of filesystem mounted on
+.Em /nand .
+.Bd -literal -offset 2n
+.Li # Ic nandfs mksnap /nand
+1
+.Ed
+.Pp
+List snapshots of filesystem mounted on
+.Em /nand .
+.Bd -literal -offset 2n
+.Li # Ic nandfs lssnap /nand
+1 2012-02-28 18:49:45 ss 138 2
+.Ed
+.Pp
+Remove snapshot 1 of filesystem mounted on
+.Em /nand .
+.Bd -literal -offset 2n
+.Li # Ic nandfs rmsnap 1 /nand
+.Ed
+.Sh AUTHORS
+This utility and manual page were written by
+.An Mateusz Guzik .
Added: projects/nand/sbin/nandfs/nandfs.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/nand/sbin/nandfs/nandfs.c Sat Mar 17 02:52:16 2012 (r233069)
@@ -0,0 +1,74 @@
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Semihalf under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+
+#include "nandfs.h"
+
+static void
+usage(void)
+{
+
+ fprintf(stderr, "usage: nandfs [lssnap | mksnap <snap> | rmsnap] "
+ "node\n");
+ exit(EX_USAGE);
+}
+
+int
+main(int argc, char **argv)
+{
+ int error = 0;
+ char *cmd;
+
+ if (argc < 2)
+ usage();
+
+ cmd = argv[1];
+ argc -= 2;
+ argv += 2;
+
+ if (strcmp(cmd, "lssnap") == 0)
+ error = nandfs_lssnap(argc, argv);
+ else if (strcmp(cmd, "mksnap") == 0)
+ error = nandfs_mksnap(argc, argv);
+ else if (strcmp(cmd, "rmsnap") == 0)
+ error = nandfs_rmsnap(argc, argv);
+ else
+ usage();
+
+ return (error);
+}
Added: projects/nand/sbin/nandfs/nandfs.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/nand/sbin/nandfs/nandfs.h Sat Mar 17 02:52:16 2012 (r233069)
@@ -0,0 +1,39 @@
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Semihalf under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef NANDFS_H
+
+int nandfs_lssnap(int, char **);
+int nandfs_mksnap(int, char **);
+int nandfs_rmsnap(int, char **);
+
+#endif /* !NANDFS_H */
Added: projects/nand/sbin/nandfs/rmsnap.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/nand/sbin/nandfs/rmsnap.c Sat Mar 17 02:52:16 2012 (r233069)
@@ -0,0 +1,98 @@
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Semihalf under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <sysexits.h>
+
+#include <fs/nandfs/nandfs_fs.h>
+#include <libnandfs.h>
+
+#include "nandfs.h"
+
+static void
+rmsnap_usage(void)
+{
+
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, "\trmsnap snap node\n");
+}
+
+int
+nandfs_rmsnap(int argc, char **argv)
+{
+ struct nandfs fs;
+ uint64_t cpno;
+ int error;
+
+ if (argc != 2) {
+ rmsnap_usage();
+ return (EX_USAGE);
+ }
+
+ cpno = strtoll(argv[0], (char **)NULL, 10);
+ if (cpno == 0) {
+ fprintf(stderr, "%s must be a number greater than 0\n",
+ argv[0]);
+ return (EX_USAGE);
+ }
+
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-projects
mailing list