udfdecl.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. #define udf_debug(fmt, ...) \
  26. pr_debug("%s:%d:%s: " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
  27. #define UDF_EXTENT_LENGTH_MASK 0x3FFFFFFF
  28. #define UDF_EXTENT_FLAG_MASK 0xC0000000
  29. #define UDF_INVALID_ID ((uint32_t)-1)
  30. #define UDF_NAME_PAD 4
  31. #define UDF_NAME_LEN 254
  32. #define UDF_NAME_LEN_CS0 255
  33. static inline size_t udf_file_entry_alloc_offset(struct inode *inode)
  34. {
  35. struct udf_inode_info *iinfo = UDF_I(inode);
  36. if (iinfo->i_use)
  37. return sizeof(struct unallocSpaceEntry);
  38. else if (iinfo->i_efe)
  39. return sizeof(struct extendedFileEntry) + iinfo->i_lenEAttr;
  40. else
  41. return sizeof(struct fileEntry) + iinfo->i_lenEAttr;
  42. }
  43. static inline size_t udf_ext0_offset(struct inode *inode)
  44. {
  45. if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
  46. return udf_file_entry_alloc_offset(inode);
  47. else
  48. return 0;
  49. }
  50. /* computes tag checksum */
  51. u8 udf_tag_checksum(const struct tag *t);
  52. typedef uint32_t udf_pblk_t;
  53. struct dentry;
  54. struct inode;
  55. struct task_struct;
  56. struct buffer_head;
  57. struct super_block;
  58. extern const struct export_operations udf_export_ops;
  59. extern const struct inode_operations udf_dir_inode_operations;
  60. extern const struct file_operations udf_dir_operations;
  61. extern const struct inode_operations udf_file_inode_operations;
  62. extern const struct file_operations udf_file_operations;
  63. extern const struct inode_operations udf_symlink_inode_operations;
  64. extern const struct address_space_operations udf_aops;
  65. extern const struct address_space_operations udf_symlink_aops;
  66. struct udf_fileident_iter {
  67. struct inode *dir; /* Directory we are working with */
  68. loff_t pos; /* Logical position in a dir */
  69. struct buffer_head *bh[2]; /* Buffer containing 'pos' and possibly
  70. * next buffer if entry straddles
  71. * blocks */
  72. struct kernel_lb_addr eloc; /* Start of extent containing 'pos' */
  73. uint32_t elen; /* Length of extent containing 'pos' */
  74. sector_t loffset; /* Block offset of 'pos' within above
  75. * extent */
  76. struct extent_position epos; /* Position after the above extent */
  77. struct fileIdentDesc fi; /* Copied directory entry */
  78. uint8_t *name; /* Pointer to entry name */
  79. uint8_t *namebuf; /* Storage for entry name in case
  80. * the name is split between two blocks
  81. */
  82. };
  83. struct udf_vds_record {
  84. uint32_t block;
  85. uint32_t volDescSeqNum;
  86. };
  87. struct generic_desc {
  88. struct tag descTag;
  89. __le32 volDescSeqNum;
  90. };
  91. /* super.c */
  92. static inline void udf_updated_lvid(struct super_block *sb)
  93. {
  94. struct buffer_head *bh = UDF_SB(sb)->s_lvid_bh;
  95. BUG_ON(!bh);
  96. WARN_ON_ONCE(((struct logicalVolIntegrityDesc *)
  97. bh->b_data)->integrityType !=
  98. cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN));
  99. UDF_SB(sb)->s_lvid_dirty = 1;
  100. }
  101. extern u64 lvid_get_unique_id(struct super_block *sb);
  102. struct inode *udf_find_metadata_inode_efe(struct super_block *sb,
  103. u32 meta_file_loc, u32 partition_num);
  104. /* namei.c */
  105. static inline unsigned int udf_dir_entry_len(struct fileIdentDesc *cfi)
  106. {
  107. return ALIGN(sizeof(struct fileIdentDesc) +
  108. le16_to_cpu(cfi->lengthOfImpUse) + cfi->lengthFileIdent,
  109. UDF_NAME_PAD);
  110. }
  111. /* file.c */
  112. extern long udf_ioctl(struct file *, unsigned int, unsigned long);
  113. /* inode.c */
  114. extern struct inode *__udf_iget(struct super_block *, struct kernel_lb_addr *,
  115. bool hidden_inode);
  116. static inline struct inode *udf_iget_special(struct super_block *sb,
  117. struct kernel_lb_addr *ino)
  118. {
  119. return __udf_iget(sb, ino, true);
  120. }
  121. static inline struct inode *udf_iget(struct super_block *sb,
  122. struct kernel_lb_addr *ino)
  123. {
  124. return __udf_iget(sb, ino, false);
  125. }
  126. extern int udf_expand_file_adinicb(struct inode *);
  127. extern struct buffer_head *udf_bread(struct inode *inode, udf_pblk_t block,
  128. int create, int *err);
  129. extern int udf_setsize(struct inode *, loff_t);
  130. extern void udf_evict_inode(struct inode *);
  131. extern int udf_write_inode(struct inode *, struct writeback_control *wbc);
  132. extern int inode_bmap(struct inode *inode, sector_t block,
  133. struct extent_position *pos, struct kernel_lb_addr *eloc,
  134. uint32_t *elen, sector_t *offset, int8_t *etype);
  135. int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
  136. extern int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block,
  137. struct extent_position *epos);
  138. extern int __udf_add_aext(struct inode *inode, struct extent_position *epos,
  139. struct kernel_lb_addr *eloc, uint32_t elen, int inc);
  140. extern int udf_add_aext(struct inode *, struct extent_position *,
  141. struct kernel_lb_addr *, uint32_t, int);
  142. extern void udf_write_aext(struct inode *, struct extent_position *,
  143. struct kernel_lb_addr *, uint32_t, int);
  144. extern int8_t udf_delete_aext(struct inode *, struct extent_position);
  145. extern int udf_next_aext(struct inode *inode, struct extent_position *epos,
  146. struct kernel_lb_addr *eloc, uint32_t *elen,
  147. int8_t *etype, int inc);
  148. extern int udf_current_aext(struct inode *inode, struct extent_position *epos,
  149. struct kernel_lb_addr *eloc, uint32_t *elen,
  150. int8_t *etype, int inc);
  151. extern void udf_update_extra_perms(struct inode *inode, umode_t mode);
  152. /* misc.c */
  153. extern struct genericFormat *udf_add_extendedattr(struct inode *, uint32_t,
  154. uint32_t, uint8_t);
  155. extern struct genericFormat *udf_get_extendedattr(struct inode *, uint32_t,
  156. uint8_t);
  157. extern struct buffer_head *udf_read_tagged(struct super_block *, uint32_t,
  158. uint32_t, uint16_t *);
  159. extern struct buffer_head *udf_read_ptagged(struct super_block *,
  160. struct kernel_lb_addr *, uint32_t,
  161. uint16_t *);
  162. extern void udf_update_tag(char *, int);
  163. extern void udf_new_tag(char *, uint16_t, uint16_t, uint16_t, uint32_t, int);
  164. /* lowlevel.c */
  165. extern unsigned int udf_get_last_session(struct super_block *);
  166. udf_pblk_t udf_get_last_block(struct super_block *);
  167. /* partition.c */
  168. extern uint32_t udf_get_pblock(struct super_block *, uint32_t, uint16_t,
  169. uint32_t);
  170. extern uint32_t udf_get_pblock_virt15(struct super_block *, uint32_t, uint16_t,
  171. uint32_t);
  172. extern uint32_t udf_get_pblock_virt20(struct super_block *, uint32_t, uint16_t,
  173. uint32_t);
  174. extern uint32_t udf_get_pblock_spar15(struct super_block *, uint32_t, uint16_t,
  175. uint32_t);
  176. extern uint32_t udf_get_pblock_meta25(struct super_block *, uint32_t, uint16_t,
  177. uint32_t);
  178. extern int udf_relocate_blocks(struct super_block *, long, long *);
  179. static inline uint32_t
  180. udf_get_lb_pblock(struct super_block *sb, struct kernel_lb_addr *loc,
  181. uint32_t offset)
  182. {
  183. return udf_get_pblock(sb, loc->logicalBlockNum,
  184. loc->partitionReferenceNum, offset);
  185. }
  186. /* unicode.c */
  187. extern int udf_get_filename(struct super_block *, const uint8_t *, int,
  188. uint8_t *, int);
  189. extern int udf_put_filename(struct super_block *, const uint8_t *, int,
  190. uint8_t *, int);
  191. extern int udf_dstrCS0toChar(struct super_block *, uint8_t *, int,
  192. const uint8_t *, int);
  193. /* ialloc.c */
  194. extern void udf_free_inode(struct inode *);
  195. extern struct inode *udf_new_inode(struct inode *, umode_t);
  196. /* truncate.c */
  197. extern void udf_truncate_tail_extent(struct inode *);
  198. extern void udf_discard_prealloc(struct inode *);
  199. extern int udf_truncate_extents(struct inode *);
  200. /* balloc.c */
  201. extern void udf_free_blocks(struct super_block *, struct inode *,
  202. struct kernel_lb_addr *, uint32_t, uint32_t);
  203. extern int udf_prealloc_blocks(struct super_block *, struct inode *, uint16_t,
  204. uint32_t, uint32_t);
  205. extern udf_pblk_t udf_new_block(struct super_block *sb, struct inode *inode,
  206. uint16_t partition, uint32_t goal, int *err);
  207. /* directory.c */
  208. int udf_fiiter_init(struct udf_fileident_iter *iter, struct inode *dir,
  209. loff_t pos);
  210. int udf_fiiter_advance(struct udf_fileident_iter *iter);
  211. void udf_fiiter_release(struct udf_fileident_iter *iter);
  212. void udf_fiiter_write_fi(struct udf_fileident_iter *iter, uint8_t *impuse);
  213. void udf_fiiter_update_elen(struct udf_fileident_iter *iter, uint32_t new_elen);
  214. int udf_fiiter_append_blk(struct udf_fileident_iter *iter);
  215. extern struct long_ad *udf_get_filelongad(uint8_t *, int, uint32_t *, int);
  216. extern struct short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
  217. /* udftime.c */
  218. extern void udf_disk_stamp_to_time(struct timespec64 *dest,
  219. struct timestamp src);
  220. extern void udf_time_to_disk_stamp(struct timestamp *dest, struct timespec64 src);
  221. #endif /* __UDF_DECL_H */