prefer asciidoc
[rrq/fusefile.git] / fusefile.c
index 632221f917b33c12e51892d6956c8893e3138a14..00f7f7fd33e3565e6cff5966cbf7690ed58273c8 100644 (file)
@@ -1,12 +1,26 @@
-/*
-  FUSE: Filesystem in Userspace
-  Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
+/***
+    fusefile - overlay a file path with a concatenation of parts of
+    other files, read only.
 
-  This program can be distributed under the terms of the GNU GPL.
-  See the file COPYING.
+    Copyright (C) 2019  Ralph Ronnquist
 
-  Overlay a file path with a concatenation of parts of other files.
-  read only
+    This program is free software: you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+    General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program. If not, see
+    <http://www.gnu.org/licenses/>.
+
+    This source was inspired by the "null.c" example of the libfuse
+    sources, which is distributed under GPL2, and copyright (C)
+    2001-2007 Miklos Szeredi <miklos@szeredi.hu>.
 */
 
 #define FUSE_USE_VERSION 31
 
 struct Source {
     char *filename;
-    size_t from;
-    size_t to;
-    size_t start; // starting position in concatenated file
+    ssize_t from;
+    ssize_t to;
+    ssize_t start; // starting position in concatenated file
     int fd;
 };
 
 static struct {
     struct Source *array;
     int count;
-    size_t size;
+    ssize_t size;
 } sources;
 
 #if DEBUG
@@ -62,6 +76,7 @@ static size_t scan_source(char *in,struct Source *p) {
            m = i;
        }
     }
+    fprintf( stderr, "m=%d s=%d\n", m, s );
     // Copy the filename, and set from and to
     p->filename = strndup( in, ( s < 0 )? e : s );
     struct stat buf;
@@ -73,6 +88,7 @@ static size_t scan_source(char *in,struct Source *p) {
     if ( p->from < 0 ) {
        p->from = 0;
     }
+    fprintf( stderr, "p->from=%ld\n", p->from );
     p->to = ( m < 0 )? buf.st_size : atol( in+m+1 );
     if ( p->from > p->to || p->to > buf.st_size ) {
        return 1;
@@ -219,16 +235,16 @@ static void fusefile_destroy(void *data) {
 }
 
 static struct fuse_operations fusefile_oper = {
-    .getattr        = fusefile_getattr,
-    .open           = fusefile_open,
-    .read           = fusefile_read,
+    .getattr = fusefile_getattr,
+    .open = fusefile_open,
+    .read = fusefile_read,
     .destroy = fusefile_destroy,
 };
 
 static void usage() {
     char *usage =
-"Usage: catfs [ <fuse options> ] <mount> <file/from-to> ... \n"
-"Mount a concatenation of files\n"
+"Usage: fusefile [ <fuse options> ] <mount> <file/from-to> ... \n"
+"Mounts a virtual, read-only file that is a concatenation of file fragments\n"
        ;
     fprintf( stderr, "%s", usage );
     exit( 1 );
@@ -236,7 +252,7 @@ static void usage() {
 
 /**
  * Mount a concatenation of files,
- * [ <fuse options> ] <mount> <file:from,to> ...
+ * [ <fuse options> ] <mount> <file/from-to> ...
  */
 int main(int argc, char *argv[])
 {