xref: /openbmc/linux/fs/isofs/isofs.h (revision 28ce50f8)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
294f2f715SAl Viro #include <linux/fs.h>
394f2f715SAl Viro #include <linux/buffer_head.h>
4a5694255SChristoph Hellwig #include <linux/exportfs.h>
594f2f715SAl Viro #include <linux/iso_fs.h>
694f2f715SAl Viro #include <asm/unaligned.h>
794f2f715SAl Viro 
894f2f715SAl Viro enum isofs_file_format {
994f2f715SAl Viro 	isofs_file_normal = 0,
1094f2f715SAl Viro 	isofs_file_sparse = 1,
1194f2f715SAl Viro 	isofs_file_compressed = 2,
1294f2f715SAl Viro };
1394f2f715SAl Viro 
1494f2f715SAl Viro /*
1594f2f715SAl Viro  * iso fs inode data in memory
1694f2f715SAl Viro  */
1794f2f715SAl Viro struct iso_inode_info {
1894f2f715SAl Viro 	unsigned long i_iget5_block;
1994f2f715SAl Viro 	unsigned long i_iget5_offset;
2094f2f715SAl Viro 	unsigned int i_first_extent;
2194f2f715SAl Viro 	unsigned char i_file_format;
2294f2f715SAl Viro 	unsigned char i_format_parm[3];
2394f2f715SAl Viro 	unsigned long i_next_section_block;
2494f2f715SAl Viro 	unsigned long i_next_section_offset;
2594f2f715SAl Viro 	off_t i_section_size;
2694f2f715SAl Viro 	struct inode vfs_inode;
2794f2f715SAl Viro };
2894f2f715SAl Viro 
2994f2f715SAl Viro /*
3094f2f715SAl Viro  * iso9660 super-block data in memory
3194f2f715SAl Viro  */
3294f2f715SAl Viro struct isofs_sb_info {
3394f2f715SAl Viro 	unsigned long s_ninodes;
3494f2f715SAl Viro 	unsigned long s_nzones;
3594f2f715SAl Viro 	unsigned long s_firstdatazone;
3694f2f715SAl Viro 	unsigned long s_log_zone_size;
3794f2f715SAl Viro 	unsigned long s_max_size;
3894f2f715SAl Viro 
3994f2f715SAl Viro 	int           s_rock_offset; /* offset of SUSP fields within SU area */
4086a1da6dSDavid Howells 	s32           s_sbsector;
4194f2f715SAl Viro 	unsigned char s_joliet_level;
425404ac8eSJan Kara 	unsigned char s_mapping;
4386a1da6dSDavid Howells 	unsigned char s_check;
4486a1da6dSDavid Howells 	unsigned char s_session;
455404ac8eSJan Kara 	unsigned int  s_high_sierra:1;
465404ac8eSJan Kara 	unsigned int  s_rock:2;
475404ac8eSJan Kara 	unsigned int  s_cruft:1; /* Broken disks with high byte of length
485404ac8eSJan Kara 				  * containing junk */
495404ac8eSJan Kara 	unsigned int  s_nocompress:1;
505404ac8eSJan Kara 	unsigned int  s_hide:1;
515404ac8eSJan Kara 	unsigned int  s_showassoc:1;
525404ac8eSJan Kara 	unsigned int  s_overriderockperm:1;
535404ac8eSJan Kara 	unsigned int  s_uid_set:1;
545404ac8eSJan Kara 	unsigned int  s_gid_set:1;
5594f2f715SAl Viro 
567328bdd6SAl Viro 	umode_t s_fmode;
577328bdd6SAl Viro 	umode_t s_dmode;
58ba64e2b9SEric W. Biederman 	kgid_t s_gid;
59ba64e2b9SEric W. Biederman 	kuid_t s_uid;
6094f2f715SAl Viro 	struct nls_table *s_nls_iocharset; /* Native language support table */
6194f2f715SAl Viro };
6294f2f715SAl Viro 
637328bdd6SAl Viro #define ISOFS_INVALID_MODE ((umode_t) -1)
6452b680c8SJan Kara 
ISOFS_SB(struct super_block * sb)6594f2f715SAl Viro static inline struct isofs_sb_info *ISOFS_SB(struct super_block *sb)
6694f2f715SAl Viro {
6794f2f715SAl Viro 	return sb->s_fs_info;
6894f2f715SAl Viro }
6994f2f715SAl Viro 
ISOFS_I(struct inode * inode)7094f2f715SAl Viro static inline struct iso_inode_info *ISOFS_I(struct inode *inode)
7194f2f715SAl Viro {
7294f2f715SAl Viro 	return container_of(inode, struct iso_inode_info, vfs_inode);
7394f2f715SAl Viro }
7494f2f715SAl Viro 
isonum_711(u8 * p)75cb917757SArnd Bergmann static inline int isonum_711(u8 *p)
7694f2f715SAl Viro {
77cb917757SArnd Bergmann 	return *p;
7894f2f715SAl Viro }
isonum_712(s8 * p)79cb917757SArnd Bergmann static inline int isonum_712(s8 *p)
8094f2f715SAl Viro {
81cb917757SArnd Bergmann 	return *p;
8294f2f715SAl Viro }
isonum_721(u8 * p)83cb917757SArnd Bergmann static inline unsigned int isonum_721(u8 *p)
8494f2f715SAl Viro {
8558d485d4SHarvey Harrison 	return get_unaligned_le16(p);
8694f2f715SAl Viro }
isonum_722(u8 * p)87cb917757SArnd Bergmann static inline unsigned int isonum_722(u8 *p)
8894f2f715SAl Viro {
8958d485d4SHarvey Harrison 	return get_unaligned_be16(p);
9094f2f715SAl Viro }
isonum_723(u8 * p)91cb917757SArnd Bergmann static inline unsigned int isonum_723(u8 *p)
9294f2f715SAl Viro {
9394f2f715SAl Viro 	/* Ignore bigendian datum due to broken mastering programs */
9458d485d4SHarvey Harrison 	return get_unaligned_le16(p);
9594f2f715SAl Viro }
isonum_731(u8 * p)96cb917757SArnd Bergmann static inline unsigned int isonum_731(u8 *p)
9794f2f715SAl Viro {
9858d485d4SHarvey Harrison 	return get_unaligned_le32(p);
9994f2f715SAl Viro }
isonum_732(u8 * p)100cb917757SArnd Bergmann static inline unsigned int isonum_732(u8 *p)
10194f2f715SAl Viro {
10258d485d4SHarvey Harrison 	return get_unaligned_be32(p);
10394f2f715SAl Viro }
isonum_733(u8 * p)104cb917757SArnd Bergmann static inline unsigned int isonum_733(u8 *p)
10594f2f715SAl Viro {
10694f2f715SAl Viro 	/* Ignore bigendian datum due to broken mastering programs */
10758d485d4SHarvey Harrison 	return get_unaligned_le32(p);
10894f2f715SAl Viro }
10934be4dbfSArnd Bergmann extern int iso_date(u8 *, int);
11094f2f715SAl Viro 
11194f2f715SAl Viro struct inode;		/* To make gcc happy */
11294f2f715SAl Viro 
113410dd3cfSJan Kara extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *, int relocated);
11494f2f715SAl Viro extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *);
11594f2f715SAl Viro extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
11694f2f715SAl Viro 
11794f2f715SAl Viro int get_joliet_filename(struct iso_directory_record *, unsigned char *, struct inode *);
11894f2f715SAl Viro int get_acorn_filename(struct iso_directory_record *, char *, struct inode *);
11994f2f715SAl Viro 
12000cd8dd3SAl Viro extern struct dentry *isofs_lookup(struct inode *, struct dentry *, unsigned int flags);
12194f2f715SAl Viro extern struct buffer_head *isofs_bread(struct inode *, sector_t);
12294f2f715SAl Viro extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long);
12394f2f715SAl Viro 
124410dd3cfSJan Kara struct inode *__isofs_iget(struct super_block *sb,
12594f2f715SAl Viro 			   unsigned long block,
126410dd3cfSJan Kara 			   unsigned long offset,
127410dd3cfSJan Kara 			   int relocated);
128410dd3cfSJan Kara 
isofs_iget(struct super_block * sb,unsigned long block,unsigned long offset)129410dd3cfSJan Kara static inline struct inode *isofs_iget(struct super_block *sb,
130410dd3cfSJan Kara 				       unsigned long block,
131410dd3cfSJan Kara 				       unsigned long offset)
132410dd3cfSJan Kara {
133410dd3cfSJan Kara 	return __isofs_iget(sb, block, offset, 0);
134410dd3cfSJan Kara }
135410dd3cfSJan Kara 
isofs_iget_reloc(struct super_block * sb,unsigned long block,unsigned long offset)136410dd3cfSJan Kara static inline struct inode *isofs_iget_reloc(struct super_block *sb,
137410dd3cfSJan Kara 					     unsigned long block,
138410dd3cfSJan Kara 					     unsigned long offset)
139410dd3cfSJan Kara {
140410dd3cfSJan Kara 	return __isofs_iget(sb, block, offset, 1);
141410dd3cfSJan Kara }
14294f2f715SAl Viro 
14394f2f715SAl Viro /* Because the inode number is no longer relevant to finding the
14494f2f715SAl Viro  * underlying meta-data for an inode, we are free to choose a more
14594f2f715SAl Viro  * convenient 32-bit number as the inode number.  The inode numbering
14694f2f715SAl Viro  * scheme was recommended by Sergey Vlasov and Eric Lammerts. */
isofs_get_ino(unsigned long block,unsigned long offset,unsigned long bufbits)14794f2f715SAl Viro static inline unsigned long isofs_get_ino(unsigned long block,
14894f2f715SAl Viro 					  unsigned long offset,
14994f2f715SAl Viro 					  unsigned long bufbits)
15094f2f715SAl Viro {
15194f2f715SAl Viro 	return (block << (bufbits - 5)) | (offset >> 5);
15294f2f715SAl Viro }
15394f2f715SAl Viro 
15494f2f715SAl Viro /* Every directory can have many redundant directory entries scattered
15594f2f715SAl Viro  * throughout the directory tree.  First there is the directory entry
15694f2f715SAl Viro  * with the name of the directory stored in the parent directory.
15794f2f715SAl Viro  * Then, there is the "." directory entry stored in the directory
15894f2f715SAl Viro  * itself.  Finally, there are possibly many ".." directory entries
15994f2f715SAl Viro  * stored in all the subdirectories.
16094f2f715SAl Viro  *
16194f2f715SAl Viro  * In order for the NFS get_parent() method to work and for the
16294f2f715SAl Viro  * general consistency of the dcache, we need to make sure the
16394f2f715SAl Viro  * "i_iget5_block" and "i_iget5_offset" all point to exactly one of
16494f2f715SAl Viro  * the many redundant entries for each directory.  We normalize the
16594f2f715SAl Viro  * block and offset by always making them point to the "."  directory.
16694f2f715SAl Viro  *
16794f2f715SAl Viro  * Notice that we do not use the entry for the directory with the name
16894f2f715SAl Viro  * that is located in the parent directory.  Even though choosing this
16994f2f715SAl Viro  * first directory is more natural, it is much easier to find the "."
17094f2f715SAl Viro  * entry in the NFS get_parent() method because it is implicitly
17194f2f715SAl Viro  * encoded in the "extent + ext_attr_length" fields of _all_ the
17294f2f715SAl Viro  * redundant entries for the directory.  Thus, it can always be
17394f2f715SAl Viro  * reached regardless of which directory entry you have in hand.
17494f2f715SAl Viro  *
17594f2f715SAl Viro  * This works because the "." entry is simply the first directory
17694f2f715SAl Viro  * record when you start reading the file that holds all the directory
17794f2f715SAl Viro  * records, and this file starts at "extent + ext_attr_length" blocks.
17894f2f715SAl Viro  * Because the "." entry is always the first entry listed in the
17994f2f715SAl Viro  * directories file, the normalized "offset" value is always 0.
18094f2f715SAl Viro  *
18194f2f715SAl Viro  * You should pass the directory entry in "de".  On return, "block"
18294f2f715SAl Viro  * and "offset" will hold normalized values.  Only directories are
18394f2f715SAl Viro  * affected making it safe to call even for non-directory file
18494f2f715SAl Viro  * types. */
18594f2f715SAl Viro static inline void
isofs_normalize_block_and_offset(struct iso_directory_record * de,unsigned long * block,unsigned long * offset)18694f2f715SAl Viro isofs_normalize_block_and_offset(struct iso_directory_record* de,
18794f2f715SAl Viro 				 unsigned long *block,
18894f2f715SAl Viro 				 unsigned long *offset)
18994f2f715SAl Viro {
19094f2f715SAl Viro 	/* Only directories are normalized. */
19194f2f715SAl Viro 	if (de->flags[0] & 2) {
19294f2f715SAl Viro 		*offset = 0;
19394f2f715SAl Viro 		*block = (unsigned long)isonum_733(de->extent)
19494f2f715SAl Viro 			+ (unsigned long)isonum_711(de->ext_attr_length);
19594f2f715SAl Viro 	}
19694f2f715SAl Viro }
19794f2f715SAl Viro 
19892e1d5beSArjan van de Ven extern const struct inode_operations isofs_dir_inode_operations;
1994b6f5d20SArjan van de Ven extern const struct file_operations isofs_dir_operations;
200f5e54d6eSChristoph Hellwig extern const struct address_space_operations isofs_symlink_aops;
20139655164SChristoph Hellwig extern const struct export_operations isofs_export_ops;
202