hfsplus_fs.h 13 KB

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