18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __UDF_DECL_H 38c2ecf20Sopenharmony_ci#define __UDF_DECL_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#define pr_fmt(fmt) "UDF-fs: " fmt 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include "ecma_167.h" 88c2ecf20Sopenharmony_ci#include "osta_udf.h" 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/fs.h> 118c2ecf20Sopenharmony_ci#include <linux/types.h> 128c2ecf20Sopenharmony_ci#include <linux/buffer_head.h> 138c2ecf20Sopenharmony_ci#include <linux/udf_fs_i.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include "udf_sb.h" 168c2ecf20Sopenharmony_ci#include "udfend.h" 178c2ecf20Sopenharmony_ci#include "udf_i.h" 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define UDF_DEFAULT_PREALLOC_BLOCKS 8 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ciextern __printf(3, 4) void _udf_err(struct super_block *sb, 228c2ecf20Sopenharmony_ci const char *function, const char *fmt, ...); 238c2ecf20Sopenharmony_ci#define udf_err(sb, fmt, ...) \ 248c2ecf20Sopenharmony_ci _udf_err(sb, __func__, fmt, ##__VA_ARGS__) 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciextern __printf(3, 4) void _udf_warn(struct super_block *sb, 278c2ecf20Sopenharmony_ci const char *function, const char *fmt, ...); 288c2ecf20Sopenharmony_ci#define udf_warn(sb, fmt, ...) \ 298c2ecf20Sopenharmony_ci _udf_warn(sb, __func__, fmt, ##__VA_ARGS__) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define udf_info(fmt, ...) \ 328c2ecf20Sopenharmony_ci pr_info("INFO " fmt, ##__VA_ARGS__) 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define udf_debug(fmt, ...) \ 358c2ecf20Sopenharmony_ci pr_debug("%s:%d:%s: " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__) 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define udf_fixed_to_variable(x) ( ( ( (x) >> 5 ) * 39 ) + ( (x) & 0x0000001F ) ) 388c2ecf20Sopenharmony_ci#define udf_variable_to_fixed(x) ( ( ( (x) / 39 ) << 5 ) + ( (x) % 39 ) ) 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define UDF_EXTENT_LENGTH_MASK 0x3FFFFFFF 418c2ecf20Sopenharmony_ci#define UDF_EXTENT_FLAG_MASK 0xC0000000 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define UDF_INVALID_ID ((uint32_t)-1) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define UDF_NAME_PAD 4 468c2ecf20Sopenharmony_ci#define UDF_NAME_LEN 254 478c2ecf20Sopenharmony_ci#define UDF_NAME_LEN_CS0 255 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic inline size_t udf_file_entry_alloc_offset(struct inode *inode) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci struct udf_inode_info *iinfo = UDF_I(inode); 528c2ecf20Sopenharmony_ci if (iinfo->i_use) 538c2ecf20Sopenharmony_ci return sizeof(struct unallocSpaceEntry); 548c2ecf20Sopenharmony_ci else if (iinfo->i_efe) 558c2ecf20Sopenharmony_ci return sizeof(struct extendedFileEntry) + iinfo->i_lenEAttr; 568c2ecf20Sopenharmony_ci else 578c2ecf20Sopenharmony_ci return sizeof(struct fileEntry) + iinfo->i_lenEAttr; 588c2ecf20Sopenharmony_ci} 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistatic inline size_t udf_ext0_offset(struct inode *inode) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 638c2ecf20Sopenharmony_ci return udf_file_entry_alloc_offset(inode); 648c2ecf20Sopenharmony_ci else 658c2ecf20Sopenharmony_ci return 0; 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* computes tag checksum */ 698c2ecf20Sopenharmony_ciu8 udf_tag_checksum(const struct tag *t); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_citypedef uint32_t udf_pblk_t; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistruct dentry; 748c2ecf20Sopenharmony_cistruct inode; 758c2ecf20Sopenharmony_cistruct task_struct; 768c2ecf20Sopenharmony_cistruct buffer_head; 778c2ecf20Sopenharmony_cistruct super_block; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ciextern const struct export_operations udf_export_ops; 808c2ecf20Sopenharmony_ciextern const struct inode_operations udf_dir_inode_operations; 818c2ecf20Sopenharmony_ciextern const struct file_operations udf_dir_operations; 828c2ecf20Sopenharmony_ciextern const struct inode_operations udf_file_inode_operations; 838c2ecf20Sopenharmony_ciextern const struct file_operations udf_file_operations; 848c2ecf20Sopenharmony_ciextern const struct inode_operations udf_symlink_inode_operations; 858c2ecf20Sopenharmony_ciextern const struct address_space_operations udf_aops; 868c2ecf20Sopenharmony_ciextern const struct address_space_operations udf_adinicb_aops; 878c2ecf20Sopenharmony_ciextern const struct address_space_operations udf_symlink_aops; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_cistruct udf_fileident_bh { 908c2ecf20Sopenharmony_ci struct buffer_head *sbh; 918c2ecf20Sopenharmony_ci struct buffer_head *ebh; 928c2ecf20Sopenharmony_ci int soffset; 938c2ecf20Sopenharmony_ci int eoffset; 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistruct udf_vds_record { 978c2ecf20Sopenharmony_ci uint32_t block; 988c2ecf20Sopenharmony_ci uint32_t volDescSeqNum; 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistruct generic_desc { 1028c2ecf20Sopenharmony_ci struct tag descTag; 1038c2ecf20Sopenharmony_ci __le32 volDescSeqNum; 1048c2ecf20Sopenharmony_ci}; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci/* super.c */ 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic inline void udf_updated_lvid(struct super_block *sb) 1108c2ecf20Sopenharmony_ci{ 1118c2ecf20Sopenharmony_ci struct buffer_head *bh = UDF_SB(sb)->s_lvid_bh; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci BUG_ON(!bh); 1148c2ecf20Sopenharmony_ci WARN_ON_ONCE(((struct logicalVolIntegrityDesc *) 1158c2ecf20Sopenharmony_ci bh->b_data)->integrityType != 1168c2ecf20Sopenharmony_ci cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN)); 1178c2ecf20Sopenharmony_ci UDF_SB(sb)->s_lvid_dirty = 1; 1188c2ecf20Sopenharmony_ci} 1198c2ecf20Sopenharmony_ciextern u64 lvid_get_unique_id(struct super_block *sb); 1208c2ecf20Sopenharmony_cistruct inode *udf_find_metadata_inode_efe(struct super_block *sb, 1218c2ecf20Sopenharmony_ci u32 meta_file_loc, u32 partition_num); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* namei.c */ 1248c2ecf20Sopenharmony_ciextern int udf_write_fi(struct inode *inode, struct fileIdentDesc *, 1258c2ecf20Sopenharmony_ci struct fileIdentDesc *, struct udf_fileident_bh *, 1268c2ecf20Sopenharmony_ci uint8_t *, uint8_t *); 1278c2ecf20Sopenharmony_cistatic inline unsigned int udf_dir_entry_len(struct fileIdentDesc *cfi) 1288c2ecf20Sopenharmony_ci{ 1298c2ecf20Sopenharmony_ci return ALIGN(sizeof(struct fileIdentDesc) + 1308c2ecf20Sopenharmony_ci le16_to_cpu(cfi->lengthOfImpUse) + cfi->lengthFileIdent, 1318c2ecf20Sopenharmony_ci UDF_NAME_PAD); 1328c2ecf20Sopenharmony_ci} 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci/* file.c */ 1358c2ecf20Sopenharmony_ciextern long udf_ioctl(struct file *, unsigned int, unsigned long); 1368c2ecf20Sopenharmony_ci/* inode.c */ 1378c2ecf20Sopenharmony_ciextern struct inode *__udf_iget(struct super_block *, struct kernel_lb_addr *, 1388c2ecf20Sopenharmony_ci bool hidden_inode); 1398c2ecf20Sopenharmony_cistatic inline struct inode *udf_iget_special(struct super_block *sb, 1408c2ecf20Sopenharmony_ci struct kernel_lb_addr *ino) 1418c2ecf20Sopenharmony_ci{ 1428c2ecf20Sopenharmony_ci return __udf_iget(sb, ino, true); 1438c2ecf20Sopenharmony_ci} 1448c2ecf20Sopenharmony_cistatic inline struct inode *udf_iget(struct super_block *sb, 1458c2ecf20Sopenharmony_ci struct kernel_lb_addr *ino) 1468c2ecf20Sopenharmony_ci{ 1478c2ecf20Sopenharmony_ci return __udf_iget(sb, ino, false); 1488c2ecf20Sopenharmony_ci} 1498c2ecf20Sopenharmony_ciextern int udf_expand_file_adinicb(struct inode *); 1508c2ecf20Sopenharmony_ciextern struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, 1518c2ecf20Sopenharmony_ci udf_pblk_t *block, int *err); 1528c2ecf20Sopenharmony_ciextern struct buffer_head *udf_bread(struct inode *inode, udf_pblk_t block, 1538c2ecf20Sopenharmony_ci int create, int *err); 1548c2ecf20Sopenharmony_ciextern int udf_setsize(struct inode *, loff_t); 1558c2ecf20Sopenharmony_ciextern void udf_evict_inode(struct inode *); 1568c2ecf20Sopenharmony_ciextern int udf_write_inode(struct inode *, struct writeback_control *wbc); 1578c2ecf20Sopenharmony_ciextern udf_pblk_t udf_block_map(struct inode *inode, sector_t block); 1588c2ecf20Sopenharmony_ciextern int8_t inode_bmap(struct inode *, sector_t, struct extent_position *, 1598c2ecf20Sopenharmony_ci struct kernel_lb_addr *, uint32_t *, sector_t *); 1608c2ecf20Sopenharmony_ciextern int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block, 1618c2ecf20Sopenharmony_ci struct extent_position *epos); 1628c2ecf20Sopenharmony_ciextern int __udf_add_aext(struct inode *inode, struct extent_position *epos, 1638c2ecf20Sopenharmony_ci struct kernel_lb_addr *eloc, uint32_t elen, int inc); 1648c2ecf20Sopenharmony_ciextern int udf_add_aext(struct inode *, struct extent_position *, 1658c2ecf20Sopenharmony_ci struct kernel_lb_addr *, uint32_t, int); 1668c2ecf20Sopenharmony_ciextern void udf_write_aext(struct inode *, struct extent_position *, 1678c2ecf20Sopenharmony_ci struct kernel_lb_addr *, uint32_t, int); 1688c2ecf20Sopenharmony_ciextern int8_t udf_delete_aext(struct inode *, struct extent_position); 1698c2ecf20Sopenharmony_ciextern int8_t udf_next_aext(struct inode *, struct extent_position *, 1708c2ecf20Sopenharmony_ci struct kernel_lb_addr *, uint32_t *, int); 1718c2ecf20Sopenharmony_ciextern int8_t udf_current_aext(struct inode *, struct extent_position *, 1728c2ecf20Sopenharmony_ci struct kernel_lb_addr *, uint32_t *, int); 1738c2ecf20Sopenharmony_ciextern void udf_update_extra_perms(struct inode *inode, umode_t mode); 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci/* misc.c */ 1768c2ecf20Sopenharmony_ciextern struct buffer_head *udf_tgetblk(struct super_block *sb, 1778c2ecf20Sopenharmony_ci udf_pblk_t block); 1788c2ecf20Sopenharmony_ciextern struct buffer_head *udf_tread(struct super_block *sb, udf_pblk_t block); 1798c2ecf20Sopenharmony_ciextern struct genericFormat *udf_add_extendedattr(struct inode *, uint32_t, 1808c2ecf20Sopenharmony_ci uint32_t, uint8_t); 1818c2ecf20Sopenharmony_ciextern struct genericFormat *udf_get_extendedattr(struct inode *, uint32_t, 1828c2ecf20Sopenharmony_ci uint8_t); 1838c2ecf20Sopenharmony_ciextern struct buffer_head *udf_read_tagged(struct super_block *, uint32_t, 1848c2ecf20Sopenharmony_ci uint32_t, uint16_t *); 1858c2ecf20Sopenharmony_ciextern struct buffer_head *udf_read_ptagged(struct super_block *, 1868c2ecf20Sopenharmony_ci struct kernel_lb_addr *, uint32_t, 1878c2ecf20Sopenharmony_ci uint16_t *); 1888c2ecf20Sopenharmony_ciextern void udf_update_tag(char *, int); 1898c2ecf20Sopenharmony_ciextern void udf_new_tag(char *, uint16_t, uint16_t, uint16_t, uint32_t, int); 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci/* lowlevel.c */ 1928c2ecf20Sopenharmony_ciextern unsigned int udf_get_last_session(struct super_block *); 1938c2ecf20Sopenharmony_ciextern unsigned long udf_get_last_block(struct super_block *); 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci/* partition.c */ 1968c2ecf20Sopenharmony_ciextern uint32_t udf_get_pblock(struct super_block *, uint32_t, uint16_t, 1978c2ecf20Sopenharmony_ci uint32_t); 1988c2ecf20Sopenharmony_ciextern uint32_t udf_get_pblock_virt15(struct super_block *, uint32_t, uint16_t, 1998c2ecf20Sopenharmony_ci uint32_t); 2008c2ecf20Sopenharmony_ciextern uint32_t udf_get_pblock_virt20(struct super_block *, uint32_t, uint16_t, 2018c2ecf20Sopenharmony_ci uint32_t); 2028c2ecf20Sopenharmony_ciextern uint32_t udf_get_pblock_spar15(struct super_block *, uint32_t, uint16_t, 2038c2ecf20Sopenharmony_ci uint32_t); 2048c2ecf20Sopenharmony_ciextern uint32_t udf_get_pblock_meta25(struct super_block *, uint32_t, uint16_t, 2058c2ecf20Sopenharmony_ci uint32_t); 2068c2ecf20Sopenharmony_ciextern int udf_relocate_blocks(struct super_block *, long, long *); 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_cistatic inline uint32_t 2098c2ecf20Sopenharmony_ciudf_get_lb_pblock(struct super_block *sb, struct kernel_lb_addr *loc, 2108c2ecf20Sopenharmony_ci uint32_t offset) 2118c2ecf20Sopenharmony_ci{ 2128c2ecf20Sopenharmony_ci return udf_get_pblock(sb, loc->logicalBlockNum, 2138c2ecf20Sopenharmony_ci loc->partitionReferenceNum, offset); 2148c2ecf20Sopenharmony_ci} 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci/* unicode.c */ 2178c2ecf20Sopenharmony_ciextern int udf_get_filename(struct super_block *, const uint8_t *, int, 2188c2ecf20Sopenharmony_ci uint8_t *, int); 2198c2ecf20Sopenharmony_ciextern int udf_put_filename(struct super_block *, const uint8_t *, int, 2208c2ecf20Sopenharmony_ci uint8_t *, int); 2218c2ecf20Sopenharmony_ciextern int udf_dstrCS0toChar(struct super_block *, uint8_t *, int, 2228c2ecf20Sopenharmony_ci const uint8_t *, int); 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci/* ialloc.c */ 2258c2ecf20Sopenharmony_ciextern void udf_free_inode(struct inode *); 2268c2ecf20Sopenharmony_ciextern struct inode *udf_new_inode(struct inode *, umode_t); 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci/* truncate.c */ 2298c2ecf20Sopenharmony_ciextern void udf_truncate_tail_extent(struct inode *); 2308c2ecf20Sopenharmony_ciextern void udf_discard_prealloc(struct inode *); 2318c2ecf20Sopenharmony_ciextern int udf_truncate_extents(struct inode *); 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci/* balloc.c */ 2348c2ecf20Sopenharmony_ciextern void udf_free_blocks(struct super_block *, struct inode *, 2358c2ecf20Sopenharmony_ci struct kernel_lb_addr *, uint32_t, uint32_t); 2368c2ecf20Sopenharmony_ciextern int udf_prealloc_blocks(struct super_block *, struct inode *, uint16_t, 2378c2ecf20Sopenharmony_ci uint32_t, uint32_t); 2388c2ecf20Sopenharmony_ciextern udf_pblk_t udf_new_block(struct super_block *sb, struct inode *inode, 2398c2ecf20Sopenharmony_ci uint16_t partition, uint32_t goal, int *err); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci/* directory.c */ 2428c2ecf20Sopenharmony_ciextern struct fileIdentDesc *udf_fileident_read(struct inode *, loff_t *, 2438c2ecf20Sopenharmony_ci struct udf_fileident_bh *, 2448c2ecf20Sopenharmony_ci struct fileIdentDesc *, 2458c2ecf20Sopenharmony_ci struct extent_position *, 2468c2ecf20Sopenharmony_ci struct kernel_lb_addr *, uint32_t *, 2478c2ecf20Sopenharmony_ci sector_t *); 2488c2ecf20Sopenharmony_ciextern struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, 2498c2ecf20Sopenharmony_ci int *offset); 2508c2ecf20Sopenharmony_ciextern struct long_ad *udf_get_filelongad(uint8_t *, int, uint32_t *, int); 2518c2ecf20Sopenharmony_ciextern struct short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int); 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci/* udftime.c */ 2548c2ecf20Sopenharmony_ciextern void udf_disk_stamp_to_time(struct timespec64 *dest, 2558c2ecf20Sopenharmony_ci struct timestamp src); 2568c2ecf20Sopenharmony_ciextern void udf_time_to_disk_stamp(struct timestamp *dest, struct timespec64 src); 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci#endif /* __UDF_DECL_H */ 259