1 // this file was borrowed from linux kernel
2 // originally it has name /usr/src/linux/include/linux/iso_fs.h
3 // unfortunately there was no copyright header on it,
4 // so i`m assume it have copyrighted under terms of
5 // GNU GENERAL PUBLIC LICENSE version 2
6 // as a whole linux kernel
7 // copy of this license included into fuseiso
8 // distribution in file COPYING
14 #include <linux/types.h>
16 * The isofs filesystem constants/structures
19 /* This part borrowed from the bsd386 isofs */
20 #define ISODCL(from, to) (to - from + 1)
22 struct iso_volume_descriptor
{
23 char type
[ISODCL(1,1)]; /* 711 */
25 char version
[ISODCL(7,7)];
26 char data
[ISODCL(8,2048)];
29 /* volume descriptor types */
30 #define ISO_VD_PRIMARY 1
31 #define ISO_VD_SUPPLEMENTARY 2
32 #define ISO_VD_END 255
34 #define ISO_STANDARD_ID "CD001"
36 struct iso_primary_descriptor
{
37 char type
[ISODCL ( 1, 1)]; /* 711 */
38 char id
[ISODCL ( 2, 6)];
39 char version
[ISODCL ( 7, 7)]; /* 711 */
40 char unused1
[ISODCL ( 8, 8)];
41 char system_id
[ISODCL ( 9, 40)]; /* achars */
42 char volume_id
[ISODCL ( 41, 72)]; /* dchars */
43 char unused2
[ISODCL ( 73, 80)];
44 char volume_space_size
[ISODCL ( 81, 88)]; /* 733 */
45 char unused3
[ISODCL ( 89, 120)];
46 char volume_set_size
[ISODCL (121, 124)]; /* 723 */
47 char volume_sequence_number
[ISODCL (125, 128)]; /* 723 */
48 char logical_block_size
[ISODCL (129, 132)]; /* 723 */
49 char path_table_size
[ISODCL (133, 140)]; /* 733 */
50 char type_l_path_table
[ISODCL (141, 144)]; /* 731 */
51 char opt_type_l_path_table
[ISODCL (145, 148)]; /* 731 */
52 char type_m_path_table
[ISODCL (149, 152)]; /* 732 */
53 char opt_type_m_path_table
[ISODCL (153, 156)]; /* 732 */
54 char root_directory_record
[ISODCL (157, 190)]; /* 9.1 */
55 char volume_set_id
[ISODCL (191, 318)]; /* dchars */
56 char publisher_id
[ISODCL (319, 446)]; /* achars */
57 char preparer_id
[ISODCL (447, 574)]; /* achars */
58 char application_id
[ISODCL (575, 702)]; /* achars */
59 char copyright_file_id
[ISODCL (703, 739)]; /* 7.5 dchars */
60 char abstract_file_id
[ISODCL (740, 776)]; /* 7.5 dchars */
61 char bibliographic_file_id
[ISODCL (777, 813)]; /* 7.5 dchars */
62 char creation_date
[ISODCL (814, 830)]; /* 8.4.26.1 */
63 char modification_date
[ISODCL (831, 847)]; /* 8.4.26.1 */
64 char expiration_date
[ISODCL (848, 864)]; /* 8.4.26.1 */
65 char effective_date
[ISODCL (865, 881)]; /* 8.4.26.1 */
66 char file_structure_version
[ISODCL (882, 882)]; /* 711 */
67 char unused4
[ISODCL (883, 883)];
68 char application_data
[ISODCL (884, 1395)];
69 char unused5
[ISODCL (1396, 2048)];
72 /* Almost the same as the primary descriptor but two fields are specified */
73 struct iso_supplementary_descriptor
{
74 char type
[ISODCL ( 1, 1)]; /* 711 */
75 char id
[ISODCL ( 2, 6)];
76 char version
[ISODCL ( 7, 7)]; /* 711 */
77 char flags
[ISODCL ( 8, 8)]; /* 853 */
78 char system_id
[ISODCL ( 9, 40)]; /* achars */
79 char volume_id
[ISODCL ( 41, 72)]; /* dchars */
80 char unused2
[ISODCL ( 73, 80)];
81 char volume_space_size
[ISODCL ( 81, 88)]; /* 733 */
82 char escape
[ISODCL ( 89, 120)]; /* 856 */
83 char volume_set_size
[ISODCL (121, 124)]; /* 723 */
84 char volume_sequence_number
[ISODCL (125, 128)]; /* 723 */
85 char logical_block_size
[ISODCL (129, 132)]; /* 723 */
86 char path_table_size
[ISODCL (133, 140)]; /* 733 */
87 char type_l_path_table
[ISODCL (141, 144)]; /* 731 */
88 char opt_type_l_path_table
[ISODCL (145, 148)]; /* 731 */
89 char type_m_path_table
[ISODCL (149, 152)]; /* 732 */
90 char opt_type_m_path_table
[ISODCL (153, 156)]; /* 732 */
91 char root_directory_record
[ISODCL (157, 190)]; /* 9.1 */
92 char volume_set_id
[ISODCL (191, 318)]; /* dchars */
93 char publisher_id
[ISODCL (319, 446)]; /* achars */
94 char preparer_id
[ISODCL (447, 574)]; /* achars */
95 char application_id
[ISODCL (575, 702)]; /* achars */
96 char copyright_file_id
[ISODCL (703, 739)]; /* 7.5 dchars */
97 char abstract_file_id
[ISODCL (740, 776)]; /* 7.5 dchars */
98 char bibliographic_file_id
[ISODCL (777, 813)]; /* 7.5 dchars */
99 char creation_date
[ISODCL (814, 830)]; /* 8.4.26.1 */
100 char modification_date
[ISODCL (831, 847)]; /* 8.4.26.1 */
101 char expiration_date
[ISODCL (848, 864)]; /* 8.4.26.1 */
102 char effective_date
[ISODCL (865, 881)]; /* 8.4.26.1 */
103 char file_structure_version
[ISODCL (882, 882)]; /* 711 */
104 char unused4
[ISODCL (883, 883)];
105 char application_data
[ISODCL (884, 1395)];
106 char unused5
[ISODCL (1396, 2048)];
110 #define HS_STANDARD_ID "CDROM"
112 struct hs_volume_descriptor
{
113 char foo
[ISODCL ( 1, 8)]; /* 733 */
114 char type
[ISODCL ( 9, 9)]; /* 711 */
115 char id
[ISODCL ( 10, 14)];
116 char version
[ISODCL ( 15, 15)]; /* 711 */
117 char data
[ISODCL(16,2048)];
121 struct hs_primary_descriptor
{
122 char foo
[ISODCL ( 1, 8)]; /* 733 */
123 char type
[ISODCL ( 9, 9)]; /* 711 */
124 char id
[ISODCL ( 10, 14)];
125 char version
[ISODCL ( 15, 15)]; /* 711 */
126 char unused1
[ISODCL ( 16, 16)]; /* 711 */
127 char system_id
[ISODCL ( 17, 48)]; /* achars */
128 char volume_id
[ISODCL ( 49, 80)]; /* dchars */
129 char unused2
[ISODCL ( 81, 88)]; /* 733 */
130 char volume_space_size
[ISODCL ( 89, 96)]; /* 733 */
131 char unused3
[ISODCL ( 97, 128)]; /* 733 */
132 char volume_set_size
[ISODCL (129, 132)]; /* 723 */
133 char volume_sequence_number
[ISODCL (133, 136)]; /* 723 */
134 char logical_block_size
[ISODCL (137, 140)]; /* 723 */
135 char path_table_size
[ISODCL (141, 148)]; /* 733 */
136 char type_l_path_table
[ISODCL (149, 152)]; /* 731 */
137 char unused4
[ISODCL (153, 180)]; /* 733 */
138 char root_directory_record
[ISODCL (181, 214)]; /* 9.1 */
141 /* We use this to help us look up the parent inode numbers. */
143 struct iso_path_table
{
144 unsigned char name_len
[2]; /* 721 */
145 char extent
[4]; /* 731 */
146 char parent
[2]; /* 721 */
148 } __attribute__((packed
));
150 /* high sierra is identical to iso, except that the date is only 6 bytes, and
151 there is an extra reserved byte after the flags */
153 struct iso_directory_record
{
154 char length
[ISODCL (1, 1)]; /* 711 */
155 char ext_attr_length
[ISODCL (2, 2)]; /* 711 */
156 char extent
[ISODCL (3, 10)]; /* 733 */
157 char size
[ISODCL (11, 18)]; /* 733 */
158 char date
[ISODCL (19, 25)]; /* 7 by 711 */
159 char flags
[ISODCL (26, 26)];
160 char file_unit_size
[ISODCL (27, 27)]; /* 711 */
161 char interleave
[ISODCL (28, 28)]; /* 711 */
162 char volume_sequence_number
[ISODCL (29, 32)]; /* 723 */
163 unsigned char name_len
[ISODCL (33, 33)]; /* 711 */
165 } __attribute__((packed
));
167 #define ISOFS_BLOCK_BITS 11
168 #define ISOFS_BLOCK_SIZE 2048
170 #define ISOFS_BUFFER_SIZE(INODE) ((INODE)->i_sb->s_blocksize)
171 #define ISOFS_BUFFER_BITS(INODE) ((INODE)->i_sb->s_blocksize_bits)
173 #define ISOFS_SUPER_MAGIC 0x9660
176 /* Number conversion inlines, named after the section in ISO 9660
177 they correspond to. */
179 #include <asm/byteorder.h>
180 #include <asm/unaligned.h>
181 #include <linux/iso_fs_i.h>
182 #include <linux/iso_fs_sb.h>
184 static inline struct isofs_sb_info
*ISOFS_SB(struct super_block
*sb
)
186 return sb
->s_fs_info
;
189 static inline struct iso_inode_info
*ISOFS_I(struct inode
*inode
)
191 return container_of(inode
, struct iso_inode_info
, vfs_inode
);
194 static inline int isonum_711(char *p
)
198 static inline int isonum_712(char *p
)
202 static inline unsigned int isonum_721(char *p
)
204 return le16_to_cpu(get_unaligned((__le16
*)p
));
206 static inline unsigned int isonum_722(char *p
)
208 return be16_to_cpu(get_unaligned((__le16
*)p
));
210 static inline unsigned int isonum_723(char *p
)
212 /* Ignore bigendian datum due to broken mastering programs */
213 return le16_to_cpu(get_unaligned((__le16
*)p
));
215 static inline unsigned int isonum_731(char *p
)
217 return le32_to_cpu(get_unaligned((__le32
*)p
));
219 static inline unsigned int isonum_732(char *p
)
221 return be32_to_cpu(get_unaligned((__le32
*)p
));
223 static inline unsigned int isonum_733(char *p
)
225 /* Ignore bigendian datum due to broken mastering programs */
226 return le32_to_cpu(get_unaligned((__le32
*)p
));
228 extern int iso_date(char *, int);
230 struct inode
; /* To make gcc happy */
232 extern int parse_rock_ridge_inode(struct iso_directory_record
*, struct inode
*);
233 extern int get_rock_ridge_filename(struct iso_directory_record
*, char *, struct inode
*);
234 extern int isofs_name_translate(struct iso_directory_record
*, char *, struct inode
*);
236 int get_joliet_filename(struct iso_directory_record
*, unsigned char *, struct inode
*);
237 int get_acorn_filename(struct iso_directory_record
*, char *, struct inode
*);
239 extern struct dentry
*isofs_lookup(struct inode
*, struct dentry
*, struct nameidata
*);
240 extern struct buffer_head
*isofs_bread(struct inode
*, sector_t
);
241 extern int isofs_get_blocks(struct inode
*, sector_t
, struct buffer_head
**, unsigned long);
243 extern struct inode
*isofs_iget(struct super_block
*sb
,
245 unsigned long offset
);
247 /* Because the inode number is no longer relevant to finding the
248 * underlying meta-data for an inode, we are free to choose a more
249 * convenient 32-bit number as the inode number. The inode numbering
250 * scheme was recommended by Sergey Vlasov and Eric Lammerts. */
251 static inline unsigned long isofs_get_ino(unsigned long block
,
252 unsigned long offset
,
253 unsigned long bufbits
)
255 return (block
<< (bufbits
- 5)) | (offset
>> 5);
258 /* Every directory can have many redundant directory entries scattered
259 * throughout the directory tree. First there is the directory entry
260 * with the name of the directory stored in the parent directory.
261 * Then, there is the "." directory entry stored in the directory
262 * itself. Finally, there are possibly many ".." directory entries
263 * stored in all the subdirectories.
265 * In order for the NFS get_parent() method to work and for the
266 * general consistency of the dcache, we need to make sure the
267 * "i_iget5_block" and "i_iget5_offset" all point to exactly one of
268 * the many redundant entries for each directory. We normalize the
269 * block and offset by always making them point to the "." directory.
271 * Notice that we do not use the entry for the directory with the name
272 * that is located in the parent directory. Even though choosing this
273 * first directory is more natural, it is much easier to find the "."
274 * entry in the NFS get_parent() method because it is implicitly
275 * encoded in the "extent + ext_attr_length" fields of _all_ the
276 * redundant entries for the directory. Thus, it can always be
277 * reached regardless of which directory entry you have in hand.
279 * This works because the "." entry is simply the first directory
280 * record when you start reading the file that holds all the directory
281 * records, and this file starts at "extent + ext_attr_length" blocks.
282 * Because the "." entry is always the first entry listed in the
283 * directories file, the normalized "offset" value is always 0.
285 * You should pass the directory entry in "de". On return, "block"
286 * and "offset" will hold normalized values. Only directories are
287 * affected making it safe to call even for non-directory file
290 isofs_normalize_block_and_offset(struct iso_directory_record
* de
,
291 unsigned long *block
,
292 unsigned long *offset
)
294 /* Only directories are normalized. */
295 if (de
->flags
[0] & 2) {
297 *block
= (unsigned long)isonum_733(de
->extent
)
298 + (unsigned long)isonum_711(de
->ext_attr_length
);
302 extern struct inode_operations isofs_dir_inode_operations
;
303 extern struct file_operations isofs_dir_operations
;
304 extern struct address_space_operations isofs_symlink_aops
;
305 extern struct export_operations isofs_export_ops
;
307 /* The following macros are used to check for memory leaks. */
309 #define free_s leak_check_free_s
310 #define malloc leak_check_malloc
311 #define sb_bread leak_check_bread
312 #define brelse leak_check_brelse
313 extern void * leak_check_malloc(unsigned int size
);
314 extern void leak_check_free_s(void * obj
, int size
);
315 extern struct buffer_head
* leak_check_bread(struct super_block
*sb
, int block
);
316 extern void leak_check_brelse(struct buffer_head
* bh
);
317 #endif /* LEAK_CHECK */
319 #endif /* __KERNEL__ */