fs_directory.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2003, 2004, 2006, 2009 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file fs/fs_directory.c
  19. * @brief Helper functions for building directories.
  20. * @author Christian Grothoff
  21. *
  22. * TODO:
  23. * - modify directory builder API to support incremental
  24. * generation of directories (to allow directories that
  25. * would not fit into memory to be created)
  26. * - modify directory processor API to support incremental
  27. * iteration over FULL directories (without missing entries)
  28. * to allow access to directories that do not fit entirely
  29. * into memory
  30. */
  31. #include "platform.h"
  32. #include "gnunet_fs_service.h"
  33. #include "fs.h"
  34. /**
  35. * String that is used to indicate that a file
  36. * is a GNUnet directory.
  37. */
  38. #define GNUNET_DIRECTORY_MAGIC "\211GND\r\n\032\n"
  39. /**
  40. * Does the meta-data claim that this is a directory?
  41. * Checks if the mime-type is that of a GNUnet directory.
  42. *
  43. * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
  44. * we have no mime-type information (treat as 'GNUNET_NO')
  45. */
  46. int
  47. GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md)
  48. {
  49. char *mime;
  50. int ret;
  51. if (NULL == md)
  52. return GNUNET_SYSERR;
  53. mime = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE);
  54. if (mime == NULL)
  55. return GNUNET_SYSERR;
  56. ret = (0 == strcmp (mime, GNUNET_FS_DIRECTORY_MIME)) ? GNUNET_YES : GNUNET_NO;
  57. GNUNET_free (mime);
  58. return ret;
  59. }
  60. /**
  61. * Set the MIMETYPE information for the given
  62. * metadata to "application/gnunet-directory".
  63. *
  64. * @param md metadata to add mimetype to
  65. */
  66. void
  67. GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md)
  68. {
  69. char *mime;
  70. mime = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_MIMETYPE);
  71. if (mime != NULL)
  72. {
  73. GNUNET_break (0 == strcmp (mime,
  74. GNUNET_FS_DIRECTORY_MIME));
  75. GNUNET_free (mime);
  76. return;
  77. }
  78. GNUNET_CONTAINER_meta_data_insert (md,
  79. "<gnunet>",
  80. EXTRACTOR_METATYPE_MIMETYPE,
  81. EXTRACTOR_METAFORMAT_UTF8,
  82. "text/plain",
  83. GNUNET_FS_DIRECTORY_MIME,
  84. strlen (GNUNET_FS_DIRECTORY_MIME)+1);
  85. }
  86. /**
  87. * Closure for 'find_full_data'.
  88. */
  89. struct GetFullDataClosure
  90. {
  91. /**
  92. * Extracted binary meta data.
  93. */
  94. void *data;
  95. /**
  96. * Number of bytes stored in data.
  97. */
  98. size_t size;
  99. };
  100. /**
  101. * Type of a function that libextractor calls for each
  102. * meta data item found.
  103. *
  104. * @param cls closure (user-defined)
  105. * @param plugin_name name of the plugin that produced this value;
  106. * special values can be used (i.e. '&lt;zlib&gt;' for zlib being
  107. * used in the main libextractor library and yielding
  108. * meta data).
  109. * @param type libextractor-type describing the meta data
  110. * @param format basic format information about data
  111. * @param data_mime_type mime-type of data (not of the original file);
  112. * can be NULL (if mime-type is not known)
  113. * @param data actual meta-data found
  114. * @param data_len number of bytes in data
  115. * @return 0 to continue extracting, 1 to abort
  116. */
  117. static int
  118. find_full_data (void *cls,
  119. const char *plugin_name,
  120. enum EXTRACTOR_MetaType type,
  121. enum EXTRACTOR_MetaFormat format,
  122. const char *data_mime_type,
  123. const char *data,
  124. size_t data_len)
  125. {
  126. struct GetFullDataClosure *gfdc = cls;
  127. if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
  128. {
  129. gfdc->size = data_len;
  130. if (data_len > 0)
  131. {
  132. gfdc->data = GNUNET_malloc (data_len);
  133. memcpy (gfdc->data,
  134. data,
  135. data_len);
  136. }
  137. return 1;
  138. }
  139. return 0;
  140. }
  141. /**
  142. * Iterate over all entries in a directory. Note that directories
  143. * are structured such that it is possible to iterate over the
  144. * individual blocks as well as over the entire directory. Thus
  145. * a client can call this function on the buffer in the
  146. * GNUNET_FS_ProgressCallback. Also, directories can optionally
  147. * include the contents of (small) files embedded in the directory
  148. * itself; for those files, the processor may be given the
  149. * contents of the file directly by this function.
  150. * <p>
  151. *
  152. * Note that this function maybe called on parts of directories. Thus
  153. * parser errors should not be reported _at all_ (with GNUNET_break).
  154. * Still, if some entries can be recovered despite these parsing
  155. * errors, the function should try to do this.
  156. *
  157. * @param size number of bytes in data
  158. * @param data pointer to the beginning of the directory
  159. * @param offset offset of data in the directory
  160. * @param dep function to call on each entry
  161. * @param dep_cls closure for dep
  162. * @return GNUNET_OK if this could be a block in a directory,
  163. * GNUNET_NO if this could be part of a directory (but not 100% OK)
  164. * GNUNET_SYSERR if 'data' does not represent a directory
  165. */
  166. int
  167. GNUNET_FS_directory_list_contents (size_t size,
  168. const void *data,
  169. uint64_t offset,
  170. GNUNET_FS_DirectoryEntryProcessor dep,
  171. void *dep_cls)
  172. {
  173. struct GetFullDataClosure full_data;
  174. const char *cdata = data;
  175. char *emsg;
  176. uint64_t pos;
  177. uint64_t align;
  178. uint32_t mdSize;
  179. uint64_t epos;
  180. struct GNUNET_FS_Uri *uri;
  181. struct GNUNET_CONTAINER_MetaData *md;
  182. char *filename;
  183. if ( (offset == 0) &&
  184. ( (size < 8 + sizeof (uint32_t)) ||
  185. (0 != memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8)) ) )
  186. {
  187. GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
  188. _("MAGIC mismatch. This is not a GNUnet directory.\n"));
  189. return GNUNET_SYSERR;
  190. }
  191. pos = offset;
  192. if (offset == 0)
  193. {
  194. memcpy (&mdSize, &cdata[8], sizeof (uint32_t));
  195. mdSize = ntohl (mdSize);
  196. if (mdSize > size - 8 - sizeof (uint32_t))
  197. {
  198. /* invalid size */
  199. GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
  200. _("MAGIC mismatch. This is not a GNUnet directory.\n"));
  201. return GNUNET_SYSERR;
  202. }
  203. md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[8 +
  204. sizeof (uint32_t)],
  205. mdSize);
  206. if (md == NULL)
  207. {
  208. GNUNET_break (0);
  209. return GNUNET_SYSERR; /* malformed ! */
  210. }
  211. dep (dep_cls,
  212. NULL,
  213. NULL,
  214. md,
  215. 0,
  216. NULL);
  217. GNUNET_CONTAINER_meta_data_destroy (md);
  218. pos = 8 + sizeof (uint32_t) + mdSize;
  219. }
  220. while (pos < size)
  221. {
  222. /* find end of URI */
  223. if (cdata[pos] == '\0')
  224. {
  225. /* URI is never empty, must be end of block,
  226. skip to next alignment */
  227. align =
  228. ((pos / DBLOCK_SIZE) + 1) * DBLOCK_SIZE;
  229. if (align == pos)
  230. {
  231. /* if we were already aligned, still skip a block! */
  232. align += DBLOCK_SIZE;
  233. }
  234. pos = align;
  235. if (pos >= size)
  236. {
  237. /* malformed - or partial download... */
  238. break;
  239. }
  240. }
  241. epos = pos;
  242. while ((epos < size) && (cdata[epos] != '\0'))
  243. epos++;
  244. if (epos >= size)
  245. return GNUNET_NO; /* malformed - or partial download */
  246. uri = GNUNET_FS_uri_parse (&cdata[pos], &emsg);
  247. pos = epos + 1;
  248. if (uri == NULL)
  249. {
  250. GNUNET_free (emsg);
  251. pos--; /* go back to '\0' to force going to next alignment */
  252. continue;
  253. }
  254. if (GNUNET_FS_uri_test_ksk (uri))
  255. {
  256. GNUNET_FS_uri_destroy (uri);
  257. GNUNET_break (0);
  258. return GNUNET_NO; /* illegal in directory! */
  259. }
  260. memcpy (&mdSize, &cdata[pos], sizeof (uint32_t));
  261. mdSize = ntohl (mdSize);
  262. pos += sizeof (uint32_t);
  263. if (pos + mdSize > size)
  264. {
  265. GNUNET_FS_uri_destroy (uri);
  266. return GNUNET_NO; /* malformed - or partial download */
  267. }
  268. md = GNUNET_CONTAINER_meta_data_deserialize (&cdata[pos], mdSize);
  269. if (md == NULL)
  270. {
  271. GNUNET_FS_uri_destroy (uri);
  272. GNUNET_break (0);
  273. return GNUNET_NO; /* malformed ! */
  274. }
  275. pos += mdSize;
  276. filename = GNUNET_CONTAINER_meta_data_get_by_type (md,
  277. EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
  278. full_data.size = 0;
  279. full_data.data = NULL;
  280. GNUNET_CONTAINER_meta_data_iterate (md,
  281. &find_full_data,
  282. &full_data);
  283. if (dep != NULL)
  284. {
  285. dep (dep_cls,
  286. filename,
  287. uri,
  288. md,
  289. full_data.size,
  290. full_data.data);
  291. }
  292. GNUNET_free_non_null (full_data.data);
  293. GNUNET_free_non_null (filename);
  294. GNUNET_CONTAINER_meta_data_destroy (md);
  295. GNUNET_FS_uri_destroy (uri);
  296. }
  297. return GNUNET_OK;
  298. }
  299. /**
  300. * Entries in the directory (builder).
  301. */
  302. struct BuilderEntry
  303. {
  304. /**
  305. * This is a linked list.
  306. */
  307. struct BuilderEntry *next;
  308. /**
  309. * Length of this entry.
  310. */
  311. size_t len;
  312. };
  313. /**
  314. * Internal state of a directory builder.
  315. */
  316. struct GNUNET_FS_DirectoryBuilder
  317. {
  318. /**
  319. * Meta-data for the directory itself.
  320. */
  321. struct GNUNET_CONTAINER_MetaData *meta;
  322. /**
  323. * Head of linked list of entries.
  324. */
  325. struct BuilderEntry *head;
  326. /**
  327. * Number of entires in the directory.
  328. */
  329. unsigned int count;
  330. };
  331. /**
  332. * Create a directory builder.
  333. *
  334. * @param mdir metadata for the directory
  335. */
  336. struct GNUNET_FS_DirectoryBuilder *
  337. GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir)
  338. {
  339. struct GNUNET_FS_DirectoryBuilder *ret;
  340. ret = GNUNET_malloc(sizeof(struct GNUNET_FS_DirectoryBuilder));
  341. if (mdir != NULL)
  342. ret->meta = GNUNET_CONTAINER_meta_data_duplicate (mdir);
  343. else
  344. ret->meta = GNUNET_CONTAINER_meta_data_create ();
  345. GNUNET_FS_meta_data_make_directory (ret->meta);
  346. return ret;
  347. }
  348. /**
  349. * Add an entry to a directory.
  350. *
  351. * @param bld directory to extend
  352. * @param uri uri of the entry (must not be a KSK)
  353. * @param md metadata of the entry
  354. * @param data raw data of the entry, can be NULL, otherwise
  355. * data must point to exactly the number of bytes specified
  356. * by the uri which must be of type LOC or CHK
  357. */
  358. void
  359. GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
  360. const struct GNUNET_FS_Uri *uri,
  361. const struct GNUNET_CONTAINER_MetaData *md,
  362. const void *data)
  363. {
  364. struct GNUNET_FS_Uri *curi;
  365. struct BuilderEntry *e;
  366. uint64_t fsize;
  367. uint32_t big;
  368. ssize_t ret;
  369. size_t mds;
  370. size_t mdxs;
  371. char *uris;
  372. char *ser;
  373. char *sptr;
  374. size_t slen;
  375. struct GNUNET_CONTAINER_MetaData *meta;
  376. const struct GNUNET_CONTAINER_MetaData *meta_use;
  377. GNUNET_assert (! GNUNET_FS_uri_test_ksk (uri));
  378. if (NULL != data)
  379. {
  380. GNUNET_assert (! GNUNET_FS_uri_test_sks (uri));
  381. if (GNUNET_FS_uri_test_chk (uri))
  382. {
  383. fsize = GNUNET_FS_uri_chk_get_file_size (uri);
  384. }
  385. else
  386. {
  387. curi = GNUNET_FS_uri_loc_get_uri (uri);
  388. GNUNET_assert (NULL != curi);
  389. fsize = GNUNET_FS_uri_chk_get_file_size (curi);
  390. GNUNET_FS_uri_destroy (curi);
  391. }
  392. }
  393. else
  394. {
  395. fsize = 0; /* not given */
  396. }
  397. if (fsize > MAX_INLINE_SIZE)
  398. fsize = 0; /* too large */
  399. uris = GNUNET_FS_uri_to_string (uri);
  400. slen = strlen (uris) + 1;
  401. mds =
  402. GNUNET_CONTAINER_meta_data_get_serialized_size (md);
  403. meta_use = md;
  404. meta = NULL;
  405. if (fsize > 0)
  406. {
  407. meta = GNUNET_CONTAINER_meta_data_duplicate (md);
  408. GNUNET_CONTAINER_meta_data_insert (meta,
  409. "<gnunet>",
  410. EXTRACTOR_METATYPE_GNUNET_FULL_DATA,
  411. EXTRACTOR_METAFORMAT_BINARY,
  412. NULL,
  413. data,
  414. fsize);
  415. mdxs =
  416. GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
  417. if ( (slen + sizeof (uint32_t) + mdxs - 1) / DBLOCK_SIZE ==
  418. (slen + sizeof (uint32_t) + mds - 1) / DBLOCK_SIZE)
  419. {
  420. /* adding full data would not cause us to cross
  421. additional blocks, so add it! */
  422. meta_use = meta;
  423. mds = mdxs;
  424. }
  425. }
  426. if (mds > GNUNET_MAX_MALLOC_CHECKED / 2)
  427. mds = GNUNET_MAX_MALLOC_CHECKED / 2;
  428. e = GNUNET_malloc (sizeof(struct BuilderEntry) +
  429. slen + mds + sizeof (uint32_t));
  430. ser = (char*) &e[1];
  431. memcpy (ser, uris, slen);
  432. GNUNET_free (uris);
  433. sptr = &ser[slen + sizeof(uint32_t)];
  434. ret = GNUNET_CONTAINER_meta_data_serialize (meta_use,
  435. &sptr,
  436. mds,
  437. GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
  438. if (NULL != meta)
  439. GNUNET_CONTAINER_meta_data_destroy (meta);
  440. if (ret == -1)
  441. mds = 0;
  442. else
  443. mds = ret;
  444. big = htonl (mds);
  445. memcpy (&ser[slen], &big, sizeof (uint32_t));
  446. e->len = slen + sizeof (uint32_t) + mds;
  447. e->next = bld->head;
  448. bld->head = e;
  449. bld->count++;
  450. }
  451. /**
  452. * Given the start and end position of a block of
  453. * data, return the end position of that data
  454. * after alignment to the DBLOCK_SIZE.
  455. */
  456. static size_t
  457. do_align (size_t start_position,
  458. size_t end_position)
  459. {
  460. size_t align;
  461. align = (end_position / DBLOCK_SIZE) * DBLOCK_SIZE;
  462. if ((start_position < align) && (end_position > align))
  463. return align + end_position - start_position;
  464. return end_position;
  465. }
  466. /**
  467. * Compute a permuation of the blocks to
  468. * minimize the cost of alignment. Greedy packer.
  469. *
  470. * @param start starting position for the first block
  471. * @param count size of the two arrays
  472. * @param sizes the sizes of the individual blocks
  473. * @param perm the permutation of the blocks (updated)
  474. */
  475. static void
  476. block_align (size_t start,
  477. unsigned int count,
  478. const size_t *sizes,
  479. unsigned int *perm)
  480. {
  481. unsigned int i;
  482. unsigned int j;
  483. unsigned int tmp;
  484. unsigned int best;
  485. ssize_t badness;
  486. size_t cpos;
  487. size_t cend;
  488. ssize_t cbad;
  489. unsigned int cval;
  490. cpos = start;
  491. for (i = 0; i < count; i++)
  492. {
  493. start = cpos;
  494. badness = 0x7FFFFFFF;
  495. best = -1;
  496. for (j = i; j < count; j++)
  497. {
  498. cval = perm[j];
  499. cend = cpos + sizes[cval];
  500. if (cpos % DBLOCK_SIZE == 0)
  501. {
  502. /* prefer placing the largest blocks first */
  503. cbad = -(cend % DBLOCK_SIZE);
  504. }
  505. else
  506. {
  507. if (cpos / DBLOCK_SIZE ==
  508. cend / DBLOCK_SIZE)
  509. {
  510. /* Data fits into the same block! Prefer small left-overs! */
  511. cbad =
  512. DBLOCK_SIZE - cend % DBLOCK_SIZE;
  513. }
  514. else
  515. {
  516. /* Would have to waste space to re-align, add big factor, this
  517. case is a real loss (proportional to space wasted)! */
  518. cbad =
  519. DBLOCK_SIZE * (DBLOCK_SIZE -
  520. cpos %
  521. DBLOCK_SIZE);
  522. }
  523. }
  524. if (cbad < badness)
  525. {
  526. best = j;
  527. badness = cbad;
  528. }
  529. }
  530. GNUNET_assert (best != -1);
  531. tmp = perm[i];
  532. perm[i] = perm[best];
  533. perm[best] = tmp;
  534. cpos += sizes[perm[i]];
  535. cpos = do_align (start, cpos);
  536. }
  537. }
  538. /**
  539. * Finish building the directory. Frees the
  540. * builder context and returns the directory
  541. * in-memory.
  542. *
  543. * @param bld directory to finish
  544. * @param rsize set to the number of bytes needed
  545. * @param rdata set to the encoded directory
  546. * @return GNUNET_OK on success
  547. */
  548. int
  549. GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
  550. size_t *rsize,
  551. void **rdata)
  552. {
  553. char *data;
  554. char *sptr;
  555. size_t *sizes;
  556. unsigned int *perm;
  557. unsigned int i;
  558. unsigned int j;
  559. struct BuilderEntry *pos;
  560. struct BuilderEntry **bes;
  561. size_t size;
  562. size_t psize;
  563. size_t off;
  564. ssize_t ret;
  565. uint32_t big;
  566. size = strlen (GNUNET_DIRECTORY_MAGIC) + sizeof (uint32_t);
  567. size += GNUNET_CONTAINER_meta_data_get_serialized_size (bld->meta);
  568. sizes = NULL;
  569. perm = NULL;
  570. bes = NULL;
  571. if (0 < bld->count)
  572. {
  573. sizes = GNUNET_malloc (bld->count * sizeof (size_t));
  574. perm = GNUNET_malloc (bld->count * sizeof (unsigned int));
  575. bes = GNUNET_malloc (bld->count * sizeof (struct BuilderEntry *));
  576. pos = bld->head;
  577. for (i = 0; i < bld->count; i++)
  578. {
  579. perm[i] = i;
  580. bes[i] = pos;
  581. sizes[i] = pos->len;
  582. pos = pos->next;
  583. }
  584. block_align (size,
  585. bld->count,
  586. sizes,
  587. perm);
  588. /* compute final size with alignment */
  589. for (i = 0; i < bld->count; i++)
  590. {
  591. psize = size;
  592. size += sizes[perm[i]];
  593. size = do_align (psize, size);
  594. }
  595. }
  596. *rsize = size;
  597. data = GNUNET_malloc_large (size);
  598. if (data == NULL)
  599. {
  600. GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
  601. "malloc");
  602. *rsize = 0;
  603. *rdata = NULL;
  604. GNUNET_free_non_null (sizes);
  605. GNUNET_free_non_null (perm);
  606. GNUNET_free_non_null (bes);
  607. return GNUNET_SYSERR;
  608. }
  609. *rdata = data;
  610. memcpy (data, GNUNET_DIRECTORY_MAGIC, strlen (GNUNET_DIRECTORY_MAGIC));
  611. off = strlen (GNUNET_DIRECTORY_MAGIC);
  612. sptr = &data[off + sizeof (uint32_t)];
  613. ret = GNUNET_CONTAINER_meta_data_serialize (bld->meta,
  614. &sptr,
  615. size - off - sizeof (uint32_t),
  616. GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL);
  617. GNUNET_assert (ret != -1);
  618. big = htonl (ret);
  619. memcpy (&data[off], &big, sizeof (uint32_t));
  620. off += sizeof (uint32_t) + ret;
  621. for (j = 0; j < bld->count; j++)
  622. {
  623. i = perm[j];
  624. psize = off;
  625. off += sizes[i];
  626. off = do_align (psize, off);
  627. memcpy (&data[off - sizes[i]],
  628. &(bes[i])[1],
  629. sizes[i]);
  630. GNUNET_free (bes[i]);
  631. }
  632. GNUNET_free_non_null (sizes);
  633. GNUNET_free_non_null (perm);
  634. GNUNET_free_non_null (bes);
  635. GNUNET_assert (off == size);
  636. GNUNET_CONTAINER_meta_data_destroy (bld->meta);
  637. GNUNET_free (bld);
  638. return GNUNET_OK;
  639. }
  640. /* end of fs_directory.c */