ext4_balloc.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
  3. *
  4. * HelenOS:
  5. * Copyright (c) 2012 Martin Sucha
  6. * Copyright (c) 2012 Frantisek Princ
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * - The name of the author may not be used to endorse or promote products
  19. * derived from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  22. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  23. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /** @addtogroup lwext4
  33. * @{
  34. */
  35. /**
  36. * @file ext4_balloc.h
  37. * @brief Physical block allocator.
  38. */
  39. #ifndef EXT4_BALLOC_H_
  40. #define EXT4_BALLOC_H_
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. #include <ext4_config.h>
  45. #include <ext4_types.h>
  46. #include <ext4_fs.h>
  47. #include <stdint.h>
  48. #include <stdbool.h>
  49. /**@brief Compute number of block group from block address.
  50. * @param sb superblock pointer.
  51. * @param baddr Absolute address of block.
  52. * @return Block group index
  53. */
  54. uint32_t ext4_balloc_get_bgid_of_block(struct ext4_sblock *s,
  55. ext4_fsblk_t baddr);
  56. /**@brief Compute the starting block address of a block group
  57. * @param sb superblock pointer.
  58. * @param bgid block group index
  59. * @return Block address
  60. */
  61. ext4_fsblk_t ext4_balloc_get_block_of_bgid(struct ext4_sblock *s,
  62. uint32_t bgid);
  63. /**@brief Calculate and set checksum of block bitmap.
  64. * @param sb superblock pointer.
  65. * @param bg block group
  66. * @param bitmap bitmap buffer
  67. */
  68. void ext4_balloc_set_bitmap_csum(struct ext4_sblock *sb,
  69. struct ext4_bgroup *bg,
  70. void *bitmap);
  71. /**@brief Free block from inode.
  72. * @param inode_ref inode reference
  73. * @param baddr block address
  74. * @return standard error code*/
  75. int ext4_balloc_free_block(struct ext4_inode_ref *inode_ref,
  76. ext4_fsblk_t baddr);
  77. /**@brief Free blocks from inode.
  78. * @param inode_ref inode reference
  79. * @param first block address
  80. * @param count block count
  81. * @return standard error code*/
  82. int ext4_balloc_free_blocks(struct ext4_inode_ref *inode_ref,
  83. ext4_fsblk_t first, uint32_t count);
  84. /**@brief Allocate block procedure.
  85. * @param inode_ref inode reference
  86. * @param goal
  87. * @param baddr allocated block address
  88. * @return standard error code*/
  89. int ext4_balloc_alloc_block(struct ext4_inode_ref *inode_ref,
  90. ext4_fsblk_t goal,
  91. ext4_fsblk_t *baddr);
  92. /**@brief Try allocate selected block.
  93. * @param inode_ref inode reference
  94. * @param baddr block address to allocate
  95. * @param free if baddr is not allocated
  96. * @return standard error code*/
  97. int ext4_balloc_try_alloc_block(struct ext4_inode_ref *inode_ref,
  98. ext4_fsblk_t baddr, bool *free);
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif /* EXT4_BALLOC_H_ */
  103. /**
  104. * @}
  105. */