isofs.h 6.0 KB

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