hfsplus_fs.h 15 KB

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