Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 9 | #ifndef _LINUX_HFS_FS_H |
| 10 | #define _LINUX_HFS_FS_H |
| 11 | |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 12 | #ifdef pr_fmt |
| 13 | #undef pr_fmt |
| 14 | #endif |
| 15 | |
| 16 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/slab.h> |
| 19 | #include <linux/types.h> |
Matthias Kaehlcke | 3084b72 | 2008-07-25 01:46:34 -0700 | [diff] [blame] | 20 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/buffer_head.h> |
| 22 | #include <linux/fs.h> |
Artem Bityutskiy | 5687b57 | 2012-07-12 17:28:49 +0300 | [diff] [blame] | 23 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | #include <asm/byteorder.h> |
| 26 | #include <asm/uaccess.h> |
| 27 | |
| 28 | #include "hfs.h" |
| 29 | |
| 30 | #define DBG_BNODE_REFS 0x00000001 |
| 31 | #define DBG_BNODE_MOD 0x00000002 |
| 32 | #define DBG_CAT_MOD 0x00000004 |
| 33 | #define DBG_INODE 0x00000008 |
| 34 | #define DBG_SUPER 0x00000010 |
| 35 | #define DBG_EXTENT 0x00000020 |
| 36 | #define DBG_BITMAP 0x00000040 |
| 37 | |
| 38 | //#define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD|DBG_CAT_MOD|DBG_BITMAP) |
| 39 | //#define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE) |
| 40 | //#define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT) |
| 41 | #define DBG_MASK (0) |
| 42 | |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 43 | #define hfs_dbg(flg, fmt, ...) \ |
| 44 | do { \ |
| 45 | if (DBG_##flg & DBG_MASK) \ |
| 46 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \ |
Joe Perches | c2b3e1f | 2013-04-30 15:27:54 -0700 | [diff] [blame] | 47 | } while (0) |
| 48 | |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 49 | #define hfs_dbg_cont(flg, fmt, ...) \ |
| 50 | do { \ |
| 51 | if (DBG_##flg & DBG_MASK) \ |
| 52 | pr_cont(fmt, ##__VA_ARGS__); \ |
Joe Perches | c2b3e1f | 2013-04-30 15:27:54 -0700 | [diff] [blame] | 53 | } while (0) |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* |
| 57 | * struct hfs_inode_info |
| 58 | * |
| 59 | * The HFS-specific part of a Linux (struct inode) |
| 60 | */ |
| 61 | struct hfs_inode_info { |
| 62 | atomic_t opencnt; |
| 63 | |
| 64 | unsigned int flags; |
| 65 | |
| 66 | /* to deal with localtime ugliness */ |
| 67 | int tz_secondswest; |
| 68 | |
| 69 | struct hfs_cat_key cat_key; |
| 70 | |
| 71 | struct list_head open_dir_list; |
| 72 | struct inode *rsrc_inode; |
| 73 | |
Matthias Kaehlcke | 39f8d47 | 2008-07-25 01:46:35 -0700 | [diff] [blame] | 74 | struct mutex extents_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | u16 alloc_blocks, clump_blocks; |
| 77 | sector_t fs_blocks; |
| 78 | /* Allocation extents from catlog record or volume header */ |
| 79 | hfs_extent_rec first_extents; |
| 80 | u16 first_blocks; |
| 81 | hfs_extent_rec cached_extents; |
| 82 | u16 cached_start, cached_blocks; |
| 83 | |
| 84 | loff_t phys_size; |
| 85 | struct inode vfs_inode; |
| 86 | }; |
| 87 | |
| 88 | #define HFS_FLG_RSRC 0x0001 |
| 89 | #define HFS_FLG_EXT_DIRTY 0x0002 |
| 90 | #define HFS_FLG_EXT_NEW 0x0004 |
| 91 | |
| 92 | #define HFS_IS_RSRC(inode) (HFS_I(inode)->flags & HFS_FLG_RSRC) |
| 93 | |
| 94 | /* |
| 95 | * struct hfs_sb_info |
| 96 | * |
| 97 | * The HFS-specific part of a Linux (struct super_block) |
| 98 | */ |
| 99 | struct hfs_sb_info { |
| 100 | struct buffer_head *mdb_bh; /* The hfs_buffer |
| 101 | holding the real |
| 102 | superblock (aka VIB |
| 103 | or MDB) */ |
| 104 | struct hfs_mdb *mdb; |
| 105 | struct buffer_head *alt_mdb_bh; /* The hfs_buffer holding |
| 106 | the alternate superblock */ |
| 107 | struct hfs_mdb *alt_mdb; |
| 108 | __be32 *bitmap; /* The page holding the |
| 109 | allocation bitmap */ |
| 110 | struct hfs_btree *ext_tree; /* Information about |
| 111 | the extents b-tree */ |
| 112 | struct hfs_btree *cat_tree; /* Information about |
| 113 | the catalog b-tree */ |
| 114 | u32 file_count; /* The number of |
| 115 | regular files in |
| 116 | the filesystem */ |
| 117 | u32 folder_count; /* The number of |
| 118 | directories in the |
| 119 | filesystem */ |
| 120 | u32 next_id; /* The next available |
| 121 | file id number */ |
| 122 | u32 clumpablks; /* The number of allocation |
| 123 | blocks to try to add when |
| 124 | extending a file */ |
| 125 | u32 fs_start; /* The first 512-byte |
| 126 | block represented |
| 127 | in the bitmap */ |
| 128 | u32 part_start; |
| 129 | u16 root_files; /* The number of |
| 130 | regular |
| 131 | (non-directory) |
| 132 | files in the root |
| 133 | directory */ |
| 134 | u16 root_dirs; /* The number of |
| 135 | directories in the |
| 136 | root directory */ |
| 137 | u16 fs_ablocks; /* The number of |
| 138 | allocation blocks |
| 139 | in the filesystem */ |
| 140 | u16 free_ablocks; /* the number of unused |
| 141 | allocation blocks |
| 142 | in the filesystem */ |
| 143 | u32 alloc_blksz; /* The size of an |
| 144 | "allocation block" */ |
| 145 | int s_quiet; /* Silent failure when |
| 146 | changing owner or mode? */ |
| 147 | __be32 s_type; /* Type for new files */ |
| 148 | __be32 s_creator; /* Creator for new files */ |
| 149 | umode_t s_file_umask; /* The umask applied to the |
| 150 | permissions on all files */ |
| 151 | umode_t s_dir_umask; /* The umask applied to the |
| 152 | permissions on all dirs */ |
Eric W. Biederman | 43b5e4c | 2012-02-07 16:26:59 -0800 | [diff] [blame] | 153 | kuid_t s_uid; /* The uid of all files */ |
| 154 | kgid_t s_gid; /* The gid of all files */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | int session, part; |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 157 | struct nls_table *nls_io, *nls_disk; |
Matthias Kaehlcke | 3084b72 | 2008-07-25 01:46:34 -0700 | [diff] [blame] | 158 | struct mutex bitmap_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | u16 blockoffset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | int fs_div; |
Artem Bityutskiy | b16ca62 | 2012-07-12 17:28:48 +0300 | [diff] [blame] | 162 | struct super_block *sb; |
Artem Bityutskiy | 5687b57 | 2012-07-12 17:28:49 +0300 | [diff] [blame] | 163 | int work_queued; /* non-zero delayed work is queued */ |
| 164 | struct delayed_work mdb_work; /* MDB flush delayed work */ |
| 165 | spinlock_t work_lock; /* protects mdb_work and work_queued */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | #define HFS_FLG_BITMAP_DIRTY 0 |
| 169 | #define HFS_FLG_MDB_DIRTY 1 |
| 170 | #define HFS_FLG_ALT_MDB_DIRTY 2 |
| 171 | |
| 172 | /* bitmap.c */ |
| 173 | extern u32 hfs_vbm_search_free(struct super_block *, u32, u32 *); |
| 174 | extern int hfs_clear_vbm_bits(struct super_block *, u16, u16); |
| 175 | |
| 176 | /* catalog.c */ |
| 177 | extern int hfs_cat_keycmp(const btree_key *, const btree_key *); |
| 178 | struct hfs_find_data; |
| 179 | extern int hfs_cat_find_brec(struct super_block *, u32, struct hfs_find_data *); |
| 180 | extern int hfs_cat_create(u32, struct inode *, struct qstr *, struct inode *); |
| 181 | extern int hfs_cat_delete(u32, struct inode *, struct qstr *); |
| 182 | extern int hfs_cat_move(u32, struct inode *, struct qstr *, |
| 183 | struct inode *, struct qstr *); |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 184 | extern void hfs_cat_build_key(struct super_block *, btree_key *, u32, struct qstr *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | /* dir.c */ |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 187 | extern const struct file_operations hfs_dir_operations; |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 188 | extern const struct inode_operations hfs_dir_inode_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | /* extent.c */ |
| 191 | extern int hfs_ext_keycmp(const btree_key *, const btree_key *); |
| 192 | extern int hfs_free_fork(struct super_block *, struct hfs_cat_file *, int); |
Alexey Khoroshilov | 9509f17 | 2013-04-30 15:27:52 -0700 | [diff] [blame] | 193 | extern int hfs_ext_write_extent(struct inode *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | extern int hfs_extend_file(struct inode *); |
| 195 | extern void hfs_file_truncate(struct inode *); |
| 196 | |
| 197 | extern int hfs_get_block(struct inode *, sector_t, struct buffer_head *, int); |
| 198 | |
| 199 | /* inode.c */ |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 200 | extern const struct address_space_operations hfs_aops; |
| 201 | extern const struct address_space_operations hfs_btree_aops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Al Viro | e021d7b | 2011-07-26 03:26:05 -0400 | [diff] [blame] | 203 | extern struct inode *hfs_new_inode(struct inode *, struct qstr *, umode_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | extern void hfs_inode_write_fork(struct inode *, struct hfs_extent *, __be32 *, __be32 *); |
Christoph Hellwig | a9185b4 | 2010-03-05 09:21:37 +0100 | [diff] [blame] | 205 | extern int hfs_write_inode(struct inode *, struct writeback_control *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | extern int hfs_inode_setattr(struct dentry *, struct iattr *); |
| 207 | extern void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext, |
| 208 | __be32 log_size, __be32 phys_size, u32 clump_size); |
| 209 | extern struct inode *hfs_iget(struct super_block *, struct hfs_cat_key *, hfs_cat_rec *); |
Al Viro | b57922d | 2010-06-07 14:34:48 -0400 | [diff] [blame] | 210 | extern void hfs_evict_inode(struct inode *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | extern void hfs_delete_inode(struct inode *); |
| 212 | |
| 213 | /* attr.c */ |
| 214 | extern int hfs_setxattr(struct dentry *dentry, const char *name, |
| 215 | const void *value, size_t size, int flags); |
| 216 | extern ssize_t hfs_getxattr(struct dentry *dentry, const char *name, |
| 217 | void *value, size_t size); |
| 218 | extern ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size); |
| 219 | |
| 220 | /* mdb.c */ |
| 221 | extern int hfs_mdb_get(struct super_block *); |
| 222 | extern void hfs_mdb_commit(struct super_block *); |
| 223 | extern void hfs_mdb_close(struct super_block *); |
| 224 | extern void hfs_mdb_put(struct super_block *); |
| 225 | |
| 226 | /* part_tbl.c */ |
| 227 | extern int hfs_part_find(struct super_block *, sector_t *, sector_t *); |
| 228 | |
| 229 | /* string.c */ |
Al Viro | e16404e | 2009-02-20 05:55:13 +0000 | [diff] [blame] | 230 | extern const struct dentry_operations hfs_dentry_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Linus Torvalds | da53be1 | 2013-05-21 15:22:44 -0700 | [diff] [blame] | 232 | extern int hfs_hash_dentry(const struct dentry *, struct qstr *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | extern int hfs_strcmp(const unsigned char *, unsigned int, |
| 234 | const unsigned char *, unsigned int); |
Linus Torvalds | da53be1 | 2013-05-21 15:22:44 -0700 | [diff] [blame] | 235 | extern int hfs_compare_dentry(const struct dentry *parent, const struct dentry *dentry, |
Nick Piggin | 621e155 | 2011-01-07 17:49:27 +1100 | [diff] [blame] | 236 | unsigned int len, const char *str, const struct qstr *name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | /* trans.c */ |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 239 | extern void hfs_asc2mac(struct super_block *, struct hfs_name *, struct qstr *); |
| 240 | extern int hfs_mac2asc(struct super_block *, char *, const struct hfs_name *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Artem Bityutskiy | 5687b57 | 2012-07-12 17:28:49 +0300 | [diff] [blame] | 242 | /* super.c */ |
| 243 | extern void hfs_mark_mdb_dirty(struct super_block *sb); |
| 244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | /* |
| 246 | * There are two time systems. Both are based on seconds since |
| 247 | * a particular time/date. |
| 248 | * Unix: unsigned lil-endian since 00:00 GMT, Jan. 1, 1970 |
| 249 | * mac: unsigned big-endian since 00:00 GMT, Jan. 1, 1904 |
| 250 | * |
| 251 | */ |
| 252 | #define __hfs_u_to_mtime(sec) cpu_to_be32(sec + 2082844800U - sys_tz.tz_minuteswest * 60) |
| 253 | #define __hfs_m_to_utime(sec) (be32_to_cpu(sec) - 2082844800U + sys_tz.tz_minuteswest * 60) |
| 254 | |
| 255 | #define HFS_I(inode) (list_entry(inode, struct hfs_inode_info, vfs_inode)) |
| 256 | #define HFS_SB(sb) ((struct hfs_sb_info *)(sb)->s_fs_info) |
| 257 | |
| 258 | #define hfs_m_to_utime(time) (struct timespec){ .tv_sec = __hfs_m_to_utime(time) } |
| 259 | #define hfs_u_to_mtime(time) __hfs_u_to_mtime((time).tv_sec) |
| 260 | #define hfs_mtime() __hfs_u_to_mtime(get_seconds()) |
| 261 | |
| 262 | static inline const char *hfs_mdb_name(struct super_block *sb) |
| 263 | { |
| 264 | return sb->s_id; |
| 265 | } |
| 266 | |
| 267 | static inline void hfs_bitmap_dirty(struct super_block *sb) |
| 268 | { |
| 269 | set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags); |
Artem Bityutskiy | 5687b57 | 2012-07-12 17:28:49 +0300 | [diff] [blame] | 270 | hfs_mark_mdb_dirty(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | #define sb_bread512(sb, sec, data) ({ \ |
| 274 | struct buffer_head *__bh; \ |
| 275 | sector_t __block; \ |
| 276 | loff_t __start; \ |
| 277 | int __offset; \ |
| 278 | \ |
| 279 | __start = (loff_t)(sec) << HFS_SECTOR_SIZE_BITS;\ |
| 280 | __block = __start >> (sb)->s_blocksize_bits; \ |
| 281 | __offset = __start & ((sb)->s_blocksize - 1); \ |
| 282 | __bh = sb_bread((sb), __block); \ |
| 283 | if (likely(__bh != NULL)) \ |
| 284 | data = (void *)(__bh->b_data + __offset);\ |
| 285 | else \ |
| 286 | data = NULL; \ |
| 287 | __bh; \ |
| 288 | }) |
| 289 | |
| 290 | #endif |