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