hfs_fs.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * linux/fs/hfs/hfs_fs.h
  3. *
  4. * Copyright (C) 1995-1997 Paul H. Hargrove
  5. * (C) 2003 Ardis Technologies <roman@ardistech.com>
  6. * This file may be distributed under the terms of the GNU General Public License.
  7. */
  8. #ifndef _LINUX_HFS_FS_H
  9. #define _LINUX_HFS_FS_H
  10. #ifdef pr_fmt
  11. #undef pr_fmt
  12. #endif
  13. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14. #include <linux/slab.h>
  15. #include <linux/types.h>
  16. #include <linux/mutex.h>
  17. #include <linux/buffer_head.h>
  18. #include <linux/fs.h>
  19. #include <linux/workqueue.h>
  20. #include <asm/byteorder.h>
  21. #include <asm/uaccess.h>
  22. #include "hfs.h"
  23. #define DBG_BNODE_REFS 0x00000001
  24. #define DBG_BNODE_MOD 0x00000002
  25. #define DBG_CAT_MOD 0x00000004
  26. #define DBG_INODE 0x00000008
  27. #define DBG_SUPER 0x00000010
  28. #define DBG_EXTENT 0x00000020
  29. #define DBG_BITMAP 0x00000040
  30. //#define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD|DBG_CAT_MOD|DBG_BITMAP)
  31. //#define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
  32. //#define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
  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. /*
  45. * struct hfs_inode_info
  46. *
  47. * The HFS-specific part of a Linux (struct inode)
  48. */
  49. struct hfs_inode_info {
  50. atomic_t opencnt;
  51. unsigned int flags;
  52. /* to deal with localtime ugliness */
  53. int tz_secondswest;
  54. struct hfs_cat_key cat_key;
  55. struct list_head open_dir_list;
  56. spinlock_t open_dir_lock;
  57. struct inode *rsrc_inode;
  58. struct mutex extents_lock;
  59. u16 alloc_blocks, clump_blocks;
  60. sector_t fs_blocks;
  61. /* Allocation extents from catlog record or volume header */
  62. hfs_extent_rec first_extents;
  63. u16 first_blocks;
  64. hfs_extent_rec cached_extents;
  65. u16 cached_start, cached_blocks;
  66. loff_t phys_size;
  67. struct inode vfs_inode;
  68. };
  69. #define HFS_FLG_RSRC 0x0001
  70. #define HFS_FLG_EXT_DIRTY 0x0002
  71. #define HFS_FLG_EXT_NEW 0x0004
  72. #define HFS_IS_RSRC(inode) (HFS_I(inode)->flags & HFS_FLG_RSRC)
  73. /*
  74. * struct hfs_sb_info
  75. *
  76. * The HFS-specific part of a Linux (struct super_block)
  77. */
  78. struct hfs_sb_info {
  79. struct buffer_head *mdb_bh; /* The hfs_buffer
  80. holding the real
  81. superblock (aka VIB
  82. or MDB) */
  83. struct hfs_mdb *mdb;
  84. struct buffer_head *alt_mdb_bh; /* The hfs_buffer holding
  85. the alternate superblock */
  86. struct hfs_mdb *alt_mdb;
  87. __be32 *bitmap; /* The page holding the
  88. allocation bitmap */
  89. struct hfs_btree *ext_tree; /* Information about
  90. the extents b-tree */
  91. struct hfs_btree *cat_tree; /* Information about
  92. the catalog b-tree */
  93. u32 file_count; /* The number of
  94. regular files in
  95. the filesystem */
  96. u32 folder_count; /* The number of
  97. directories in the
  98. filesystem */
  99. u32 next_id; /* The next available
  100. file id number */
  101. u32 clumpablks; /* The number of allocation
  102. blocks to try to add when
  103. extending a file */
  104. u32 fs_start; /* The first 512-byte
  105. block represented
  106. in the bitmap */
  107. u32 part_start;
  108. u16 root_files; /* The number of
  109. regular
  110. (non-directory)
  111. files in the root
  112. directory */
  113. u16 root_dirs; /* The number of
  114. directories in the
  115. root directory */
  116. u16 fs_ablocks; /* The number of
  117. allocation blocks
  118. in the filesystem */
  119. u16 free_ablocks; /* the number of unused
  120. allocation blocks
  121. in the filesystem */
  122. u32 alloc_blksz; /* The size of an
  123. "allocation block" */
  124. int s_quiet; /* Silent failure when
  125. changing owner or mode? */
  126. __be32 s_type; /* Type for new files */
  127. __be32 s_creator; /* Creator for new files */
  128. umode_t s_file_umask; /* The umask applied to the
  129. permissions on all files */
  130. umode_t s_dir_umask; /* The umask applied to the
  131. permissions on all dirs */
  132. kuid_t s_uid; /* The uid of all files */
  133. kgid_t s_gid; /* The gid of all files */
  134. int session, part;
  135. struct nls_table *nls_io, *nls_disk;
  136. struct mutex bitmap_lock;
  137. unsigned long flags;
  138. u16 blockoffset;
  139. int fs_div;
  140. struct super_block *sb;
  141. int work_queued; /* non-zero delayed work is queued */
  142. struct delayed_work mdb_work; /* MDB flush delayed work */
  143. spinlock_t work_lock; /* protects mdb_work and work_queued */
  144. };
  145. #define HFS_FLG_BITMAP_DIRTY 0
  146. #define HFS_FLG_MDB_DIRTY 1
  147. #define HFS_FLG_ALT_MDB_DIRTY 2
  148. /* bitmap.c */
  149. extern u32 hfs_vbm_search_free(struct super_block *, u32, u32 *);
  150. extern int hfs_clear_vbm_bits(struct super_block *, u16, u16);
  151. /* catalog.c */
  152. extern int hfs_cat_keycmp(const btree_key *, const btree_key *);
  153. struct hfs_find_data;
  154. extern int hfs_cat_find_brec(struct super_block *, u32, struct hfs_find_data *);
  155. extern int hfs_cat_create(u32, struct inode *, const struct qstr *, struct inode *);
  156. extern int hfs_cat_delete(u32, struct inode *, const struct qstr *);
  157. extern int hfs_cat_move(u32, struct inode *, const struct qstr *,
  158. struct inode *, const struct qstr *);
  159. extern void hfs_cat_build_key(struct super_block *, btree_key *, u32, const struct qstr *);
  160. /* dir.c */
  161. extern const struct file_operations hfs_dir_operations;
  162. extern const struct inode_operations hfs_dir_inode_operations;
  163. /* extent.c */
  164. extern int hfs_ext_keycmp(const btree_key *, const btree_key *);
  165. extern int hfs_free_fork(struct super_block *, struct hfs_cat_file *, int);
  166. extern int hfs_ext_write_extent(struct inode *);
  167. extern int hfs_extend_file(struct inode *);
  168. extern void hfs_file_truncate(struct inode *);
  169. extern int hfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
  170. /* inode.c */
  171. extern const struct address_space_operations hfs_aops;
  172. extern const struct address_space_operations hfs_btree_aops;
  173. extern struct inode *hfs_new_inode(struct inode *, const struct qstr *, umode_t);
  174. extern void hfs_inode_write_fork(struct inode *, struct hfs_extent *, __be32 *, __be32 *);
  175. extern int hfs_write_inode(struct inode *, struct writeback_control *);
  176. extern int hfs_inode_setattr(struct dentry *, struct iattr *);
  177. extern void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
  178. __be32 log_size, __be32 phys_size, u32 clump_size);
  179. extern struct inode *hfs_iget(struct super_block *, struct hfs_cat_key *, hfs_cat_rec *);
  180. extern void hfs_evict_inode(struct inode *);
  181. extern void hfs_delete_inode(struct inode *);
  182. /* attr.c */
  183. extern const struct xattr_handler *hfs_xattr_handlers[];
  184. /* mdb.c */
  185. extern int hfs_mdb_get(struct super_block *);
  186. extern void hfs_mdb_commit(struct super_block *);
  187. extern void hfs_mdb_close(struct super_block *);
  188. extern void hfs_mdb_put(struct super_block *);
  189. /* part_tbl.c */
  190. extern int hfs_part_find(struct super_block *, sector_t *, sector_t *);
  191. /* string.c */
  192. extern const struct dentry_operations hfs_dentry_operations;
  193. extern int hfs_hash_dentry(const struct dentry *, struct qstr *);
  194. extern int hfs_strcmp(const unsigned char *, unsigned int,
  195. const unsigned char *, unsigned int);
  196. extern int hfs_compare_dentry(const struct dentry *dentry,
  197. unsigned int len, const char *str, const struct qstr *name);
  198. /* trans.c */
  199. extern void hfs_asc2mac(struct super_block *, struct hfs_name *, const struct qstr *);
  200. extern int hfs_mac2asc(struct super_block *, char *, const struct hfs_name *);
  201. /* super.c */
  202. extern void hfs_mark_mdb_dirty(struct super_block *sb);
  203. /*
  204. * There are two time systems. Both are based on seconds since
  205. * a particular time/date.
  206. * Unix: unsigned lil-endian since 00:00 GMT, Jan. 1, 1970
  207. * mac: unsigned big-endian since 00:00 GMT, Jan. 1, 1904
  208. *
  209. */
  210. #define __hfs_u_to_mtime(sec) cpu_to_be32(sec + 2082844800U - sys_tz.tz_minuteswest * 60)
  211. #define __hfs_m_to_utime(sec) (be32_to_cpu(sec) - 2082844800U + sys_tz.tz_minuteswest * 60)
  212. #define HFS_I(inode) (container_of(inode, struct hfs_inode_info, vfs_inode))
  213. #define HFS_SB(sb) ((struct hfs_sb_info *)(sb)->s_fs_info)
  214. #define hfs_m_to_utime(time) (struct timespec){ .tv_sec = __hfs_m_to_utime(time) }
  215. #define hfs_u_to_mtime(time) __hfs_u_to_mtime((time).tv_sec)
  216. #define hfs_mtime() __hfs_u_to_mtime(get_seconds())
  217. static inline const char *hfs_mdb_name(struct super_block *sb)
  218. {
  219. return sb->s_id;
  220. }
  221. static inline void hfs_bitmap_dirty(struct super_block *sb)
  222. {
  223. set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags);
  224. hfs_mark_mdb_dirty(sb);
  225. }
  226. #define sb_bread512(sb, sec, data) ({ \
  227. struct buffer_head *__bh; \
  228. sector_t __block; \
  229. loff_t __start; \
  230. int __offset; \
  231. \
  232. __start = (loff_t)(sec) << HFS_SECTOR_SIZE_BITS;\
  233. __block = __start >> (sb)->s_blocksize_bits; \
  234. __offset = __start & ((sb)->s_blocksize - 1); \
  235. __bh = sb_bread((sb), __block); \
  236. if (likely(__bh != NULL)) \
  237. data = (void *)(__bh->b_data + __offset);\
  238. else \
  239. data = NULL; \
  240. __bh; \
  241. })
  242. #endif