diff options
author | gber <gber@FreeBSD.org> | 2012-05-17 10:11:18 +0000 |
---|---|---|
committer | gber <gber@FreeBSD.org> | 2012-05-17 10:11:18 +0000 |
commit | 6f7c7353004e2ff9709b326a4008ce8ea63d9270 (patch) | |
tree | a325137a898341311de8641f7212e28b7d87950e /sbin/nandfs | |
parent | 661b9d94414ea6d11d5b7960aef1f172975ce52b (diff) | |
download | FreeBSD-src-6f7c7353004e2ff9709b326a4008ce8ea63d9270.zip FreeBSD-src-6f7c7353004e2ff9709b326a4008ce8ea63d9270.tar.gz |
Import work done under project/nand (@235533) into head.
The NAND Flash environment consists of several distinct components:
- NAND framework (drivers harness for NAND controllers and NAND chips)
- NAND simulator (NANDsim)
- NAND file system (NAND FS)
- Companion tools and utilities
- Documentation (manual pages)
This work is still experimental. Please use with caution.
Obtained from: Semihalf
Supported by: FreeBSD Foundation, Juniper Networks
Diffstat (limited to 'sbin/nandfs')
-rw-r--r-- | sbin/nandfs/Makefile | 10 | ||||
-rw-r--r-- | sbin/nandfs/lssnap.c | 112 | ||||
-rw-r--r-- | sbin/nandfs/mksnap.c | 80 | ||||
-rw-r--r-- | sbin/nandfs/nandfs.8 | 75 | ||||
-rw-r--r-- | sbin/nandfs/nandfs.c | 74 | ||||
-rw-r--r-- | sbin/nandfs/nandfs.h | 40 | ||||
-rw-r--r-- | sbin/nandfs/rmsnap.c | 87 |
7 files changed, 478 insertions, 0 deletions
diff --git a/sbin/nandfs/Makefile b/sbin/nandfs/Makefile new file mode 100644 index 0000000..8474b09 --- /dev/null +++ b/sbin/nandfs/Makefile @@ -0,0 +1,10 @@ +# $FreeBSD$ + +PROG= nandfs +SRCS= nandfs.c lssnap.c mksnap.c rmsnap.c +MAN= nandfs.8 + +DPADD= ${LIBNANDFS} +LDADD= -lnandfs + +.include <bsd.prog.mk> diff --git a/sbin/nandfs/lssnap.c b/sbin/nandfs/lssnap.c new file mode 100644 index 0000000..fbee3cd --- /dev/null +++ b/sbin/nandfs/lssnap.c @@ -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]; + + 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; + uint64_t next; + int error, nsnap, i; + + 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; + } + + for (next = 1; next != 0; next = cpinfos[nsnap - 1].nci_next) { + nsnap = nandfs_get_snap(&fs, next, cpinfos, NCPINFO); + if (nsnap < 1) + break; + + for (i = 0; i < nsnap; i++) + print_cpinfo(&cpinfos[i]); + } + + if (nsnap == -1) + fprintf(stderr, "nandfs_get_snap: %s\n", nandfs_errmsg(&fs)); + +out: + nandfs_close(&fs); + nandfs_destroy(&fs); + free(cpinfos); + return (error); +} diff --git a/sbin/nandfs/mksnap.c b/sbin/nandfs/mksnap.c new file mode 100644 index 0000000..cd2d130 --- /dev/null +++ b/sbin/nandfs/mksnap.c @@ -0,0 +1,80 @@ +/*- + * 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(&fs); + if (error == -1) { + fprintf(stderr, "nandfs_open: %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); + +out: + nandfs_close(&fs); + nandfs_destroy(&fs); + return (error); +} diff --git a/sbin/nandfs/nandfs.8 b/sbin/nandfs/nandfs.8 new file mode 100644 index 0000000..b1cfa05 --- /dev/null +++ b/sbin/nandfs/nandfs.8 @@ -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 . diff --git a/sbin/nandfs/nandfs.c b/sbin/nandfs/nandfs.c new file mode 100644 index 0000000..f7ddda1 --- /dev/null +++ b/sbin/nandfs/nandfs.c @@ -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 | rmsnap <snap>] " + "node\n"); + exit(1); +} + +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); +} diff --git a/sbin/nandfs/nandfs.h b/sbin/nandfs/nandfs.h new file mode 100644 index 0000000..f544cc2 --- /dev/null +++ b/sbin/nandfs/nandfs.h @@ -0,0 +1,40 @@ +/*- + * 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 +#define NANDFS_H + +int nandfs_lssnap(int, char **); +int nandfs_mksnap(int, char **); +int nandfs_rmsnap(int, char **); + +#endif /* !NANDFS_H */ diff --git a/sbin/nandfs/rmsnap.c b/sbin/nandfs/rmsnap.c new file mode 100644 index 0000000..df2cbd5 --- /dev/null +++ b/sbin/nandfs/rmsnap.c @@ -0,0 +1,87 @@ +/*- + * 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); + } + + nandfs_init(&fs, argv[1]); + error = nandfs_open(&fs); + if (error == -1) { + fprintf(stderr, "nandfs_open: %s\n", nandfs_errmsg(&fs)); + goto out; + } + + error = nandfs_delete_snap(&fs, cpno); + if (error == -1) + fprintf(stderr, "nandfs_delete_snap: %s\n", nandfs_errmsg(&fs)); + +out: + nandfs_close(&fs); + nandfs_destroy(&fs); + return (error); +} |