malloc-ecos.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * JFFS2 -- Journalling Flash File System, Version 2.
  3. *
  4. * Copyright (C) 2001-2003 Free Software Foundation, Inc.
  5. *
  6. * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
  7. *
  8. * For licensing information, see the file 'LICENCE' in this directory.
  9. *
  10. * $Id: malloc-ecos.c,v 1.4 2003/11/26 15:55:35 dwmw2 Exp $
  11. *
  12. */
  13. #include <linux/kernel.h>
  14. #include <cyg/hal/drv_api.h>
  15. #include "nodelist.h"
  16. #if !defined(CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE)
  17. # define CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE 0
  18. #endif
  19. struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
  20. {
  21. return rt_malloc(sizeof(struct jffs2_full_dirent) + namesize);
  22. }
  23. void jffs2_free_full_dirent(struct jffs2_full_dirent *x)
  24. {
  25. rt_free(x);
  26. }
  27. struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
  28. {
  29. return rt_malloc(sizeof(struct jffs2_full_dnode));
  30. }
  31. void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
  32. {
  33. rt_free(x);
  34. }
  35. struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
  36. {
  37. return rt_malloc(sizeof(struct jffs2_raw_dirent));
  38. }
  39. void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
  40. {
  41. rt_free(x);
  42. }
  43. struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
  44. {
  45. return rt_malloc(sizeof(struct jffs2_raw_inode));
  46. }
  47. void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
  48. {
  49. rt_free(x);
  50. }
  51. struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
  52. {
  53. return rt_malloc(sizeof(struct jffs2_tmp_dnode_info));
  54. }
  55. void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
  56. {
  57. rt_free(x);
  58. }
  59. struct jffs2_node_frag *jffs2_alloc_node_frag(void)
  60. {
  61. return rt_malloc(sizeof(struct jffs2_node_frag));
  62. }
  63. void jffs2_free_node_frag(struct jffs2_node_frag *x)
  64. {
  65. rt_free(x);
  66. }
  67. #if CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
  68. int jffs2_create_slab_caches(void)
  69. {
  70. return 0;
  71. }
  72. void jffs2_destroy_slab_caches(void)
  73. {
  74. }
  75. struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
  76. {
  77. return rt_malloc(sizeof(struct jffs2_raw_node_ref));
  78. }
  79. void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
  80. {
  81. rt_free(x);
  82. }
  83. #else // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
  84. static struct jffs2_raw_node_ref
  85. rnr_pool[CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE] __attribute__ ((aligned (4))),
  86. * first = NULL;
  87. static cyg_drv_mutex_t mutex;
  88. int jffs2_create_slab_caches(void)
  89. {
  90. struct jffs2_raw_node_ref * p;
  91. cyg_drv_mutex_init(&mutex);
  92. for (
  93. p = rnr_pool;
  94. p < rnr_pool + CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE - 1;
  95. p++
  96. )
  97. p->next_phys = p + 1;
  98. rnr_pool[CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE - 1].next_phys = NULL;
  99. first = &rnr_pool[0];
  100. return 0;
  101. }
  102. void jffs2_destroy_slab_caches(void)
  103. {
  104. }
  105. struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
  106. {
  107. struct jffs2_raw_node_ref * p;
  108. cyg_drv_mutex_lock(&mutex);
  109. p = first;
  110. if (p != NULL)
  111. first = p->next_phys;
  112. cyg_drv_mutex_unlock(&mutex);
  113. return p;
  114. }
  115. void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
  116. {
  117. cyg_drv_mutex_lock(&mutex);
  118. x->next_phys = first;
  119. first = x;
  120. cyg_drv_mutex_unlock(&mutex);
  121. }
  122. #endif // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
  123. struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
  124. {
  125. struct jffs2_inode_cache *ret = rt_malloc(sizeof(struct jffs2_inode_cache));
  126. D1(printk(KERN_DEBUG "Allocated inocache at %p\n", ret));
  127. return ret;
  128. }
  129. void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
  130. {
  131. D1(printk(KERN_DEBUG "Freeing inocache at %p\n", x));
  132. rt_free(x);
  133. }