1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef _OCFS2_FS_H
26#define _OCFS2_FS_H
27
28#include <linux/magic.h>
29
30
31#define OCFS2_MAJOR_REV_LEVEL 0
32#define OCFS2_MINOR_REV_LEVEL 90
33
34
35
36
37
38
39
40
41
42
43
44
45#define OCFS2_SUPER_BLOCK_BLKNO 2
46
47
48
49
50
51#define OCFS2_MIN_CLUSTERSIZE 4096
52#define OCFS2_MAX_CLUSTERSIZE 1048576
53
54
55
56
57
58#define OCFS2_MIN_BLOCKSIZE 512
59#define OCFS2_MAX_BLOCKSIZE OCFS2_MIN_CLUSTERSIZE
60
61
62#define OCFS2_SUPER_BLOCK_SIGNATURE "OCFSV2"
63#define OCFS2_INODE_SIGNATURE "INODE01"
64#define OCFS2_EXTENT_BLOCK_SIGNATURE "EXBLK01"
65#define OCFS2_GROUP_DESC_SIGNATURE "GROUP01"
66#define OCFS2_XATTR_BLOCK_SIGNATURE "XATTR01"
67#define OCFS2_DIR_TRAILER_SIGNATURE "DIRTRL1"
68#define OCFS2_DX_ROOT_SIGNATURE "DXDIR01"
69#define OCFS2_DX_LEAF_SIGNATURE "DXLEAF1"
70#define OCFS2_REFCOUNT_BLOCK_SIGNATURE "REFCNT1"
71
72
73#define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \
74 ( OCFS2_SB(sb)->s_feature_compat & (mask) )
75#define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \
76 ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
77#define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \
78 ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
79#define OCFS2_SET_COMPAT_FEATURE(sb,mask) \
80 OCFS2_SB(sb)->s_feature_compat |= (mask)
81#define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \
82 OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
83#define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \
84 OCFS2_SB(sb)->s_feature_incompat |= (mask)
85#define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \
86 OCFS2_SB(sb)->s_feature_compat &= ~(mask)
87#define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
88 OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
89#define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
90 OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
91
92#define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \
93 | OCFS2_FEATURE_COMPAT_JBD2_SB)
94#define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
95 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
96 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
97 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
98 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
99 | OCFS2_FEATURE_INCOMPAT_XATTR \
100 | OCFS2_FEATURE_INCOMPAT_META_ECC \
101 | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS \
102 | OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE \
103 | OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG \
104 | OCFS2_FEATURE_INCOMPAT_CLUSTERINFO \
105 | OCFS2_FEATURE_INCOMPAT_APPEND_DIO)
106#define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
107 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
108 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
109
110
111
112
113
114
115#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
116
117
118
119
120
121
122#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
123
124
125#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
126
127
128#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
129
130
131
132
133
134
135
136
137
138
139#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
140
141
142#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
143
144
145
146
147
148
149
150
151
152
153#define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
154
155
156#define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
157
158
159#define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200
160
161
162#define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400
163
164
165#define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800
166
167
168#define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE 0x1000
169
170
171#define OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG 0x2000
172
173
174
175
176
177
178#define OCFS2_FEATURE_INCOMPAT_CLUSTERINFO 0x4000
179
180
181
182
183#define OCFS2_FEATURE_INCOMPAT_APPEND_DIO 0x8000
184
185
186
187
188
189#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
190
191
192
193
194#define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
195
196
197
198
199#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
200
201
202
203
204#define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
205#define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
206
207
208
209
210
211#define OCFS2_BACKUP_SB_START 1 << 30
212
213
214#define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
215
216
217
218
219#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001
220
221
222
223
224#define OCFS2_VALID_FL (0x00000001)
225#define OCFS2_UNUSED2_FL (0x00000002)
226#define OCFS2_ORPHANED_FL (0x00000004)
227#define OCFS2_UNUSED3_FL (0x00000008)
228
229#define OCFS2_SYSTEM_FL (0x00000010)
230#define OCFS2_SUPER_BLOCK_FL (0x00000020)
231#define OCFS2_LOCAL_ALLOC_FL (0x00000040)
232#define OCFS2_BITMAP_FL (0x00000080)
233#define OCFS2_JOURNAL_FL (0x00000100)
234#define OCFS2_HEARTBEAT_FL (0x00000200)
235#define OCFS2_CHAIN_FL (0x00000400)
236#define OCFS2_DEALLOC_FL (0x00000800)
237#define OCFS2_QUOTA_FL (0x00001000)
238#define OCFS2_DIO_ORPHANED_FL (0X00002000)
239
240
241
242
243
244
245
246
247#define OCFS2_INLINE_DATA_FL (0x0001)
248#define OCFS2_HAS_XATTR_FL (0x0002)
249#define OCFS2_INLINE_XATTR_FL (0x0004)
250#define OCFS2_INDEXED_DIR_FL (0x0008)
251#define OCFS2_HAS_REFCOUNT_FL (0x0010)
252
253
254#define OCFS2_SECRM_FL FS_SECRM_FL
255#define OCFS2_UNRM_FL FS_UNRM_FL
256#define OCFS2_COMPR_FL FS_COMPR_FL
257#define OCFS2_SYNC_FL FS_SYNC_FL
258#define OCFS2_IMMUTABLE_FL FS_IMMUTABLE_FL
259#define OCFS2_APPEND_FL FS_APPEND_FL
260#define OCFS2_NODUMP_FL FS_NODUMP_FL
261#define OCFS2_NOATIME_FL FS_NOATIME_FL
262
263#define OCFS2_DIRTY_FL FS_DIRTY_FL
264#define OCFS2_COMPRBLK_FL FS_COMPRBLK_FL
265#define OCFS2_NOCOMP_FL FS_NOCOMP_FL
266#define OCFS2_ECOMPR_FL FS_ECOMPR_FL
267
268#define OCFS2_BTREE_FL FS_BTREE_FL
269#define OCFS2_INDEX_FL FS_INDEX_FL
270#define OCFS2_IMAGIC_FL FS_IMAGIC_FL
271#define OCFS2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL
272#define OCFS2_NOTAIL_FL FS_NOTAIL_FL
273#define OCFS2_DIRSYNC_FL FS_DIRSYNC_FL
274#define OCFS2_TOPDIR_FL FS_TOPDIR_FL
275#define OCFS2_RESERVED_FL FS_RESERVED_FL
276
277#define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE
278#define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE
279
280
281
282
283#define OCFS2_EXT_UNWRITTEN (0x01)
284
285#define OCFS2_EXT_REFCOUNTED (0x02)
286
287
288
289
290
291
292#define OCFS2_JOURNAL_DIRTY_FL (0x00000001)
293
294
295
296
297#define OCFS2_ERROR_FS (0x00000001)
298
299
300#define OCFS2_MAX_FILENAME_LEN 255
301
302
303#define OCFS2_MAX_SLOTS 255
304
305
306#define OCFS2_INVALID_SLOT -1
307
308#define OCFS2_VOL_UUID_LEN 16
309#define OCFS2_MAX_VOL_LABEL_LEN 64
310
311
312#define OCFS2_STACK_LABEL_LEN 4
313#define OCFS2_CLUSTER_NAME_LEN 16
314
315
316#define OCFS2_CLASSIC_CLUSTER_STACK "o2cb"
317
318
319#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
320
321
322
323
324
325#define OCFS2_MIN_XATTR_INLINE_SIZE 256
326
327
328
329
330#define OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT (0x01)
331
332struct ocfs2_system_inode_info {
333 char *si_name;
334 int si_iflags;
335 int si_mode;
336};
337
338
339enum {
340 BAD_BLOCK_SYSTEM_INODE = 0,
341 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
342 SLOT_MAP_SYSTEM_INODE,
343#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
344 HEARTBEAT_SYSTEM_INODE,
345 GLOBAL_BITMAP_SYSTEM_INODE,
346 USER_QUOTA_SYSTEM_INODE,
347 GROUP_QUOTA_SYSTEM_INODE,
348#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
349#define OCFS2_FIRST_LOCAL_SYSTEM_INODE ORPHAN_DIR_SYSTEM_INODE
350 ORPHAN_DIR_SYSTEM_INODE,
351 EXTENT_ALLOC_SYSTEM_INODE,
352 INODE_ALLOC_SYSTEM_INODE,
353 JOURNAL_SYSTEM_INODE,
354 LOCAL_ALLOC_SYSTEM_INODE,
355 TRUNCATE_LOG_SYSTEM_INODE,
356 LOCAL_USER_QUOTA_SYSTEM_INODE,
357 LOCAL_GROUP_QUOTA_SYSTEM_INODE,
358#define OCFS2_LAST_LOCAL_SYSTEM_INODE LOCAL_GROUP_QUOTA_SYSTEM_INODE
359 NUM_SYSTEM_INODES
360};
361#define NUM_GLOBAL_SYSTEM_INODES OCFS2_FIRST_LOCAL_SYSTEM_INODE
362#define NUM_LOCAL_SYSTEM_INODES \
363 (NUM_SYSTEM_INODES - OCFS2_FIRST_LOCAL_SYSTEM_INODE)
364
365static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
366
367
368 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
369 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
370
371
372 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
373 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
374 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
375 [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
376 [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
377
378
379 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
380 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
381 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
382 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
383 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
384 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
385 [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
386 [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
387};
388
389
390#define OCFS2_HB_NONE "heartbeat=none"
391#define OCFS2_HB_LOCAL "heartbeat=local"
392#define OCFS2_HB_GLOBAL "heartbeat=global"
393
394
395
396
397
398#define OCFS2_FT_UNKNOWN 0
399#define OCFS2_FT_REG_FILE 1
400#define OCFS2_FT_DIR 2
401#define OCFS2_FT_CHRDEV 3
402#define OCFS2_FT_BLKDEV 4
403#define OCFS2_FT_FIFO 5
404#define OCFS2_FT_SOCK 6
405#define OCFS2_FT_SYMLINK 7
406
407#define OCFS2_FT_MAX 8
408
409
410
411
412
413
414#define OCFS2_DIR_PAD 4
415#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
416#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
417#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
418 OCFS2_DIR_ROUND) & \
419 ~OCFS2_DIR_ROUND)
420#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
421
422#define OCFS2_LINK_MAX 32000
423#define OCFS2_DX_LINK_MAX ((1U << 31) - 1U)
424#define OCFS2_LINKS_HI_SHIFT 16
425#define OCFS2_DX_ENTRIES_MAX (0xffffffffU)
426
427#define S_SHIFT 12
428static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
429 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
430 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
431 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
432 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
433 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
434 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
435 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
436};
437
438
439
440
441
442#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
443
444
445
446
447
448
449struct ocfs2_block_check {
450 __le32 bc_crc32e;
451 __le16 bc_ecc;
452
453
454
455
456 __le16 bc_reserved1;
457
458};
459
460
461
462
463
464
465
466
467struct ocfs2_extent_rec {
468 __le32 e_cpos;
469 union {
470 __le32 e_int_clusters;
471 struct {
472 __le16 e_leaf_clusters;
473
474 __u8 e_reserved1;
475 __u8 e_flags;
476 };
477 };
478 __le64 e_blkno;
479
480};
481
482struct ocfs2_chain_rec {
483 __le32 c_free;
484 __le32 c_total;
485 __le64 c_blkno;
486};
487
488struct ocfs2_truncate_rec {
489 __le32 t_start;
490 __le32 t_clusters;
491};
492
493
494
495
496
497
498
499struct ocfs2_extent_list {
500 __le16 l_tree_depth;
501
502
503
504
505
506
507 __le16 l_count;
508 __le16 l_next_free_rec;
509 __le16 l_reserved1;
510 __le64 l_reserved2;
511
512 struct ocfs2_extent_rec l_recs[0];
513};
514
515
516
517
518
519
520struct ocfs2_chain_list {
521 __le16 cl_cpg;
522 __le16 cl_bpc;
523 __le16 cl_count;
524 __le16 cl_next_free_rec;
525 __le64 cl_reserved1;
526 struct ocfs2_chain_rec cl_recs[0];
527};
528
529
530
531
532
533
534struct ocfs2_truncate_log {
535 __le16 tl_count;
536 __le16 tl_used;
537 __le32 tl_reserved1;
538 struct ocfs2_truncate_rec tl_recs[0];
539};
540
541
542
543
544struct ocfs2_extent_block
545{
546 __u8 h_signature[8];
547 struct ocfs2_block_check h_check;
548 __le16 h_suballoc_slot;
549
550 __le16 h_suballoc_bit;
551
552 __le32 h_fs_generation;
553 __le64 h_blkno;
554 __le64 h_suballoc_loc;
555
556
557
558 __le64 h_next_leaf_blk;
559
560
561 struct ocfs2_extent_list h_list;
562
563};
564
565
566
567
568
569
570struct ocfs2_slot_map {
571 __le16 sm_slots[0];
572
573
574
575
576};
577
578struct ocfs2_extended_slot {
579 __u8 es_valid;
580 __u8 es_reserved1[3];
581 __le32 es_node_num;
582
583};
584
585
586
587
588
589
590
591struct ocfs2_slot_map_extended {
592 struct ocfs2_extended_slot se_slots[0];
593
594
595
596
597};
598
599
600
601
602
603struct ocfs2_cluster_info {
604 __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
605 union {
606 __le32 ci_reserved;
607 struct {
608 __u8 ci_stackflags;
609 __u8 ci_reserved1;
610 __u8 ci_reserved2;
611 __u8 ci_reserved3;
612 };
613 };
614 __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
615
616};
617
618
619
620
621
622
623struct ocfs2_super_block {
624 __le16 s_major_rev_level;
625 __le16 s_minor_rev_level;
626 __le16 s_mnt_count;
627 __le16 s_max_mnt_count;
628 __le16 s_state;
629 __le16 s_errors;
630 __le32 s_checkinterval;
631 __le64 s_lastcheck;
632 __le32 s_creator_os;
633 __le32 s_feature_compat;
634 __le32 s_feature_incompat;
635 __le32 s_feature_ro_compat;
636 __le64 s_root_blkno;
637
638 __le64 s_system_dir_blkno;
639
640 __le32 s_blocksize_bits;
641 __le32 s_clustersize_bits;
642 __le16 s_max_slots;
643
644 __le16 s_tunefs_flag;
645 __le32 s_uuid_hash;
646 __le64 s_first_cluster_group;
647
648 __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN];
649 __u8 s_uuid[OCFS2_VOL_UUID_LEN];
650 struct ocfs2_cluster_info s_cluster_info;
651
652
653 __le16 s_xattr_inline_size;
654
655 __le16 s_reserved0;
656 __le32 s_dx_seed[3];
657
658 __le64 s_reserved2[15];
659
660
661
662
663
664
665
666
667
668
669};
670
671
672
673
674
675
676struct ocfs2_local_alloc
677{
678 __le32 la_bm_off;
679 __le16 la_size;
680 __le16 la_reserved1;
681 __le64 la_reserved2;
682 __u8 la_bitmap[0];
683};
684
685
686
687
688
689struct ocfs2_inline_data
690{
691 __le16 id_count;
692
693 __le16 id_reserved0;
694 __le32 id_reserved1;
695 __u8 id_data[0];
696};
697
698
699
700
701struct ocfs2_dinode {
702 __u8 i_signature[8];
703 __le32 i_generation;
704 __le16 i_suballoc_slot;
705
706 __le16 i_suballoc_bit;
707
708 __le16 i_links_count_hi;
709 __le16 i_xattr_inline_size;
710 __le32 i_clusters;
711 __le32 i_uid;
712 __le32 i_gid;
713 __le64 i_size;
714 __le16 i_mode;
715 __le16 i_links_count;
716 __le32 i_flags;
717 __le64 i_atime;
718 __le64 i_ctime;
719 __le64 i_mtime;
720 __le64 i_dtime;
721 __le64 i_blkno;
722 __le64 i_last_eb_blk;
723
724 __le32 i_fs_generation;
725 __le32 i_atime_nsec;
726 __le32 i_ctime_nsec;
727 __le32 i_mtime_nsec;
728 __le32 i_attr;
729 __le16 i_orphaned_slot;
730
731 __le16 i_dyn_features;
732 __le64 i_xattr_loc;
733 struct ocfs2_block_check i_check;
734 __le64 i_dx_root;
735 __le64 i_refcount_loc;
736 __le64 i_suballoc_loc;
737
738
739
740 __le16 i_dio_orphaned_slot;
741 __le16 i_reserved1[3];
742 __le64 i_reserved2[2];
743 union {
744 __le64 i_pad1;
745
746 struct {
747 __le64 i_rdev;
748 } dev1;
749 struct {
750
751 __le32 i_used;
752 __le32 i_total;
753
754 } bitmap1;
755 struct {
756
757 __le32 ij_flags;
758 __le32 ij_recovery_generation;
759
760
761
762 } journal1;
763 } id1;
764 union {
765 struct ocfs2_super_block i_super;
766 struct ocfs2_local_alloc i_lab;
767 struct ocfs2_chain_list i_chain;
768 struct ocfs2_extent_list i_list;
769 struct ocfs2_truncate_log i_dealloc;
770 struct ocfs2_inline_data i_data;
771 __u8 i_symlink[0];
772 } id2;
773
774};
775
776
777
778
779
780
781struct ocfs2_dir_entry {
782 __le64 inode;
783 __le16 rec_len;
784 __u8 name_len;
785 __u8 file_type;
786 char name[OCFS2_MAX_FILENAME_LEN];
787
788} __attribute__ ((packed));
789
790
791
792
793
794
795
796
797
798struct ocfs2_dir_block_trailer {
799 __le64 db_compat_inode;
800
801 __le16 db_compat_rec_len;
802
803 __u8 db_compat_name_len;
804 __u8 db_reserved0;
805 __le16 db_reserved1;
806 __le16 db_free_rec_len;
807
808 __u8 db_signature[8];
809 __le64 db_reserved2;
810 __le64 db_free_next;
811 __le64 db_blkno;
812 __le64 db_parent_dinode;
813
814 struct ocfs2_block_check db_check;
815
816};
817
818
819
820
821
822
823
824
825struct ocfs2_dx_entry {
826 __le32 dx_major_hash;
827
828 __le32 dx_minor_hash;
829
830 __le64 dx_dirent_blk;
831
832};
833
834struct ocfs2_dx_entry_list {
835 __le32 de_reserved;
836 __le16 de_count;
837
838 __le16 de_num_used;
839
840 struct ocfs2_dx_entry de_entries[0];
841
842
843};
844
845#define OCFS2_DX_FLAG_INLINE 0x01
846
847
848
849
850
851
852
853
854struct ocfs2_dx_root_block {
855 __u8 dr_signature[8];
856 struct ocfs2_block_check dr_check;
857 __le16 dr_suballoc_slot;
858
859 __le16 dr_suballoc_bit;
860
861 __le32 dr_fs_generation;
862 __le64 dr_blkno;
863 __le64 dr_last_eb_blk;
864
865 __le32 dr_clusters;
866
867 __u8 dr_flags;
868 __u8 dr_reserved0;
869 __le16 dr_reserved1;
870 __le64 dr_dir_blkno;
871 __le32 dr_num_entries;
872
873
874 __le32 dr_reserved2;
875 __le64 dr_free_blk;
876
877 __le64 dr_suballoc_loc;
878
879
880
881
882 __le64 dr_reserved3[14];
883 union {
884 struct ocfs2_extent_list dr_list;
885
886
887 struct ocfs2_dx_entry_list dr_entries;
888
889
890
891 };
892};
893
894
895
896
897struct ocfs2_dx_leaf {
898 __u8 dl_signature[8];
899 struct ocfs2_block_check dl_check;
900 __le64 dl_blkno;
901 __le32 dl_fs_generation;
902 __le32 dl_reserved0;
903 __le64 dl_reserved1;
904 struct ocfs2_dx_entry_list dl_list;
905};
906
907
908
909
910
911
912#define OCFS2_MAX_BG_BITMAP_SIZE 256
913
914
915
916
917struct ocfs2_group_desc
918{
919 __u8 bg_signature[8];
920 __le16 bg_size;
921
922 __le16 bg_bits;
923
924 __le16 bg_free_bits_count;
925 __le16 bg_chain;
926 __le32 bg_generation;
927 __le32 bg_reserved1;
928 __le64 bg_next_group;
929
930 __le64 bg_parent_dinode;
931
932 __le64 bg_blkno;
933 struct ocfs2_block_check bg_check;
934 __le64 bg_reserved2;
935 union {
936 __u8 bg_bitmap[0];
937 struct {
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953 __u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE];
954 struct ocfs2_extent_list bg_list;
955 };
956 };
957
958};
959
960struct ocfs2_refcount_rec {
961 __le64 r_cpos;
962 __le32 r_clusters;
963 __le32 r_refcount;
964
965};
966#define OCFS2_32BIT_POS_MASK (0xffffffffULL)
967
968#define OCFS2_REFCOUNT_LEAF_FL (0x00000001)
969#define OCFS2_REFCOUNT_TREE_FL (0x00000002)
970
971struct ocfs2_refcount_list {
972 __le16 rl_count;
973
974 __le16 rl_used;
975 __le32 rl_reserved2;
976 __le64 rl_reserved1;
977 struct ocfs2_refcount_rec rl_recs[0];
978};
979
980
981struct ocfs2_refcount_block {
982 __u8 rf_signature[8];
983 __le16 rf_suballoc_slot;
984
985 __le16 rf_suballoc_bit;
986
987 __le32 rf_fs_generation;
988 __le64 rf_blkno;
989 __le64 rf_parent;
990
991
992 struct ocfs2_block_check rf_check;
993 __le64 rf_last_eb_blk;
994 __le32 rf_count;
995
996 __le32 rf_flags;
997 __le32 rf_clusters;
998 __le32 rf_cpos;
999 __le32 rf_generation;
1000
1001 __le32 rf_reserved0;
1002 __le64 rf_suballoc_loc;
1003
1004
1005
1006 __le64 rf_reserved1[6];
1007 union {
1008 struct ocfs2_refcount_list rf_records;
1009
1010 struct ocfs2_extent_list rf_list;
1011
1012
1013
1014 };
1015
1016};
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027struct ocfs2_xattr_entry {
1028 __le32 xe_name_hash;
1029 __le16 xe_name_offset;
1030
1031
1032 __u8 xe_name_len;
1033 __u8 xe_type;
1034
1035
1036 __le64 xe_value_size;
1037};
1038
1039
1040
1041
1042
1043
1044
1045struct ocfs2_xattr_header {
1046 __le16 xh_count;
1047
1048
1049 __le16 xh_free_start;
1050
1051 __le16 xh_name_value_len;
1052
1053 __le16 xh_num_buckets;
1054
1055
1056
1057 struct ocfs2_block_check xh_check;
1058
1059
1060
1061
1062
1063 struct ocfs2_xattr_entry xh_entries[0];
1064};
1065
1066
1067
1068
1069
1070
1071
1072struct ocfs2_xattr_value_root {
1073 __le32 xr_clusters;
1074 __le32 xr_reserved0;
1075 __le64 xr_last_eb_blk;
1076 struct ocfs2_extent_list xr_list;
1077};
1078
1079
1080
1081
1082
1083
1084
1085struct ocfs2_xattr_tree_root {
1086 __le32 xt_clusters;
1087 __le32 xt_reserved0;
1088 __le64 xt_last_eb_blk;
1089 struct ocfs2_extent_list xt_list;
1090};
1091
1092#define OCFS2_XATTR_INDEXED 0x1
1093#define OCFS2_HASH_SHIFT 5
1094#define OCFS2_XATTR_ROUND 3
1095#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
1096 ~(OCFS2_XATTR_ROUND))
1097
1098#define OCFS2_XATTR_BUCKET_SIZE 4096
1099#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
1100 / OCFS2_MIN_BLOCKSIZE)
1101
1102
1103
1104
1105struct ocfs2_xattr_block {
1106 __u8 xb_signature[8];
1107 __le16 xb_suballoc_slot;
1108
1109 __le16 xb_suballoc_bit;
1110
1111 __le32 xb_fs_generation;
1112 __le64 xb_blkno;
1113 struct ocfs2_block_check xb_check;
1114 __le16 xb_flags;
1115
1116 __le16 xb_reserved0;
1117 __le32 xb_reserved1;
1118 __le64 xb_suballoc_loc;
1119
1120
1121
1122 union {
1123 struct ocfs2_xattr_header xb_header;
1124
1125 struct ocfs2_xattr_tree_root xb_root;
1126
1127
1128 } xb_attrs;
1129};
1130
1131#define OCFS2_XATTR_ENTRY_LOCAL 0x80
1132#define OCFS2_XATTR_TYPE_MASK 0x7F
1133static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1134 int local)
1135{
1136 if (local)
1137 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1138 else
1139 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1140}
1141
1142static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1143{
1144 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1145}
1146
1147static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1148{
1149 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1150}
1151
1152static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1153{
1154 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1155}
1156
1157
1158
1159
1160
1161
1162#define OCFS2_GLOBAL_QMAGICS {\
1163 0x0cf52470, \
1164 0x0cf52471 \
1165}
1166
1167#define OCFS2_GLOBAL_QVERSIONS {\
1168 0, \
1169 0, \
1170}
1171
1172
1173
1174
1175
1176#define OCFS2_QBLK_RESERVED_SPACE 8
1177
1178
1179struct ocfs2_disk_dqheader {
1180 __le32 dqh_magic;
1181 __le32 dqh_version;
1182};
1183
1184#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1185
1186
1187
1188struct ocfs2_global_disk_dqinfo {
1189 __le32 dqi_bgrace;
1190 __le32 dqi_igrace;
1191 __le32 dqi_syncms;
1192
1193 __le32 dqi_blocks;
1194 __le32 dqi_free_blk;
1195 __le32 dqi_free_entry;
1196
1197};
1198
1199
1200
1201struct ocfs2_global_disk_dqblk {
1202 __le32 dqb_id;
1203 __le32 dqb_use_count;
1204 __le64 dqb_ihardlimit;
1205 __le64 dqb_isoftlimit;
1206 __le64 dqb_curinodes;
1207 __le64 dqb_bhardlimit;
1208 __le64 dqb_bsoftlimit;
1209 __le64 dqb_curspace;
1210 __le64 dqb_btime;
1211 __le64 dqb_itime;
1212 __le64 dqb_pad1;
1213 __le64 dqb_pad2;
1214};
1215
1216
1217
1218
1219
1220
1221#define OCFS2_LOCAL_QMAGICS {\
1222 0x0cf524c0, \
1223 0x0cf524c1 \
1224}
1225
1226#define OCFS2_LOCAL_QVERSIONS {\
1227 0, \
1228 0, \
1229}
1230
1231
1232#define OLQF_CLEAN 0x0001
1233
1234
1235#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1236
1237
1238
1239struct ocfs2_local_disk_dqinfo {
1240 __le32 dqi_flags;
1241 __le32 dqi_chunks;
1242
1243 __le32 dqi_blocks;
1244};
1245
1246
1247struct ocfs2_local_disk_chunk {
1248 __le32 dqc_free;
1249 __u8 dqc_bitmap[0];
1250
1251};
1252
1253
1254struct ocfs2_local_disk_dqblk {
1255 __le64 dqb_id;
1256 __le64 dqb_spacemod;
1257 __le64 dqb_inodemod;
1258};
1259
1260
1261
1262
1263
1264
1265struct ocfs2_disk_dqtrailer {
1266 struct ocfs2_block_check dq_check;
1267
1268};
1269
1270static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1271 void *buf)
1272{
1273 char *ptr = buf;
1274 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1275
1276 return (struct ocfs2_disk_dqtrailer *)ptr;
1277}
1278
1279#ifdef __KERNEL__
1280static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1281{
1282 return sb->s_blocksize -
1283 offsetof(struct ocfs2_dinode, id2.i_symlink);
1284}
1285
1286static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1287 struct ocfs2_dinode *di)
1288{
1289 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1290
1291 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1292 return sb->s_blocksize -
1293 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1294 xattrsize;
1295 else
1296 return sb->s_blocksize -
1297 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1298}
1299
1300static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1301{
1302 int size;
1303
1304 size = sb->s_blocksize -
1305 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1306
1307 return size / sizeof(struct ocfs2_extent_rec);
1308}
1309
1310static inline int ocfs2_extent_recs_per_inode_with_xattr(
1311 struct super_block *sb,
1312 struct ocfs2_dinode *di)
1313{
1314 int size;
1315 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1316
1317 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1318 size = sb->s_blocksize -
1319 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1320 xattrsize;
1321 else
1322 size = sb->s_blocksize -
1323 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1324
1325 return size / sizeof(struct ocfs2_extent_rec);
1326}
1327
1328static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1329{
1330 int size;
1331
1332 size = sb->s_blocksize -
1333 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1334
1335 return size / sizeof(struct ocfs2_extent_rec);
1336}
1337
1338static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1339{
1340 int size;
1341
1342 size = sb->s_blocksize -
1343 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1344
1345 return size / sizeof(struct ocfs2_chain_rec);
1346}
1347
1348static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1349{
1350 int size;
1351
1352 size = sb->s_blocksize -
1353 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1354
1355 return size / sizeof(struct ocfs2_extent_rec);
1356}
1357
1358static inline u16 ocfs2_extent_recs_per_gd(struct super_block *sb)
1359{
1360 int size;
1361
1362 size = sb->s_blocksize -
1363 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1364
1365 return size / sizeof(struct ocfs2_extent_rec);
1366}
1367
1368static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1369{
1370 int size;
1371
1372 size = sb->s_blocksize -
1373 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1374
1375 return size / sizeof(struct ocfs2_dx_entry);
1376}
1377
1378static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1379{
1380 int size;
1381
1382 size = sb->s_blocksize -
1383 offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1384
1385 return size / sizeof(struct ocfs2_dx_entry);
1386}
1387
1388static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1389{
1390 u16 size;
1391
1392 size = sb->s_blocksize -
1393 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1394
1395 return size;
1396}
1397
1398static inline int ocfs2_group_bitmap_size(struct super_block *sb,
1399 int suballocator,
1400 u32 feature_incompat)
1401{
1402 int size = sb->s_blocksize -
1403 offsetof(struct ocfs2_group_desc, bg_bitmap);
1404
1405
1406
1407
1408
1409
1410
1411 if (suballocator &&
1412 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
1413 size = OCFS2_MAX_BG_BITMAP_SIZE;
1414
1415 return size;
1416}
1417
1418static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1419{
1420 int size;
1421
1422 size = sb->s_blocksize -
1423 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1424
1425 return size / sizeof(struct ocfs2_truncate_rec);
1426}
1427
1428static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1429{
1430 u64 offset = OCFS2_BACKUP_SB_START;
1431
1432 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1433 offset <<= (2 * index);
1434 offset >>= sb->s_blocksize_bits;
1435 return offset;
1436 }
1437
1438 return 0;
1439
1440}
1441
1442static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1443{
1444 int size;
1445
1446 size = sb->s_blocksize -
1447 offsetof(struct ocfs2_xattr_block,
1448 xb_attrs.xb_root.xt_list.l_recs);
1449
1450 return size / sizeof(struct ocfs2_extent_rec);
1451}
1452
1453static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
1454{
1455 int size;
1456
1457 size = sb->s_blocksize -
1458 offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
1459
1460 return size / sizeof(struct ocfs2_extent_rec);
1461}
1462
1463static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
1464{
1465 int size;
1466
1467 size = sb->s_blocksize -
1468 offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
1469
1470 return size / sizeof(struct ocfs2_refcount_rec);
1471}
1472
1473static inline u32
1474ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec)
1475{
1476 return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK;
1477}
1478#else
1479static inline int ocfs2_fast_symlink_chars(int blocksize)
1480{
1481 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1482}
1483
1484static inline int ocfs2_max_inline_data_with_xattr(int blocksize,
1485 struct ocfs2_dinode *di)
1486{
1487 if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL))
1488 return blocksize -
1489 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1490 di->i_xattr_inline_size;
1491 else
1492 return blocksize -
1493 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1494}
1495
1496static inline int ocfs2_extent_recs_per_inode(int blocksize)
1497{
1498 int size;
1499
1500 size = blocksize -
1501 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1502
1503 return size / sizeof(struct ocfs2_extent_rec);
1504}
1505
1506static inline int ocfs2_chain_recs_per_inode(int blocksize)
1507{
1508 int size;
1509
1510 size = blocksize -
1511 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1512
1513 return size / sizeof(struct ocfs2_chain_rec);
1514}
1515
1516static inline int ocfs2_extent_recs_per_eb(int blocksize)
1517{
1518 int size;
1519
1520 size = blocksize -
1521 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1522
1523 return size / sizeof(struct ocfs2_extent_rec);
1524}
1525
1526static inline int ocfs2_extent_recs_per_gd(int blocksize)
1527{
1528 int size;
1529
1530 size = blocksize -
1531 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1532
1533 return size / sizeof(struct ocfs2_extent_rec);
1534}
1535
1536static inline int ocfs2_local_alloc_size(int blocksize)
1537{
1538 int size;
1539
1540 size = blocksize -
1541 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1542
1543 return size;
1544}
1545
1546static inline int ocfs2_group_bitmap_size(int blocksize,
1547 int suballocator,
1548 uint32_t feature_incompat)
1549{
1550 int size = sb->s_blocksize -
1551 offsetof(struct ocfs2_group_desc, bg_bitmap);
1552
1553
1554
1555
1556
1557
1558
1559 if (suballocator &&
1560 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
1561 size = OCFS2_MAX_BG_BITMAP_SIZE;
1562
1563 return size;
1564}
1565
1566static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1567{
1568 int size;
1569
1570 size = blocksize -
1571 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1572
1573 return size / sizeof(struct ocfs2_truncate_rec);
1574}
1575
1576static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1577{
1578 uint64_t offset = OCFS2_BACKUP_SB_START;
1579
1580 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1581 offset <<= (2 * index);
1582 offset /= blocksize;
1583 return offset;
1584 }
1585
1586 return 0;
1587}
1588
1589static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1590{
1591 int size;
1592
1593 size = blocksize -
1594 offsetof(struct ocfs2_xattr_block,
1595 xb_attrs.xb_root.xt_list.l_recs);
1596
1597 return size / sizeof(struct ocfs2_extent_rec);
1598}
1599#endif
1600
1601
1602static inline int ocfs2_system_inode_is_global(int type)
1603{
1604 return ((type >= 0) &&
1605 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1606}
1607
1608static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1609 int type, int slot)
1610{
1611 int chars;
1612
1613
1614
1615
1616
1617
1618 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
1619 chars = snprintf(buf, len, "%s",
1620 ocfs2_system_inodes[type].si_name);
1621 else
1622 chars = snprintf(buf, len,
1623 ocfs2_system_inodes[type].si_name,
1624 slot);
1625
1626 return chars;
1627}
1628
1629static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1630 umode_t mode)
1631{
1632 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1633}
1634
1635static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd)
1636{
1637 if ((offsetof(struct ocfs2_group_desc, bg_bitmap) +
1638 le16_to_cpu(gd->bg_size)) !=
1639 offsetof(struct ocfs2_group_desc, bg_list))
1640 return 0;
1641
1642
1643
1644
1645 if (!gd->bg_list.l_next_free_rec)
1646 return 0;
1647 return 1;
1648}
1649#endif
1650
1651