hfs_fs.h 8.9 KB

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