summaryrefslogtreecommitdiffstats
path: root/src/fuse/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fuse/main.c')
-rwxr-xr-xsrc/fuse/main.c59
1 files changed, 37 insertions, 22 deletions
diff --git a/src/fuse/main.c b/src/fuse/main.c
index 861ab86..5c2db34 100755
--- a/src/fuse/main.c
+++ b/src/fuse/main.c
@@ -94,7 +94,7 @@ static int image_getattr(const char *path, struct stat *stbuf)
stbuf->st_ctim = stbuf->st_atim = stbuf->st_mtim = startupTime;
stbuf->st_uid = owner;
if ( strcmp( path, "/" ) == 0 ) {
- stbuf->st_mode = S_IFDIR | 0550;
+ stbuf->st_mode = S_IFDIR | 0777;
stbuf->st_nlink = 2;
} else if ( strcmp( path, IMAGE_PATH ) == 0 ) {
if(useCow){
@@ -163,8 +163,8 @@ static int image_write(const char *path, char *buf, size_t size, off_t offset, s
return -EIO;
}
if((((size_t)offset)+size) > imageSize){
- //TODO Add Changed IMGASZE TO COW File
imageSize = ((size_t)offset)+size;
+ writeImageSizeToFile((uint64_t)size);
}
return write_cow(buf,size, offset);
}
@@ -219,13 +219,15 @@ static int image_read(const char *path, char *buf, size_t size, off_t offset, st
}
if ( useDebug ) {
+ //TODO Check why this crashes
/* count the requested blocks */
+ /*
uint64_t startBlock = offset / ( 4096 );
const uint64_t endBlock = ( offset + size - 1 ) / ( 4096 );
for ( ; startBlock <= endBlock; startBlock++ ) {
++logInfo.blockRequestCount[startBlock];
- }
+ }*/
}
if(useCow){
return cow_read(buf, size, offset);
@@ -278,14 +280,20 @@ static void image_destroy(void *private_data UNUSED)
static int image_truncate(const char *path, off_t size, struct fuse_file_info *fi UNUSED){
- imageSize=size;
- //TODO Add Changed IMGASZE TO COW File
- return 0;
+ if ( strcmp( path, IMAGE_PATH ) == 0 ) {
+ imageSize=size;
+ writeImageSizeToFile((uint64_t)size);
+ return 0;
+ }
+ return -1;
}
static int image_ftruncate(const char *path, off_t size, struct fuse_file_info *fi UNUSED){
- imageSize=size;
- //TODO Add Changed IMGASZE TO COW File
- return 0;
+ if ( strcmp( path, IMAGE_PATH ) == 0 ) {
+ imageSize=size;
+ writeImageSizeToFile((uint64_t)size);
+ return 0;
+ }
+ return -1;
}
static int image_flush(const char *path, struct fuse_file_info *fi UNUSED){
return 0;
@@ -294,12 +302,6 @@ static int image_release(const char *path, struct fuse_file_info *fi UNUSED){
return 0;
}
-static int image_fsync(const char *path, int in, struct fuse_file_info *fi UNUSED){
- return 0;
-}
-static int image_access (const char *path, int in){
- return 0;
-}
@@ -325,10 +327,11 @@ static struct fuse_operations image_oper_cow = {
.release = image_release,
.write = image_write,
.truncate =image_truncate,
- .fsync = image_fsync,
- .access= image_access,
};
+void setImagesize(uint64_t size){
+ imageSize = size;
+}
static void printVersion()
{
@@ -349,12 +352,12 @@ static void printUsage(char *argv0, int exitCode)
printf( " -l --log Write log to given location\n" );
printf( " -o --option Mount options to pass to libfuse\n" );
printf( " -d --debug Don't fork and print debug output (fuse > stderr, dnbd3 > stdout)\n" );
- printf( " -c --cow Path where the cow file should be crated");
+ printf( " -c --cow Path where the cow file should be created");
fuse_main( 2, arg, &dnbd3_fuse_no_operations, NULL );
exit( exitCode );
}
-static const char *optString = "h:c:i:r:l:o:HvVdtsf";
+static const char *optString = "h:c:i:r:l:o:HvVdtsfz";
static const struct option longOpts[] = {
{ "host", required_argument, NULL, 'h' },
{ "image", required_argument, NULL, 'i' },
@@ -378,6 +381,7 @@ int main(int argc, char *argv[])
int newArgc;
int opt, lidx;
bool testOpt = false;
+ bool loadCow = false;
if ( argc <= 1 || strcmp( argv[1], "--help" ) == 0 || strcmp( argv[1], "--usage" ) == 0 ) {
printUsage( argv[0], 0 );
@@ -445,6 +449,9 @@ int main(int argc, char *argv[])
cow_path = optarg;
useCow=true;
break;
+ case 'z':
+ loadCow = true;
+ break;
default:
printUsage( argv[0], EXIT_FAILURE );
}
@@ -487,9 +494,17 @@ int main(int argc, char *argv[])
}
if(useCow){
printf("Using Cow");
- if(!create_cow_file(cow_path, image_Name, imageSize)){
- logadd( LOG_ERROR, "Could not create COW FIle. Bye.\n" );
- return EXIT_FAILURE;
+ if(loadCow){
+ printf("Loading Cow");
+ if(!load_cow_file(cow_path, imageSize)){
+ logadd( LOG_ERROR, "Could not load COW FIle. Bye.\n" );
+ return EXIT_FAILURE;
+ }
+ } else {
+ if(!create_cow_file(cow_path, image_Name, imageSize)){
+ logadd( LOG_ERROR, "Could not create COW FIle. Bye.\n" );
+ return EXIT_FAILURE;
+ }
}
}
// Since dnbd3 is always read only and the remote image will not change