hfsplus_fs.h 15 KB

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