1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-26 12:10:59 +01:00

Added ext3cow lib

This commit is contained in:
Wouter den Breejen 2007-07-23 14:38:23 +00:00
parent e3034da88b
commit 45bb1ae6a5
6 changed files with 198 additions and 0 deletions

View file

@ -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}

View file

@ -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;
}

View file

@ -0,0 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <time.h>
#include <sys/time.h>
#include </nix/store/8nirllv1w6qv6c5srjgah2m82bfi1d6k-linux-2.6.21.5/lib/modules/2.6.21.5-default/build/include/linux/ext3cow_fs.h>

View file

@ -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 <mountpoint>\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;
}
}

View file

@ -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_*/

46
src/libext3cow/tt.c Normal file
View file

@ -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 <mountpoint>\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;
}