+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
+ size_t * rsize, void **rdata);
+
+
+/* ******************** DirScanner API *********************** */
+
+/**
+ * Progress reasons of the directory scanner.
+ */
+enum GNUNET_FS_DirScannerProgressUpdateReason
+{
+
+ /**
+ * We've started processing a file or directory.
+ */
+ GNUNET_FS_DIRSCANNER_FILE_START = 0,
+
+ /**
+ * We're having trouble accessing a file (soft-error); it will
+ * be ignored.
+ */
+ GNUNET_FS_DIRSCANNER_FILE_IGNORED,
+
+ /**
+ * We've found all files (in the pre-pass).
+ */
+ GNUNET_FS_DIRSCANNER_ALL_COUNTED,
+
+ /**
+ * We've finished extracting meta data from a file.
+ */
+ GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
+
+ /**
+ * Last call to the progress function: we have finished scanning
+ * the directory.
+ */
+ GNUNET_FS_DIRSCANNER_FINISHED,
+
+ /**
+ * There was an internal error. Application should abort the scan.
+ */
+ GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
+
+};
+
+
+/**
+ * Function called over time as the directory scanner makes
+ * progress on the job at hand.
+ *
+ * @param cls closure
+ * @param filename which file we are making progress on
+ * @param is_directory #GNUNET_YES if this is a directory,
+ * #GNUNET_NO if this is a file
+ * #GNUNET_SYSERR if it is neither (or unknown)
+ * @param reason kind of progress we are making
+ */
+typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls,
+ const char *filename,
+ int is_directory,
+ enum GNUNET_FS_DirScannerProgressUpdateReason reason);
+
+
+/**
+ * A node of a directory tree (produced by dirscanner)
+ */
+struct GNUNET_FS_ShareTreeItem
+{
+ /**
+ * This is a doubly-linked list
+ */
+ struct GNUNET_FS_ShareTreeItem *prev;
+
+ /**
+ * This is a doubly-linked list
+ */
+ struct GNUNET_FS_ShareTreeItem *next;
+
+ /**
+ * This is a doubly-linked tree
+ * NULL for top-level entries.
+ */
+ struct GNUNET_FS_ShareTreeItem *parent;
+
+ /**
+ * This is a doubly-linked tree
+ * NULL for files and empty directories
+ */
+ struct GNUNET_FS_ShareTreeItem *children_head;
+
+ /**
+ * This is a doubly-linked tree
+ * NULL for files and empty directories
+ */
+ struct GNUNET_FS_ShareTreeItem *children_tail;
+
+ /**
+ * Metadata for this file or directory
+ */
+ struct GNUNET_CONTAINER_MetaData *meta;
+
+ /**
+ * Keywords for this file or directory (derived from metadata).
+ */
+ struct GNUNET_FS_Uri *ksk_uri;
+
+ /**
+ * Name of the file/directory
+ */
+ char *filename;
+
+ /**
+ * Base name of the file/directory.
+ */
+ char *short_filename;
+
+ /**
+ * #GNUNET_YES if this is a directory
+ */
+ int is_directory;
+
+};
+
+
+/**
+ * Opaqe handle to an asynchronous directory scanning activity.
+ */
+struct GNUNET_FS_DirScanner;
+
+
+/**
+ * Start a directory scanner.
+ *
+ * @param filename name of the directory to scan
+ * @param disable_extractor #GNUNET_YES to not to run libextractor on files (only build a tree)
+ * @param ex if not NULL, must be a list of extra plugins for extractor
+ * @param cb the callback to call when there are scanning progress messages
+ * @param cb_cls closure for @a cb
+ * @return directory scanner object to be used for controlling the scanner
+ */
+struct GNUNET_FS_DirScanner *
+GNUNET_FS_directory_scan_start (const char *filename,
+ int disable_extractor,
+ const char *ex,
+ GNUNET_FS_DirScannerProgressCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Abort the scan. Must not be called from within the progress_callback
+ * function.
+ *
+ * @param ds directory scanner structure
+ */
+void
+GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
+
+
+/**
+ * Obtain the result of the scan after the scan has signalled
+ * completion. Must not be called prior to completion. The @a ds is
+ * freed as part of this call.
+ *
+ * @param ds directory scanner structure
+ * @return the results of the scan (a directory tree)
+ */
+struct GNUNET_FS_ShareTreeItem *
+GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
+
+
+/**
+ * Process a share item tree, moving frequent keywords up and
+ * copying frequent metadata up.
+ *
+ * @param toplevel toplevel directory in the tree, returned by the scanner
+ */
+void
+GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
+
+
+/**
+ * Release memory of a share item tree.
+ *
+ * @param toplevel toplevel of the tree to be freed