xref: /linux/fs/isofs/isofs.h (revision 9f3d3b4b5300124416d87e71280a8fea6a60f6c9)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/fs.h>
3 #include <linux/buffer_head.h>
4 #include <linux/exportfs.h>
5 #include <linux/iso_fs.h>
6 #include <linux/unaligned.h>
7 
8 enum isofs_file_format {
9 	isofs_file_normal = 0,
10 	isofs_file_sparse = 1,
11 	isofs_file_compressed = 2,
12 };
13 
14 /*
15  * iso fs inode data in memory
16  */
17 struct iso_inode_info {
18 	unsigned long i_iget5_block;
19 	unsigned long i_iget5_offset;
20 	unsigned int i_first_extent;
21 	unsigned char i_file_format;
22 	unsigned char i_format_parm[3];
23 	unsigned long i_next_section_block;
24 	unsigned long i_next_section_offset;
25 	off_t i_section_size;
26 	struct inode vfs_inode;
27 };
28 
29 /*
30  * iso9660 super-block data in memory
31  */
32 struct isofs_sb_info {
33 	unsigned long s_ninodes;
34 	unsigned long s_nzones;
35 	unsigned long s_firstdatazone;
36 	unsigned long s_log_zone_size;
37 	unsigned long s_max_size;
38 	/* Session start in filesystem block units. */
39 	sector_t s_session_start;
40 
41 	int           s_rock_offset; /* offset of SUSP fields within SU area */
42 	s32           s_sbsector;
43 	unsigned char s_joliet_level;
44 	unsigned char s_mapping;
45 	unsigned char s_check;
46 	unsigned char s_session;
47 	unsigned int  s_high_sierra:1;
48 	unsigned int  s_rock:2;
49 	unsigned int  s_cruft:1; /* Broken disks with high byte of length
50 				  * containing junk */
51 	unsigned int  s_nocompress:1;
52 	unsigned int  s_hide:1;
53 	unsigned int  s_showassoc:1;
54 	unsigned int  s_overriderockperm:1;
55 	unsigned int  s_uid_set:1;
56 	unsigned int  s_gid_set:1;
57 
58 	umode_t s_fmode;
59 	umode_t s_dmode;
60 	kgid_t s_gid;
61 	kuid_t s_uid;
62 	struct nls_table *s_nls_iocharset; /* Native language support table */
63 };
64 
65 #define ISOFS_INVALID_MODE ((umode_t) -1)
66 
67 static inline struct isofs_sb_info *ISOFS_SB(struct super_block *sb)
68 {
69 	return sb->s_fs_info;
70 }
71 
72 static inline struct iso_inode_info *ISOFS_I(struct inode *inode)
73 {
74 	return container_of(inode, struct iso_inode_info, vfs_inode);
75 }
76 
77 static inline int isonum_711(u8 *p)
78 {
79 	return *p;
80 }
81 static inline int isonum_712(s8 *p)
82 {
83 	return *p;
84 }
85 static inline unsigned int isonum_721(u8 *p)
86 {
87 	return get_unaligned_le16(p);
88 }
89 static inline unsigned int isonum_722(u8 *p)
90 {
91 	return get_unaligned_be16(p);
92 }
93 static inline unsigned int isonum_723(u8 *p)
94 {
95 	/* Ignore bigendian datum due to broken mastering programs */
96 	return get_unaligned_le16(p);
97 }
98 static inline unsigned int isonum_731(u8 *p)
99 {
100 	return get_unaligned_le32(p);
101 }
102 static inline unsigned int isonum_732(u8 *p)
103 {
104 	return get_unaligned_be32(p);
105 }
106 static inline unsigned int isonum_733(u8 *p)
107 {
108 	/* Ignore bigendian datum due to broken mastering programs */
109 	return get_unaligned_le32(p);
110 }
111 #define ISO_DATE_HIGH_SIERRA (1 << 0)
112 #define ISO_DATE_LONG_FORM (1 << 1)
113 struct timespec64 iso_date(u8 *p, int flags);
114 
115 struct inode;		/* To make gcc happy */
116 
117 extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *, int relocated);
118 int get_rock_ridge_filename(struct iso_directory_record *de, char *retname,
119 			    int retnamesize, struct inode *inode);
120 extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
121 bool isofs_dir_record_valid(struct iso_directory_record *de,
122 			    unsigned long offset,
123 			    unsigned long bufsize);
124 
125 /*
126  * The longest name the Joliet converter returns, in bytes.  A directory
127  * record is at most 255 bytes long, which leaves room for 111 UTF-16 units
128  * of name, and no character set needs more than three bytes for one unit.
129  */
130 #define JOLIET_NAME_MAX \
131 	((255 - sizeof(struct iso_directory_record)) / 2 * 3)
132 
133 int get_joliet_filename(struct iso_directory_record *de, unsigned char *outname,
134 			int outsize, struct inode *inode);
135 int get_acorn_filename(struct iso_directory_record *, char *, struct inode *);
136 
137 extern struct dentry *isofs_lookup(struct inode *, struct dentry *, unsigned int flags);
138 extern struct buffer_head *isofs_bread(struct inode *, sector_t);
139 extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long);
140 
141 struct inode *__isofs_iget(struct super_block *sb,
142 			   unsigned long block,
143 			   unsigned long offset,
144 			   int relocated);
145 
146 static inline struct inode *isofs_iget(struct super_block *sb,
147 				       unsigned long block,
148 				       unsigned long offset)
149 {
150 	return __isofs_iget(sb, block, offset, 0);
151 }
152 
153 static inline struct inode *isofs_iget_reloc(struct super_block *sb,
154 					     unsigned long block,
155 					     unsigned long offset)
156 {
157 	return __isofs_iget(sb, block, offset, 1);
158 }
159 
160 /* Because the inode number is no longer relevant to finding the
161  * underlying meta-data for an inode, we are free to choose a more
162  * convenient 32-bit number as the inode number.  The inode numbering
163  * scheme was recommended by Sergey Vlasov and Eric Lammerts. */
164 static inline unsigned long isofs_get_ino(unsigned long block,
165 					  unsigned long offset,
166 					  unsigned long bufbits)
167 {
168 	return (block << (bufbits - 5)) | (offset >> 5);
169 }
170 
171 /* Every directory can have many redundant directory entries scattered
172  * throughout the directory tree.  First there is the directory entry
173  * with the name of the directory stored in the parent directory.
174  * Then, there is the "." directory entry stored in the directory
175  * itself.  Finally, there are possibly many ".." directory entries
176  * stored in all the subdirectories.
177  *
178  * In order for the NFS get_parent() method to work and for the
179  * general consistency of the dcache, we need to make sure the
180  * "i_iget5_block" and "i_iget5_offset" all point to exactly one of
181  * the many redundant entries for each directory.  We normalize the
182  * block and offset by always making them point to the "."  directory.
183  *
184  * Notice that we do not use the entry for the directory with the name
185  * that is located in the parent directory.  Even though choosing this
186  * first directory is more natural, it is much easier to find the "."
187  * entry in the NFS get_parent() method because it is implicitly
188  * encoded in the "extent + ext_attr_length" fields of _all_ the
189  * redundant entries for the directory.  Thus, it can always be
190  * reached regardless of which directory entry you have in hand.
191  *
192  * This works because the "." entry is simply the first directory
193  * record when you start reading the file that holds all the directory
194  * records, and this file starts at "extent + ext_attr_length" blocks.
195  * Because the "." entry is always the first entry listed in the
196  * directories file, the normalized "offset" value is always 0.
197  *
198  * You should pass the directory entry in "de".  On return, "block"
199  * and "offset" will hold normalized values.  Only directories are
200  * affected making it safe to call even for non-directory file
201  * types. */
202 static inline void
203 isofs_normalize_block_and_offset(struct iso_directory_record* de,
204 				 unsigned long *block,
205 				 unsigned long *offset)
206 {
207 	/* Only directories are normalized. */
208 	if (de->flags[0] & 2) {
209 		*offset = 0;
210 		*block = (unsigned long)isonum_733(de->extent)
211 			+ (unsigned long)isonum_711(de->ext_attr_length);
212 	}
213 }
214 
215 struct file_kattr;
216 int isofs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
217 
218 extern const struct inode_operations isofs_dir_inode_operations;
219 extern const struct file_operations isofs_dir_operations;
220 extern const struct address_space_operations isofs_symlink_aops;
221 extern const struct export_operations isofs_export_ops;
222