hfs_fs.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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/slab.h>
  11. #include <linux/types.h>
  12. #include <linux/mutex.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/fs.h>
  15. #include <linux/workqueue.h>
  16. #include <asm/byteorder.h>
  17. #include <linux/uaccess.h>
  18. #include "hfs.h"
  19. /*
  20. * struct hfs_inode_info
  21. *
  22. * The HFS-specific part of a Linux (struct inode)
  23. */
  24. struct hfs_inode_info {
  25. atomic_t opencnt;
  26. unsigned int flags;
  27. /* to deal with localtime ugliness */
  28. int tz_secondswest;
  29. struct hfs_cat_key cat_key;
  30. struct list_head open_dir_list;
  31. spinlock_t open_dir_lock;
  32. struct inode *rsrc_inode;
  33. struct mutex extents_lock;
  34. u16 alloc_blocks, clump_blocks;
  35. sector_t fs_blocks;
  36. /* Allocation extents from catlog record or volume header */
  37. hfs_extent_rec first_extents;
  38. u16 first_blocks;
  39. hfs_extent_rec cached_extents;
  40. u16 cached_start, cached_blocks;
  41. loff_t phys_size;
  42. struct inode vfs_inode;
  43. };
  44. #define HFS_FLG_RSRC 0x0001
  45. #define HFS_FLG_EXT_DIRTY 0x0002
  46. #define HFS_FLG_EXT_NEW 0x0004
  47. #define HFS_IS_RSRC(inode) (HFS_I(inode)->flags & HFS_FLG_RSRC)
  48. /*
  49. * struct hfs_sb_info
  50. *
  51. * The HFS-specific part of a Linux (struct super_block)
  52. */
  53. struct hfs_sb_info {
  54. struct buffer_head *mdb_bh; /* The hfs_buffer
  55. holding the real
  56. superblock (aka VIB
  57. or MDB) */
  58. struct hfs_mdb *mdb;
  59. struct buffer_head *alt_mdb_bh; /* The hfs_buffer holding
  60. the alternate superblock */
  61. struct hfs_mdb *alt_mdb;
  62. __be32 *bitmap; /* The page holding the
  63. allocation bitmap */
  64. struct hfs_btree *ext_tree; /* Information about
  65. the extents b-tree */
  66. struct hfs_btree *cat_tree; /* Information about
  67. the catalog b-tree */
  68. atomic64_t file_count; /* The number of
  69. regular files in
  70. the filesystem */
  71. atomic64_t folder_count; /* The number of
  72. directories in the
  73. filesystem */
  74. atomic64_t next_id; /* The next available
  75. file id number */
  76. u32 clumpablks; /* The number of allocation
  77. blocks to try to add when
  78. extending a file */
  79. u32 fs_start; /* The first 512-byte
  80. block represented
  81. in the bitmap */
  82. u32 part_start;
  83. u16 root_files; /* The number of
  84. regular
  85. (non-directory)
  86. files in the root
  87. directory */
  88. u16 root_dirs; /* The number of
  89. directories in the
  90. root directory */
  91. u16 fs_ablocks; /* The number of
  92. allocation blocks
  93. in the filesystem */
  94. u16 free_ablocks; /* the number of unused
  95. allocation blocks
  96. in the filesystem */
  97. u32 alloc_blksz; /* The size of an
  98. "allocation block" */
  99. int s_quiet; /* Silent failure when
  100. changing owner or mode? */
  101. __be32 s_type; /* Type for new files */
  102. __be32 s_creator; /* Creator for new files */
  103. umode_t s_file_umask; /* The umask applied to the
  104. permissions on all files */
  105. umode_t s_dir_umask; /* The umask applied to the
  106. permissions on all dirs */
  107. kuid_t s_uid; /* The uid of all files */
  108. kgid_t s_gid; /* The gid of all files */
  109. int session, part;
  110. struct nls_table *nls_io, *nls_disk;
  111. struct mutex bitmap_lock;
  112. unsigned long flags;
  113. u16 blockoffset;
  114. int fs_div;
  115. struct super_block *sb;
  116. int work_queued; /* non-zero delayed work is queued */
  117. struct delayed_work mdb_work; /* MDB flush delayed work */
  118. spinlock_t work_lock; /* protects mdb_work and work_queued */
  119. };
  120. #define HFS_FLG_BITMAP_DIRTY 0
  121. #define HFS_FLG_MDB_DIRTY 1
  122. #define HFS_FLG_ALT_MDB_DIRTY 2
  123. /* bitmap.c */
  124. extern u32 hfs_vbm_search_free(struct super_block *sb, u32 goal, u32 *num_bits);
  125. extern int hfs_clear_vbm_bits(struct super_block *sb, u16 start, u16 count);
  126. /* catalog.c */
  127. extern int hfs_cat_keycmp(const btree_key *key1, const btree_key *key2);
  128. struct hfs_find_data;
  129. extern int hfs_cat_find_brec(struct super_block *sb, u32 cnid,
  130. struct hfs_find_data *fd);
  131. extern int hfs_cat_create(u32 cnid, struct inode *dir,
  132. const struct qstr *str, struct inode *inode);
  133. extern int hfs_cat_delete(u32 cnid, struct inode *dir, const struct qstr *str);
  134. extern int hfs_cat_move(u32 cnid, struct inode *src_dir,
  135. const struct qstr *src_name,
  136. struct inode *dst_dir,
  137. const struct qstr *dst_name);
  138. extern void hfs_cat_build_key(struct super_block *sb, btree_key *key,
  139. u32 parent, const struct qstr *name);
  140. /* dir.c */
  141. extern const struct file_operations hfs_dir_operations;
  142. extern const struct inode_operations hfs_dir_inode_operations;
  143. /* extent.c */
  144. extern int hfs_ext_keycmp(const btree_key *key1, const btree_key *key2);
  145. extern u16 hfs_ext_find_block(struct hfs_extent *ext, u16 off);
  146. extern int hfs_free_fork(struct super_block *sb,
  147. struct hfs_cat_file *file, int type);
  148. extern int hfs_ext_write_extent(struct inode *inode);
  149. extern int hfs_extend_file(struct inode *inode);
  150. extern void hfs_file_truncate(struct inode *inode);
  151. extern int hfs_get_block(struct inode *inode, sector_t block,
  152. struct buffer_head *bh_result, int create);
  153. /* inode.c */
  154. extern const struct address_space_operations hfs_aops;
  155. extern const struct address_space_operations hfs_btree_aops;
  156. int hfs_write_begin(const struct kiocb *iocb, struct address_space *mapping,
  157. loff_t pos, unsigned int len, struct folio **foliop,
  158. void **fsdata);
  159. extern struct inode *hfs_new_inode(struct inode *dir, const struct qstr *name,
  160. umode_t mode);
  161. extern void hfs_inode_write_fork(struct inode *inode, struct hfs_extent *ext,
  162. __be32 *log_size, __be32 *phys_size);
  163. extern int hfs_write_inode(struct inode *inode, struct writeback_control *wbc);
  164. extern int hfs_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
  165. struct iattr *attr);
  166. extern void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
  167. __be32 __log_size, __be32 phys_size,
  168. u32 clump_size);
  169. extern struct inode *hfs_iget(struct super_block *sb, struct hfs_cat_key *key,
  170. hfs_cat_rec *rec);
  171. extern void hfs_evict_inode(struct inode *inode);
  172. extern void hfs_delete_inode(struct inode *inode);
  173. /* attr.c */
  174. extern const struct xattr_handler * const hfs_xattr_handlers[];
  175. /* mdb.c */
  176. extern bool is_hfs_cnid_counts_valid(struct super_block *sb);
  177. extern int hfs_mdb_get(struct super_block *sb);
  178. extern void hfs_mdb_commit(struct super_block *sb);
  179. extern void hfs_mdb_close(struct super_block *sb);
  180. extern void hfs_mdb_put(struct super_block *sb);
  181. /* part_tbl.c */
  182. extern int hfs_part_find(struct super_block *sb,
  183. sector_t *part_start, sector_t *part_size);
  184. /* string.c */
  185. extern const struct dentry_operations hfs_dentry_operations;
  186. extern int hfs_hash_dentry(const struct dentry *dentry, struct qstr *this);
  187. extern int hfs_strcmp(const unsigned char *s1, unsigned int len1,
  188. const unsigned char *s2, unsigned int len2);
  189. extern int hfs_compare_dentry(const struct dentry *dentry,
  190. unsigned int len, const char *str,
  191. const struct qstr *name);
  192. /* trans.c */
  193. extern void hfs_asc2mac(struct super_block *sb,
  194. struct hfs_name *out, const struct qstr *in);
  195. extern int hfs_mac2asc(struct super_block *sb,
  196. char *out, const struct hfs_name *in);
  197. /* super.c */
  198. extern void hfs_mark_mdb_dirty(struct super_block *sb);
  199. /*
  200. * There are two time systems. Both are based on seconds since
  201. * a particular time/date.
  202. * Unix: signed little-endian since 00:00 GMT, Jan. 1, 1970
  203. * mac: unsigned big-endian since 00:00 GMT, Jan. 1, 1904
  204. *
  205. * HFS implementations are highly inconsistent, this one matches the
  206. * traditional behavior of 64-bit Linux, giving the most useful
  207. * time range between 1970 and 2106, by treating any on-disk timestamp
  208. * under HFS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
  209. */
  210. #define HFS_UTC_OFFSET 2082844800U
  211. static inline time64_t __hfs_m_to_utime(__be32 mt)
  212. {
  213. time64_t ut = (u32)(be32_to_cpu(mt) - HFS_UTC_OFFSET);
  214. return ut + sys_tz.tz_minuteswest * 60;
  215. }
  216. static inline __be32 __hfs_u_to_mtime(time64_t ut)
  217. {
  218. ut -= sys_tz.tz_minuteswest * 60;
  219. return cpu_to_be32(lower_32_bits(ut) + HFS_UTC_OFFSET);
  220. }
  221. #define HFS_I(inode) (container_of(inode, struct hfs_inode_info, vfs_inode))
  222. #define HFS_SB(sb) ((struct hfs_sb_info *)(sb)->s_fs_info)
  223. #define hfs_m_to_utime(time) (struct timespec64){ .tv_sec = __hfs_m_to_utime(time) }
  224. #define hfs_u_to_mtime(time) __hfs_u_to_mtime((time).tv_sec)
  225. #define hfs_mtime() __hfs_u_to_mtime(ktime_get_real_seconds())
  226. static inline const char *hfs_mdb_name(struct super_block *sb)
  227. {
  228. return sb->s_id;
  229. }
  230. static inline void hfs_bitmap_dirty(struct super_block *sb)
  231. {
  232. set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags);
  233. hfs_mark_mdb_dirty(sb);
  234. }
  235. #define sb_bread512(sb, sec, data) ({ \
  236. struct buffer_head *__bh; \
  237. sector_t __block; \
  238. loff_t __start; \
  239. int __offset; \
  240. \
  241. __start = (loff_t)(sec) << HFS_SECTOR_SIZE_BITS;\
  242. __block = __start >> (sb)->s_blocksize_bits; \
  243. __offset = __start & ((sb)->s_blocksize - 1); \
  244. __bh = sb_bread((sb), __block); \
  245. if (likely(__bh != NULL)) \
  246. data = (void *)(__bh->b_data + __offset);\
  247. else \
  248. data = NULL; \
  249. __bh; \
  250. })
  251. #endif