arg
[oweals/gnunet.git] / src / fs / fs_file_information.c
index a110822d12517817fd586bdb22ac8f2d26b417bf..b248fae44353d1440316ed52fba20714fa68fb31 100644 (file)
@@ -1,10 +1,10 @@
 /*
      This file is part of GNUnet.
-     (C) 2009 Christian Grothoff (and other contributing authors)
+     (C) 2009, 2011 Christian Grothoff (and other contributing authors)
 
      GNUnet 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 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -24,7 +24,6 @@
  * @author Christian Grothoff
  *
  * TODO:
- * - serialization/deserialization (& deserialization API)
  * - metadata filename clean up code
  * - metadata/ksk generation for directories from contained files
  */
 
 
 /**
- * Create a temporary file on disk to store the current
- * state of "fi" in.
+ * Add meta data that libextractor finds to our meta data
+ * container.
  *
- * @param fi file information to sync with disk
+ * @param cls closure, our meta data container
+ * @param plugin_name name of the plugin that produced this value;
+ *        special values can be used (i.e. '<zlib>' for zlib being
+ *        used in the main libextractor library and yielding
+ *        meta data).
+ * @param type libextractor-type describing the meta data
+ * @param format basic format information about data
+ * @param data_mime_type mime-type of data (not of the original file);
+ *        can be NULL (if mime-type is not known)
+ * @param data actual meta-data found
+ * @param data_len number of bytes in data
+ * @return always 0 to continue extracting
  */
-void
-GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation * fi)
+static int
+add_to_md(void *cls,
+         const char *plugin_name,
+         enum EXTRACTOR_MetaType type,
+         enum EXTRACTOR_MetaFormat format,
+         const char *data_mime_type,
+         const char *data,
+         size_t data_len)
 {
-  if (NULL == fi->serialization)
-    {
-      fi->serialization = NULL; // FIXME -- need cfg!
-    }
-  // FIXME...
+  struct GNUNET_CONTAINER_MetaData *md = cls;
+  (void) GNUNET_CONTAINER_meta_data_insert (md,
+                                           plugin_name,
+                                           type,
+                                           format,
+                                           data_mime_type,
+                                           data,
+                                           data_len);
+  return 0;
 }
 
 
 /**
- * Load file information from the file to which
- * it was sync'ed.
+ * Extract meta-data from a file.
  *
- * @param fn name of the file to use
- * @return NULL on error
+ * @return GNUNET_SYSERR on error, otherwise the number
+ *   of meta-data items obtained
  */
-struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_recover (const char *fn)
+int
+GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData
+                                      *md, const char *filename,
+                                      struct EXTRACTOR_PluginList *
+                                      extractors)
 {
-  struct GNUNET_FS_FileInformation *ret;
-  ret = NULL;
-  // FIXME!
-  return ret;
+  int old;
+
+  if (filename == NULL)
+    return GNUNET_SYSERR;
+  if (extractors == NULL)
+    return 0;
+  old = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
+  GNUNET_assert (old >= 0);
+  EXTRACTOR_extract (extractors, 
+                    filename,
+                    NULL, 0,
+                    &add_to_md,
+                    md);
+  return (GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL) - old);
 }
 
 
+
 /**
  * Obtain the name under which this file information
  * structure is stored on disk.  Only works for top-level
@@ -88,95 +121,10 @@ GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s)
 }
 
 
-/**
- * Closure for "data_reader_file".
- */
-struct FileInfo
-{
-  /**
-   * Name of the file to read.
-   */
-  char *filename;
-
-  /**
-   * File descriptor, NULL if it has not yet been opened.
-   */
-  struct GNUNET_DISK_FileHandle *fd;
-};
-
-
-/**
- * Function that provides data by reading from a file.
- *
- * @param cls closure (points to the file information)
- * @param offset offset to read from; it is possible
- *            that the caller might need to go backwards
- *            a bit at times
- * @param max maximum number of bytes that should be 
- *            copied to buf; readers are not allowed
- *            to provide less data unless there is an error;
- *            a value of "0" will be used at the end to allow
- *            the reader to clean up its internal state
- * @param buf where the reader should write the data
- * @param emsg location for the reader to store an error message
- * @return number of bytes written, usually "max", 0 on error
- */
-static size_t
-data_reader_file(void *cls, 
-                uint64_t offset,
-                size_t max, 
-                void *buf,
-                char **emsg)
-{
-  struct FileInfo *fi = cls;
-  ssize_t ret;
-
-  if (max == 0)
-    {
-      if (fi->fd != NULL)
-       GNUNET_DISK_file_close (fi->fd);
-      GNUNET_free (fi->filename);
-      GNUNET_free (fi);
-      return 0;
-    }  
-  if (fi->fd == NULL)
-    {
-      fi->fd = GNUNET_DISK_file_open (fi->filename,
-                                     GNUNET_DISK_OPEN_READ,
-                                     GNUNET_DISK_PERM_NONE);
-      if (fi->fd == NULL)
-       {
-         GNUNET_asprintf (emsg, 
-                          _("Could not open file `%s': %s"),
-                          fi->filename,
-                          STRERROR (errno));
-         return 0;
-       }
-    }
-  GNUNET_DISK_file_seek (fi->fd, offset, GNUNET_DISK_SEEK_SET);
-  ret = GNUNET_DISK_file_read (fi->fd, buf, max);
-  if (ret == -1)
-    {
-      GNUNET_asprintf (emsg, 
-                      _("Could not read file `%s': %s"),
-                      fi->filename,
-                      STRERROR (errno));
-      return 0;
-    }
-  if (ret != max)
-    {
-      GNUNET_asprintf (emsg, 
-                      _("Short read reading from file `%s'!"),
-                      fi->filename);
-      return 0;
-    }
-  return max;
-}
-
-
 /**
  * Create an entry for a file in a publish-structure.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial value for the client-info value for this entry
  * @param filename name of the file or directory to publish
  * @param keywords under which keywords should this file be available
@@ -184,26 +132,23 @@ data_reader_file(void *cls,
  * @param meta metadata for the file
  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
  *                GNUNET_SYSERR for simulation
- * @param anonymity what is the desired anonymity level for sharing?
- * @param priority what is the priority for OUR node to
- *   keep this file available?  Use 0 for maximum anonymity and
- *   minimum reliability...
- * @param expirationTime when should this content expire?
+ * @param bo block options
  * @return publish structure entry for the file
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_file (void *client_info,
+GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
+                                            void *client_info,
                                             const char *filename,
                                             const struct GNUNET_FS_Uri *keywords,
                                             const struct GNUNET_CONTAINER_MetaData *meta,
                                             int do_index,
-                                            uint32_t anonymity,
-                                            uint32_t priority,
-                                            struct GNUNET_TIME_Absolute expirationTime)
+                                            const struct GNUNET_FS_BlockOptions *bo)
 {
   struct FileInfo *fi;
   struct stat sbuf;
   struct GNUNET_FS_FileInformation *ret;
+  const char *fn;
+  const char *ss;
 
   if (0 != STAT (filename, &sbuf))
     {
@@ -212,66 +157,44 @@ GNUNET_FS_file_information_create_from_file (void *client_info,
                                filename);
       return NULL;
     }
-  fi = GNUNET_malloc (sizeof(struct FileInfo));
-  fi->filename = GNUNET_STRINGS_filename_expand (filename);
-  if (fi->filename == NULL)
+  fi = GNUNET_FS_make_file_reader_context_ (filename);
+  if (fi == NULL)
     {
-      GNUNET_free (fi);
+      GNUNET_break (0);
       return NULL;
     }
-  ret = GNUNET_FS_file_information_create_from_reader (client_info,
+  ret = GNUNET_FS_file_information_create_from_reader (h,
+                                                      client_info,
                                                       sbuf.st_size,
-                                                      &data_reader_file,
+                                                      &GNUNET_FS_data_reader_file_,
                                                       fi,
                                                       keywords,
                                                       meta,
                                                       do_index,
-                                                      anonymity,
-                                                      priority,
-                                                      expirationTime);
-  ret->data.file.filename = GNUNET_strdup (filename);
+                                                      bo);
+  if (ret == NULL)
+    return NULL;
+  ret->h = h;
+  ret->filename = GNUNET_strdup (filename);
+  fn = filename;
+  while (NULL != (ss = strstr (fn,
+                              DIR_SEPARATOR_STR)))
+    fn = ss + 1;
+  GNUNET_CONTAINER_meta_data_insert (ret->meta,
+                                    "<gnunet>",
+                                    EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
+                                    EXTRACTOR_METAFORMAT_C_STRING,
+                                    "text/plain",
+                                    fn,
+                                    strlen (fn) + 1);
   return ret;
 }
 
 
-/**
- * Function that provides data by copying from a buffer.
- *
- * @param cls closure (points to the buffer)
- * @param offset offset to read from; it is possible
- *            that the caller might need to go backwards
- *            a bit at times
- * @param max maximum number of bytes that should be 
- *            copied to buf; readers are not allowed
- *            to provide less data unless there is an error;
- *            a value of "0" will be used at the end to allow
- *            the reader to clean up its internal state
- * @param buf where the reader should write the data
- * @param emsg location for the reader to store an error message
- * @return number of bytes written, usually "max", 0 on error
- */
-static size_t
-data_reader_copy(void *cls, 
-                uint64_t offset,
-                size_t max, 
-                void *buf,
-                char **emsg)
-{
-  char *data = cls;
-
-  if (max == 0)
-    {
-      GNUNET_free (data);
-      return 0;
-    }  
-  memcpy (buf, &data[offset], max);
-  return max;
-}
-
-
 /**
  * Create an entry for a file in a publish-structure.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial value for the client-info value for this entry
  * @param length length of the file
  * @param data data for the file (should not be used afterwards by
@@ -281,40 +204,40 @@ data_reader_copy(void *cls,
  * @param meta metadata for the file
  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
  *                GNUNET_SYSERR for simulation
- * @param anonymity what is the desired anonymity level for sharing?
- * @param priority what is the priority for OUR node to
- *   keep this file available?  Use 0 for maximum anonymity and
- *   minimum reliability...
- * @param expirationTime when should this content expire?
+ * @param bo block options
  * @return publish structure entry for the file
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_data (void *client_info,
+GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
+                                            void *client_info,
                                             uint64_t length,
                                             void *data,
                                             const struct GNUNET_FS_Uri *keywords,
                                             const struct GNUNET_CONTAINER_MetaData *meta,
                                             int do_index,
-                                            uint32_t anonymity,
-                                            uint32_t priority,
-                                            struct GNUNET_TIME_Absolute expirationTime)
+                                            const struct GNUNET_FS_BlockOptions *bo)
 {
-  return GNUNET_FS_file_information_create_from_reader (client_info,
+  if (GNUNET_YES == do_index)        
+    {
+      GNUNET_break (0);
+      return NULL;
+    }
+  return GNUNET_FS_file_information_create_from_reader (h,
+                                                       client_info,
                                                        length,
-                                                       &data_reader_copy,
+                                                       &GNUNET_FS_data_reader_copy_,
                                                        data,
                                                        keywords,
                                                        meta,
                                                        do_index,
-                                                       anonymity,
-                                                       priority,
-                                                       expirationTime);
+                                                       bo);
 }
 
 
 /**
  * Create an entry for a file in a publish-structure.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial value for the client-info value for this entry
  * @param length length of the file
  * @param reader function that can be used to obtain the data for the file 
@@ -324,41 +247,40 @@ GNUNET_FS_file_information_create_from_data (void *client_info,
  * @param meta metadata for the file
  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
  *                GNUNET_SYSERR for simulation
- * @param anonymity what is the desired anonymity level for sharing?
- * @param priority what is the priority for OUR node to
- *   keep this file available?  Use 0 for maximum anonymity and
- *   minimum reliability...
- * @param expirationTime when should this content expire?
+ * @param bo block options
  * @return publish structure entry for the file
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_reader (void *client_info,
+GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
+                                              void *client_info,
                                               uint64_t length,
                                               GNUNET_FS_DataReader reader,
                                               void *reader_cls,
                                               const struct GNUNET_FS_Uri *keywords,
                                               const struct GNUNET_CONTAINER_MetaData *meta,
                                               int do_index,
-                                              uint32_t anonymity,
-                                              uint32_t priority,
-                                              struct GNUNET_TIME_Absolute expirationTime)
+                                              const struct GNUNET_FS_BlockOptions *bo)
 {
   struct GNUNET_FS_FileInformation *ret;
 
+  if ( (GNUNET_YES == do_index) &&
+       (reader != &GNUNET_FS_data_reader_file_) )
+    {
+      GNUNET_break (0);
+      return NULL;
+    }
   ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
+  ret->h = h;
   ret->client_info = client_info;  
   ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
   if (ret->meta == NULL)
     ret->meta = GNUNET_CONTAINER_meta_data_create ();
   ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords);
-  ret->expirationTime = expirationTime;
   ret->data.file.reader = reader; 
   ret->data.file.reader_cls = reader_cls;
   ret->data.file.do_index = do_index;
   ret->data.file.file_size = length;
-  ret->anonymity = anonymity;
-  ret->priority = priority;
-  GNUNET_FS_file_information_sync (ret);
+  ret->bo = *bo;
   return ret;
 }
 
@@ -373,6 +295,11 @@ struct DirScanCls
    */
   struct EXTRACTOR_PluginList *extractors;
 
+  /**
+   * Master context.
+   */ 
+  struct GNUNET_FS_Handle *h;
+
   /**
    * Function to call on each directory entry.
    */
@@ -399,24 +326,15 @@ struct DirScanCls
   char *emsg; 
 
   /**
-   * Should files be indexed?
-   */ 
-  int do_index;
-
-  /**
-   * Desired anonymity level.
+   * Block options.
    */
-  uint32_t anonymity;
+  const struct GNUNET_FS_BlockOptions *bo;
 
   /**
-   * Desired publishing priority.
-   */
-  uint32_t priority;
+   * Should files be indexed?
+   */ 
+  int do_index;
 
-  /**
-   * Expiration time for publication.
-   */
-  struct GNUNET_TIME_Absolute expiration;
 };
 
 
@@ -449,14 +367,13 @@ dir_scan_cb (void *cls,
     }
   if (S_ISDIR (sbuf.st_mode))
     {
-      fi = GNUNET_FS_file_information_create_from_directory (NULL,
+      fi = GNUNET_FS_file_information_create_from_directory (dsc->h,
+                                                            NULL,
                                                             filename,
                                                             dsc->scanner,
                                                             dsc->scanner_cls,
                                                             dsc->do_index,
-                                                            dsc->anonymity,
-                                                            dsc->priority,
-                                                            dsc->expiration,
+                                                            dsc->bo,
                                                             &dsc->emsg);
       if (NULL == fi)
        {
@@ -467,20 +384,18 @@ dir_scan_cb (void *cls,
   else
     {
       meta = GNUNET_CONTAINER_meta_data_create ();
-      GNUNET_CONTAINER_meta_data_extract_from_file (meta,
-                                                   filename,
-                                                   dsc->extractors);
-      // FIXME: remove path from filename in metadata!
+      GNUNET_FS_meta_data_extract_from_file (meta,
+                                            filename,
+                                            dsc->extractors);
       keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
       ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords);
-      fi = GNUNET_FS_file_information_create_from_file (NULL,
+      fi = GNUNET_FS_file_information_create_from_file (dsc->h,
+                                                       NULL,
                                                        filename,
                                                        ksk_uri,
                                                        meta,
                                                        dsc->do_index,
-                                                       dsc->anonymity,
-                                                       dsc->priority,
-                                                       dsc->expiration);
+                                                       dsc->bo);
       GNUNET_CONTAINER_meta_data_destroy (meta);
       GNUNET_FS_uri_destroy (keywords);
       GNUNET_FS_uri_destroy (ksk_uri);
@@ -504,11 +419,10 @@ dir_scan_cb (void *cls,
  * convenience function.
  *
  * @param cls must be of type "struct EXTRACTOR_Extractor*"
+ * @param h handle to the file sharing subsystem
  * @param dirname name of the directory to scan
  * @param do_index should files be indexed or inserted
- * @param anonymity desired anonymity level
- * @param priority priority for publishing
- * @param expirationTime expiration for publication
+ * @param bo block options
  * @param proc function called on each entry
  * @param proc_cls closure for proc
  * @param emsg where to store an error message (on errors)
@@ -516,11 +430,10 @@ dir_scan_cb (void *cls,
  */
 int
 GNUNET_FS_directory_scanner_default (void *cls,
+                                    struct GNUNET_FS_Handle *h,
                                     const char *dirname,
                                     int do_index,
-                                    uint32_t anonymity,
-                                    uint32_t priority,
-                                    struct GNUNET_TIME_Absolute expirationTime,
+                                    const struct GNUNET_FS_BlockOptions *bo,
                                     GNUNET_FS_FileProcessor proc,
                                     void *proc_cls,
                                     char **emsg)
@@ -528,15 +441,14 @@ GNUNET_FS_directory_scanner_default (void *cls,
   struct EXTRACTOR_PluginList *ex = cls;
   struct DirScanCls dsc;
 
+  dsc.h = h;
   dsc.extractors = ex;
   dsc.proc = proc;
   dsc.proc_cls = proc_cls;
   dsc.scanner = &GNUNET_FS_directory_scanner_default;
   dsc.scanner_cls = cls;
   dsc.do_index = do_index;
-  dsc.anonymity = anonymity;
-  dsc.priority = priority;
-  dsc.expiration = expirationTime;
+  dsc.bo = bo;
   if (-1 == GNUNET_DISK_directory_scan (dirname,
                                        &dir_scan_cb,
                                        &dsc))
@@ -594,107 +506,123 @@ dirproc (void *cls,
  * passed (GNUNET_FS_directory_scanner_default).  This is strictly a
  * convenience function.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial value for the client-info value for this entry
  * @param filename name of the top-level file or directory
  * @param scanner function used to get a list of files in a directory
  * @param scanner_cls closure for scanner
  * @param do_index should files in the hierarchy be indexed?
- * @param anonymity what is the desired anonymity level for sharing?
- * @param priority what is the priority for OUR node to
- *   keep this file available?  Use 0 for maximum anonymity and
- *   minimum reliability...
- * @param expirationTime when should this content expire?
+ * @param bo block options
  * @param emsg where to store an error message
  * @return publish structure entry for the directory, NULL on error
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_directory (void *client_info,
+GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
+                                                 void *client_info,
                                                  const char *filename,
                                                  GNUNET_FS_DirectoryScanner scanner,
                                                  void *scanner_cls,
                                                  int do_index,
-                                                 uint32_t anonymity,
-                                                 uint32_t priority,
-                                                 struct GNUNET_TIME_Absolute expirationTime,
+                                                 const struct GNUNET_FS_BlockOptions *bo,
                                                  char **emsg)
 {
   struct GNUNET_FS_FileInformation *ret;
   struct EntryProcCls dc;
   struct GNUNET_FS_Uri *ksk;
   struct GNUNET_CONTAINER_MetaData *meta;
-
-  
+  const char *fn;
+  const char *ss;
+  char *dn;
 
   dc.entries = NULL;
   meta = GNUNET_CONTAINER_meta_data_create ();
   GNUNET_FS_meta_data_make_directory (meta);
-  
   scanner (scanner_cls,
+          h,
           filename,
           do_index,
-          anonymity,
-          priority,
-          expirationTime,
+          bo,
           &dirproc,
           &dc,
           emsg);
   ksk = NULL; // FIXME...
   // FIXME: create meta!
-  ret = GNUNET_FS_file_information_create_empty_directory (client_info,
+  ret = GNUNET_FS_file_information_create_empty_directory (h,
+                                                          client_info,
                                                           ksk,
                                                           meta,
-                                                          anonymity,
-                                                          priority,
-                                                          expirationTime);
+                                                          bo);
   GNUNET_CONTAINER_meta_data_destroy (meta);
   ret->data.dir.entries = dc.entries;
   while (dc.entries != NULL)
     {
       dc.entries->dir = ret;
-      GNUNET_FS_file_information_sync (dc.entries);
       dc.entries = dc.entries->next;
     }
-  GNUNET_FS_file_information_sync (ret);
+  fn = filename;
+  while ( (NULL != (ss = strstr (fn,
+                                DIR_SEPARATOR_STR))) &&
+         (strlen (ss) > 1) )
+    fn = ss + 1;
+  GNUNET_asprintf (&dn,
+                  "%s/", 
+                  fn);
+  GNUNET_CONTAINER_meta_data_insert (ret->meta,
+                                    "<gnunet>",
+                                    EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
+                                    EXTRACTOR_METAFORMAT_C_STRING,
+                                    "text/plain",
+                                    dn,
+                                    strlen (dn) + 1);
+  GNUNET_free (dn);
+  ret->filename = GNUNET_strdup (filename);
   return ret;
 }
 
 
+/**
+ * Test if a given entry represents a directory.
+ *
+ * @param ent check if this FI represents a directory
+ * @return GNUNET_YES if so, GNUNET_NO if not
+ */
+int
+GNUNET_FS_file_information_is_directory (struct GNUNET_FS_FileInformation *ent)
+{
+  return ent->is_directory;
+}
+
+
 /**
  * Create an entry for an empty directory in a publish-structure.
  * This function should be used by applications for which the
  * use of "GNUNET_FS_file_information_create_from_directory"
  * is not appropriate.
  *
+ * @param h handle to the file sharing subsystem
  * @param client_info initial value for the client-info value for this entry
  * @param meta metadata for the directory
  * @param keywords under which keywords should this directory be available
  *         directly; can be NULL
- * @param anonymity what is the desired anonymity level for sharing?
- * @param priority what is the priority for OUR node to
- *   keep this file available?  Use 0 for maximum anonymity and
- *   minimum reliability...
- * @param expirationTime when should this content expire?
+ * @param bo block options
  * @return publish structure entry for the directory , NULL on error
  */
 struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_empty_directory (void *client_info,
+GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
+                                                  void *client_info,
                                                   const struct GNUNET_FS_Uri *keywords,
                                                   const struct GNUNET_CONTAINER_MetaData *meta,
-                                                  uint32_t anonymity,
-                                                  uint32_t priority,
-                                                  struct GNUNET_TIME_Absolute expirationTime)
+                                                  const struct GNUNET_FS_BlockOptions *bo)
 {
   struct GNUNET_FS_FileInformation *ret;
 
   ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
+  ret->h = h;
   ret->client_info = client_info;
   ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
   ret->keywords = GNUNET_FS_uri_dup (keywords);
-  ret->expirationTime = expirationTime;
+  ret->bo = *bo;
   ret->is_directory = GNUNET_YES;
-  ret->anonymity = anonymity;
-  ret->priority = priority;
-  GNUNET_FS_file_information_sync (ret);
   return ret;
 }
 
@@ -725,8 +653,6 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
   ent->next = dir->data.dir.entries;
   dir->data.dir.entries = ent;
   dir->data.dir.dir_size = 0;
-  GNUNET_FS_file_information_sync (ent);
-  GNUNET_FS_file_information_sync (dir);
   return GNUNET_OK;
 }
 
@@ -751,44 +677,36 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
                                    void *proc_cls)
 {
   struct GNUNET_FS_FileInformation *pos;
+  int no;
 
-  if (dir->is_directory)
-    {
+  no = GNUNET_NO;
+  if (GNUNET_OK !=
       proc (proc_cls, 
            dir,
-           dir->data.dir.dir_size,
+           (dir->is_directory) ? dir->data.dir.dir_size : dir->data.file.file_size,
            dir->meta,
            &dir->keywords,
-           &dir->anonymity,
-           &dir->priority,
-           &dir->expirationTime,
-           &dir->client_info);
-      pos = dir->data.dir.entries;
-      while (pos != NULL)
-       {
+           &dir->bo,
+           (dir->is_directory) ? &no : &dir->data.file.do_index,
+           &dir->client_info))
+    return;
+  if (! dir->is_directory)
+    return;
+  pos = dir->data.dir.entries;
+  while (pos != NULL)
+    {
+      no = GNUNET_NO;
+      if (GNUNET_OK != 
          proc (proc_cls, 
                pos,
                (pos->is_directory) ? pos->data.dir.dir_size : pos->data.file.file_size,
                pos->meta,
                &pos->keywords,
-               &pos->anonymity,
-               &pos->priority,
-               &pos->expirationTime,
-               &pos->client_info);
-         pos = pos->next;
-       }
-    }
-  else
-    {
-      proc (proc_cls, 
-           dir,
-           dir->data.file.file_size,
-           dir->meta,
-           &dir->keywords,
-           &dir->anonymity,
-           &dir->priority,
-           &dir->expirationTime,
-           &dir->client_info);
+               &pos->bo,
+               (dir->is_directory) ? &no : &dir->data.file.do_index,
+               &pos->client_info))
+       break;
+      pos = pos->next;
     }
 }
 
@@ -809,7 +727,9 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
                                    void *cleaner_cls)
 {
   struct GNUNET_FS_FileInformation *pos;
+  int no;
 
+  no = GNUNET_NO;
   if (fi->is_directory)
     {
       /* clean up directory */
@@ -825,17 +745,17 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
                 fi->data.dir.dir_size,
                 fi->meta,
                 &fi->keywords,
-                &fi->anonymity,
-                &fi->priority,
-                &fi->expirationTime,
+                &fi->bo,
+                &no,
                 &fi->client_info);
       GNUNET_free_non_null (fi->data.dir.dir_data);
-      GNUNET_free_non_null (fi->data.dir.dirname);
     }
   else
     {
       /* call clean-up function of the reader */
-      fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL);
+      if (fi->data.file.reader != NULL)
+       fi->data.file.reader (fi->data.file.reader_cls, 0, 0, 
+                             NULL, NULL);
       /* clean up client-info */
       if (NULL != cleaner)
        cleaner (cleaner_cls, 
@@ -843,11 +763,11 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
                 fi->data.file.file_size,
                 fi->meta,
                 &fi->keywords,
-                &fi->anonymity,
-                &fi->priority,
-                &fi->expirationTime,
+                &fi->bo,
+                &fi->data.file.do_index,
                 &fi->client_info);
     }
+  GNUNET_free_non_null (fi->filename);
   GNUNET_free_non_null (fi->emsg);
   GNUNET_free_non_null (fi->chk_uri);
   /* clean up serialization */
@@ -858,7 +778,8 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
                              fi->serialization);
   if (NULL != fi->keywords)
     GNUNET_FS_uri_destroy (fi->keywords);
-  GNUNET_CONTAINER_meta_data_destroy (fi->meta);
+  if (NULL != fi->meta)
+    GNUNET_CONTAINER_meta_data_destroy (fi->meta);
   GNUNET_free_non_null (fi->serialization);
   if (fi->te != NULL)
     {