From 45bb1ae6a507552dc6631d6b37e75cc6f1d73d34 Mon Sep 17 00:00:00 2001 From: Wouter den Breejen Date: Mon, 23 Jul 2007 14:38:23 +0000 Subject: [PATCH] Added ext3cow lib --- src/libext3cow/Makefile.am | 13 +++++ src/libext3cow/epoch2date.c | 24 +++++++++ src/libext3cow/ext3cow_tools.h | 10 ++++ src/libext3cow/snapshot.cc | 94 ++++++++++++++++++++++++++++++++++ src/libext3cow/snapshot.hh | 11 ++++ src/libext3cow/tt.c | 46 +++++++++++++++++ 6 files changed, 198 insertions(+) create mode 100644 src/libext3cow/Makefile.am create mode 100644 src/libext3cow/epoch2date.c create mode 100644 src/libext3cow/ext3cow_tools.h create mode 100644 src/libext3cow/snapshot.cc create mode 100644 src/libext3cow/snapshot.hh create mode 100644 src/libext3cow/tt.c diff --git a/src/libext3cow/Makefile.am b/src/libext3cow/Makefile.am new file mode 100644 index 000000000..bb9dc579a --- /dev/null +++ b/src/libext3cow/Makefile.am @@ -0,0 +1,13 @@ +pkglib_LTLIBRARIES = libext3cow.la + +libext3cow_la_SOURCES = epoch2date.c snapshot.cc tt.c ext3cow_tools.h + +pkginclude_HEADERS = snapshot.hh + +#TODO linux kernel header + +libext3cow_la_LIBADD = ../boost/format/libformat.la + +AM_CXXFLAGS = -Wall \ + -I$(srcdir)/.. ${aterm_include} + diff --git a/src/libext3cow/epoch2date.c b/src/libext3cow/epoch2date.c new file mode 100644 index 000000000..7e834473e --- /dev/null +++ b/src/libext3cow/epoch2date.c @@ -0,0 +1,24 @@ + +/* epoch2date.c - an ext3cow tool for turning epoch numbers into dates. + * Copyright (C) 2003-2007 Zachary N. J. Peterson + */ + + +#include "ext3cow_tools.h" + +int main(int argc, char** argv){ + + time_t time; + + if(argc < 2){ + fprintf(stderr, "usage: %s seconds\n", argv[0]); + exit(1); + } + + time = atoi(argv[1]); + + printf("%s", ctime(&time)); + + return 0; + +} diff --git a/src/libext3cow/ext3cow_tools.h b/src/libext3cow/ext3cow_tools.h new file mode 100644 index 000000000..8feade595 --- /dev/null +++ b/src/libext3cow/ext3cow_tools.h @@ -0,0 +1,10 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/src/libext3cow/snapshot.cc b/src/libext3cow/snapshot.cc new file mode 100644 index 000000000..992f3ec84 --- /dev/null +++ b/src/libext3cow/snapshot.cc @@ -0,0 +1,94 @@ + +/* snapshot.c - an ext3cow tool for taking file system snapshots + * Copyright (C) 2003-2007 Zachary N. J. Peterson + */ + + +#include "ext3cow_tools.h" +#include "snapshot.hh" + +//using namespace nix; + +namespace nix { + +/* +void snapshot_usage(void){ + + fprintf(stderr, "usage: snapshot \n"); + +} + + +int snapshot_main(int argc, char** argv){ + + int fd; + int ret; + unsigned int epoch = 0; + char path[256] = ".\0"; + + if(argc > 1) + strcpy(path, argv[1]); + + printf("Snapshot on %s: ", path); + + fd = open(path, O_RDONLY); + + // test for ext3cow fs type + + if(fd < 0){ + printf("failed.\n"); + perror(argv[0]); + exit(1); + } + + epoch = (int)ioctl(fd, EXT3COW_IOC_TAKESNAPSHOT, &epoch); + if((int)epoch < 0){ + printf("failed.\n"); + perror(argv[0]); + exit(1); + } + + printf("%u\n", (unsigned int)epoch); + + + return 0; + +} +*/ + +//End original function +unsigned int take_snapshot(const char* dir) //const string & file_or_dir) +{ + //const char* dir = "test"; + + int fd; + int ret; + unsigned int epoch = 0; + + //char path[256] = ".\0"; + //TODO 256 length check ??? + //strcpy(path, dir); + + fd = open(dir, O_RDONLY); + + /* test for ext3cow fs type */ + + if(fd < 0){ + printf("failed.\n"); + perror(dir); + exit(1); + } + + epoch = (int)ioctl(fd, EXT3COW_IOC_TAKESNAPSHOT, &epoch); + if((int)epoch < 0){ + printf("failed.\n"); + perror(dir); + exit(1); + } + + printf("%u\n", (unsigned int)epoch); + + return epoch; +} + +} \ No newline at end of file diff --git a/src/libext3cow/snapshot.hh b/src/libext3cow/snapshot.hh new file mode 100644 index 000000000..299a32bf0 --- /dev/null +++ b/src/libext3cow/snapshot.hh @@ -0,0 +1,11 @@ +#ifndef SNAPSHOT_H_ +#define SNAPSHOT_H_ + +namespace nix { + +//unsigned int take_snapshot(const string & file_or_dir); +unsigned int take_snapshot(const char* dir); + +} + +#endif /*SNAPSHOT_H_*/ diff --git a/src/libext3cow/tt.c b/src/libext3cow/tt.c new file mode 100644 index 000000000..0114232e1 --- /dev/null +++ b/src/libext3cow/tt.c @@ -0,0 +1,46 @@ + +/* tt.c - an ext3cow tool for retreiving the current file system epoch + * Copyright (C) 2003-2007 Zachary N. J. Peterson + */ + +#include "ext3cow_tools.h" + +void tt_usage(void){ + + fprintf(stderr, "usage: tt \n"); + +} + +int tt_main(int argc, char** argv){ + + int fd; + int ret; + unsigned int epoch = 0; + char path[255] = ".\0"; + + if(argc > 1) + strcpy(path, argv[1]); + + + fd = open(path, O_RDONLY); + + /* test for ext3cow fs type */ + + if(fd < 0){ + fprintf(stderr, "Couldn't open %s\n", path); + exit(1); + } + + + ret = ioctl(fd, EXT3COW_IOC_GETEPOCH, &epoch); + if(ret < 0){ + printf("tt on %s failed.\n", path); + perror(argv[0]); + exit(1); + } + printf("Epoch: %d\n", ret); + close(fd); + + return 0; + +}