isofs.h 6.4 KB

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