hfsplus_fs.h 13 KB

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