blob: 055ec6c586f7fd5199f24ed3f703bd7a99a83228 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Al Viro94f2f7152005-04-25 18:32:12 -07002#include <linux/fs.h>
3#include <linux/buffer_head.h>
Christoph Hellwiga5694252007-07-17 04:04:28 -07004#include <linux/exportfs.h>
Al Viro94f2f7152005-04-25 18:32:12 -07005#include <linux/iso_fs.h>
6#include <asm/unaligned.h>
7
8enum 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 */
17struct 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 */
32struct 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
Al Viro94f2f7152005-04-25 18:32:12 -070039 int s_rock_offset; /* offset of SUSP fields within SU area */
David Howells86a1da62017-07-05 16:25:30 +010040 s32 s_sbsector;
Al Viro94f2f7152005-04-25 18:32:12 -070041 unsigned char s_joliet_level;
Jan Kara5404ac82009-06-17 16:26:27 -070042 unsigned char s_mapping;
David Howells86a1da62017-07-05 16:25:30 +010043 unsigned char s_check;
44 unsigned char s_session;
Jan Kara5404ac82009-06-17 16:26:27 -070045 unsigned int s_high_sierra:1;
46 unsigned int s_rock:2;
47 unsigned int s_utf8:1;
48 unsigned int s_cruft:1; /* Broken disks with high byte of length
49 * containing junk */
50 unsigned int s_nocompress:1;
51 unsigned int s_hide:1;
52 unsigned int s_showassoc:1;
53 unsigned int s_overriderockperm:1;
54 unsigned int s_uid_set:1;
55 unsigned int s_gid_set:1;
Al Viro94f2f7152005-04-25 18:32:12 -070056
Al Viro7328bdd2011-07-26 03:19:52 -040057 umode_t s_fmode;
58 umode_t s_dmode;
Eric W. Biedermanba64e2b2012-02-10 11:35:50 -080059 kgid_t s_gid;
60 kuid_t s_uid;
Al Viro94f2f7152005-04-25 18:32:12 -070061 struct nls_table *s_nls_iocharset; /* Native language support table */
62};
63
Al Viro7328bdd2011-07-26 03:19:52 -040064#define ISOFS_INVALID_MODE ((umode_t) -1)
Jan Kara52b680c2009-06-17 16:26:25 -070065
Al Viro94f2f7152005-04-25 18:32:12 -070066static inline struct isofs_sb_info *ISOFS_SB(struct super_block *sb)
67{
68 return sb->s_fs_info;
69}
70
71static inline struct iso_inode_info *ISOFS_I(struct inode *inode)
72{
73 return container_of(inode, struct iso_inode_info, vfs_inode);
74}
75
Arnd Bergmanncb917752017-10-19 16:47:49 +020076static inline int isonum_711(u8 *p)
Al Viro94f2f7152005-04-25 18:32:12 -070077{
Arnd Bergmanncb917752017-10-19 16:47:49 +020078 return *p;
Al Viro94f2f7152005-04-25 18:32:12 -070079}
Arnd Bergmanncb917752017-10-19 16:47:49 +020080static inline int isonum_712(s8 *p)
Al Viro94f2f7152005-04-25 18:32:12 -070081{
Arnd Bergmanncb917752017-10-19 16:47:49 +020082 return *p;
Al Viro94f2f7152005-04-25 18:32:12 -070083}
Arnd Bergmanncb917752017-10-19 16:47:49 +020084static inline unsigned int isonum_721(u8 *p)
Al Viro94f2f7152005-04-25 18:32:12 -070085{
Harvey Harrison58d485d2008-04-29 01:03:44 -070086 return get_unaligned_le16(p);
Al Viro94f2f7152005-04-25 18:32:12 -070087}
Arnd Bergmanncb917752017-10-19 16:47:49 +020088static inline unsigned int isonum_722(u8 *p)
Al Viro94f2f7152005-04-25 18:32:12 -070089{
Harvey Harrison58d485d2008-04-29 01:03:44 -070090 return get_unaligned_be16(p);
Al Viro94f2f7152005-04-25 18:32:12 -070091}
Arnd Bergmanncb917752017-10-19 16:47:49 +020092static inline unsigned int isonum_723(u8 *p)
Al Viro94f2f7152005-04-25 18:32:12 -070093{
94 /* Ignore bigendian datum due to broken mastering programs */
Harvey Harrison58d485d2008-04-29 01:03:44 -070095 return get_unaligned_le16(p);
Al Viro94f2f7152005-04-25 18:32:12 -070096}
Arnd Bergmanncb917752017-10-19 16:47:49 +020097static inline unsigned int isonum_731(u8 *p)
Al Viro94f2f7152005-04-25 18:32:12 -070098{
Harvey Harrison58d485d2008-04-29 01:03:44 -070099 return get_unaligned_le32(p);
Al Viro94f2f7152005-04-25 18:32:12 -0700100}
Arnd Bergmanncb917752017-10-19 16:47:49 +0200101static inline unsigned int isonum_732(u8 *p)
Al Viro94f2f7152005-04-25 18:32:12 -0700102{
Harvey Harrison58d485d2008-04-29 01:03:44 -0700103 return get_unaligned_be32(p);
Al Viro94f2f7152005-04-25 18:32:12 -0700104}
Arnd Bergmanncb917752017-10-19 16:47:49 +0200105static inline unsigned int isonum_733(u8 *p)
Al Viro94f2f7152005-04-25 18:32:12 -0700106{
107 /* Ignore bigendian datum due to broken mastering programs */
Harvey Harrison58d485d2008-04-29 01:03:44 -0700108 return get_unaligned_le32(p);
Al Viro94f2f7152005-04-25 18:32:12 -0700109}
Arnd Bergmann34be4db2017-10-19 16:47:48 +0200110extern int iso_date(u8 *, int);
Al Viro94f2f7152005-04-25 18:32:12 -0700111
112struct inode; /* To make gcc happy */
113
Jan Kara410dd3c2014-08-17 11:49:57 +0200114extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *, int relocated);
Al Viro94f2f7152005-04-25 18:32:12 -0700115extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *);
116extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
117
118int get_joliet_filename(struct iso_directory_record *, unsigned char *, struct inode *);
119int get_acorn_filename(struct iso_directory_record *, char *, struct inode *);
120
Al Viro00cd8dd2012-06-10 17:13:09 -0400121extern struct dentry *isofs_lookup(struct inode *, struct dentry *, unsigned int flags);
Al Viro94f2f7152005-04-25 18:32:12 -0700122extern struct buffer_head *isofs_bread(struct inode *, sector_t);
123extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long);
124
Jan Kara410dd3c2014-08-17 11:49:57 +0200125struct inode *__isofs_iget(struct super_block *sb,
126 unsigned long block,
127 unsigned long offset,
128 int relocated);
129
130static inline struct inode *isofs_iget(struct super_block *sb,
131 unsigned long block,
132 unsigned long offset)
133{
134 return __isofs_iget(sb, block, offset, 0);
135}
136
137static inline struct inode *isofs_iget_reloc(struct super_block *sb,
138 unsigned long block,
139 unsigned long offset)
140{
141 return __isofs_iget(sb, block, offset, 1);
142}
Al Viro94f2f7152005-04-25 18:32:12 -0700143
144/* Because the inode number is no longer relevant to finding the
145 * underlying meta-data for an inode, we are free to choose a more
146 * convenient 32-bit number as the inode number. The inode numbering
147 * scheme was recommended by Sergey Vlasov and Eric Lammerts. */
148static inline unsigned long isofs_get_ino(unsigned long block,
149 unsigned long offset,
150 unsigned long bufbits)
151{
152 return (block << (bufbits - 5)) | (offset >> 5);
153}
154
155/* Every directory can have many redundant directory entries scattered
156 * throughout the directory tree. First there is the directory entry
157 * with the name of the directory stored in the parent directory.
158 * Then, there is the "." directory entry stored in the directory
159 * itself. Finally, there are possibly many ".." directory entries
160 * stored in all the subdirectories.
161 *
162 * In order for the NFS get_parent() method to work and for the
163 * general consistency of the dcache, we need to make sure the
164 * "i_iget5_block" and "i_iget5_offset" all point to exactly one of
165 * the many redundant entries for each directory. We normalize the
166 * block and offset by always making them point to the "." directory.
167 *
168 * Notice that we do not use the entry for the directory with the name
169 * that is located in the parent directory. Even though choosing this
170 * first directory is more natural, it is much easier to find the "."
171 * entry in the NFS get_parent() method because it is implicitly
172 * encoded in the "extent + ext_attr_length" fields of _all_ the
173 * redundant entries for the directory. Thus, it can always be
174 * reached regardless of which directory entry you have in hand.
175 *
176 * This works because the "." entry is simply the first directory
177 * record when you start reading the file that holds all the directory
178 * records, and this file starts at "extent + ext_attr_length" blocks.
179 * Because the "." entry is always the first entry listed in the
180 * directories file, the normalized "offset" value is always 0.
181 *
182 * You should pass the directory entry in "de". On return, "block"
183 * and "offset" will hold normalized values. Only directories are
184 * affected making it safe to call even for non-directory file
185 * types. */
186static inline void
187isofs_normalize_block_and_offset(struct iso_directory_record* de,
188 unsigned long *block,
189 unsigned long *offset)
190{
191 /* Only directories are normalized. */
192 if (de->flags[0] & 2) {
193 *offset = 0;
194 *block = (unsigned long)isonum_733(de->extent)
195 + (unsigned long)isonum_711(de->ext_attr_length);
196 }
197}
198
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -0800199extern const struct inode_operations isofs_dir_inode_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800200extern const struct file_operations isofs_dir_operations;
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700201extern const struct address_space_operations isofs_symlink_aops;
Christoph Hellwig39655162007-10-21 16:42:17 -0700202extern const struct export_operations isofs_export_ops;