hfs_fs.h 8.5 KB

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