isofs.h 6.5 KB

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