gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r5321 - gnunet-fuse


From: gnunet
Subject: [GNUnet-SVN] r5321 - gnunet-fuse
Date: Wed, 18 Jul 2007 23:02:53 -0600 (MDT)

Author: amatus
Date: 2007-07-18 23:02:53 -0600 (Wed, 18 Jul 2007)
New Revision: 5321

Added:
   gnunet-fuse/truncate.c
Modified:
   gnunet-fuse/Makefile.am
   gnunet-fuse/getattr.c
   gnunet-fuse/gnfs.h
   gnunet-fuse/main.c
Log:
Added file truncation support

Modified: gnunet-fuse/Makefile.am
===================================================================
--- gnunet-fuse/Makefile.am     2007-07-17 20:21:43 UTC (rev 5320)
+++ gnunet-fuse/Makefile.am     2007-07-19 05:02:53 UTC (rev 5321)
@@ -13,6 +13,7 @@
        rename.c \
        rmdir.c \
        special_file.c \
+       truncate.c \
        unlink.c \
        utimens.c \
        write.c \

Modified: gnunet-fuse/getattr.c
===================================================================
--- gnunet-fuse/getattr.c       2007-07-17 20:21:43 UTC (rev 5320)
+++ gnunet-fuse/getattr.c       2007-07-19 05:02:53 UTC (rev 5321)
@@ -60,7 +60,7 @@
        }
        if(de->de_cached && de->de_type == DE_FILE)
        {
-               ret = stat(path, stbuf);
+               ret = stat(de->de_filename, stbuf);
                if(ret == -1)
                {
                        ret = -errno;

Modified: gnunet-fuse/gnfs.h
===================================================================
--- gnunet-fuse/gnfs.h  2007-07-17 20:21:43 UTC (rev 5320)
+++ gnunet-fuse/gnfs.h  2007-07-19 05:02:53 UTC (rev 5321)
@@ -119,6 +119,7 @@
 int gn_unlink(const char *path);
 int gn_rmdir(const char *path);
 int gn_rename(const char *from, const char *to);
+int gn_truncate(const char *path, off_t size);
 int gn_utimens(const char *path, const struct timespec ts[2]);
 int gn_open(const char *path, struct fuse_file_info *fi);
 int gn_read(const char *path, char *buf, size_t size, off_t offset,

Modified: gnunet-fuse/main.c
===================================================================
--- gnunet-fuse/main.c  2007-07-17 20:21:43 UTC (rev 5320)
+++ gnunet-fuse/main.c  2007-07-19 05:02:53 UTC (rev 5321)
@@ -78,6 +78,7 @@
        .unlink = gn_unlink,
        .rmdir = gn_rmdir,
        .rename = gn_rename,
+       .truncate = gn_truncate,
        .utimens = gn_utimens,
        .open = gn_open,
        .read = gn_read,

Added: gnunet-fuse/truncate.c
===================================================================
--- gnunet-fuse/truncate.c                              (rev 0)
+++ gnunet-fuse/truncate.c      2007-07-19 05:02:53 UTC (rev 5321)
@@ -0,0 +1,84 @@
+/*
+ * truncate.c - FUSE truncate function
+ *
+ * This file is part of gnunet-fuse.
+ * Copyright (C) 2007 David Barksdale
+ *
+ * gnunet-fuse is free software; you can redistribute it and/or
+ * modify if under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ *
+ * gnunet-fuse 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <errno.h>
+#include <unistd.h>
+#include <fuse.h>
+#include "gnfs.h"
+
+int gn_truncate(const char *path, off_t size)
+{
+       struct dirent *de;
+       int ret = 0;
+
+       GE_LOG(ectx, GE_BULK | GE_DEVELOPER | GE_DEBUG,
+               "%s: called for '%s' %lld bytes\n", __FUNCTION__, path, size);
+
+       /* Check for special file */
+       if(gn_exists_special_file(path))
+               return -EACCES;
+
+       /* Lookup dirent for path */
+       de = gn_dirent_find(path);
+       if(de == NULL)
+       {
+               GE_LOG(ectx, GE_BULK | GE_DEVELOPER | GE_DEBUG,
+                       "%s: file not found\n", __FUNCTION__);
+               return -ENOENT;
+       }
+       if(de->de_type != DE_FILE)
+       {
+               GE_LOG(ectx, GE_BULK | GE_DEVELOPER | GE_DEBUG,
+                       "%s: not a file\n", __FUNCTION__);
+               ret = -EISDIR;
+               goto out;
+       }
+
+       /* We must be cached */
+       if(SEMAPHORE_DOWN(de->de_sema, YES) == SYSERR)
+       {
+               ret = -EIO;
+               goto out;
+       }
+       if(!de->de_cached)
+       {
+               if(gn_dirent_download_locked(de) == -1)
+               {
+                       ret = -EIO;
+                       goto out_unlock;
+               }
+       }
+
+       /* Perform truncate */
+       ret = ftruncate(de->de_fd, size);
+       if(ret == -1)
+       {
+               ret = -errno;
+               goto out_unlock;
+       }
+
+       /* Mark us dirty */
+       de->de_dirty = 1;
+out_unlock:
+       SEMAPHORE_UP(de->de_sema);
+out:
+       gn_dirent_put(de);
+       return ret;
+}





reply via email to

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