iso_fs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #ifndef _ISOFS_FS_H
  2. #define _ISOFS_FS_H
  3. #include <linux/types.h>
  4. /*
  5. * The isofs filesystem constants/structures
  6. */
  7. /* This part borrowed from the bsd386 isofs */
  8. #define ISODCL(from, to) (to - from + 1)
  9. struct iso_volume_descriptor {
  10. char type[ISODCL(1,1)]; /* 711 */
  11. char id[ISODCL(2,6)];
  12. char version[ISODCL(7,7)];
  13. char data[ISODCL(8,2048)];
  14. };
  15. /* volume descriptor types */
  16. #define ISO_VD_PRIMARY 1
  17. #define ISO_VD_SUPPLEMENTARY 2
  18. #define ISO_VD_END 255
  19. #define ISO_STANDARD_ID "CD001"
  20. struct iso_primary_descriptor {
  21. char type [ISODCL ( 1, 1)]; /* 711 */
  22. char id [ISODCL ( 2, 6)];
  23. char version [ISODCL ( 7, 7)]; /* 711 */
  24. char unused1 [ISODCL ( 8, 8)];
  25. char system_id [ISODCL ( 9, 40)]; /* achars */
  26. char volume_id [ISODCL ( 41, 72)]; /* dchars */
  27. char unused2 [ISODCL ( 73, 80)];
  28. char volume_space_size [ISODCL ( 81, 88)]; /* 733 */
  29. char unused3 [ISODCL ( 89, 120)];
  30. char volume_set_size [ISODCL (121, 124)]; /* 723 */
  31. char volume_sequence_number [ISODCL (125, 128)]; /* 723 */
  32. char logical_block_size [ISODCL (129, 132)]; /* 723 */
  33. char path_table_size [ISODCL (133, 140)]; /* 733 */
  34. char type_l_path_table [ISODCL (141, 144)]; /* 731 */
  35. char opt_type_l_path_table [ISODCL (145, 148)]; /* 731 */
  36. char type_m_path_table [ISODCL (149, 152)]; /* 732 */
  37. char opt_type_m_path_table [ISODCL (153, 156)]; /* 732 */
  38. char root_directory_record [ISODCL (157, 190)]; /* 9.1 */
  39. char volume_set_id [ISODCL (191, 318)]; /* dchars */
  40. char publisher_id [ISODCL (319, 446)]; /* achars */
  41. char preparer_id [ISODCL (447, 574)]; /* achars */
  42. char application_id [ISODCL (575, 702)]; /* achars */
  43. char copyright_file_id [ISODCL (703, 739)]; /* 7.5 dchars */
  44. char abstract_file_id [ISODCL (740, 776)]; /* 7.5 dchars */
  45. char bibliographic_file_id [ISODCL (777, 813)]; /* 7.5 dchars */
  46. char creation_date [ISODCL (814, 830)]; /* 8.4.26.1 */
  47. char modification_date [ISODCL (831, 847)]; /* 8.4.26.1 */
  48. char expiration_date [ISODCL (848, 864)]; /* 8.4.26.1 */
  49. char effective_date [ISODCL (865, 881)]; /* 8.4.26.1 */
  50. char file_structure_version [ISODCL (882, 882)]; /* 711 */
  51. char unused4 [ISODCL (883, 883)];
  52. char application_data [ISODCL (884, 1395)];
  53. char unused5 [ISODCL (1396, 2048)];
  54. };
  55. /* Almost the same as the primary descriptor but two fields are specified */
  56. struct iso_supplementary_descriptor {
  57. char type [ISODCL ( 1, 1)]; /* 711 */
  58. char id [ISODCL ( 2, 6)];
  59. char version [ISODCL ( 7, 7)]; /* 711 */
  60. char flags [ISODCL ( 8, 8)]; /* 853 */
  61. char system_id [ISODCL ( 9, 40)]; /* achars */
  62. char volume_id [ISODCL ( 41, 72)]; /* dchars */
  63. char unused2 [ISODCL ( 73, 80)];
  64. char volume_space_size [ISODCL ( 81, 88)]; /* 733 */
  65. char escape [ISODCL ( 89, 120)]; /* 856 */
  66. char volume_set_size [ISODCL (121, 124)]; /* 723 */
  67. char volume_sequence_number [ISODCL (125, 128)]; /* 723 */
  68. char logical_block_size [ISODCL (129, 132)]; /* 723 */
  69. char path_table_size [ISODCL (133, 140)]; /* 733 */
  70. char type_l_path_table [ISODCL (141, 144)]; /* 731 */
  71. char opt_type_l_path_table [ISODCL (145, 148)]; /* 731 */
  72. char type_m_path_table [ISODCL (149, 152)]; /* 732 */
  73. char opt_type_m_path_table [ISODCL (153, 156)]; /* 732 */
  74. char root_directory_record [ISODCL (157, 190)]; /* 9.1 */
  75. char volume_set_id [ISODCL (191, 318)]; /* dchars */
  76. char publisher_id [ISODCL (319, 446)]; /* achars */
  77. char preparer_id [ISODCL (447, 574)]; /* achars */
  78. char application_id [ISODCL (575, 702)]; /* achars */
  79. char copyright_file_id [ISODCL (703, 739)]; /* 7.5 dchars */
  80. char abstract_file_id [ISODCL (740, 776)]; /* 7.5 dchars */
  81. char bibliographic_file_id [ISODCL (777, 813)]; /* 7.5 dchars */
  82. char creation_date [ISODCL (814, 830)]; /* 8.4.26.1 */
  83. char modification_date [ISODCL (831, 847)]; /* 8.4.26.1 */
  84. char expiration_date [ISODCL (848, 864)]; /* 8.4.26.1 */
  85. char effective_date [ISODCL (865, 881)]; /* 8.4.26.1 */
  86. char file_structure_version [ISODCL (882, 882)]; /* 711 */
  87. char unused4 [ISODCL (883, 883)];
  88. char application_data [ISODCL (884, 1395)];
  89. char unused5 [ISODCL (1396, 2048)];
  90. };
  91. #define HS_STANDARD_ID "CDROM"
  92. struct hs_volume_descriptor {
  93. char foo [ISODCL ( 1, 8)]; /* 733 */
  94. char type [ISODCL ( 9, 9)]; /* 711 */
  95. char id [ISODCL ( 10, 14)];
  96. char version [ISODCL ( 15, 15)]; /* 711 */
  97. char data[ISODCL(16,2048)];
  98. };
  99. struct hs_primary_descriptor {
  100. char foo [ISODCL ( 1, 8)]; /* 733 */
  101. char type [ISODCL ( 9, 9)]; /* 711 */
  102. char id [ISODCL ( 10, 14)];
  103. char version [ISODCL ( 15, 15)]; /* 711 */
  104. char unused1 [ISODCL ( 16, 16)]; /* 711 */
  105. char system_id [ISODCL ( 17, 48)]; /* achars */
  106. char volume_id [ISODCL ( 49, 80)]; /* dchars */
  107. char unused2 [ISODCL ( 81, 88)]; /* 733 */
  108. char volume_space_size [ISODCL ( 89, 96)]; /* 733 */
  109. char unused3 [ISODCL ( 97, 128)]; /* 733 */
  110. char volume_set_size [ISODCL (129, 132)]; /* 723 */
  111. char volume_sequence_number [ISODCL (133, 136)]; /* 723 */
  112. char logical_block_size [ISODCL (137, 140)]; /* 723 */
  113. char path_table_size [ISODCL (141, 148)]; /* 733 */
  114. char type_l_path_table [ISODCL (149, 152)]; /* 731 */
  115. char unused4 [ISODCL (153, 180)]; /* 733 */
  116. char root_directory_record [ISODCL (181, 214)]; /* 9.1 */
  117. };
  118. /* We use this to help us look up the parent inode numbers. */
  119. struct iso_path_table{
  120. unsigned char name_len[2]; /* 721 */
  121. char extent[4]; /* 731 */
  122. char parent[2]; /* 721 */
  123. char name[0];
  124. } __attribute__((packed));
  125. /* high sierra is identical to iso, except that the date is only 6 bytes, and
  126. there is an extra reserved byte after the flags */
  127. struct iso_directory_record {
  128. char length [ISODCL (1, 1)]; /* 711 */
  129. char ext_attr_length [ISODCL (2, 2)]; /* 711 */
  130. char extent [ISODCL (3, 10)]; /* 733 */
  131. char size [ISODCL (11, 18)]; /* 733 */
  132. char date [ISODCL (19, 25)]; /* 7 by 711 */
  133. char flags [ISODCL (26, 26)];
  134. char file_unit_size [ISODCL (27, 27)]; /* 711 */
  135. char interleave [ISODCL (28, 28)]; /* 711 */
  136. char volume_sequence_number [ISODCL (29, 32)]; /* 723 */
  137. unsigned char name_len [ISODCL (33, 33)]; /* 711 */
  138. char name [0];
  139. } __attribute__((packed));
  140. #define ISOFS_BLOCK_BITS 11
  141. #define ISOFS_BLOCK_SIZE 2048
  142. #define ISOFS_BUFFER_SIZE(INODE) ((INODE)->i_sb->s_blocksize)
  143. #define ISOFS_BUFFER_BITS(INODE) ((INODE)->i_sb->s_blocksize_bits)
  144. #define ISOFS_SUPER_MAGIC 0x9660
  145. #ifdef __KERNEL__
  146. /* Number conversion inlines, named after the section in ISO 9660
  147. they correspond to. */
  148. #include <asm/byteorder.h>
  149. #include <asm/unaligned.h>
  150. #include <linux/iso_fs_i.h>
  151. #include <linux/iso_fs_sb.h>
  152. static inline struct isofs_sb_info *ISOFS_SB(struct super_block *sb)
  153. {
  154. return sb->s_fs_info;
  155. }
  156. static inline struct iso_inode_info *ISOFS_I(struct inode *inode)
  157. {
  158. return container_of(inode, struct iso_inode_info, vfs_inode);
  159. }
  160. static inline int isonum_711(char *p)
  161. {
  162. return *(u8 *)p;
  163. }
  164. static inline int isonum_712(char *p)
  165. {
  166. return *(s8 *)p;
  167. }
  168. static inline unsigned int isonum_721(char *p)
  169. {
  170. return le16_to_cpu(get_unaligned((__le16 *)p));
  171. }
  172. static inline unsigned int isonum_722(char *p)
  173. {
  174. return be16_to_cpu(get_unaligned((__le16 *)p));
  175. }
  176. static inline unsigned int isonum_723(char *p)
  177. {
  178. /* Ignore bigendian datum due to broken mastering programs */
  179. return le16_to_cpu(get_unaligned((__le16 *)p));
  180. }
  181. static inline unsigned int isonum_731(char *p)
  182. {
  183. return le32_to_cpu(get_unaligned((__le32 *)p));
  184. }
  185. static inline unsigned int isonum_732(char *p)
  186. {
  187. return be32_to_cpu(get_unaligned((__le32 *)p));
  188. }
  189. static inline unsigned int isonum_733(char *p)
  190. {
  191. /* Ignore bigendian datum due to broken mastering programs */
  192. return le32_to_cpu(get_unaligned((__le32 *)p));
  193. }
  194. extern int iso_date(char *, int);
  195. struct inode; /* To make gcc happy */
  196. extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *);
  197. extern int get_rock_ridge_filename(struct iso_directory_record *, char *, struct inode *);
  198. extern int isofs_name_translate(struct iso_directory_record *, char *, struct inode *);
  199. int get_joliet_filename(struct iso_directory_record *, unsigned char *, struct inode *);
  200. int get_acorn_filename(struct iso_directory_record *, char *, struct inode *);
  201. extern struct dentry *isofs_lookup(struct inode *, struct dentry *, struct nameidata *);
  202. extern struct buffer_head *isofs_bread(struct inode *, sector_t);
  203. extern int isofs_get_blocks(struct inode *, sector_t, struct buffer_head **, unsigned long);
  204. extern struct inode *isofs_iget(struct super_block *sb,
  205. unsigned long block,
  206. unsigned long offset);
  207. /* Because the inode number is no longer relevant to finding the
  208. * underlying meta-data for an inode, we are free to choose a more
  209. * convenient 32-bit number as the inode number. The inode numbering
  210. * scheme was recommended by Sergey Vlasov and Eric Lammerts. */
  211. static inline unsigned long isofs_get_ino(unsigned long block,
  212. unsigned long offset,
  213. unsigned long bufbits)
  214. {
  215. return (block << (bufbits - 5)) | (offset >> 5);
  216. }
  217. /* Every directory can have many redundant directory entries scattered
  218. * throughout the directory tree. First there is the directory entry
  219. * with the name of the directory stored in the parent directory.
  220. * Then, there is the "." directory entry stored in the directory
  221. * itself. Finally, there are possibly many ".." directory entries
  222. * stored in all the subdirectories.
  223. *
  224. * In order for the NFS get_parent() method to work and for the
  225. * general consistency of the dcache, we need to make sure the
  226. * "i_iget5_block" and "i_iget5_offset" all point to exactly one of
  227. * the many redundant entries for each directory. We normalize the
  228. * block and offset by always making them point to the "." directory.
  229. *
  230. * Notice that we do not use the entry for the directory with the name
  231. * that is located in the parent directory. Even though choosing this
  232. * first directory is more natural, it is much easier to find the "."
  233. * entry in the NFS get_parent() method because it is implicitly
  234. * encoded in the "extent + ext_attr_length" fields of _all_ the
  235. * redundant entries for the directory. Thus, it can always be
  236. * reached regardless of which directory entry you have in hand.
  237. *
  238. * This works because the "." entry is simply the first directory
  239. * record when you start reading the file that holds all the directory
  240. * records, and this file starts at "extent + ext_attr_length" blocks.
  241. * Because the "." entry is always the first entry listed in the
  242. * directories file, the normalized "offset" value is always 0.
  243. *
  244. * You should pass the directory entry in "de". On return, "block"
  245. * and "offset" will hold normalized values. Only directories are
  246. * affected making it safe to call even for non-directory file
  247. * types. */
  248. static inline void
  249. isofs_normalize_block_and_offset(struct iso_directory_record* de,
  250. unsigned long *block,
  251. unsigned long *offset)
  252. {
  253. /* Only directories are normalized. */
  254. if (de->flags[0] & 2) {
  255. *offset = 0;
  256. *block = (unsigned long)isonum_733(de->extent)
  257. + (unsigned long)isonum_711(de->ext_attr_length);
  258. }
  259. }
  260. extern struct inode_operations isofs_dir_inode_operations;
  261. extern struct file_operations isofs_dir_operations;
  262. extern struct address_space_operations isofs_symlink_aops;
  263. extern struct export_operations isofs_export_ops;
  264. /* The following macros are used to check for memory leaks. */
  265. #ifdef LEAK_CHECK
  266. #define free_s leak_check_free_s
  267. #define malloc leak_check_malloc
  268. #define sb_bread leak_check_bread
  269. #define brelse leak_check_brelse
  270. extern void * leak_check_malloc(unsigned int size);
  271. extern void leak_check_free_s(void * obj, int size);
  272. extern struct buffer_head * leak_check_bread(struct super_block *sb, int block);
  273. extern void leak_check_brelse(struct buffer_head * bh);
  274. #endif /* LEAK_CHECK */
  275. #endif /* __KERNEL__ */
  276. #endif