1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef __UDF_DECL_H
31da177e4SLinus Torvalds #define __UDF_DECL_H
41da177e4SLinus Torvalds
578ace70cSJoe Perches #define pr_fmt(fmt) "UDF-fs: " fmt
678ace70cSJoe Perches
71da177e4SLinus Torvalds #include "ecma_167.h"
81da177e4SLinus Torvalds #include "osta_udf.h"
91da177e4SLinus Torvalds
101da177e4SLinus Torvalds #include <linux/fs.h>
111da177e4SLinus Torvalds #include <linux/types.h>
121da177e4SLinus Torvalds #include <linux/buffer_head.h>
1315aebd28SChristoph Hellwig #include <linux/udf_fs_i.h>
141da177e4SLinus Torvalds
1515aebd28SChristoph Hellwig #include "udf_sb.h"
161da177e4SLinus Torvalds #include "udfend.h"
17d652eefbSmarcin.slusarz@gmail.com #include "udf_i.h"
181da177e4SLinus Torvalds
1915aebd28SChristoph Hellwig #define UDF_DEFAULT_PREALLOC_BLOCKS 8
2015aebd28SChristoph Hellwig
2134116645SLinus Torvalds extern __printf(3, 4) void _udf_err(struct super_block *sb,
2234116645SLinus Torvalds const char *function, const char *fmt, ...);
2378ace70cSJoe Perches #define udf_err(sb, fmt, ...) \
2478ace70cSJoe Perches _udf_err(sb, __func__, fmt, ##__VA_ARGS__)
2515aebd28SChristoph Hellwig
2634116645SLinus Torvalds extern __printf(3, 4) void _udf_warn(struct super_block *sb,
2734116645SLinus Torvalds const char *function, const char *fmt, ...);
28a40ecd7bSJoe Perches #define udf_warn(sb, fmt, ...) \
29a40ecd7bSJoe Perches _udf_warn(sb, __func__, fmt, ##__VA_ARGS__)
307e273e3bSJoe Perches
3178ace70cSJoe Perches #define udf_info(fmt, ...) \
3278ace70cSJoe Perches pr_info("INFO " fmt, ##__VA_ARGS__)
337e273e3bSJoe Perches
3478ace70cSJoe Perches #define udf_debug(fmt, ...) \
358cbd9af9SJan Kara pr_debug("%s:%d:%s: " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
3615aebd28SChristoph Hellwig
371da177e4SLinus Torvalds #define UDF_EXTENT_LENGTH_MASK 0x3FFFFFFF
381da177e4SLinus Torvalds #define UDF_EXTENT_FLAG_MASK 0xC0000000
391da177e4SLinus Torvalds
400c9850f4SJan Kara #define UDF_INVALID_ID ((uint32_t)-1)
410c9850f4SJan Kara
421da177e4SLinus Torvalds #define UDF_NAME_PAD 4
439fba7056SAndrew Gabbasov #define UDF_NAME_LEN 254
449fba7056SAndrew Gabbasov #define UDF_NAME_LEN_CS0 255
451da177e4SLinus Torvalds
udf_file_entry_alloc_offset(struct inode * inode)46d652eefbSmarcin.slusarz@gmail.com static inline size_t udf_file_entry_alloc_offset(struct inode *inode)
47d652eefbSmarcin.slusarz@gmail.com {
48d652eefbSmarcin.slusarz@gmail.com struct udf_inode_info *iinfo = UDF_I(inode);
49d652eefbSmarcin.slusarz@gmail.com if (iinfo->i_use)
50d652eefbSmarcin.slusarz@gmail.com return sizeof(struct unallocSpaceEntry);
51d652eefbSmarcin.slusarz@gmail.com else if (iinfo->i_efe)
52d652eefbSmarcin.slusarz@gmail.com return sizeof(struct extendedFileEntry) + iinfo->i_lenEAttr;
53d652eefbSmarcin.slusarz@gmail.com else
54d652eefbSmarcin.slusarz@gmail.com return sizeof(struct fileEntry) + iinfo->i_lenEAttr;
55d652eefbSmarcin.slusarz@gmail.com }
561da177e4SLinus Torvalds
udf_ext0_offset(struct inode * inode)57d652eefbSmarcin.slusarz@gmail.com static inline size_t udf_ext0_offset(struct inode *inode)
58d652eefbSmarcin.slusarz@gmail.com {
59d652eefbSmarcin.slusarz@gmail.com if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
60d652eefbSmarcin.slusarz@gmail.com return udf_file_entry_alloc_offset(inode);
61d652eefbSmarcin.slusarz@gmail.com else
62d652eefbSmarcin.slusarz@gmail.com return 0;
63d652eefbSmarcin.slusarz@gmail.com }
641da177e4SLinus Torvalds
653f2587bbSMarcin Slusarz /* computes tag checksum */
665ca4e4beSPekka Enberg u8 udf_tag_checksum(const struct tag *t);
673f2587bbSMarcin Slusarz
68b490bdd6SSteve Magnani typedef uint32_t udf_pblk_t;
69b490bdd6SSteve Magnani
701da177e4SLinus Torvalds struct dentry;
711da177e4SLinus Torvalds struct inode;
721da177e4SLinus Torvalds struct task_struct;
731da177e4SLinus Torvalds struct buffer_head;
741da177e4SLinus Torvalds struct super_block;
751da177e4SLinus Torvalds
76221e583aSRasmus Rohde extern const struct export_operations udf_export_ops;
77c5ef1c42SArjan van de Ven extern const struct inode_operations udf_dir_inode_operations;
784b6f5d20SArjan van de Ven extern const struct file_operations udf_dir_operations;
79c5ef1c42SArjan van de Ven extern const struct inode_operations udf_file_inode_operations;
804b6f5d20SArjan van de Ven extern const struct file_operations udf_file_operations;
81ad4d0532SJan Kara extern const struct inode_operations udf_symlink_inode_operations;
82f5e54d6eSChristoph Hellwig extern const struct address_space_operations udf_aops;
83f5e54d6eSChristoph Hellwig extern const struct address_space_operations udf_symlink_aops;
841da177e4SLinus Torvalds
85d16076d9SJan Kara struct udf_fileident_iter {
86d16076d9SJan Kara struct inode *dir; /* Directory we are working with */
87d16076d9SJan Kara loff_t pos; /* Logical position in a dir */
88d16076d9SJan Kara struct buffer_head *bh[2]; /* Buffer containing 'pos' and possibly
89d16076d9SJan Kara * next buffer if entry straddles
90d16076d9SJan Kara * blocks */
91d16076d9SJan Kara struct kernel_lb_addr eloc; /* Start of extent containing 'pos' */
92d16076d9SJan Kara uint32_t elen; /* Length of extent containing 'pos' */
93d16076d9SJan Kara sector_t loffset; /* Block offset of 'pos' within above
94d16076d9SJan Kara * extent */
95d16076d9SJan Kara struct extent_position epos; /* Position after the above extent */
96d16076d9SJan Kara struct fileIdentDesc fi; /* Copied directory entry */
97d16076d9SJan Kara uint8_t *name; /* Pointer to entry name */
980aba4860SJan Kara uint8_t *namebuf; /* Storage for entry name in case
99d16076d9SJan Kara * the name is split between two blocks
100d16076d9SJan Kara */
101d16076d9SJan Kara };
102d16076d9SJan Kara
103cb00ea35SCyrill Gorcunov struct udf_vds_record {
1041da177e4SLinus Torvalds uint32_t block;
1051da177e4SLinus Torvalds uint32_t volDescSeqNum;
1061da177e4SLinus Torvalds };
1071da177e4SLinus Torvalds
108cb00ea35SCyrill Gorcunov struct generic_desc {
1095ca4e4beSPekka Enberg struct tag descTag;
1101da177e4SLinus Torvalds __le32 volDescSeqNum;
1111da177e4SLinus Torvalds };
1121da177e4SLinus Torvalds
113ff116fc8SJan Kara
1141da177e4SLinus Torvalds /* super.c */
115fab3c858SJoe Perches
udf_updated_lvid(struct super_block * sb)116146bca72SJan Kara static inline void udf_updated_lvid(struct super_block *sb)
117146bca72SJan Kara {
118146bca72SJan Kara struct buffer_head *bh = UDF_SB(sb)->s_lvid_bh;
119146bca72SJan Kara
120146bca72SJan Kara BUG_ON(!bh);
121146bca72SJan Kara WARN_ON_ONCE(((struct logicalVolIntegrityDesc *)
122146bca72SJan Kara bh->b_data)->integrityType !=
123146bca72SJan Kara cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN));
124146bca72SJan Kara UDF_SB(sb)->s_lvid_dirty = 1;
125146bca72SJan Kara }
126d664b6afSJan Kara extern u64 lvid_get_unique_id(struct super_block *sb);
1273080a74eSNamjae Jeon struct inode *udf_find_metadata_inode_efe(struct super_block *sb,
1283080a74eSNamjae Jeon u32 meta_file_loc, u32 partition_num);
1291da177e4SLinus Torvalds
1301da177e4SLinus Torvalds /* namei.c */
udf_dir_entry_len(struct fileIdentDesc * cfi)131f2e83347SJan Kara static inline unsigned int udf_dir_entry_len(struct fileIdentDesc *cfi)
132f2e83347SJan Kara {
133f2e83347SJan Kara return ALIGN(sizeof(struct fileIdentDesc) +
134f2e83347SJan Kara le16_to_cpu(cfi->lengthOfImpUse) + cfi->lengthFileIdent,
135f2e83347SJan Kara UDF_NAME_PAD);
136f2e83347SJan Kara }
1371da177e4SLinus Torvalds
1381da177e4SLinus Torvalds /* file.c */
1392f07a88bSJohn Kacur extern long udf_ioctl(struct file *, unsigned int, unsigned long);
140f3a30be7SJan Kara
1411da177e4SLinus Torvalds /* inode.c */
1426174c2ebSJan Kara extern struct inode *__udf_iget(struct super_block *, struct kernel_lb_addr *,
1436174c2ebSJan Kara bool hidden_inode);
udf_iget_special(struct super_block * sb,struct kernel_lb_addr * ino)1446174c2ebSJan Kara static inline struct inode *udf_iget_special(struct super_block *sb,
1456174c2ebSJan Kara struct kernel_lb_addr *ino)
1466174c2ebSJan Kara {
1476174c2ebSJan Kara return __udf_iget(sb, ino, true);
1486174c2ebSJan Kara }
udf_iget(struct super_block * sb,struct kernel_lb_addr * ino)1496174c2ebSJan Kara static inline struct inode *udf_iget(struct super_block *sb,
1506174c2ebSJan Kara struct kernel_lb_addr *ino)
1516174c2ebSJan Kara {
1526174c2ebSJan Kara return __udf_iget(sb, ino, false);
1536174c2ebSJan Kara }
1547e49b6f2SJan Kara extern int udf_expand_file_adinicb(struct inode *);
155b490bdd6SSteve Magnani extern struct buffer_head *udf_bread(struct inode *inode, udf_pblk_t block,
156b490bdd6SSteve Magnani int create, int *err);
1577e49b6f2SJan Kara extern int udf_setsize(struct inode *, loff_t);
1583aac2b62SAl Viro extern void udf_evict_inode(struct inode *);
159a9185b41SChristoph Hellwig extern int udf_write_inode(struct inode *, struct writeback_control *wbc);
160*493447ddSZhao Mengmeng extern int inode_bmap(struct inode *inode, sector_t block,
161*493447ddSZhao Mengmeng struct extent_position *pos, struct kernel_lb_addr *eloc,
162*493447ddSZhao Mengmeng uint32_t *elen, sector_t *offset, int8_t *etype);
1633c212048SJan Kara int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
164b490bdd6SSteve Magnani extern int udf_setup_indirect_aext(struct inode *inode, udf_pblk_t block,
165fcea62baSJan Kara struct extent_position *epos);
166fcea62baSJan Kara extern int __udf_add_aext(struct inode *inode, struct extent_position *epos,
167fcea62baSJan Kara struct kernel_lb_addr *eloc, uint32_t elen, int inc);
1687e49b6f2SJan Kara extern int udf_add_aext(struct inode *, struct extent_position *,
16997e961fdSPekka Enberg struct kernel_lb_addr *, uint32_t, int);
1707e49b6f2SJan Kara extern void udf_write_aext(struct inode *, struct extent_position *,
17197e961fdSPekka Enberg struct kernel_lb_addr *, uint32_t, int);
1726c1e4d06SJan Kara extern int8_t udf_delete_aext(struct inode *, struct extent_position);
1735fc8da4dSZhao Mengmeng extern int udf_next_aext(struct inode *inode, struct extent_position *epos,
1745fc8da4dSZhao Mengmeng struct kernel_lb_addr *eloc, uint32_t *elen,
1755fc8da4dSZhao Mengmeng int8_t *etype, int inc);
176402c8862SZhao Mengmeng extern int udf_current_aext(struct inode *inode, struct extent_position *epos,
177402c8862SZhao Mengmeng struct kernel_lb_addr *eloc, uint32_t *elen,
178402c8862SZhao Mengmeng int8_t *etype, int inc);
179c3367a1bSSteven J. Magnani extern void udf_update_extra_perms(struct inode *inode, umode_t mode);
1801da177e4SLinus Torvalds
1811da177e4SLinus Torvalds /* misc.c */
182cb00ea35SCyrill Gorcunov extern struct genericFormat *udf_add_extendedattr(struct inode *, uint32_t,
183cb00ea35SCyrill Gorcunov uint32_t, uint8_t);
184cb00ea35SCyrill Gorcunov extern struct genericFormat *udf_get_extendedattr(struct inode *, uint32_t,
185cb00ea35SCyrill Gorcunov uint8_t);
186cb00ea35SCyrill Gorcunov extern struct buffer_head *udf_read_tagged(struct super_block *, uint32_t,
187cb00ea35SCyrill Gorcunov uint32_t, uint16_t *);
188cb00ea35SCyrill Gorcunov extern struct buffer_head *udf_read_ptagged(struct super_block *,
18997e961fdSPekka Enberg struct kernel_lb_addr *, uint32_t,
190cb00ea35SCyrill Gorcunov uint16_t *);
1911da177e4SLinus Torvalds extern void udf_update_tag(char *, int);
1921da177e4SLinus Torvalds extern void udf_new_tag(char *, uint16_t, uint16_t, uint16_t, uint32_t, int);
1931da177e4SLinus Torvalds
1941da177e4SLinus Torvalds /* lowlevel.c */
1951da177e4SLinus Torvalds extern unsigned int udf_get_last_session(struct super_block *);
196bd904f3cSJan Kara udf_pblk_t udf_get_last_block(struct super_block *);
1971da177e4SLinus Torvalds
1981da177e4SLinus Torvalds /* partition.c */
199cb00ea35SCyrill Gorcunov extern uint32_t udf_get_pblock(struct super_block *, uint32_t, uint16_t,
200cb00ea35SCyrill Gorcunov uint32_t);
201cb00ea35SCyrill Gorcunov extern uint32_t udf_get_pblock_virt15(struct super_block *, uint32_t, uint16_t,
202cb00ea35SCyrill Gorcunov uint32_t);
203cb00ea35SCyrill Gorcunov extern uint32_t udf_get_pblock_virt20(struct super_block *, uint32_t, uint16_t,
204cb00ea35SCyrill Gorcunov uint32_t);
205cb00ea35SCyrill Gorcunov extern uint32_t udf_get_pblock_spar15(struct super_block *, uint32_t, uint16_t,
206cb00ea35SCyrill Gorcunov uint32_t);
207bfb257a5SJan Kara extern uint32_t udf_get_pblock_meta25(struct super_block *, uint32_t, uint16_t,
208bfb257a5SJan Kara uint32_t);
2091da177e4SLinus Torvalds extern int udf_relocate_blocks(struct super_block *, long, long *);
2101da177e4SLinus Torvalds
21197e961fdSPekka Enberg static inline uint32_t
udf_get_lb_pblock(struct super_block * sb,struct kernel_lb_addr * loc,uint32_t offset)21297e961fdSPekka Enberg udf_get_lb_pblock(struct super_block *sb, struct kernel_lb_addr *loc,
21397e961fdSPekka Enberg uint32_t offset)
21497e961fdSPekka Enberg {
21597e961fdSPekka Enberg return udf_get_pblock(sb, loc->logicalBlockNum,
21697e961fdSPekka Enberg loc->partitionReferenceNum, offset);
21797e961fdSPekka Enberg }
21897e961fdSPekka Enberg
2191da177e4SLinus Torvalds /* unicode.c */
2209293fcfbSAndrew Gabbasov extern int udf_get_filename(struct super_block *, const uint8_t *, int,
2219293fcfbSAndrew Gabbasov uint8_t *, int);
222525e2c56SAndrew Gabbasov extern int udf_put_filename(struct super_block *, const uint8_t *, int,
223525e2c56SAndrew Gabbasov uint8_t *, int);
224e966fc8dSJan Kara extern int udf_dstrCS0toChar(struct super_block *, uint8_t *, int,
225e966fc8dSJan Kara const uint8_t *, int);
2261da177e4SLinus Torvalds
2271da177e4SLinus Torvalds /* ialloc.c */
2281da177e4SLinus Torvalds extern void udf_free_inode(struct inode *);
2290b93a92bSAl Viro extern struct inode *udf_new_inode(struct inode *, umode_t);
2301da177e4SLinus Torvalds
2311da177e4SLinus Torvalds /* truncate.c */
23274584ae5SJan Kara extern void udf_truncate_tail_extent(struct inode *);
2331da177e4SLinus Torvalds extern void udf_discard_prealloc(struct inode *);
2342b42be5eSJan Kara extern int udf_truncate_extents(struct inode *);
2351da177e4SLinus Torvalds
2361da177e4SLinus Torvalds /* balloc.c */
237cb00ea35SCyrill Gorcunov extern void udf_free_blocks(struct super_block *, struct inode *,
23897e961fdSPekka Enberg struct kernel_lb_addr *, uint32_t, uint32_t);
239cb00ea35SCyrill Gorcunov extern int udf_prealloc_blocks(struct super_block *, struct inode *, uint16_t,
240cb00ea35SCyrill Gorcunov uint32_t, uint32_t);
241b490bdd6SSteve Magnani extern udf_pblk_t udf_new_block(struct super_block *sb, struct inode *inode,
242b490bdd6SSteve Magnani uint16_t partition, uint32_t goal, int *err);
2431da177e4SLinus Torvalds
2441da177e4SLinus Torvalds /* directory.c */
245d16076d9SJan Kara int udf_fiiter_init(struct udf_fileident_iter *iter, struct inode *dir,
246d16076d9SJan Kara loff_t pos);
247d16076d9SJan Kara int udf_fiiter_advance(struct udf_fileident_iter *iter);
248d16076d9SJan Kara void udf_fiiter_release(struct udf_fileident_iter *iter);
249d16076d9SJan Kara void udf_fiiter_write_fi(struct udf_fileident_iter *iter, uint8_t *impuse);
250f2844803SJan Kara void udf_fiiter_update_elen(struct udf_fileident_iter *iter, uint32_t new_elen);
251f2844803SJan Kara int udf_fiiter_append_blk(struct udf_fileident_iter *iter);
2525ca4e4beSPekka Enberg extern struct long_ad *udf_get_filelongad(uint8_t *, int, uint32_t *, int);
2535ca4e4beSPekka Enberg extern struct short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
2541da177e4SLinus Torvalds
2551da177e4SLinus Torvalds /* udftime.c */
256c3b9cecdSArnd Bergmann extern void udf_disk_stamp_to_time(struct timespec64 *dest,
2575ca4e4beSPekka Enberg struct timestamp src);
258c3b9cecdSArnd Bergmann extern void udf_time_to_disk_stamp(struct timestamp *dest, struct timespec64 src);
2591da177e4SLinus Torvalds
2601da177e4SLinus Torvalds #endif /* __UDF_DECL_H */
261