Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 1 | #include <linux/fs.h> |
| 2 | #include <linux/buffer_head.h> |
Christoph Hellwig | a569425 | 2007-07-17 04:04:28 -0700 | [diff] [blame] | 3 | #include <linux/exportfs.h> |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 4 | #include <linux/iso_fs.h> |
| 5 | #include <asm/unaligned.h> |
| 6 | |
| 7 | enum 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 | */ |
| 16 | struct 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 | */ |
| 31 | struct 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 Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 38 | int s_rock_offset; /* offset of SUSP fields within SU area */ |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 39 | unsigned char s_joliet_level; |
Jan Kara | 5404ac8 | 2009-06-17 16:26:27 -0700 | [diff] [blame] | 40 | unsigned char s_mapping; |
| 41 | unsigned int s_high_sierra:1; |
| 42 | unsigned int s_rock:2; |
| 43 | unsigned int s_utf8:1; |
| 44 | unsigned int s_cruft:1; /* Broken disks with high byte of length |
| 45 | * containing junk */ |
| 46 | unsigned int s_nocompress:1; |
| 47 | unsigned int s_hide:1; |
| 48 | unsigned int s_showassoc:1; |
| 49 | unsigned int s_overriderockperm:1; |
| 50 | unsigned int s_uid_set:1; |
| 51 | unsigned int s_gid_set:1; |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 52 | |
Jan Kara | 9b7880e | 2008-02-08 04:21:09 -0800 | [diff] [blame] | 53 | mode_t s_fmode; |
| 54 | mode_t s_dmode; |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 55 | gid_t s_gid; |
| 56 | uid_t s_uid; |
| 57 | struct nls_table *s_nls_iocharset; /* Native language support table */ |
Arnd Bergmann | 4f819a7 | 2010-09-12 19:05:56 +0200 | [diff] [blame] | 58 | struct mutex s_mutex; /* replaces BKL, please remove if possible */ |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Jan Kara | 52b680c | 2009-06-17 16:26:25 -0700 | [diff] [blame] | 61 | #define ISOFS_INVALID_MODE ((mode_t) -1) |
| 62 | |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 63 | static inline struct isofs_sb_info *ISOFS_SB(struct super_block *sb) |
| 64 | { |
| 65 | return sb->s_fs_info; |
| 66 | } |
| 67 | |
| 68 | static inline struct iso_inode_info *ISOFS_I(struct inode *inode) |
| 69 | { |
| 70 | return container_of(inode, struct iso_inode_info, vfs_inode); |
| 71 | } |
| 72 | |
| 73 | static inline int isonum_711(char *p) |
| 74 | { |
| 75 | return *(u8 *)p; |
| 76 | } |
| 77 | static inline int isonum_712(char *p) |
| 78 | { |
| 79 | return *(s8 *)p; |
| 80 | } |
| 81 | static inline unsigned int isonum_721(char *p) |
| 82 | { |
Harvey Harrison | 58d485d | 2008-04-29 01:03:44 -0700 | [diff] [blame] | 83 | return get_unaligned_le16(p); |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 84 | } |
| 85 | static inline unsigned int isonum_722(char *p) |
| 86 | { |
Harvey Harrison | 58d485d | 2008-04-29 01:03:44 -0700 | [diff] [blame] | 87 | return get_unaligned_be16(p); |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 88 | } |
| 89 | static inline unsigned int isonum_723(char *p) |
| 90 | { |
| 91 | /* Ignore bigendian datum due to broken mastering programs */ |
Harvey Harrison | 58d485d | 2008-04-29 01:03:44 -0700 | [diff] [blame] | 92 | return get_unaligned_le16(p); |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 93 | } |
| 94 | static inline unsigned int isonum_731(char *p) |
| 95 | { |
Harvey Harrison | 58d485d | 2008-04-29 01:03:44 -0700 | [diff] [blame] | 96 | return get_unaligned_le32(p); |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 97 | } |
| 98 | static inline unsigned int isonum_732(char *p) |
| 99 | { |
Harvey Harrison | 58d485d | 2008-04-29 01:03:44 -0700 | [diff] [blame] | 100 | return get_unaligned_be32(p); |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 101 | } |
| 102 | static inline unsigned int isonum_733(char *p) |
| 103 | { |
| 104 | /* Ignore bigendian datum due to broken mastering programs */ |
Harvey Harrison | 58d485d | 2008-04-29 01:03:44 -0700 | [diff] [blame] | 105 | return get_unaligned_le32(p); |
Al Viro | 94f2f715 | 2005-04-25 18:32:12 -0700 | [diff] [blame] | 106 | } |
| 107 | extern int iso_date(char *, int); |
| 108 | |
| 109 | struct inode; /* To make gcc happy */ |
| 110 | |
| 111 | extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *); |
| 112 | extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *); |
| 113 | extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *); |
| 114 | |
| 115 | int get_joliet_filename(struct iso_directory_record *, unsigned char *, struct inode *); |
| 116 | int get_acorn_filename(struct iso_directory_record *, char *, struct inode *); |
| 117 | |
| 118 | extern struct dentry *isofs_lookup(struct inode *, struct dentry *, struct nameidata *); |
| 119 | extern struct buffer_head *isofs_bread(struct inode *, sector_t); |
| 120 | extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long); |
| 121 | |
| 122 | extern struct inode *isofs_iget(struct super_block *sb, |
| 123 | unsigned long block, |
| 124 | unsigned long offset); |
| 125 | |
| 126 | /* Because the inode number is no longer relevant to finding the |
| 127 | * underlying meta-data for an inode, we are free to choose a more |
| 128 | * convenient 32-bit number as the inode number. The inode numbering |
| 129 | * scheme was recommended by Sergey Vlasov and Eric Lammerts. */ |
| 130 | static inline unsigned long isofs_get_ino(unsigned long block, |
| 131 | unsigned long offset, |
| 132 | unsigned long bufbits) |
| 133 | { |
| 134 | return (block << (bufbits - 5)) | (offset >> 5); |
| 135 | } |
| 136 | |
| 137 | /* Every directory can have many redundant directory entries scattered |
| 138 | * throughout the directory tree. First there is the directory entry |
| 139 | * with the name of the directory stored in the parent directory. |
| 140 | * Then, there is the "." directory entry stored in the directory |
| 141 | * itself. Finally, there are possibly many ".." directory entries |
| 142 | * stored in all the subdirectories. |
| 143 | * |
| 144 | * In order for the NFS get_parent() method to work and for the |
| 145 | * general consistency of the dcache, we need to make sure the |
| 146 | * "i_iget5_block" and "i_iget5_offset" all point to exactly one of |
| 147 | * the many redundant entries for each directory. We normalize the |
| 148 | * block and offset by always making them point to the "." directory. |
| 149 | * |
| 150 | * Notice that we do not use the entry for the directory with the name |
| 151 | * that is located in the parent directory. Even though choosing this |
| 152 | * first directory is more natural, it is much easier to find the "." |
| 153 | * entry in the NFS get_parent() method because it is implicitly |
| 154 | * encoded in the "extent + ext_attr_length" fields of _all_ the |
| 155 | * redundant entries for the directory. Thus, it can always be |
| 156 | * reached regardless of which directory entry you have in hand. |
| 157 | * |
| 158 | * This works because the "." entry is simply the first directory |
| 159 | * record when you start reading the file that holds all the directory |
| 160 | * records, and this file starts at "extent + ext_attr_length" blocks. |
| 161 | * Because the "." entry is always the first entry listed in the |
| 162 | * directories file, the normalized "offset" value is always 0. |
| 163 | * |
| 164 | * You should pass the directory entry in "de". On return, "block" |
| 165 | * and "offset" will hold normalized values. Only directories are |
| 166 | * affected making it safe to call even for non-directory file |
| 167 | * types. */ |
| 168 | static inline void |
| 169 | isofs_normalize_block_and_offset(struct iso_directory_record* de, |
| 170 | unsigned long *block, |
| 171 | unsigned long *offset) |
| 172 | { |
| 173 | /* Only directories are normalized. */ |
| 174 | if (de->flags[0] & 2) { |
| 175 | *offset = 0; |
| 176 | *block = (unsigned long)isonum_733(de->extent) |
| 177 | + (unsigned long)isonum_711(de->ext_attr_length); |
| 178 | } |
| 179 | } |
| 180 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 181 | extern const struct inode_operations isofs_dir_inode_operations; |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 182 | extern const struct file_operations isofs_dir_operations; |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 183 | extern const struct address_space_operations isofs_symlink_aops; |
Christoph Hellwig | 3965516 | 2007-10-21 16:42:17 -0700 | [diff] [blame] | 184 | extern const struct export_operations isofs_export_ops; |