xref: /openbmc/linux/fs/isofs/isofs.h (revision 92e1d5be)
194f2f715SAl Viro #include <linux/fs.h>
294f2f715SAl Viro #include <linux/buffer_head.h>
394f2f715SAl Viro #include <linux/iso_fs.h>
494f2f715SAl Viro #include <asm/unaligned.h>
594f2f715SAl Viro 
694f2f715SAl Viro enum isofs_file_format {
794f2f715SAl Viro 	isofs_file_normal = 0,
894f2f715SAl Viro 	isofs_file_sparse = 1,
994f2f715SAl Viro 	isofs_file_compressed = 2,
1094f2f715SAl Viro };
1194f2f715SAl Viro 
1294f2f715SAl Viro /*
1394f2f715SAl Viro  * iso fs inode data in memory
1494f2f715SAl Viro  */
1594f2f715SAl Viro struct iso_inode_info {
1694f2f715SAl Viro 	unsigned long i_iget5_block;
1794f2f715SAl Viro 	unsigned long i_iget5_offset;
1894f2f715SAl Viro 	unsigned int i_first_extent;
1994f2f715SAl Viro 	unsigned char i_file_format;
2094f2f715SAl Viro 	unsigned char i_format_parm[3];
2194f2f715SAl Viro 	unsigned long i_next_section_block;
2294f2f715SAl Viro 	unsigned long i_next_section_offset;
2394f2f715SAl Viro 	off_t i_section_size;
2494f2f715SAl Viro 	struct inode vfs_inode;
2594f2f715SAl Viro };
2694f2f715SAl Viro 
2794f2f715SAl Viro /*
2894f2f715SAl Viro  * iso9660 super-block data in memory
2994f2f715SAl Viro  */
3094f2f715SAl Viro struct isofs_sb_info {
3194f2f715SAl Viro 	unsigned long s_ninodes;
3294f2f715SAl Viro 	unsigned long s_nzones;
3394f2f715SAl Viro 	unsigned long s_firstdatazone;
3494f2f715SAl Viro 	unsigned long s_log_zone_size;
3594f2f715SAl Viro 	unsigned long s_max_size;
3694f2f715SAl Viro 
3794f2f715SAl Viro 	unsigned char s_high_sierra; /* A simple flag */
3894f2f715SAl Viro 	unsigned char s_mapping;
3994f2f715SAl Viro 	int           s_rock_offset; /* offset of SUSP fields within SU area */
4094f2f715SAl Viro 	unsigned char s_rock;
4194f2f715SAl Viro 	unsigned char s_joliet_level;
4294f2f715SAl Viro 	unsigned char s_utf8;
4394f2f715SAl Viro 	unsigned char s_cruft; /* Broken disks with high
4494f2f715SAl Viro 				  byte of length containing
4594f2f715SAl Viro 				  junk */
4694f2f715SAl Viro 	unsigned char s_unhide;
4794f2f715SAl Viro 	unsigned char s_nosuid;
4894f2f715SAl Viro 	unsigned char s_nodev;
4994f2f715SAl Viro 	unsigned char s_nocompress;
509769f4ebSJeremy White 	unsigned char s_hide;
519769f4ebSJeremy White 	unsigned char s_showassoc;
5294f2f715SAl Viro 
5394f2f715SAl Viro 	mode_t s_mode;
5494f2f715SAl Viro 	gid_t s_gid;
5594f2f715SAl Viro 	uid_t s_uid;
5694f2f715SAl Viro 	struct nls_table *s_nls_iocharset; /* Native language support table */
5794f2f715SAl Viro };
5894f2f715SAl Viro 
5994f2f715SAl Viro static inline struct isofs_sb_info *ISOFS_SB(struct super_block *sb)
6094f2f715SAl Viro {
6194f2f715SAl Viro 	return sb->s_fs_info;
6294f2f715SAl Viro }
6394f2f715SAl Viro 
6494f2f715SAl Viro static inline struct iso_inode_info *ISOFS_I(struct inode *inode)
6594f2f715SAl Viro {
6694f2f715SAl Viro 	return container_of(inode, struct iso_inode_info, vfs_inode);
6794f2f715SAl Viro }
6894f2f715SAl Viro 
6994f2f715SAl Viro static inline int isonum_711(char *p)
7094f2f715SAl Viro {
7194f2f715SAl Viro 	return *(u8 *)p;
7294f2f715SAl Viro }
7394f2f715SAl Viro static inline int isonum_712(char *p)
7494f2f715SAl Viro {
7594f2f715SAl Viro 	return *(s8 *)p;
7694f2f715SAl Viro }
7794f2f715SAl Viro static inline unsigned int isonum_721(char *p)
7894f2f715SAl Viro {
7994f2f715SAl Viro 	return le16_to_cpu(get_unaligned((__le16 *)p));
8094f2f715SAl Viro }
8194f2f715SAl Viro static inline unsigned int isonum_722(char *p)
8294f2f715SAl Viro {
8394f2f715SAl Viro 	return be16_to_cpu(get_unaligned((__le16 *)p));
8494f2f715SAl Viro }
8594f2f715SAl Viro static inline unsigned int isonum_723(char *p)
8694f2f715SAl Viro {
8794f2f715SAl Viro 	/* Ignore bigendian datum due to broken mastering programs */
8894f2f715SAl Viro 	return le16_to_cpu(get_unaligned((__le16 *)p));
8994f2f715SAl Viro }
9094f2f715SAl Viro static inline unsigned int isonum_731(char *p)
9194f2f715SAl Viro {
9294f2f715SAl Viro 	return le32_to_cpu(get_unaligned((__le32 *)p));
9394f2f715SAl Viro }
9494f2f715SAl Viro static inline unsigned int isonum_732(char *p)
9594f2f715SAl Viro {
9694f2f715SAl Viro 	return be32_to_cpu(get_unaligned((__le32 *)p));
9794f2f715SAl Viro }
9894f2f715SAl Viro static inline unsigned int isonum_733(char *p)
9994f2f715SAl Viro {
10094f2f715SAl Viro 	/* Ignore bigendian datum due to broken mastering programs */
10194f2f715SAl Viro 	return le32_to_cpu(get_unaligned((__le32 *)p));
10294f2f715SAl Viro }
10394f2f715SAl Viro extern int iso_date(char *, int);
10494f2f715SAl Viro 
10594f2f715SAl Viro struct inode;		/* To make gcc happy */
10694f2f715SAl Viro 
10794f2f715SAl Viro extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *);
10894f2f715SAl Viro extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *);
10994f2f715SAl Viro extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
11094f2f715SAl Viro 
11194f2f715SAl Viro int get_joliet_filename(struct iso_directory_record *, unsigned char *, struct inode *);
11294f2f715SAl Viro int get_acorn_filename(struct iso_directory_record *, char *, struct inode *);
11394f2f715SAl Viro 
11494f2f715SAl Viro extern struct dentry *isofs_lookup(struct inode *, struct dentry *, struct nameidata *);
11594f2f715SAl Viro extern struct buffer_head *isofs_bread(struct inode *, sector_t);
11694f2f715SAl Viro extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long);
11794f2f715SAl Viro 
11894f2f715SAl Viro extern struct inode *isofs_iget(struct super_block *sb,
11994f2f715SAl Viro                                 unsigned long block,
12094f2f715SAl Viro                                 unsigned long offset);
12194f2f715SAl Viro 
12294f2f715SAl Viro /* Because the inode number is no longer relevant to finding the
12394f2f715SAl Viro  * underlying meta-data for an inode, we are free to choose a more
12494f2f715SAl Viro  * convenient 32-bit number as the inode number.  The inode numbering
12594f2f715SAl Viro  * scheme was recommended by Sergey Vlasov and Eric Lammerts. */
12694f2f715SAl Viro static inline unsigned long isofs_get_ino(unsigned long block,
12794f2f715SAl Viro 					  unsigned long offset,
12894f2f715SAl Viro 					  unsigned long bufbits)
12994f2f715SAl Viro {
13094f2f715SAl Viro 	return (block << (bufbits - 5)) | (offset >> 5);
13194f2f715SAl Viro }
13294f2f715SAl Viro 
13394f2f715SAl Viro /* Every directory can have many redundant directory entries scattered
13494f2f715SAl Viro  * throughout the directory tree.  First there is the directory entry
13594f2f715SAl Viro  * with the name of the directory stored in the parent directory.
13694f2f715SAl Viro  * Then, there is the "." directory entry stored in the directory
13794f2f715SAl Viro  * itself.  Finally, there are possibly many ".." directory entries
13894f2f715SAl Viro  * stored in all the subdirectories.
13994f2f715SAl Viro  *
14094f2f715SAl Viro  * In order for the NFS get_parent() method to work and for the
14194f2f715SAl Viro  * general consistency of the dcache, we need to make sure the
14294f2f715SAl Viro  * "i_iget5_block" and "i_iget5_offset" all point to exactly one of
14394f2f715SAl Viro  * the many redundant entries for each directory.  We normalize the
14494f2f715SAl Viro  * block and offset by always making them point to the "."  directory.
14594f2f715SAl Viro  *
14694f2f715SAl Viro  * Notice that we do not use the entry for the directory with the name
14794f2f715SAl Viro  * that is located in the parent directory.  Even though choosing this
14894f2f715SAl Viro  * first directory is more natural, it is much easier to find the "."
14994f2f715SAl Viro  * entry in the NFS get_parent() method because it is implicitly
15094f2f715SAl Viro  * encoded in the "extent + ext_attr_length" fields of _all_ the
15194f2f715SAl Viro  * redundant entries for the directory.  Thus, it can always be
15294f2f715SAl Viro  * reached regardless of which directory entry you have in hand.
15394f2f715SAl Viro  *
15494f2f715SAl Viro  * This works because the "." entry is simply the first directory
15594f2f715SAl Viro  * record when you start reading the file that holds all the directory
15694f2f715SAl Viro  * records, and this file starts at "extent + ext_attr_length" blocks.
15794f2f715SAl Viro  * Because the "." entry is always the first entry listed in the
15894f2f715SAl Viro  * directories file, the normalized "offset" value is always 0.
15994f2f715SAl Viro  *
16094f2f715SAl Viro  * You should pass the directory entry in "de".  On return, "block"
16194f2f715SAl Viro  * and "offset" will hold normalized values.  Only directories are
16294f2f715SAl Viro  * affected making it safe to call even for non-directory file
16394f2f715SAl Viro  * types. */
16494f2f715SAl Viro static inline void
16594f2f715SAl Viro isofs_normalize_block_and_offset(struct iso_directory_record* de,
16694f2f715SAl Viro 				 unsigned long *block,
16794f2f715SAl Viro 				 unsigned long *offset)
16894f2f715SAl Viro {
16994f2f715SAl Viro 	/* Only directories are normalized. */
17094f2f715SAl Viro 	if (de->flags[0] & 2) {
17194f2f715SAl Viro 		*offset = 0;
17294f2f715SAl Viro 		*block = (unsigned long)isonum_733(de->extent)
17394f2f715SAl Viro 			+ (unsigned long)isonum_711(de->ext_attr_length);
17494f2f715SAl Viro 	}
17594f2f715SAl Viro }
17694f2f715SAl Viro 
17792e1d5beSArjan van de Ven extern const struct inode_operations isofs_dir_inode_operations;
1784b6f5d20SArjan van de Ven extern const struct file_operations isofs_dir_operations;
179f5e54d6eSChristoph Hellwig extern const struct address_space_operations isofs_symlink_aops;
18094f2f715SAl Viro extern struct export_operations isofs_export_ops;
181