udfdecl.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __UDF_DECL_H
  3. #define __UDF_DECL_H
  4. #define pr_fmt(fmt) "UDF-fs: " fmt
  5. #include "ecma_167.h"
  6. #include "osta_udf.h"
  7. #include <linux/fs.h>
  8. #include <linux/types.h>
  9. #include <linux/buffer_head.h>
  10. #include <linux/udf_fs_i.h>
  11. #include "udf_sb.h"
  12. #include "udfend.h"
  13. #include "udf_i.h"
  14. #define UDF_DEFAULT_PREALLOC_BLOCKS 8
  15. extern __printf(3, 4) void _udf_err(struct super_block *sb,
  16. const char *function, const char *fmt, ...);
  17. #define udf_err(sb, fmt, ...) \
  18. _udf_err(sb, __func__, fmt, ##__VA_ARGS__)
  19. extern __printf(3, 4) void _udf_warn(struct super_block *sb,
  20. const char *function, const char *fmt, ...);
  21. #define udf_warn(sb, fmt, ...) \
  22. _udf_warn(sb, __func__, fmt, ##__VA_ARGS__)
  23. #define udf_info(fmt, ...) \
  24. pr_info("INFO " fmt, ##__VA_ARGS__)
  25. #undef UDFFS_DEBUG
  26. #ifdef UDFFS_DEBUG
  27. #define udf_debug(fmt, ...) \
  28. printk(KERN_DEBUG pr_fmt("%s:%d:%s: " fmt), \
  29. __FILE__, __LINE__, __func__, ##__VA_ARGS__)
  30. #else
  31. #define udf_debug(fmt, ...) \
  32. no_printk(fmt, ##__VA_ARGS__)
  33. #endif
  34. #define udf_fixed_to_variable(x) ( ( ( (x) >> 5 ) * 39 ) + ( (x) & 0x0000001F ) )
  35. #define udf_variable_to_fixed(x) ( ( ( (x) / 39 ) << 5 ) + ( (x) % 39 ) )
  36. #define UDF_EXTENT_LENGTH_MASK 0x3FFFFFFF
  37. #define UDF_EXTENT_FLAG_MASK 0xC0000000
  38. #define UDF_INVALID_ID ((uint32_t)-1)
  39. #define UDF_NAME_PAD 4
  40. #define UDF_NAME_LEN 254
  41. #define UDF_NAME_LEN_CS0 255
  42. static inline size_t udf_file_entry_alloc_offset(struct inode *inode)
  43. {
  44. struct udf_inode_info *iinfo = UDF_I(inode);
  45. if (iinfo->i_use)
  46. return sizeof(struct unallocSpaceEntry);
  47. else if (iinfo->i_efe)
  48. return sizeof(struct extendedFileEntry) + iinfo->i_lenEAttr;
  49. else
  50. return sizeof(struct fileEntry) + iinfo->i_lenEAttr;
  51. }
  52. static inline size_t udf_ext0_offset(struct inode *inode)
  53. {
  54. if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
  55. return udf_file_entry_alloc_offset(inode);
  56. else
  57. return 0;
  58. }
  59. /* computes tag checksum */
  60. u8 udf_tag_checksum(const struct tag *t);
  61. typedef uint32_t udf_pblk_t;
  62. struct dentry;
  63. struct inode;
  64. struct task_struct;
  65. struct buffer_head;
  66. struct super_block;
  67. extern const struct export_operations udf_export_ops;
  68. extern const struct inode_operations udf_dir_inode_operations;
  69. extern const struct file_operations udf_dir_operations;
  70. extern const struct inode_operations udf_file_inode_operations;
  71. extern const struct file_operations udf_file_operations;
  72. extern const struct inode_operations udf_symlink_inode_operations;
  73. extern const struct address_space_operations udf_aops;
  74. extern const struct address_space_operations udf_adinicb_aops;
  75. extern const struct address_space_operations udf_symlink_aops;
  76. struct udf_fileident_bh {
  77. struct buffer_head *sbh;
  78. struct buffer_head *ebh;
  79. int soffset;
  80. int eoffset;
  81. };
  82. struct udf_vds_record {
  83. uint32_t block;
  84. uint32_t volDescSeqNum;
  85. };
  86. struct generic_desc {
  87. struct tag descTag;
  88. __le32 volDescSeqNum;
  89. };
  90. /* super.c */
  91. static inline void udf_updated_lvid(struct super_block *sb)
  92. {
  93. struct buffer_head *bh = UDF_SB(sb)->s_lvid_bh;
  94. BUG_ON(!bh);
  95. WARN_ON_ONCE(((struct logicalVolIntegrityDesc *)
  96. bh->b_data)->integrityType !=
  97. cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN));
  98. UDF_SB(sb)->s_lvid_dirty = 1;
  99. }
  100. extern u64 lvid_get_unique_id(struct super_block *sb);
  101. struct inode *udf_find_metadata_inode_efe(struct super_block *sb,
  102. u32 meta_file_loc, u32 partition_num);
  103. /* namei.c */
  104. extern int udf_write_fi(struct inode *inode, struct fileIdentDesc *,
  105. struct fileIdentDesc *, struct udf_fileident_bh *,
  106. uint8_t *, uint8_t *);
  107. static inline unsigned int udf_dir_entry_len(struct fileIdentDesc *cfi)
  108. {
  109. return ALIGN(sizeof(struct fileIdentDesc) +
  110. le16_to_cpu(cfi->lengthOfImpUse) + cfi->lengthFileIdent,
  111. UDF_NAME_PAD);
  112. }
  113. /* file.c */
  114. extern long udf_ioctl(struct file *, unsigned int, unsigned long);
  115. /* inode.c */
  116. extern struct inode *__udf_iget(struct super_block *, struct kernel_lb_addr *,
  117. bool hidden_inode);
  118. static inline struct inode *udf_iget_special(struct super_block *sb,
  119. struct kernel_lb_addr *ino)
  120. {
  121. return __udf_iget(sb, ino, true);
  122. }
  123. static inline struct inode *udf_iget(struct super_block *sb,
  124. struct kernel_lb_addr *ino)
  125. {
  126. return __udf_iget(sb, ino, false);
  127. }
  128. extern int udf_expand_file_adinicb(struct inode *);
  129. extern struct buffer_head *udf_expand_dir_adinicb(struct inode *inode,
  130. udf_pblk_t *block, int *err);
  131. extern struct buffer_head *udf_bread(struct inode *inode, udf_pblk_t block,
  132. int create, int *err);
  133. extern int udf_setsize(struct inode *, loff_t);
  134. extern void udf_evict_inode(struct inode *);
  135. extern int udf_write_inode(struct inode *, struct writeback_control *wbc);
  136. extern udf_pblk_t udf_block_map(struct inode *inode, sector_t block);
  137. extern int8_t inode_bmap(struct inode *, sector_t, struct extent_position *,
  138. struct kernel_lb_addr *, uint32_t *, sector_t *);
  139. extern int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block,
  140. struct extent_position *epos);
  141. extern int __udf_add_aext(struct inode *inode, struct extent_position *epos,
  142. struct kernel_lb_addr *eloc, uint32_t elen, int inc);
  143. extern int udf_add_aext(struct inode *, struct extent_position *,
  144. struct kernel_lb_addr *, uint32_t, int);
  145. extern void udf_write_aext(struct inode *, struct extent_position *,
  146. struct kernel_lb_addr *, uint32_t, int);
  147. extern int8_t udf_delete_aext(struct inode *, struct extent_position);
  148. extern int8_t udf_next_aext(struct inode *, struct extent_position *,
  149. struct kernel_lb_addr *, uint32_t *, int);
  150. extern int8_t udf_current_aext(struct inode *, struct extent_position *,
  151. struct kernel_lb_addr *, uint32_t *, int);
  152. /* misc.c */
  153. extern struct buffer_head *udf_tgetblk(struct super_block *sb,
  154. udf_pblk_t block);
  155. extern struct buffer_head *udf_tread(struct super_block *sb, udf_pblk_t block);
  156. extern struct genericFormat *udf_add_extendedattr(struct inode *, uint32_t,
  157. uint32_t, uint8_t);
  158. extern struct genericFormat *udf_get_extendedattr(struct inode *, uint32_t,
  159. uint8_t);
  160. extern struct buffer_head *udf_read_tagged(struct super_block *, uint32_t,
  161. uint32_t, uint16_t *);
  162. extern struct buffer_head *udf_read_ptagged(struct super_block *,
  163. struct kernel_lb_addr *, uint32_t,
  164. uint16_t *);
  165. extern void udf_update_tag(char *, int);
  166. extern void udf_new_tag(char *, uint16_t, uint16_t, uint16_t, uint32_t, int);
  167. /* lowlevel.c */
  168. extern unsigned int udf_get_last_session(struct super_block *);
  169. extern unsigned long udf_get_last_block(struct super_block *);
  170. /* partition.c */
  171. extern uint32_t udf_get_pblock(struct super_block *, uint32_t, uint16_t,
  172. uint32_t);
  173. extern uint32_t udf_get_pblock_virt15(struct super_block *, uint32_t, uint16_t,
  174. uint32_t);
  175. extern uint32_t udf_get_pblock_virt20(struct super_block *, uint32_t, uint16_t,
  176. uint32_t);
  177. extern uint32_t udf_get_pblock_spar15(struct super_block *, uint32_t, uint16_t,
  178. uint32_t);
  179. extern uint32_t udf_get_pblock_meta25(struct super_block *, uint32_t, uint16_t,
  180. uint32_t);
  181. extern int udf_relocate_blocks(struct super_block *, long, long *);
  182. static inline uint32_t
  183. udf_get_lb_pblock(struct super_block *sb, struct kernel_lb_addr *loc,
  184. uint32_t offset)
  185. {
  186. return udf_get_pblock(sb, loc->logicalBlockNum,
  187. loc->partitionReferenceNum, offset);
  188. }
  189. /* unicode.c */
  190. extern int udf_get_filename(struct super_block *, const uint8_t *, int,
  191. uint8_t *, int);
  192. extern int udf_put_filename(struct super_block *, const uint8_t *, int,
  193. uint8_t *, int);
  194. extern int udf_dstrCS0toChar(struct super_block *, uint8_t *, int,
  195. const uint8_t *, int);
  196. /* ialloc.c */
  197. extern void udf_free_inode(struct inode *);
  198. extern struct inode *udf_new_inode(struct inode *, umode_t);
  199. /* truncate.c */
  200. extern void udf_truncate_tail_extent(struct inode *);
  201. extern void udf_discard_prealloc(struct inode *);
  202. extern void udf_truncate_extents(struct inode *);
  203. /* balloc.c */
  204. extern void udf_free_blocks(struct super_block *, struct inode *,
  205. struct kernel_lb_addr *, uint32_t, uint32_t);
  206. extern int udf_prealloc_blocks(struct super_block *, struct inode *, uint16_t,
  207. uint32_t, uint32_t);
  208. extern udf_pblk_t udf_new_block(struct super_block *sb, struct inode *inode,
  209. uint16_t partition, uint32_t goal, int *err);
  210. /* directory.c */
  211. extern struct fileIdentDesc *udf_fileident_read(struct inode *, loff_t *,
  212. struct udf_fileident_bh *,
  213. struct fileIdentDesc *,
  214. struct extent_position *,
  215. struct kernel_lb_addr *, uint32_t *,
  216. sector_t *);
  217. extern struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize,
  218. int *offset);
  219. extern struct long_ad *udf_get_filelongad(uint8_t *, int, uint32_t *, int);
  220. extern struct short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
  221. /* udftime.c */
  222. extern void udf_disk_stamp_to_time(struct timespec64 *dest,
  223. struct timestamp src);
  224. extern void udf_time_to_disk_stamp(struct timestamp *dest, struct timespec64 src);
  225. #endif /* __UDF_DECL_H */