]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - fs/hfsplus/hfsplus_fs.h
hfsplus: add support of manipulation by attributes file
[karo-tx-linux.git] / fs / hfsplus / hfsplus_fs.h
1 /*
2  *  linux/include/linux/hfsplus_fs.h
3  *
4  * Copyright (C) 1999
5  * Brad Boyer (flar@pants.nu)
6  * (C) 2003 Ardis Technologies <roman@ardistech.com>
7  *
8  */
9
10 #ifndef _LINUX_HFSPLUS_FS_H
11 #define _LINUX_HFSPLUS_FS_H
12
13 #include <linux/fs.h>
14 #include <linux/mutex.h>
15 #include <linux/buffer_head.h>
16 #include <linux/blkdev.h>
17 #include "hfsplus_raw.h"
18
19 #define DBG_BNODE_REFS  0x00000001
20 #define DBG_BNODE_MOD   0x00000002
21 #define DBG_CAT_MOD     0x00000004
22 #define DBG_INODE       0x00000008
23 #define DBG_SUPER       0x00000010
24 #define DBG_EXTENT      0x00000020
25 #define DBG_BITMAP      0x00000040
26 #define DBG_ATTR_MOD    0x00000080
27
28 #if 0
29 #define DBG_MASK        (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
30 #define DBG_MASK        (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
31 #define DBG_MASK        (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
32 #endif
33 #define DBG_MASK        (0)
34
35 #define dprint(flg, fmt, args...) \
36         if (flg & DBG_MASK) \
37                 printk(fmt , ## args)
38
39 /* Runtime config options */
40 #define HFSPLUS_DEF_CR_TYPE    0x3F3F3F3F  /* '????' */
41
42 #define HFSPLUS_TYPE_DATA 0x00
43 #define HFSPLUS_TYPE_RSRC 0xFF
44
45 typedef int (*btree_keycmp)(const hfsplus_btree_key *,
46                 const hfsplus_btree_key *);
47
48 #define NODE_HASH_SIZE  256
49
50 /* An HFS+ BTree held in memory */
51 struct hfs_btree {
52         struct super_block *sb;
53         struct inode *inode;
54         btree_keycmp keycmp;
55
56         u32 cnid;
57         u32 root;
58         u32 leaf_count;
59         u32 leaf_head;
60         u32 leaf_tail;
61         u32 node_count;
62         u32 free_nodes;
63         u32 attributes;
64
65         unsigned int node_size;
66         unsigned int node_size_shift;
67         unsigned int max_key_len;
68         unsigned int depth;
69
70         struct mutex tree_lock;
71
72         unsigned int pages_per_bnode;
73         spinlock_t hash_lock;
74         struct hfs_bnode *node_hash[NODE_HASH_SIZE];
75         int node_hash_cnt;
76 };
77
78 struct page;
79
80 /* An HFS+ BTree node in memory */
81 struct hfs_bnode {
82         struct hfs_btree *tree;
83
84         u32 prev;
85         u32 this;
86         u32 next;
87         u32 parent;
88
89         u16 num_recs;
90         u8 type;
91         u8 height;
92
93         struct hfs_bnode *next_hash;
94         unsigned long flags;
95         wait_queue_head_t lock_wq;
96         atomic_t refcnt;
97         unsigned int page_offset;
98         struct page *page[0];
99 };
100
101 #define HFS_BNODE_LOCK          0
102 #define HFS_BNODE_ERROR         1
103 #define HFS_BNODE_NEW           2
104 #define HFS_BNODE_DIRTY         3
105 #define HFS_BNODE_DELETED       4
106
107 /*
108  * HFS+ superblock info (built from Volume Header on disk)
109  */
110
111 struct hfsplus_vh;
112 struct hfs_btree;
113
114 struct hfsplus_sb_info {
115         void *s_vhdr_buf;
116         struct hfsplus_vh *s_vhdr;
117         void *s_backup_vhdr_buf;
118         struct hfsplus_vh *s_backup_vhdr;
119         struct hfs_btree *ext_tree;
120         struct hfs_btree *cat_tree;
121         struct hfs_btree *attr_tree;
122         struct inode *alloc_file;
123         struct inode *hidden_dir;
124         struct nls_table *nls;
125
126         /* Runtime variables */
127         u32 blockoffset;
128         sector_t part_start;
129         sector_t sect_count;
130         int fs_shift;
131
132         /* immutable data from the volume header */
133         u32 alloc_blksz;
134         int alloc_blksz_shift;
135         u32 total_blocks;
136         u32 data_clump_blocks, rsrc_clump_blocks;
137
138         /* mutable data from the volume header, protected by alloc_mutex */
139         u32 free_blocks;
140         struct mutex alloc_mutex;
141
142         /* mutable data from the volume header, protected by vh_mutex */
143         u32 next_cnid;
144         u32 file_count;
145         u32 folder_count;
146         struct mutex vh_mutex;
147
148         /* Config options */
149         u32 creator;
150         u32 type;
151
152         umode_t umask;
153         kuid_t uid;
154         kgid_t gid;
155
156         int part, session;
157         unsigned long flags;
158
159         int work_queued;               /* non-zero delayed work is queued */
160         struct delayed_work sync_work; /* FS sync delayed work */
161         spinlock_t work_lock;          /* protects sync_work and work_queued */
162 };
163
164 #define HFSPLUS_SB_WRITEBACKUP  0
165 #define HFSPLUS_SB_NODECOMPOSE  1
166 #define HFSPLUS_SB_FORCE        2
167 #define HFSPLUS_SB_HFSX         3
168 #define HFSPLUS_SB_CASEFOLD     4
169 #define HFSPLUS_SB_NOBARRIER    5
170
171 static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
172 {
173         return sb->s_fs_info;
174 }
175
176
177 struct hfsplus_inode_info {
178         atomic_t opencnt;
179
180         /*
181          * Extent allocation information, protected by extents_lock.
182          */
183         u32 first_blocks;
184         u32 clump_blocks;
185         u32 alloc_blocks;
186         u32 cached_start;
187         u32 cached_blocks;
188         hfsplus_extent_rec first_extents;
189         hfsplus_extent_rec cached_extents;
190         unsigned int extent_state;
191         struct mutex extents_lock;
192
193         /*
194          * Immutable data.
195          */
196         struct inode *rsrc_inode;
197         __be32 create_date;
198
199         /*
200          * Protected by sbi->vh_mutex.
201          */
202         u32 linkid;
203
204         /*
205          * Accessed using atomic bitops.
206          */
207         unsigned long flags;
208
209         /*
210          * Protected by i_mutex.
211          */
212         sector_t fs_blocks;
213         u8 userflags;           /* BSD user file flags */
214         struct list_head open_dir_list;
215         loff_t phys_size;
216
217         struct inode vfs_inode;
218 };
219
220 #define HFSPLUS_EXT_DIRTY       0x0001
221 #define HFSPLUS_EXT_NEW         0x0002
222
223 #define HFSPLUS_I_RSRC          0       /* represents a resource fork */
224 #define HFSPLUS_I_CAT_DIRTY     1       /* has changes in the catalog tree */
225 #define HFSPLUS_I_EXT_DIRTY     2       /* has changes in the extent tree */
226 #define HFSPLUS_I_ALLOC_DIRTY   3       /* has changes in the allocation file */
227 #define HFSPLUS_I_ATTR_DIRTY    4       /* has changes in the attributes tree */
228
229 #define HFSPLUS_IS_RSRC(inode) \
230         test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
231
232 static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
233 {
234         return list_entry(inode, struct hfsplus_inode_info, vfs_inode);
235 }
236
237 /*
238  * Mark an inode dirty, and also mark the btree in which the
239  * specific type of metadata is stored.
240  * For data or metadata that gets written back by into the catalog btree
241  * by hfsplus_write_inode a plain mark_inode_dirty call is enough.
242  */
243 static inline void hfsplus_mark_inode_dirty(struct inode *inode,
244                 unsigned int flag)
245 {
246         set_bit(flag, &HFSPLUS_I(inode)->flags);
247         mark_inode_dirty(inode);
248 }
249
250 struct hfs_find_data {
251         /* filled by caller */
252         hfsplus_btree_key *search_key;
253         hfsplus_btree_key *key;
254         /* filled by find */
255         struct hfs_btree *tree;
256         struct hfs_bnode *bnode;
257         /* filled by findrec */
258         int record;
259         int keyoffset, keylength;
260         int entryoffset, entrylength;
261 };
262
263 struct hfsplus_readdir_data {
264         struct list_head list;
265         struct file *file;
266         struct hfsplus_cat_key key;
267 };
268
269 /*
270  * Find minimum acceptible I/O size for an hfsplus sb.
271  */
272 static inline unsigned short hfsplus_min_io_size(struct super_block *sb)
273 {
274         return max_t(unsigned short, bdev_logical_block_size(sb->s_bdev),
275                      HFSPLUS_SECTOR_SIZE);
276 }
277
278 #define hfs_btree_open hfsplus_btree_open
279 #define hfs_btree_close hfsplus_btree_close
280 #define hfs_btree_write hfsplus_btree_write
281 #define hfs_bmap_alloc hfsplus_bmap_alloc
282 #define hfs_bmap_free hfsplus_bmap_free
283 #define hfs_bnode_read hfsplus_bnode_read
284 #define hfs_bnode_read_u16 hfsplus_bnode_read_u16
285 #define hfs_bnode_read_u8 hfsplus_bnode_read_u8
286 #define hfs_bnode_read_key hfsplus_bnode_read_key
287 #define hfs_bnode_write hfsplus_bnode_write
288 #define hfs_bnode_write_u16 hfsplus_bnode_write_u16
289 #define hfs_bnode_clear hfsplus_bnode_clear
290 #define hfs_bnode_copy hfsplus_bnode_copy
291 #define hfs_bnode_move hfsplus_bnode_move
292 #define hfs_bnode_dump hfsplus_bnode_dump
293 #define hfs_bnode_unlink hfsplus_bnode_unlink
294 #define hfs_bnode_findhash hfsplus_bnode_findhash
295 #define hfs_bnode_find hfsplus_bnode_find
296 #define hfs_bnode_unhash hfsplus_bnode_unhash
297 #define hfs_bnode_free hfsplus_bnode_free
298 #define hfs_bnode_create hfsplus_bnode_create
299 #define hfs_bnode_get hfsplus_bnode_get
300 #define hfs_bnode_put hfsplus_bnode_put
301 #define hfs_brec_lenoff hfsplus_brec_lenoff
302 #define hfs_brec_keylen hfsplus_brec_keylen
303 #define hfs_brec_insert hfsplus_brec_insert
304 #define hfs_brec_remove hfsplus_brec_remove
305 #define hfs_find_init hfsplus_find_init
306 #define hfs_find_exit hfsplus_find_exit
307 #define __hfs_brec_find __hfsplus_brec_find
308 #define hfs_brec_find hfsplus_brec_find
309 #define hfs_brec_read hfsplus_brec_read
310 #define hfs_brec_goto hfsplus_brec_goto
311 #define hfs_part_find hfsplus_part_find
312
313 /*
314  * definitions for ext2 flag ioctls (linux really needs a generic
315  * interface for this).
316  */
317
318 /* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support
319  * chattr/lsattr */
320 #define HFSPLUS_IOC_EXT2_GETFLAGS       FS_IOC_GETFLAGS
321 #define HFSPLUS_IOC_EXT2_SETFLAGS       FS_IOC_SETFLAGS
322
323
324 /*
325  * hfs+-specific ioctl for making the filesystem bootable
326  */
327 #define HFSPLUS_IOC_BLESS _IO('h', 0x80)
328
329 typedef int (*search_strategy_t)(struct hfs_bnode *,
330                                 struct hfs_find_data *,
331                                 int *, int *, int *);
332
333 /*
334  * Functions in any *.c used in other files
335  */
336
337 /* attributes.c */
338 int hfsplus_create_attr_tree_cache(void);
339 void hfsplus_destroy_attr_tree_cache(void);
340 hfsplus_attr_entry *hfsplus_alloc_attr_entry(void);
341 void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry_p);
342 int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *,
343                 const hfsplus_btree_key *);
344 int hfsplus_attr_build_key(struct super_block *, hfsplus_btree_key *,
345                         u32, const char *);
346 void hfsplus_attr_build_key_uni(hfsplus_btree_key *key,
347                                         u32 cnid,
348                                         struct hfsplus_attr_unistr *name);
349 int hfsplus_find_attr(struct super_block *, u32,
350                         const char *, struct hfs_find_data *);
351 int hfsplus_attr_exists(struct inode *inode, const char *name);
352 int hfsplus_create_attr(struct inode *, const char *, const void *, size_t);
353 int hfsplus_delete_attr(struct inode *, const char *);
354 int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid);
355
356 /* bitmap.c */
357 int hfsplus_block_allocate(struct super_block *, u32, u32, u32 *);
358 int hfsplus_block_free(struct super_block *, u32, u32);
359
360 /* btree.c */
361 struct hfs_btree *hfs_btree_open(struct super_block *, u32);
362 void hfs_btree_close(struct hfs_btree *);
363 void hfs_btree_write(struct hfs_btree *);
364 struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *);
365 void hfs_bmap_free(struct hfs_bnode *);
366
367 /* bnode.c */
368 void hfs_bnode_read(struct hfs_bnode *, void *, int, int);
369 u16 hfs_bnode_read_u16(struct hfs_bnode *, int);
370 u8 hfs_bnode_read_u8(struct hfs_bnode *, int);
371 void hfs_bnode_read_key(struct hfs_bnode *, void *, int);
372 void hfs_bnode_write(struct hfs_bnode *, void *, int, int);
373 void hfs_bnode_write_u16(struct hfs_bnode *, int, u16);
374 void hfs_bnode_clear(struct hfs_bnode *, int, int);
375 void hfs_bnode_copy(struct hfs_bnode *, int,
376                     struct hfs_bnode *, int, int);
377 void hfs_bnode_move(struct hfs_bnode *, int, int, int);
378 void hfs_bnode_dump(struct hfs_bnode *);
379 void hfs_bnode_unlink(struct hfs_bnode *);
380 struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *, u32);
381 struct hfs_bnode *hfs_bnode_find(struct hfs_btree *, u32);
382 void hfs_bnode_unhash(struct hfs_bnode *);
383 void hfs_bnode_free(struct hfs_bnode *);
384 struct hfs_bnode *hfs_bnode_create(struct hfs_btree *, u32);
385 void hfs_bnode_get(struct hfs_bnode *);
386 void hfs_bnode_put(struct hfs_bnode *);
387
388 /* brec.c */
389 u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *);
390 u16 hfs_brec_keylen(struct hfs_bnode *, u16);
391 int hfs_brec_insert(struct hfs_find_data *, void *, int);
392 int hfs_brec_remove(struct hfs_find_data *);
393
394 /* bfind.c */
395 int hfs_find_init(struct hfs_btree *, struct hfs_find_data *);
396 void hfs_find_exit(struct hfs_find_data *);
397 int hfs_find_1st_rec_by_cnid(struct hfs_bnode *,
398                                 struct hfs_find_data *,
399                                 int *, int *, int *);
400 int hfs_find_rec_by_key(struct hfs_bnode *,
401                                 struct hfs_find_data *,
402                                 int *, int *, int *);
403 int __hfs_brec_find(struct hfs_bnode *, struct hfs_find_data *,
404                                 search_strategy_t);
405 int hfs_brec_find(struct hfs_find_data *, search_strategy_t);
406 int hfs_brec_read(struct hfs_find_data *, void *, int);
407 int hfs_brec_goto(struct hfs_find_data *, int);
408
409 /* catalog.c */
410 int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *,
411                 const hfsplus_btree_key *);
412 int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *,
413                 const hfsplus_btree_key *);
414 void hfsplus_cat_build_key(struct super_block *sb,
415                 hfsplus_btree_key *, u32, struct qstr *);
416 int hfsplus_find_cat(struct super_block *, u32, struct hfs_find_data *);
417 int hfsplus_create_cat(u32, struct inode *, struct qstr *, struct inode *);
418 int hfsplus_delete_cat(u32, struct inode *, struct qstr *);
419 int hfsplus_rename_cat(u32, struct inode *, struct qstr *,
420                        struct inode *, struct qstr *);
421 void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms);
422
423 /* dir.c */
424 extern const struct inode_operations hfsplus_dir_inode_operations;
425 extern const struct file_operations hfsplus_dir_operations;
426
427 /* extents.c */
428 int hfsplus_ext_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
429 int hfsplus_ext_write_extent(struct inode *);
430 int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int);
431 int hfsplus_free_fork(struct super_block *, u32,
432                 struct hfsplus_fork_raw *, int);
433 int hfsplus_file_extend(struct inode *);
434 void hfsplus_file_truncate(struct inode *);
435
436 /* inode.c */
437 extern const struct address_space_operations hfsplus_aops;
438 extern const struct address_space_operations hfsplus_btree_aops;
439 extern const struct dentry_operations hfsplus_dentry_operations;
440
441 void hfsplus_inode_read_fork(struct inode *, struct hfsplus_fork_raw *);
442 void hfsplus_inode_write_fork(struct inode *, struct hfsplus_fork_raw *);
443 int hfsplus_cat_read_inode(struct inode *, struct hfs_find_data *);
444 int hfsplus_cat_write_inode(struct inode *);
445 struct inode *hfsplus_new_inode(struct super_block *, umode_t);
446 void hfsplus_delete_inode(struct inode *);
447 int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
448                        int datasync);
449
450 /* ioctl.c */
451 long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
452 int hfsplus_setxattr(struct dentry *dentry, const char *name,
453                      const void *value, size_t size, int flags);
454 ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
455                          void *value, size_t size);
456 ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
457 int hfsplus_removexattr(struct dentry *dentry, const char *name);
458
459 /* options.c */
460 int hfsplus_parse_options(char *, struct hfsplus_sb_info *);
461 int hfsplus_parse_options_remount(char *input, int *force);
462 void hfsplus_fill_defaults(struct hfsplus_sb_info *);
463 int hfsplus_show_options(struct seq_file *, struct dentry *);
464
465 /* super.c */
466 struct inode *hfsplus_iget(struct super_block *, unsigned long);
467 void hfsplus_mark_mdb_dirty(struct super_block *sb);
468
469 /* tables.c */
470 extern u16 hfsplus_case_fold_table[];
471 extern u16 hfsplus_decompose_table[];
472 extern u16 hfsplus_compose_table[];
473
474 /* unicode.c */
475 int hfsplus_strcasecmp(const struct hfsplus_unistr *,
476                 const struct hfsplus_unistr *);
477 int hfsplus_strcmp(const struct hfsplus_unistr *,
478                 const struct hfsplus_unistr *);
479 int hfsplus_uni2asc(struct super_block *,
480                 const struct hfsplus_unistr *, char *, int *);
481 int hfsplus_asc2uni(struct super_block *,
482                 struct hfsplus_unistr *, int, const char *, int);
483 int hfsplus_hash_dentry(const struct dentry *dentry,
484                 const struct inode *inode, struct qstr *str);
485 int hfsplus_compare_dentry(const struct dentry *parent,
486                 const struct inode *pinode,
487                 const struct dentry *dentry, const struct inode *inode,
488                 unsigned int len, const char *str, const struct qstr *name);
489
490 /* wrapper.c */
491 int hfsplus_read_wrapper(struct super_block *);
492 int hfs_part_find(struct super_block *, sector_t *, sector_t *);
493 int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
494                 void *buf, void **data, int rw);
495
496 /* time macros */
497 #define __hfsp_mt2ut(t)         (be32_to_cpu(t) - 2082844800U)
498 #define __hfsp_ut2mt(t)         (cpu_to_be32(t + 2082844800U))
499
500 /* compatibility */
501 #define hfsp_mt2ut(t)           (struct timespec){ .tv_sec = __hfsp_mt2ut(t) }
502 #define hfsp_ut2mt(t)           __hfsp_ut2mt((t).tv_sec)
503 #define hfsp_now2mt()           __hfsp_ut2mt(get_seconds())
504
505 #endif