ext4_inode.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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 cnt 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 cnt 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 gen 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 sb Superblock
  179. * @param inode I-node
  180. * @return extra I-node size
  181. */
  182. uint16_t ext4_inode_get_extra_isize(struct ext4_sblock *sb,
  183. struct ext4_inode *inode);
  184. /**@brief Set extra I-node size field.
  185. * @param sb Superblock
  186. * @param inode I-node
  187. * @param size extra I-node size
  188. */
  189. void ext4_inode_set_extra_isize(struct ext4_sblock *sb,
  190. struct ext4_inode *inode,
  191. uint16_t size);
  192. /**@brief Get address of block, where are extended attributes located.
  193. * @param inode I-node
  194. * @param sb Superblock
  195. * @return Block address
  196. */
  197. uint64_t ext4_inode_get_file_acl(struct ext4_inode *inode,
  198. struct ext4_sblock *sb);
  199. /**@brief Set address of block, where are extended attributes located.
  200. * @param inode I-node
  201. * @param sb Superblock
  202. * @param acl Block address
  203. */
  204. void ext4_inode_set_file_acl(struct ext4_inode *inode, struct ext4_sblock *sb,
  205. uint64_t acl);
  206. /**@brief Get block address of specified direct block.
  207. * @param inode I-node to load block from
  208. * @param idx Index of logical block
  209. * @return Physical block address
  210. */
  211. uint32_t ext4_inode_get_direct_block(struct ext4_inode *inode, uint32_t idx);
  212. /**@brief Set block address of specified direct block.
  213. * @param inode I-node to set block address to
  214. * @param idx Index of logical block
  215. * @param block Physical block address
  216. */
  217. void ext4_inode_set_direct_block(struct ext4_inode *inode, uint32_t idx,
  218. uint32_t block);
  219. /**@brief Get block address of specified indirect block.
  220. * @param inode I-node to get block address from
  221. * @param idx Index of indirect block
  222. * @return Physical block address
  223. */
  224. uint32_t ext4_inode_get_indirect_block(struct ext4_inode *inode, uint32_t idx);
  225. /**@brief Set block address of specified indirect block.
  226. * @param inode I-node to set block address to
  227. * @param idx Index of indirect block
  228. * @param block Physical block address
  229. */
  230. void ext4_inode_set_indirect_block(struct ext4_inode *inode, uint32_t idx,
  231. uint32_t block);
  232. /**@brief Get device number
  233. * @param inode I-node to get device number from
  234. * @return Device number
  235. */
  236. uint32_t ext4_inode_get_dev(struct ext4_inode *inode);
  237. /**@brief Set device number
  238. * @param inode I-node to set device number to
  239. * @param dev Device number
  240. */
  241. void ext4_inode_set_dev(struct ext4_inode *inode, uint32_t dev);
  242. /**@brief return the type of i-node
  243. * @param sb Superblock
  244. * @param inode I-node to return the type of
  245. * @return Result of check operation
  246. */
  247. uint32_t ext4_inode_type(struct ext4_sblock *sb, struct ext4_inode *inode);
  248. /**@brief Check if i-node has specified type.
  249. * @param sb Superblock
  250. * @param inode I-node to check type of
  251. * @param type Type to check
  252. * @return Result of check operation
  253. */
  254. bool ext4_inode_is_type(struct ext4_sblock *sb, struct ext4_inode *inode,
  255. uint32_t type);
  256. /**@brief Check if i-node has specified flag.
  257. * @param inode I-node to check flags of
  258. * @param f Flag to check
  259. * @return Result of check operation
  260. */
  261. bool ext4_inode_has_flag(struct ext4_inode *inode, uint32_t f);
  262. /**@brief Remove specified flag from i-node.
  263. * @param inode I-node to clear flag on
  264. * @param f Flag to be cleared
  265. */
  266. void ext4_inode_clear_flag(struct ext4_inode *inode, uint32_t f);
  267. /**@brief Set specified flag to i-node.
  268. * @param inode I-node to set flag on
  269. * @param f Flag to be set
  270. */
  271. void ext4_inode_set_flag(struct ext4_inode *inode, uint32_t f);
  272. /**@brief Get inode checksum(crc32)
  273. * @param sb Superblock
  274. * @param inode I-node to get checksum value from
  275. */
  276. uint32_t
  277. ext4_inode_get_csum(struct ext4_sblock *sb, struct ext4_inode *inode);
  278. /**@brief Get inode checksum(crc32)
  279. * @param sb Superblock
  280. * @param inode I-node to get checksum value from
  281. */
  282. void
  283. ext4_inode_set_csum(struct ext4_sblock *sb, struct ext4_inode *inode,
  284. uint32_t checksum);
  285. /**@brief Check if i-node can be truncated.
  286. * @param sb Superblock
  287. * @param inode I-node to check
  288. * @return Result of the check operation
  289. */
  290. bool ext4_inode_can_truncate(struct ext4_sblock *sb, struct ext4_inode *inode);
  291. /**@brief Get extent header from the root of the extent tree.
  292. * @param inode I-node to get extent header from
  293. * @return Pointer to extent header of the root node
  294. */
  295. struct ext4_extent_header *
  296. ext4_inode_get_extent_header(struct ext4_inode *inode);
  297. #ifdef __cplusplus
  298. }
  299. #endif
  300. #endif /* EXT4_INODE_H_ */
  301. /**
  302. * @}
  303. */