Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #include <linux/fs.h>
0003 #include <linux/buffer_head.h>
0004 #include <linux/exportfs.h>
0005 #include <linux/iso_fs.h>
0006 #include <asm/unaligned.h>
0007 
0008 enum isofs_file_format {
0009     isofs_file_normal = 0,
0010     isofs_file_sparse = 1,
0011     isofs_file_compressed = 2,
0012 };
0013     
0014 /*
0015  * iso fs inode data in memory
0016  */
0017 struct iso_inode_info {
0018     unsigned long i_iget5_block;
0019     unsigned long i_iget5_offset;
0020     unsigned int i_first_extent;
0021     unsigned char i_file_format;
0022     unsigned char i_format_parm[3];
0023     unsigned long i_next_section_block;
0024     unsigned long i_next_section_offset;
0025     off_t i_section_size;
0026     struct inode vfs_inode;
0027 };
0028 
0029 /*
0030  * iso9660 super-block data in memory
0031  */
0032 struct isofs_sb_info {
0033     unsigned long s_ninodes;
0034     unsigned long s_nzones;
0035     unsigned long s_firstdatazone;
0036     unsigned long s_log_zone_size;
0037     unsigned long s_max_size;
0038     
0039     int           s_rock_offset; /* offset of SUSP fields within SU area */
0040     s32           s_sbsector;
0041     unsigned char s_joliet_level;
0042     unsigned char s_mapping;
0043     unsigned char s_check;
0044     unsigned char s_session;
0045     unsigned int  s_high_sierra:1;
0046     unsigned int  s_rock:2;
0047     unsigned int  s_cruft:1; /* Broken disks with high byte of length
0048                   * containing junk */
0049     unsigned int  s_nocompress:1;
0050     unsigned int  s_hide:1;
0051     unsigned int  s_showassoc:1;
0052     unsigned int  s_overriderockperm:1;
0053     unsigned int  s_uid_set:1;
0054     unsigned int  s_gid_set:1;
0055 
0056     umode_t s_fmode;
0057     umode_t s_dmode;
0058     kgid_t s_gid;
0059     kuid_t s_uid;
0060     struct nls_table *s_nls_iocharset; /* Native language support table */
0061 };
0062 
0063 #define ISOFS_INVALID_MODE ((umode_t) -1)
0064 
0065 static inline struct isofs_sb_info *ISOFS_SB(struct super_block *sb)
0066 {
0067     return sb->s_fs_info;
0068 }
0069 
0070 static inline struct iso_inode_info *ISOFS_I(struct inode *inode)
0071 {
0072     return container_of(inode, struct iso_inode_info, vfs_inode);
0073 }
0074 
0075 static inline int isonum_711(u8 *p)
0076 {
0077     return *p;
0078 }
0079 static inline int isonum_712(s8 *p)
0080 {
0081     return *p;
0082 }
0083 static inline unsigned int isonum_721(u8 *p)
0084 {
0085     return get_unaligned_le16(p);
0086 }
0087 static inline unsigned int isonum_722(u8 *p)
0088 {
0089     return get_unaligned_be16(p);
0090 }
0091 static inline unsigned int isonum_723(u8 *p)
0092 {
0093     /* Ignore bigendian datum due to broken mastering programs */
0094     return get_unaligned_le16(p);
0095 }
0096 static inline unsigned int isonum_731(u8 *p)
0097 {
0098     return get_unaligned_le32(p);
0099 }
0100 static inline unsigned int isonum_732(u8 *p)
0101 {
0102     return get_unaligned_be32(p);
0103 }
0104 static inline unsigned int isonum_733(u8 *p)
0105 {
0106     /* Ignore bigendian datum due to broken mastering programs */
0107     return get_unaligned_le32(p);
0108 }
0109 extern int iso_date(u8 *, int);
0110 
0111 struct inode;       /* To make gcc happy */
0112 
0113 extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *, int relocated);
0114 extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *);
0115 extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
0116 
0117 int get_joliet_filename(struct iso_directory_record *, unsigned char *, struct inode *);
0118 int get_acorn_filename(struct iso_directory_record *, char *, struct inode *);
0119 
0120 extern struct dentry *isofs_lookup(struct inode *, struct dentry *, unsigned int flags);
0121 extern struct buffer_head *isofs_bread(struct inode *, sector_t);
0122 extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long);
0123 
0124 struct inode *__isofs_iget(struct super_block *sb,
0125                unsigned long block,
0126                unsigned long offset,
0127                int relocated);
0128 
0129 static inline struct inode *isofs_iget(struct super_block *sb,
0130                        unsigned long block,
0131                        unsigned long offset)
0132 {
0133     return __isofs_iget(sb, block, offset, 0);
0134 }
0135 
0136 static inline struct inode *isofs_iget_reloc(struct super_block *sb,
0137                          unsigned long block,
0138                          unsigned long offset)
0139 {
0140     return __isofs_iget(sb, block, offset, 1);
0141 }
0142 
0143 /* Because the inode number is no longer relevant to finding the
0144  * underlying meta-data for an inode, we are free to choose a more
0145  * convenient 32-bit number as the inode number.  The inode numbering
0146  * scheme was recommended by Sergey Vlasov and Eric Lammerts. */
0147 static inline unsigned long isofs_get_ino(unsigned long block,
0148                       unsigned long offset,
0149                       unsigned long bufbits)
0150 {
0151     return (block << (bufbits - 5)) | (offset >> 5);
0152 }
0153 
0154 /* Every directory can have many redundant directory entries scattered
0155  * throughout the directory tree.  First there is the directory entry
0156  * with the name of the directory stored in the parent directory.
0157  * Then, there is the "." directory entry stored in the directory
0158  * itself.  Finally, there are possibly many ".." directory entries
0159  * stored in all the subdirectories.
0160  *
0161  * In order for the NFS get_parent() method to work and for the
0162  * general consistency of the dcache, we need to make sure the
0163  * "i_iget5_block" and "i_iget5_offset" all point to exactly one of
0164  * the many redundant entries for each directory.  We normalize the
0165  * block and offset by always making them point to the "."  directory.
0166  *
0167  * Notice that we do not use the entry for the directory with the name
0168  * that is located in the parent directory.  Even though choosing this
0169  * first directory is more natural, it is much easier to find the "."
0170  * entry in the NFS get_parent() method because it is implicitly
0171  * encoded in the "extent + ext_attr_length" fields of _all_ the
0172  * redundant entries for the directory.  Thus, it can always be
0173  * reached regardless of which directory entry you have in hand.
0174  *
0175  * This works because the "." entry is simply the first directory
0176  * record when you start reading the file that holds all the directory
0177  * records, and this file starts at "extent + ext_attr_length" blocks.
0178  * Because the "." entry is always the first entry listed in the
0179  * directories file, the normalized "offset" value is always 0.
0180  *
0181  * You should pass the directory entry in "de".  On return, "block"
0182  * and "offset" will hold normalized values.  Only directories are
0183  * affected making it safe to call even for non-directory file
0184  * types. */
0185 static inline void
0186 isofs_normalize_block_and_offset(struct iso_directory_record* de,
0187                  unsigned long *block,
0188                  unsigned long *offset)
0189 {
0190     /* Only directories are normalized. */
0191     if (de->flags[0] & 2) {
0192         *offset = 0;
0193         *block = (unsigned long)isonum_733(de->extent)
0194             + (unsigned long)isonum_711(de->ext_attr_length);
0195     }
0196 }
0197 
0198 extern const struct inode_operations isofs_dir_inode_operations;
0199 extern const struct file_operations isofs_dir_operations;
0200 extern const struct address_space_operations isofs_symlink_aops;
0201 extern const struct export_operations isofs_export_ops;