ext4_inode.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
  3. *
  4. *
  5. * HelenOS:
  6. * Copyright (c) 2012 Martin Sucha
  7. * Copyright (c) 2012 Frantisek Princ
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * - The name of the author may not be used to endorse or promote products
  20. * derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  24. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  25. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. /** @addtogroup lwext4
  34. * @{
  35. */
  36. /**
  37. * @file ext4_inode.h
  38. * @brief Inode handle functions
  39. */
  40. #ifndef EXT4_INODE_H_
  41. #define EXT4_INODE_H_
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. #include "ext4_config.h"
  46. #include "ext4_types.h"
  47. #include <stdint.h>
  48. /**@brief Get mode of the i-node.
  49. * @param sb Superblock
  50. * @param inode I-node to load mode from
  51. * @return Mode of the i-node
  52. */
  53. uint32_t ext4_inode_get_mode(struct ext4_sblock *sb, struct ext4_inode *inode);
  54. /**@brief Set mode of the i-node.
  55. * @param sb Superblock
  56. * @param inode I-node to set mode to
  57. * @param mode Mode to set to i-node
  58. */
  59. void ext4_inode_set_mode(struct ext4_sblock *sb, struct ext4_inode *inode,
  60. uint32_t mode);
  61. /**@brief Get ID of the i-node owner (user id).
  62. * @param inode I-node to load uid from
  63. * @return User ID of the i-node owner
  64. */
  65. uint32_t ext4_inode_get_uid(struct ext4_inode *inode);
  66. /**@brief Set ID of the i-node owner.
  67. * @param inode I-node to set uid to
  68. * @param uid ID of the i-node owner
  69. */
  70. void ext4_inode_set_uid(struct ext4_inode *inode, uint32_t uid);
  71. /**@brief Get real i-node size.
  72. * @param sb Superblock
  73. * @param inode I-node to load size from
  74. * @return Real size of i-node
  75. */
  76. uint64_t ext4_inode_get_size(struct ext4_sblock *sb, struct ext4_inode *inode);
  77. /**@brief Set real i-node size.
  78. * @param inode I-node to set size to
  79. * @param size Size of the i-node
  80. */
  81. void ext4_inode_set_size(struct ext4_inode *inode, uint64_t size);
  82. /**@brief Get time, when i-node was last accessed.
  83. * @param inode I-node
  84. * @return Time of the last access (POSIX)
  85. */
  86. uint32_t ext4_inode_get_access_time(struct ext4_inode *inode);
  87. /**@brief Set time, when i-node was last accessed.
  88. * @param inode I-node
  89. * @param time Time of the last access (POSIX)
  90. */
  91. void ext4_inode_set_access_time(struct ext4_inode *inode, uint32_t time);
  92. /**@brief Get time, when i-node was last changed.
  93. * @param inode I-node
  94. * @return Time of the last change (POSIX)
  95. */
  96. uint32_t ext4_inode_get_change_inode_time(struct ext4_inode *inode);
  97. /**@brief Set time, when i-node was last changed.
  98. * @param inode I-node
  99. * @param time Time of the last change (POSIX)
  100. */
  101. void ext4_inode_set_change_inode_time(struct ext4_inode *inode, uint32_t time);
  102. /**@brief Get time, when i-node content was last modified.
  103. * @param inode I-node
  104. * @return Time of the last content modification (POSIX)
  105. */
  106. uint32_t ext4_inode_get_modif_time(struct ext4_inode *inode);
  107. /**@brief Set time, when i-node content was last modified.
  108. * @param inode I-node
  109. * @param time Time of the last content modification (POSIX)
  110. */
  111. void ext4_inode_set_modif_time(struct ext4_inode *inode, uint32_t time);
  112. /**@brief Get time, when i-node was deleted.
  113. * @param inode I-node
  114. * @return Time of the delete action (POSIX)
  115. */
  116. uint32_t ext4_inode_get_del_time(struct ext4_inode *inode);
  117. /**@brief Set time, when i-node was deleted.
  118. * @param inode I-node
  119. * @param time Time of the delete action (POSIX)
  120. */
  121. void ext4_inode_set_del_time(struct ext4_inode *inode, uint32_t time);
  122. /**@brief Get ID of the i-node owner's group.
  123. * @param inode I-node to load gid from
  124. * @return Group ID of the i-node owner
  125. */
  126. uint32_t ext4_inode_get_gid(struct ext4_inode *inode);
  127. /**@brief Set ID to the i-node owner's group.
  128. * @param inode I-node to set gid to
  129. * @param gid Group ID of the i-node owner
  130. */
  131. void ext4_inode_set_gid(struct ext4_inode *inode, uint32_t gid);
  132. /**@brief Get number of links to i-node.
  133. * @param inode I-node to load number of links from
  134. * @return Number of links to i-node
  135. */
  136. uint16_t ext4_inode_get_links_cnt(struct ext4_inode *inode);
  137. /**@brief Set number of links to i-node.
  138. * @param inode I-node to set number of links to
  139. * @param count Number of links to i-node
  140. */
  141. void ext4_inode_set_links_cnt(struct ext4_inode *inode, uint16_t cnt);
  142. /**@brief Get number of 512-bytes blocks used for i-node.
  143. * @param sb Superblock
  144. * @param inode I-node
  145. * @return Number of 512-bytes blocks
  146. */
  147. uint64_t ext4_inode_get_blocks_count(struct ext4_sblock *sb,
  148. struct ext4_inode *inode);
  149. /**@brief Set number of 512-bytes blocks used for i-node.
  150. * @param sb Superblock
  151. * @param inode I-node
  152. * @param count Number of 512-bytes blocks
  153. * @return Error code
  154. */
  155. int ext4_inode_set_blocks_count(struct ext4_sblock *sb,
  156. struct ext4_inode *inode, uint64_t cnt);
  157. /**@brief Get flags (features) of i-node.
  158. * @param inode I-node to get flags from
  159. * @return Flags (bitmap)
  160. */
  161. uint32_t ext4_inode_get_flags(struct ext4_inode *inode);
  162. /**@brief Set flags (features) of i-node.
  163. * @param inode I-node to set flags to
  164. * @param flags Flags to set to i-node
  165. */
  166. void ext4_inode_set_flags(struct ext4_inode *inode, uint32_t flags);
  167. /**@brief Get file generation (used by NFS).
  168. * @param inode I-node
  169. * @return File generation
  170. */
  171. uint32_t ext4_inode_get_generation(struct ext4_inode *inode);
  172. /**@brief Set file generation (used by NFS).
  173. * @param inode I-node
  174. * @param generation File generation
  175. */
  176. void ext4_inode_set_generation(struct ext4_inode *inode, uint32_t gen);
  177. /**@brief Get extra I-node size field.
  178. * @param inode I-node
  179. * @return extra I-node size
  180. */
  181. uint16_t ext4_inode_get_extra_isize(struct ext4_inode *inode);
  182. /**@brief Set extra I-node size field.
  183. * @param inode I-node
  184. * @param size extra I-node size
  185. */
  186. void ext4_inode_set_extra_isize(struct ext4_inode *inode, uint16_t size);
  187. /**@brief Get address of block, where are extended attributes located.
  188. * @param inode I-node
  189. * @param sb Superblock
  190. * @return Block address
  191. */
  192. uint64_t ext4_inode_get_file_acl(struct ext4_inode *inode,
  193. struct ext4_sblock *sb);
  194. /**@brief Set address of block, where are extended attributes located.
  195. * @param inode I-node
  196. * @param sb Superblock
  197. * @param file_acl Block address
  198. */
  199. void ext4_inode_set_file_acl(struct ext4_inode *inode, struct ext4_sblock *sb,
  200. uint64_t acl);
  201. /**@brief Get block address of specified direct block.
  202. * @param inode I-node to load block from
  203. * @param idx Index of logical block
  204. * @return Physical block address
  205. */
  206. uint32_t ext4_inode_get_direct_block(struct ext4_inode *inode, uint32_t idx);
  207. /**@brief Set block address of specified direct block.
  208. * @param inode I-node to set block address to
  209. * @param idx Index of logical block
  210. * @param fblock Physical block address
  211. */
  212. void ext4_inode_set_direct_block(struct ext4_inode *inode, uint32_t idx,
  213. uint32_t block);
  214. /**@brief Get block address of specified indirect block.
  215. * @param inode I-node to get block address from
  216. * @param idx Index of indirect block
  217. * @return Physical block address
  218. */
  219. uint32_t ext4_inode_get_indirect_block(struct ext4_inode *inode, uint32_t idx);
  220. /**@brief Set block address of specified indirect block.
  221. * @param inode I-node to set block address to
  222. * @param idx Index of indirect block
  223. * @param fblock Physical block address
  224. */
  225. void ext4_inode_set_indirect_block(struct ext4_inode *inode, uint32_t idx,
  226. uint32_t block);
  227. /**@brief return the type of i-node
  228. * @param sb Superblock
  229. * @param inode I-node to return the type of
  230. * @return Result of check operation
  231. */
  232. uint32_t ext4_inode_type(struct ext4_sblock *sb, struct ext4_inode *inode);
  233. /**@brief Check if i-node has specified type.
  234. * @param sb Superblock
  235. * @param inode I-node to check type of
  236. * @param type Type to check
  237. * @return Result of check operation
  238. */
  239. bool ext4_inode_is_type(struct ext4_sblock *sb, struct ext4_inode *inode,
  240. uint32_t type);
  241. /**@brief Check if i-node has specified flag.
  242. * @param inode I-node to check flags of
  243. * @param flag Flag to check
  244. * @return Result of check operation
  245. */
  246. bool ext4_inode_has_flag(struct ext4_inode *inode, uint32_t f);
  247. /**@brief Remove specified flag from i-node.
  248. * @param inode I-node to clear flag on
  249. * @param clear_flag Flag to be cleared
  250. */
  251. void ext4_inode_clear_flag(struct ext4_inode *inode, uint32_t f);
  252. /**@brief Set specified flag to i-node.
  253. * @param inode I-node to set flag on
  254. * @param set_flag Flag to be set
  255. */
  256. void ext4_inode_set_flag(struct ext4_inode *inode, uint32_t f);
  257. /**@brief Get inode checksum(crc32)
  258. * @param sb Superblock
  259. * @param inode I-node to get checksum value from
  260. */
  261. uint32_t
  262. ext4_inode_get_csum(struct ext4_sblock *sb, struct ext4_inode *inode);
  263. /**@brief Get inode checksum(crc32)
  264. * @param sb Superblock
  265. * @param inode I-node to get checksum value from
  266. */
  267. void
  268. ext4_inode_set_csum(struct ext4_sblock *sb, struct ext4_inode *inode,
  269. uint32_t checksum);
  270. /**@brief Check if i-node can be truncated.
  271. * @param sb Superblock
  272. * @param inode I-node to check
  273. * @return Result of the check operation
  274. */
  275. bool ext4_inode_can_truncate(struct ext4_sblock *sb, struct ext4_inode *inode);
  276. /**@brief Get extent header from the root of the extent tree.
  277. * @param inode I-node to get extent header from
  278. * @return Pointer to extent header of the root node
  279. */
  280. struct ext4_extent_header *
  281. ext4_inode_get_extent_header(struct ext4_inode *inode);
  282. #ifdef __cplusplus
  283. }
  284. #endif
  285. #endif /* EXT4_INODE_H_ */
  286. /**
  287. * @}
  288. */