blob: 133a456b04259bd84262723ce0d0ba27f85830d2 [file] [log] [blame]
Al Viro94f2f7152005-04-25 18:32:12 -07001#include <linux/fs.h>
2#include <linux/buffer_head.h>
Christoph Hellwiga5694252007-07-17 04:04:28 -07003#include <linux/exportfs.h>
Al Viro94f2f7152005-04-25 18:32:12 -07004#include <linux/iso_fs.h>
5#include <asm/unaligned.h>
6
7enum isofs_file_format {
8 isofs_file_normal = 0,
9 isofs_file_sparse = 1,
10 isofs_file_compressed = 2,
11};
12
13/*
14 * iso fs inode data in memory
15 */
16struct iso_inode_info {
17 unsigned long i_iget5_block;
18 unsigned long i_iget5_offset;
19 unsigned int i_first_extent;
20 unsigned char i_file_format;
21 unsigned char i_format_parm[3];
22 unsigned long i_next_section_block;
23 unsigned long i_next_section_offset;
24 off_t i_section_size;
25 struct inode vfs_inode;
26};
27
28/*
29 * iso9660 super-block data in memory
30 */
31struct isofs_sb_info {
32 unsigned long s_ninodes;
33 unsigned long s_nzones;
34 unsigned long s_firstdatazone;
35 unsigned long s_log_zone_size;
36 unsigned long s_max_size;
37
Al Viro94f2f7152005-04-25 18:32:12 -070038 int s_rock_offset; /* offset of SUSP fields within SU area */
David Howells86a1da62017-07-05 16:25:30 +010039 s32 s_sbsector;
Al Viro94f2f7152005-04-25 18:32:12 -070040 unsigned char s_joliet_level;
Jan Kara5404ac82009-06-17 16:26:27 -070041 unsigned char s_mapping;
David Howells86a1da62017-07-05 16:25:30 +010042 unsigned char s_check;
43 unsigned char s_session;
Jan Kara5404ac82009-06-17 16:26:27 -070044 unsigned int s_high_sierra:1;
45 unsigned int s_rock:2;
46 unsigned int s_utf8:1;
47 unsigned int s_cruft:1; /* Broken disks with high byte of length
48 * containing junk */
49 unsigned int s_nocompress:1;
50 unsigned int s_hide:1;
51 unsigned int s_showassoc:1;
52 unsigned int s_overriderockperm:1;
53 unsigned int s_uid_set:1;
54 unsigned int s_gid_set:1;
Al Viro94f2f7152005-04-25 18:32:12 -070055
Al Viro7328bdd2011-07-26 03:19:52 -040056 umode_t s_fmode;
57 umode_t s_dmode;
Eric W. Biedermanba64e2b2012-02-10 11:35:50 -080058 kgid_t s_gid;
59 kuid_t s_uid;
Al Viro94f2f7152005-04-25 18:32:12 -070060 struct nls_table *s_nls_iocharset; /* Native language support table */
61};
62
Al Viro7328bdd2011-07-26 03:19:52 -040063#define ISOFS_INVALID_MODE ((umode_t) -1)
Jan Kara52b680c2009-06-17 16:26:25 -070064
Al Viro94f2f7152005-04-25 18:32:12 -070065static inline struct isofs_sb_info *ISOFS_SB(struct super_block *sb)
66{
67 return sb->s_fs_info;
68}
69
70static inline struct iso_inode_info *ISOFS_I(struct inode *inode)
71{
72 return container_of(inode, struct iso_inode_info, vfs_inode);
73}
74
75static inline int isonum_711(char *p)
76{
77 return *(u8 *)p;
78}
79static inline int isonum_712(char *p)
80{
81 return *(s8 *)p;
82}
83static inline unsigned int isonum_721(char *p)
84{
Harvey Harrison58d485d2008-04-29 01:03:44 -070085 return get_unaligned_le16(p);
Al Viro94f2f7152005-04-25 18:32:12 -070086}
87static inline unsigned int isonum_722(char *p)
88{
Harvey Harrison58d485d2008-04-29 01:03:44 -070089 return get_unaligned_be16(p);
Al Viro94f2f7152005-04-25 18:32:12 -070090}
91static inline unsigned int isonum_723(char *p)
92{
93 /* Ignore bigendian datum due to broken mastering programs */
Harvey Harrison58d485d2008-04-29 01:03:44 -070094 return get_unaligned_le16(p);
Al Viro94f2f7152005-04-25 18:32:12 -070095}
96static inline unsigned int isonum_731(char *p)
97{
Harvey Harrison58d485d2008-04-29 01:03:44 -070098 return get_unaligned_le32(p);
Al Viro94f2f7152005-04-25 18:32:12 -070099}
100static inline unsigned int isonum_732(char *p)
101{
Harvey Harrison58d485d2008-04-29 01:03:44 -0700102 return get_unaligned_be32(p);
Al Viro94f2f7152005-04-25 18:32:12 -0700103}
104static inline unsigned int isonum_733(char *p)
105{
106 /* Ignore bigendian datum due to broken mastering programs */
Harvey Harrison58d485d2008-04-29 01:03:44 -0700107 return get_unaligned_le32(p);
Al Viro94f2f7152005-04-25 18:32:12 -0700108}
109extern int iso_date(char *, int);
110
111struct inode; /* To make gcc happy */
112
Jan Kara410dd3c2014-08-17 11:49:57 +0200113extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *, int relocated);
Al Viro94f2f7152005-04-25 18:32:12 -0700114extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *);
115extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
116
117int get_joliet_filename(struct iso_directory_record *, unsigned char *, struct inode *);
118int get_acorn_filename(struct iso_directory_record *, char *, struct inode *);
119
Al Viro00cd8dd2012-06-10 17:13:09 -0400120extern struct dentry *isofs_lookup(struct inode *, struct dentry *, unsigned int flags);
Al Viro94f2f7152005-04-25 18:32:12 -0700121extern struct buffer_head *isofs_bread(struct inode *, sector_t);
122extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long);
123
Jan Kara410dd3c2014-08-17 11:49:57 +0200124struct inode *__isofs_iget(struct super_block *sb,
125 unsigned long block,
126 unsigned long offset,
127 int relocated);
128
129static inline struct inode *isofs_iget(struct super_block *sb,
130 unsigned long block,
131 unsigned long offset)
132{
133 return __isofs_iget(sb, block, offset, 0);
134}
135
136static inline struct inode *isofs_iget_reloc(struct super_block *sb,
137 unsigned long block,
138 unsigned long offset)
139{
140 return __isofs_iget(sb, block, offset, 1);
141}
Al Viro94f2f7152005-04-25 18:32:12 -0700142
143/* Because the inode number is no longer relevant to finding the
144 * underlying meta-data for an inode, we are free to choose a more
145 * convenient 32-bit number as the inode number. The inode numbering
146 * scheme was recommended by Sergey Vlasov and Eric Lammerts. */
147static inline unsigned long isofs_get_ino(unsigned long block,
148 unsigned long offset,
149 unsigned long bufbits)
150{
151 return (block << (bufbits - 5)) | (offset >> 5);
152}
153
154/* Every directory can have many redundant directory entries scattered
155 * throughout the directory tree. First there is the directory entry
156 * with the name of the directory stored in the parent directory.
157 * Then, there is the "." directory entry stored in the directory
158 * itself. Finally, there are possibly many ".." directory entries
159 * stored in all the subdirectories.
160 *
161 * In order for the NFS get_parent() method to work and for the
162 * general consistency of the dcache, we need to make sure the
163 * "i_iget5_block" and "i_iget5_offset" all point to exactly one of
164 * the many redundant entries for each directory. We normalize the
165 * block and offset by always making them point to the "." directory.
166 *
167 * Notice that we do not use the entry for the directory with the name
168 * that is located in the parent directory. Even though choosing this
169 * first directory is more natural, it is much easier to find the "."
170 * entry in the NFS get_parent() method because it is implicitly
171 * encoded in the "extent + ext_attr_length" fields of _all_ the
172 * redundant entries for the directory. Thus, it can always be
173 * reached regardless of which directory entry you have in hand.
174 *
175 * This works because the "." entry is simply the first directory
176 * record when you start reading the file that holds all the directory
177 * records, and this file starts at "extent + ext_attr_length" blocks.
178 * Because the "." entry is always the first entry listed in the
179 * directories file, the normalized "offset" value is always 0.
180 *
181 * You should pass the directory entry in "de". On return, "block"
182 * and "offset" will hold normalized values. Only directories are
183 * affected making it safe to call even for non-directory file
184 * types. */
185static inline void
186isofs_normalize_block_and_offset(struct iso_directory_record* de,
187 unsigned long *block,
188 unsigned long *offset)
189{
190 /* Only directories are normalized. */
191 if (de->flags[0] & 2) {
192 *offset = 0;
193 *block = (unsigned long)isonum_733(de->extent)
194 + (unsigned long)isonum_711(de->ext_attr_length);
195 }
196}
197
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -0800198extern const struct inode_operations isofs_dir_inode_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800199extern const struct file_operations isofs_dir_operations;
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700200extern const struct address_space_operations isofs_symlink_aops;
Christoph Hellwig39655162007-10-21 16:42:17 -0700201extern const struct export_operations isofs_export_ops;