hurdextras-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

libfuse/src fuse_i.h main.c netfs.c


From: Stefan Siegl
Subject: libfuse/src fuse_i.h main.c netfs.c
Date: Fri, 04 Aug 2006 12:16:13 +0000

CVSROOT:        /sources/hurdextras
Module name:    libfuse
Changes by:     Stefan Siegl <stesie>   06/08/04 12:16:12

Modified files:
        src            : fuse_i.h main.c netfs.c 

Log message:
        added support for libfuse 2.5 api

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libfuse/src/fuse_i.h?cvsroot=hurdextras&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/libfuse/src/main.c?cvsroot=hurdextras&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/libfuse/src/netfs.c?cvsroot=hurdextras&r1=1.4&r2=1.5

Patches:
Index: fuse_i.h
===================================================================
RCS file: /sources/hurdextras/libfuse/src/fuse_i.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- fuse_i.h    4 Aug 2006 00:45:35 -0000       1.4
+++ fuse_i.h    4 Aug 2006 12:16:12 -0000       1.5
@@ -32,13 +32,37 @@
 /* pointer to the fuse_operations structure of this translator process */
 extern const struct fuse_operations_compat22 *fuse_ops_compat22;
 extern const struct fuse_operations_compat2 *fuse_ops_compat2;
+extern const struct fuse_operations *fuse_ops25;
 
-#define FUSE_OP_HAVE(a) ((fuse_ops_compat22) ? \
+#define FUSE_OP_HAVE(a) (fuse_ops25 ? \
+                        (fuse_ops25->a != NULL) \
+                        : ((fuse_ops_compat22) ? \
                           (fuse_ops_compat22->a != NULL) : \
-                         (fuse_ops_compat2->a != NULL))
-#define FUSE_OP_CALL(a,b...) ((fuse_ops_compat22) ? \
+                           (fuse_ops_compat2->a != NULL)))
+#define FUSE_OP_CALL(a,b...) (fuse_ops25 ? \
+                             (fuse_ops25->a(b)) : \
+                             ((fuse_ops_compat22) ?       \
                                (fuse_ops_compat22->a(b)) : \
-                               (fuse_ops_compat2->a(b)))
+                               (fuse_ops_compat2->a(b))))
+
+#define FUSE_OP_HAVE22(a) (fuse_ops25 ? \
+                          (fuse_ops25->a != NULL)      \
+                          : ((fuse_ops_compat22) ?             \
+                             (fuse_ops_compat22->a != NULL) : 0))
+
+#define FUSE_OP_CALL22(a,b...) (fuse_ops25 ? \
+                               (fuse_ops25->a(b)) :       \
+                               ((fuse_ops_compat22) ?     \
+                                (fuse_ops_compat22->a(b)) : (0)))
+
+#define NN_INFO(dir)   (fuse_ops25 ?                           \
+                       ((void *) &(dir)->nn->info.info25)      \
+                       : ((void *) &(dir)->nn->info.compat22))
+
+#define NN_INFO_APPLY(node,key) do {           \
+    if(fuse_ops25) (node)->nn->info.info25.key;        \
+    else (node)->nn->info.compat22.key;                \
+  } while(0)
 
 /*****************************************************************************
  *** netnodes (in memory representation of libfuse's files or directories) ***
@@ -57,6 +81,7 @@
    */
   union {
     struct fuse_file_info_compat22 compat22;
+    struct fuse_file_info info25;
   } info;
 
   /* pointer to our parent's netnode, if any */

Index: main.c
===================================================================
RCS file: /sources/hurdextras/libfuse/src/main.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- main.c      4 Aug 2006 00:45:35 -0000       1.7
+++ main.c      4 Aug 2006 12:16:12 -0000       1.8
@@ -35,6 +35,7 @@
 /* pointer to the fuse_operations structure of this translator process */
 const struct fuse_operations_compat22 *fuse_ops_compat22 = NULL;
 const struct fuse_operations_compat2 *fuse_ops_compat2 = NULL;
+const struct fuse_operations *fuse_ops25 = NULL;
 
 /* the port where to write out debug messages to, NULL to omit these */
 FILE *debug_port = NULL;
@@ -42,6 +43,9 @@
 /* the private data pointer returned from init() callback */
 void *fsys_privdata = NULL;
 
+/* bootstrap fuse translator */
+static int fuse_bootstrap(const char *mountpoint);
+
 
 /* Interpret a __single__ mount option 
  * The option itself `opt' may be modified during this call.
@@ -271,7 +275,11 @@
 fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
               size_t op_size)
 {
-  assert(0);
+  fuse_parse_argv(argc, argv);
+
+  int fd = fuse_mount(argv[0], NULL);
+  return (libfuse_params.disable_mt ? fuse_loop : fuse_loop_mt)
+    (fuse_new(fd, NULL, op, op_size));
 }
 
 
@@ -304,7 +312,26 @@
 fuse_new(int fd, struct fuse_args *args,
         const struct fuse_operations *op, size_t op_size)
 {
-  assert(0);
+  (void) op_size; /* FIXME, see what the real Fuse library does with 
+                  * this argument */
+
+  if(fd != FUSE_MAGIC)
+    return NULL; 
+
+  if(args && args->allocated)
+    {
+      int i;
+      for(i = 0; i < args->argc; i ++)
+       if(fuse_parse_opt(args->argv[i]))
+         return NULL;
+    }
+
+  fuse_ops25 = op;
+
+  if(op->init)
+    fsys_privdata = op->init();
+
+  return (void *) FUSE_MAGIC; /* we don't have a fuse structure, sorry. */
 }
 
 
@@ -339,7 +366,15 @@
 int 
 fuse_mount(const char *mountpoint, struct fuse_args *args)
 {
-  assert(0);
+  if(args && args->allocated)
+    {
+      int i;
+      for(i = 0; i < args->argc; i ++)
+       if(fuse_parse_opt(args->argv[i]))
+         return 0;
+    }
+
+  return fuse_bootstrap(mountpoint);
 }
 
 
@@ -349,6 +384,12 @@
   if(fuse_parse_opts(opts))
     return 0;
 
+  return fuse_bootstrap(mountpoint);
+}
+
+static int
+fuse_bootstrap(const char *mountpoint)
+{
   mach_port_t bootstrap, ul_node;
   task_get_bootstrap_port(mach_task_self(), &bootstrap);
 
@@ -519,6 +560,7 @@
 void
 fuse_exit(struct fuse *f)
 {
+  (void) f;
   /*
    * well, we should make fuse_main exit, this is, we would have to
    * cancel ports_manage_port_operations_one_thread. however this is
@@ -531,6 +573,8 @@
 int
 fuse_exited(struct fuse *f)
 {
+  (void) f;
+
   /*
    * if fuse_exit is called, we buy the farm, therefore we still must be alive.
    */

Index: netfs.c
===================================================================
RCS file: /sources/hurdextras/libfuse/src/netfs.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- netfs.c     4 Aug 2006 00:39:36 -0000       1.4
+++ netfs.c     4 Aug 2006 12:16:12 -0000       1.5
@@ -314,7 +314,34 @@
   else if(FUSE_OP_HAVE(statfs))
     {
       refresh_context_struct(cred);
-      err = -FUSE_OP_CALL(statfs, node->nn->path, st);
+
+      if(fuse_ops25)
+       {
+         struct statvfs stvfs;
+         err = -fuse_ops25->statfs(node->nn->path, &stvfs);
+
+         st->f_type = stvfs.__f_type;
+         st->f_bsize = stvfs.f_bsize;
+         st->f_blocks = stvfs.f_blocks;
+         st->f_bfree = stvfs.f_bfree;
+         st->f_bavail = stvfs.f_bavail;
+         st->f_files = stvfs.f_files;
+         st->f_ffree = stvfs.f_ffree;
+         st->f_fsid = stvfs.f_fsid;
+         st->f_namelen = stvfs.f_namemax;
+         st->f_favail = stvfs.f_favail;
+         st->f_frsize = stvfs.f_frsize;
+         st->f_flag = stvfs.f_flag;
+       }
+
+      else if(fuse_ops_compat22)
+       err = -fuse_ops_compat22->statfs(node->nn->path, st);
+
+      else if(fuse_ops_compat2)
+       err = -fuse_ops_compat2->statfs(node->nn->path, st);
+
+      else
+       assert(0);
     }
 
   else
@@ -417,8 +444,8 @@
    * into memory. */
   if(! err) 
     {
-      node->nn->info.compat22.flags = flags;
-      if(flags & O_EXEC) node->nn->info.compat22.flags |= O_RDONLY;
+      NN_INFO_APPLY(node, flags = flags);
+      if(flags & O_EXEC) NN_INFO_APPLY(node, flags |= O_RDONLY);
     }
 
  out:
@@ -561,12 +588,15 @@
       goto out;
     }
 
-  if(fuse_ops_compat22)
-    err = -fuse_ops_compat22->fsync(node->nn->path, 0,
-                                   &node->nn->info.compat22);
-  else
+  if(FUSE_OP_HAVE22(fsync))
+    err = -FUSE_OP_CALL22(fsync, node->nn->path, 0, NN_INFO(node));
+
+  else if(fuse_ops_compat2)
     err = -fuse_ops_compat2->fsync(node->nn->path, 0);
         
+  else
+    assert(0);
+        
   if(! err)
     node->nn->may_need_sync = 0; 
 
@@ -1061,21 +1091,33 @@
       goto out;
     }
 
-  node->nn->info.compat22.writepage = 0; /* cannot distinct on the Hurd :( */
+  NN_INFO_APPLY(node, writepage = 0); /* cannot distinct on the Hurd :( */
 
-  if(fuse_ops_compat2 && fuse_ops_compat2->open
-     && (err = fuse_ops_compat2->open(node->nn->path,
-                                     node->nn->info.compat22.flags)))
-    goto out;
-  else if(fuse_ops_compat22 && fuse_ops_compat22->open
-         && (err = fuse_ops_compat22->open(node->nn->path,
-                                           &node->nn->info.compat22)))
-    goto out;
+  if(FUSE_OP_HAVE(open))
+    {
+      if(FUSE_OP_HAVE22(open))
+       err = FUSE_OP_CALL22(open, node->nn->path, NN_INFO(node));
+      
+      else if(fuse_ops_compat2)
+       err = fuse_ops_compat2->open(node->nn->path,
+                                    node->nn->info.compat22.flags);
+
+      else
+       assert(0);
 
-  int sz = fuse_ops_compat22 ? 
-    (fuse_ops_compat22->write(node->nn->path, data, *len,
-                             offset, &node->nn->info.compat22)) : 
-    (fuse_ops_compat2->write(node->nn->path, data, *len, offset));
+      if(err) goto out;
+    }
+
+  int sz;
+  if(FUSE_OP_HAVE22(write))
+    sz = FUSE_OP_CALL22(write, node->nn->path, data, *len, offset,
+                       NN_INFO(node));
+                          
+  else if(fuse_ops_compat2)
+    sz = fuse_ops_compat2->write(node->nn->path, data, *len, offset);
+
+  else
+    assert(0);
 
   /* FIXME: open, flush and release handling probably should be changed
    * completely, I mean, we probably should do fuse_ops->open in 
@@ -1084,15 +1126,21 @@
    *
    * This way we wouldn't be able to report any errors back.
    */
-  if(sz >= 0 && fuse_ops_compat22 && fuse_ops_compat22->flush)
-    err = fuse_ops_compat22->flush(node->nn->path, &node->nn->info.compat22);
+  if(sz >= 0 && FUSE_OP_HAVE22(flush))
+    err = FUSE_OP_CALL22(flush, node->nn->path, NN_INFO(node));
 
-  if(fuse_ops_compat2 && fuse_ops_compat2->open && fuse_ops_compat2->release)
-    fuse_ops_compat2->release(node->nn->path, node->nn->info.compat22.flags);
+  if(FUSE_OP_HAVE(open) && FUSE_OP_HAVE(release))
+    {
+      if(FUSE_OP_HAVE22(release))
+       FUSE_OP_CALL22(release, node->nn->path, NN_INFO(node));
+
+      else if(fuse_ops_compat2)
+       fuse_ops_compat2->release(node->nn->path,
+                                 node->nn->info.compat22.flags);
 
-  else if(fuse_ops_compat22 && fuse_ops_compat22->open
-         && fuse_ops_compat22->release)
-    fuse_ops_compat22->release(node->nn->path, &node->nn->info.compat22);
+      else
+       assert(0);
+    }
   
   if(sz < 0)
     err = -sz;
@@ -1170,19 +1218,31 @@
       goto out;
     }
 
-  if(fuse_ops_compat2 && fuse_ops_compat2->open
-     && (err = fuse_ops_compat2->open(node->nn->path,
-                                     node->nn->info.compat22.flags)))
-    goto out;
-  else if(fuse_ops_compat22 && fuse_ops_compat22->open
-         && (err = fuse_ops_compat22->open(node->nn->path,
-                                           &node->nn->info.compat22)))
-    goto out;
+  if(FUSE_OP_HAVE(open))
+    {
+      if(FUSE_OP_HAVE22(open))
+       err = FUSE_OP_CALL22(open, node->nn->path, NN_INFO(node));
+
+      else if(fuse_ops_compat2)
+       err = fuse_ops_compat2->open(node->nn->path,
+                                    node->nn->info.compat22.flags);
+
+      else
+       assert(0);
+
+      if(err) goto out;
+    }
 
-  int sz = fuse_ops_compat22 ? 
-    (fuse_ops_compat22->read(node->nn->path, data, *len,
-                            offset, &node->nn->info.compat22)) : 
-    (fuse_ops_compat2->read(node->nn->path, data, *len, offset));
+  int sz;
+  if(FUSE_OP_HAVE22(read))
+    sz = FUSE_OP_CALL22(read, node->nn->path, data, *len, offset,
+                       NN_INFO(node));
+
+  else if(fuse_ops_compat2)
+    sz = fuse_ops_compat2->read(node->nn->path, data, *len, offset);
+
+  else
+    assert(0);
 
   /* FIXME: open, flush and release handling probably should be changed
    * completely, I mean, we probably should do fuse_ops->open in 
@@ -1191,15 +1251,21 @@
    *
    * This way we wouldn't be able to report any errors back.
    */
-  if(sz >= 0 && fuse_ops_compat22 && fuse_ops_compat22->flush)
-    err = fuse_ops_compat22->flush(node->nn->path, &node->nn->info.compat22);
+  if(sz >= 0 && FUSE_OP_HAVE22(flush))
+    err = FUSE_OP_CALL22(flush, node->nn->path, NN_INFO(node));
 
-  if(fuse_ops_compat2 && fuse_ops_compat2->open && fuse_ops_compat2->release)
-    fuse_ops_compat2->release(node->nn->path, node->nn->info.compat22.flags);
+  if(FUSE_OP_HAVE(open) && FUSE_OP_HAVE(release))
+    {
+      if(FUSE_OP_HAVE22(release))
+       FUSE_OP_CALL22(release, node->nn->path, NN_INFO(node));
 
-  else if(fuse_ops_compat22 && fuse_ops_compat22->open
-         && fuse_ops_compat22->release)
-    fuse_ops_compat22->release(node->nn->path, &node->nn->info.compat22);
+      else if(fuse_ops_compat2)
+       fuse_ops_compat2->release(node->nn->path,
+                                 node->nn->info.compat22.flags);
+
+      else
+       assert(0);
+    }
 
   if(sz < 0)
     err = -sz;
@@ -1236,10 +1302,9 @@
 {
   struct stat stat;
   
-  assert(fuse_ops_compat22);
-  assert(fuse_ops_compat22->getattr);
+  assert(FUSE_OP_HAVE22(getattr));
+  FUSE_OP_CALL22(getattr, name, &stat);
   
-  fuse_ops_compat22->getattr(name, &stat);
   return stat.st_ino;
 }
 
@@ -1388,13 +1453,15 @@
   handle->parent = dir->nn;
   handle->hdrpos = (struct dirent*) *data;
 
-  if(fuse_ops_compat22)
-    fuse_ops_compat22->getdir(dir->nn->path, handle,
-                             get_dirents_getdir_helper);
-  else
+  if(FUSE_OP_HAVE22(getdir))
+    FUSE_OP_CALL22(getdir, dir->nn->path, handle, get_dirents_getdir_helper);
+
+  else if(fuse_ops_compat2)
     fuse_ops_compat2->getdir(dir->nn->path, handle,
                            get_dirents_getdir_helper_compat);
                            
+  else
+    assert(0);
 
   *data_len -= handle->size; /* subtract number of bytes left in the
                              * buffer from the length of the buffer we
@@ -1522,8 +1589,7 @@
   error_t err;
   FUNC_PROLOGUE_NODE("get_dirents_readdir", dir);
 
-  if(! (fuse_ops_compat22 && fuse_ops_compat22->readdir))
-    FUNC_RETURN(EOPNOTSUPP);
+  assert(FUSE_OP_HAVE22(readdir));
 
   fuse_dirh_t handle;
   if(! (handle = malloc(sizeof(struct fuse_dirhandle))))
@@ -1552,22 +1618,21 @@
   handle->parent = dir->nn;
   handle->hdrpos = (struct dirent*) *data;
 
-  if(fuse_ops_compat22->opendir
-     && (err = fuse_ops_compat22->opendir(dir->nn->path,
-                                         &dir->nn->info.compat22)))
+  if(FUSE_OP_HAVE22(opendir)
+     && (err = FUSE_OP_CALL22(opendir, dir->nn->path, NN_INFO(dir))))
     goto out;
 
-  if((err = fuse_ops_compat22->readdir(dir->nn->path, handle, 
+  if((err = FUSE_OP_CALL22(readdir, dir->nn->path, handle, 
                                       get_dirents_readdir_helper,
-                                      first_entry, &dir->nn->info.compat22))) 
+                          first_entry, NN_INFO(dir))))
     {
-      fuse_ops_compat22->releasedir(dir->nn->path, &dir->nn->info.compat22);
+      if(FUSE_OP_HAVE22(releasedir))
+       FUSE_OP_CALL22(releasedir, dir->nn->path, NN_INFO(dir));
       goto out;
     }
 
-  if(fuse_ops_compat22->releasedir
-     && (err = fuse_ops_compat22->releasedir(dir->nn->path,
-                                            &dir->nn->info.compat22)))
+  if(FUSE_OP_HAVE22(releasedir)
+     && (err = FUSE_OP_CALL22(releasedir, dir->nn->path, NN_INFO(dir))))
     goto out;
 
   *data_len -= handle->size; /* subtract number of bytes left in the
@@ -1601,7 +1666,7 @@
     goto out;
 
 
-  if(fuse_ops_compat22 && fuse_ops_compat22->readdir)
+  if(FUSE_OP_HAVE22(readdir))
     err = get_dirents_readdir(dir, first_entry, num_entries, data, data_len,
                              data_entries);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]