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