hfsplus_fs.h 12 KB

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