hfsplus_fs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /*
  2. * linux/include/linux/hfsplus_fs.h
  3. *
  4. * Copyright (C) 1999
  5. * Brad Boyer (flar@pants.nu)
  6. * (C) 2003 Ardis Technologies <roman@ardistech.com>
  7. *
  8. */
  9. #ifndef _LINUX_HFSPLUS_FS_H
  10. #define _LINUX_HFSPLUS_FS_H
  11. #include <linux/fs.h>
  12. #include <linux/mutex.h>
  13. #include <linux/buffer_head.h>
  14. #include "hfsplus_raw.h"
  15. #define DBG_BNODE_REFS 0x00000001
  16. #define DBG_BNODE_MOD 0x00000002
  17. #define DBG_CAT_MOD 0x00000004
  18. #define DBG_INODE 0x00000008
  19. #define DBG_SUPER 0x00000010
  20. #define DBG_EXTENT 0x00000020
  21. #define DBG_BITMAP 0x00000040
  22. //#define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
  23. //#define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
  24. //#define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
  25. #define DBG_MASK (0)
  26. #define dprint(flg, fmt, args...) \
  27. if (flg & DBG_MASK) printk(fmt , ## args)
  28. /* Runtime config options */
  29. #define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */
  30. #define HFSPLUS_TYPE_DATA 0x00
  31. #define HFSPLUS_TYPE_RSRC 0xFF
  32. typedef int (*btree_keycmp)(const hfsplus_btree_key *, const hfsplus_btree_key *);
  33. #define NODE_HASH_SIZE 256
  34. /* An HFS+ BTree held in memory */
  35. struct hfs_btree {
  36. struct super_block *sb;
  37. struct inode *inode;
  38. btree_keycmp keycmp;
  39. u32 cnid;
  40. u32 root;
  41. u32 leaf_count;
  42. u32 leaf_head;
  43. u32 leaf_tail;
  44. u32 node_count;
  45. u32 free_nodes;
  46. u32 attributes;
  47. unsigned int node_size;
  48. unsigned int node_size_shift;
  49. unsigned int max_key_len;
  50. unsigned int depth;
  51. //unsigned int map1_size, map_size;
  52. struct mutex tree_lock;
  53. unsigned int pages_per_bnode;
  54. spinlock_t hash_lock;
  55. struct hfs_bnode *node_hash[NODE_HASH_SIZE];
  56. int node_hash_cnt;
  57. };
  58. struct page;
  59. /* An HFS+ BTree node in memory */
  60. struct hfs_bnode {
  61. struct hfs_btree *tree;
  62. u32 prev;
  63. u32 this;
  64. u32 next;
  65. u32 parent;
  66. u16 num_recs;
  67. u8 type;
  68. u8 height;
  69. struct hfs_bnode *next_hash;
  70. unsigned long flags;
  71. wait_queue_head_t lock_wq;
  72. atomic_t refcnt;
  73. unsigned int page_offset;
  74. struct page *page[0];
  75. };
  76. #define HFS_BNODE_LOCK 0
  77. #define HFS_BNODE_ERROR 1
  78. #define HFS_BNODE_NEW 2
  79. #define HFS_BNODE_DIRTY 3
  80. #define HFS_BNODE_DELETED 4
  81. /*
  82. * HFS+ superblock info (built from Volume Header on disk)
  83. */
  84. struct hfsplus_vh;
  85. struct hfs_btree;
  86. struct hfsplus_sb_info {
  87. struct hfsplus_vh *s_vhdr;
  88. struct hfsplus_vh *s_backup_vhdr;
  89. struct hfs_btree *ext_tree;
  90. struct hfs_btree *cat_tree;
  91. struct hfs_btree *attr_tree;
  92. struct inode *alloc_file;
  93. struct inode *hidden_dir;
  94. struct nls_table *nls;
  95. /* Runtime variables */
  96. u32 blockoffset;
  97. sector_t part_start;
  98. sector_t sect_count;
  99. int fs_shift;
  100. /* immutable data from the volume header */
  101. u32 alloc_blksz;
  102. int alloc_blksz_shift;
  103. u32 total_blocks;
  104. u32 data_clump_blocks, rsrc_clump_blocks;
  105. /* mutable data from the volume header, protected by alloc_mutex */
  106. u32 free_blocks;
  107. struct mutex alloc_mutex;
  108. /* mutable data from the volume header, protected by vh_mutex */
  109. u32 next_cnid;
  110. u32 file_count;
  111. u32 folder_count;
  112. struct mutex vh_mutex;
  113. /* Config options */
  114. u32 creator;
  115. u32 type;
  116. umode_t umask;
  117. uid_t uid;
  118. gid_t gid;
  119. int part, session;
  120. unsigned long flags;
  121. };
  122. #define HFSPLUS_SB_WRITEBACKUP 0
  123. #define HFSPLUS_SB_NODECOMPOSE 1
  124. #define HFSPLUS_SB_FORCE 2
  125. #define HFSPLUS_SB_HFSX 3
  126. #define HFSPLUS_SB_CASEFOLD 4
  127. struct hfsplus_inode_info {
  128. atomic_t opencnt;
  129. /*
  130. * Extent allocation information, protected by extents_lock.
  131. */
  132. u32 first_blocks;
  133. u32 clump_blocks;
  134. u32 alloc_blocks;
  135. u32 cached_start;
  136. u32 cached_blocks;
  137. hfsplus_extent_rec first_extents;
  138. hfsplus_extent_rec cached_extents;
  139. unsigned int extent_state;
  140. struct mutex extents_lock;
  141. /*
  142. * Immutable data.
  143. */
  144. struct inode *rsrc_inode;
  145. __be32 create_date;
  146. /*
  147. * Protected by sbi->vh_mutex.
  148. */
  149. u32 linkid;
  150. /*
  151. * Accessed using atomic bitops.
  152. */
  153. unsigned long flags;
  154. /*
  155. * Protected by i_mutex.
  156. */
  157. sector_t fs_blocks;
  158. u8 userflags; /* BSD user file flags */
  159. struct list_head open_dir_list;
  160. loff_t phys_size;
  161. struct inode vfs_inode;
  162. };
  163. #define HFSPLUS_EXT_DIRTY 0x0001
  164. #define HFSPLUS_EXT_NEW 0x0002
  165. #define HFSPLUS_I_RSRC 0 /* represents a resource fork */
  166. #define HFSPLUS_IS_RSRC(inode) \
  167. test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
  168. struct hfs_find_data {
  169. /* filled by caller */
  170. hfsplus_btree_key *search_key;
  171. hfsplus_btree_key *key;
  172. /* filled by find */
  173. struct hfs_btree *tree;
  174. struct hfs_bnode *bnode;
  175. /* filled by findrec */
  176. int record;
  177. int keyoffset, keylength;
  178. int entryoffset, entrylength;
  179. };
  180. struct hfsplus_readdir_data {
  181. struct list_head list;
  182. struct file *file;
  183. struct hfsplus_cat_key key;
  184. };
  185. #define hfs_btree_open hfsplus_btree_open
  186. #define hfs_btree_close hfsplus_btree_close
  187. #define hfs_btree_write hfsplus_btree_write
  188. #define hfs_bmap_alloc hfsplus_bmap_alloc
  189. #define hfs_bmap_free hfsplus_bmap_free
  190. #define hfs_bnode_read hfsplus_bnode_read
  191. #define hfs_bnode_read_u16 hfsplus_bnode_read_u16
  192. #define hfs_bnode_read_u8 hfsplus_bnode_read_u8
  193. #define hfs_bnode_read_key hfsplus_bnode_read_key
  194. #define hfs_bnode_write hfsplus_bnode_write
  195. #define hfs_bnode_write_u16 hfsplus_bnode_write_u16
  196. #define hfs_bnode_clear hfsplus_bnode_clear
  197. #define hfs_bnode_copy hfsplus_bnode_copy
  198. #define hfs_bnode_move hfsplus_bnode_move
  199. #define hfs_bnode_dump hfsplus_bnode_dump
  200. #define hfs_bnode_unlink hfsplus_bnode_unlink
  201. #define hfs_bnode_findhash hfsplus_bnode_findhash
  202. #define hfs_bnode_find hfsplus_bnode_find
  203. #define hfs_bnode_unhash hfsplus_bnode_unhash
  204. #define hfs_bnode_free hfsplus_bnode_free
  205. #define hfs_bnode_create hfsplus_bnode_create
  206. #define hfs_bnode_get hfsplus_bnode_get
  207. #define hfs_bnode_put hfsplus_bnode_put
  208. #define hfs_brec_lenoff hfsplus_brec_lenoff
  209. #define hfs_brec_keylen hfsplus_brec_keylen
  210. #define hfs_brec_insert hfsplus_brec_insert
  211. #define hfs_brec_remove hfsplus_brec_remove
  212. #define hfs_find_init hfsplus_find_init
  213. #define hfs_find_exit hfsplus_find_exit
  214. #define __hfs_brec_find __hplusfs_brec_find
  215. #define hfs_brec_find hfsplus_brec_find
  216. #define hfs_brec_read hfsplus_brec_read
  217. #define hfs_brec_goto hfsplus_brec_goto
  218. #define hfs_part_find hfsplus_part_find
  219. /*
  220. * definitions for ext2 flag ioctls (linux really needs a generic
  221. * interface for this).
  222. */
  223. /* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support
  224. * chattr/lsattr */
  225. #define HFSPLUS_IOC_EXT2_GETFLAGS FS_IOC_GETFLAGS
  226. #define HFSPLUS_IOC_EXT2_SETFLAGS FS_IOC_SETFLAGS
  227. /*
  228. * Functions in any *.c used in other files
  229. */
  230. /* bitmap.c */
  231. int hfsplus_block_allocate(struct super_block *, u32, u32, u32 *);
  232. int hfsplus_block_free(struct super_block *, u32, u32);
  233. /* btree.c */
  234. struct hfs_btree *hfs_btree_open(struct super_block *, u32);
  235. void hfs_btree_close(struct hfs_btree *);
  236. void hfs_btree_write(struct hfs_btree *);
  237. struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *);
  238. void hfs_bmap_free(struct hfs_bnode *);
  239. /* bnode.c */
  240. void hfs_bnode_read(struct hfs_bnode *, void *, int, int);
  241. u16 hfs_bnode_read_u16(struct hfs_bnode *, int);
  242. u8 hfs_bnode_read_u8(struct hfs_bnode *, int);
  243. void hfs_bnode_read_key(struct hfs_bnode *, void *, int);
  244. void hfs_bnode_write(struct hfs_bnode *, void *, int, int);
  245. void hfs_bnode_write_u16(struct hfs_bnode *, int, u16);
  246. void hfs_bnode_clear(struct hfs_bnode *, int, int);
  247. void hfs_bnode_copy(struct hfs_bnode *, int,
  248. struct hfs_bnode *, int, int);
  249. void hfs_bnode_move(struct hfs_bnode *, int, int, int);
  250. void hfs_bnode_dump(struct hfs_bnode *);
  251. void hfs_bnode_unlink(struct hfs_bnode *);
  252. struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *, u32);
  253. struct hfs_bnode *hfs_bnode_find(struct hfs_btree *, u32);
  254. void hfs_bnode_unhash(struct hfs_bnode *);
  255. void hfs_bnode_free(struct hfs_bnode *);
  256. struct hfs_bnode *hfs_bnode_create(struct hfs_btree *, u32);
  257. void hfs_bnode_get(struct hfs_bnode *);
  258. void hfs_bnode_put(struct hfs_bnode *);
  259. /* brec.c */
  260. u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *);
  261. u16 hfs_brec_keylen(struct hfs_bnode *, u16);
  262. int hfs_brec_insert(struct hfs_find_data *, void *, int);
  263. int hfs_brec_remove(struct hfs_find_data *);
  264. /* bfind.c */
  265. int hfs_find_init(struct hfs_btree *, struct hfs_find_data *);
  266. void hfs_find_exit(struct hfs_find_data *);
  267. int __hfs_brec_find(struct hfs_bnode *, struct hfs_find_data *);
  268. int hfs_brec_find(struct hfs_find_data *);
  269. int hfs_brec_read(struct hfs_find_data *, void *, int);
  270. int hfs_brec_goto(struct hfs_find_data *, int);
  271. /* catalog.c */
  272. int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
  273. int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
  274. void hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *, u32, struct qstr *);
  275. int hfsplus_find_cat(struct super_block *, u32, struct hfs_find_data *);
  276. int hfsplus_create_cat(u32, struct inode *, struct qstr *, struct inode *);
  277. int hfsplus_delete_cat(u32, struct inode *, struct qstr *);
  278. int hfsplus_rename_cat(u32, struct inode *, struct qstr *,
  279. struct inode *, struct qstr *);
  280. void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms);
  281. /* dir.c */
  282. extern const struct inode_operations hfsplus_dir_inode_operations;
  283. extern const struct file_operations hfsplus_dir_operations;
  284. /* extents.c */
  285. int hfsplus_ext_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
  286. void hfsplus_ext_write_extent(struct inode *);
  287. int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int);
  288. int hfsplus_free_fork(struct super_block *, u32, struct hfsplus_fork_raw *, int);
  289. int hfsplus_file_extend(struct inode *);
  290. void hfsplus_file_truncate(struct inode *);
  291. /* inode.c */
  292. extern const struct address_space_operations hfsplus_aops;
  293. extern const struct address_space_operations hfsplus_btree_aops;
  294. extern const struct dentry_operations hfsplus_dentry_operations;
  295. void hfsplus_inode_read_fork(struct inode *, struct hfsplus_fork_raw *);
  296. void hfsplus_inode_write_fork(struct inode *, struct hfsplus_fork_raw *);
  297. int hfsplus_cat_read_inode(struct inode *, struct hfs_find_data *);
  298. int hfsplus_cat_write_inode(struct inode *);
  299. struct inode *hfsplus_new_inode(struct super_block *, int);
  300. void hfsplus_delete_inode(struct inode *);
  301. int hfsplus_file_fsync(struct file *file, int datasync);
  302. /* ioctl.c */
  303. long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
  304. int hfsplus_setxattr(struct dentry *dentry, const char *name,
  305. const void *value, size_t size, int flags);
  306. ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
  307. void *value, size_t size);
  308. ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
  309. /* options.c */
  310. int hfsplus_parse_options(char *, struct hfsplus_sb_info *);
  311. int hfsplus_parse_options_remount(char *input, int *force);
  312. void hfsplus_fill_defaults(struct hfsplus_sb_info *);
  313. int hfsplus_show_options(struct seq_file *, struct vfsmount *);
  314. /* super.c */
  315. struct inode *hfsplus_iget(struct super_block *, unsigned long);
  316. int hfsplus_sync_fs(struct super_block *sb, int wait);
  317. /* tables.c */
  318. extern u16 hfsplus_case_fold_table[];
  319. extern u16 hfsplus_decompose_table[];
  320. extern u16 hfsplus_compose_table[];
  321. /* unicode.c */
  322. int hfsplus_strcasecmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *);
  323. int hfsplus_strcmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *);
  324. int hfsplus_uni2asc(struct super_block *, const struct hfsplus_unistr *, char *, int *);
  325. int hfsplus_asc2uni(struct super_block *, struct hfsplus_unistr *, const char *, int);
  326. int hfsplus_hash_dentry(struct dentry *dentry, struct qstr *str);
  327. int hfsplus_compare_dentry(struct dentry *dentry, struct qstr *s1, struct qstr *s2);
  328. /* wrapper.c */
  329. int hfsplus_read_wrapper(struct super_block *);
  330. int hfs_part_find(struct super_block *, sector_t *, sector_t *);
  331. int hfsplus_submit_bio(struct block_device *bdev, sector_t sector,
  332. void *data, int rw);
  333. /* access macros */
  334. static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
  335. {
  336. return sb->s_fs_info;
  337. }
  338. static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
  339. {
  340. return list_entry(inode, struct hfsplus_inode_info, vfs_inode);
  341. }
  342. /* time macros */
  343. #define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U)
  344. #define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U))
  345. /* compatibility */
  346. #define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) }
  347. #define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
  348. #define hfsp_now2mt() __hfsp_ut2mt(get_seconds())
  349. #endif