blob: c5b1ac547c158885c10be46f4b33935a83f6dd52 [file] [log] [blame]
Mark Fashehccd979b2005-12-15 14:31:24 -08001/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * ocfs2_fs.h
5 *
6 * On-disk structures for OCFS2.
7 *
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License, version 2, as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 021110-1307, USA.
23 */
24
25#ifndef _OCFS2_FS_H
26#define _OCFS2_FS_H
27
28/* Version */
29#define OCFS2_MAJOR_REV_LEVEL 0
30#define OCFS2_MINOR_REV_LEVEL 90
31
32/*
33 * An OCFS2 volume starts this way:
34 * Sector 0: Valid ocfs1_vol_disk_hdr that cleanly fails to mount OCFS.
35 * Sector 1: Valid ocfs1_vol_label that cleanly fails to mount OCFS.
36 * Block OCFS2_SUPER_BLOCK_BLKNO: OCFS2 superblock.
37 *
38 * All other structures are found from the superblock information.
39 *
40 * OCFS2_SUPER_BLOCK_BLKNO is in blocks, not sectors. eg, for a
41 * blocksize of 2K, it is 4096 bytes into disk.
42 */
43#define OCFS2_SUPER_BLOCK_BLKNO 2
44
45/*
46 * Cluster size limits. The maximum is kept arbitrarily at 1 MB, and could
47 * grow if needed.
48 */
49#define OCFS2_MIN_CLUSTERSIZE 4096
50#define OCFS2_MAX_CLUSTERSIZE 1048576
51
52/*
53 * Blocks cannot be bigger than clusters, so the maximum blocksize is the
54 * minimum cluster size.
55 */
56#define OCFS2_MIN_BLOCKSIZE 512
57#define OCFS2_MAX_BLOCKSIZE OCFS2_MIN_CLUSTERSIZE
58
59/* Filesystem magic number */
60#define OCFS2_SUPER_MAGIC 0x7461636f
61
62/* Object signatures */
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
68/* Compatibility flags */
69#define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \
70 ( OCFS2_SB(sb)->s_feature_compat & (mask) )
71#define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \
72 ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
73#define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \
74 ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
75#define OCFS2_SET_COMPAT_FEATURE(sb,mask) \
76 OCFS2_SB(sb)->s_feature_compat |= (mask)
77#define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \
78 OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
79#define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \
80 OCFS2_SB(sb)->s_feature_incompat |= (mask)
81#define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \
82 OCFS2_SB(sb)->s_feature_compat &= ~(mask)
83#define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
84 OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
85#define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
86 OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
87
88#define OCFS2_FEATURE_COMPAT_SUPP 0
89#define OCFS2_FEATURE_INCOMPAT_SUPP 0
90#define OCFS2_FEATURE_RO_COMPAT_SUPP 0
91
92/*
93 * Heartbeat-only devices are missing journals and other files. The
94 * filesystem driver can't load them, but the library can. Never put
95 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
96 */
97#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
98
99
100/*
101 * Flags on ocfs2_dinode.i_flags
102 */
103#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
104#define OCFS2_UNUSED2_FL (0x00000002)
105#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
106#define OCFS2_UNUSED3_FL (0x00000008)
107/* System inode flags */
108#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
109#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
110#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
111#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
112#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
113#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
114#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
115#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
116
117/*
118 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
119 */
120#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
121
122/*
123 * superblock s_state flags
124 */
125#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
126
127/* Limit of space in ocfs2_dir_entry */
128#define OCFS2_MAX_FILENAME_LEN 255
129
130/* Maximum slots on an ocfs2 file system */
131#define OCFS2_MAX_SLOTS 255
132
133/* Slot map indicator for an empty slot */
134#define OCFS2_INVALID_SLOT -1
135
136#define OCFS2_VOL_UUID_LEN 16
137#define OCFS2_MAX_VOL_LABEL_LEN 64
138
139/* Journal limits (in bytes) */
140#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800141
142struct ocfs2_system_inode_info {
143 char *si_name;
144 int si_iflags;
145 int si_mode;
146};
147
148/* System file index */
149enum {
150 BAD_BLOCK_SYSTEM_INODE = 0,
151 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
152 SLOT_MAP_SYSTEM_INODE,
153#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
154 HEARTBEAT_SYSTEM_INODE,
155 GLOBAL_BITMAP_SYSTEM_INODE,
156#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE
157 ORPHAN_DIR_SYSTEM_INODE,
158 EXTENT_ALLOC_SYSTEM_INODE,
159 INODE_ALLOC_SYSTEM_INODE,
160 JOURNAL_SYSTEM_INODE,
161 LOCAL_ALLOC_SYSTEM_INODE,
162 TRUNCATE_LOG_SYSTEM_INODE,
163 NUM_SYSTEM_INODES
164};
165
166static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
167 /* Global system inodes (single copy) */
168 /* The first two are only used from userspace mfks/tunefs */
169 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
170 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
171
172 /* These are used by the running filesystem */
173 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
174 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
175 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
176
177 /* Slot-specific system inodes (one copy per slot) */
178 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
179 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
180 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
181 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
182 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
183 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }
184};
185
186/* Parameter passed from mount.ocfs2 to module */
187#define OCFS2_HB_NONE "heartbeat=none"
188#define OCFS2_HB_LOCAL "heartbeat=local"
189
190/*
191 * OCFS2 directory file types. Only the low 3 bits are used. The
192 * other bits are reserved for now.
193 */
194#define OCFS2_FT_UNKNOWN 0
195#define OCFS2_FT_REG_FILE 1
196#define OCFS2_FT_DIR 2
197#define OCFS2_FT_CHRDEV 3
198#define OCFS2_FT_BLKDEV 4
199#define OCFS2_FT_FIFO 5
200#define OCFS2_FT_SOCK 6
201#define OCFS2_FT_SYMLINK 7
202
203#define OCFS2_FT_MAX 8
204
205/*
206 * OCFS2_DIR_PAD defines the directory entries boundaries
207 *
208 * NOTE: It must be a multiple of 4
209 */
210#define OCFS2_DIR_PAD 4
211#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
212#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
213#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
214 OCFS2_DIR_ROUND) & \
215 ~OCFS2_DIR_ROUND)
216
217#define OCFS2_LINK_MAX 32000
218
219#define S_SHIFT 12
220static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
221 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
222 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
223 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
224 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
225 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
226 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
227 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
228};
229
230
231/*
232 * Convenience casts
233 */
234#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
235
236/*
237 * On disk extent record for OCFS2
238 * It describes a range of clusters on disk.
239 */
240struct ocfs2_extent_rec {
241/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
242 __le32 e_clusters; /* Clusters covered by this extent */
243 __le64 e_blkno; /* Physical disk offset, in blocks */
244/*10*/
245};
246
247struct ocfs2_chain_rec {
248 __le32 c_free; /* Number of free bits in this chain. */
249 __le32 c_total; /* Number of total bits in this chain */
250 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
251};
252
253struct ocfs2_truncate_rec {
254 __le32 t_start; /* 1st cluster in this log */
255 __le32 t_clusters; /* Number of total clusters covered */
256};
257
258/*
259 * On disk extent list for OCFS2 (node in the tree). Note that this
260 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
261 * offsets are relative to ocfs2_dinode.id2.i_list or
262 * ocfs2_extent_block.h_list, respectively.
263 */
264struct ocfs2_extent_list {
265/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
266 point. 0 means data extents
267 hang directly off this
268 header (a leaf) */
269 __le16 l_count; /* Number of extent records */
270 __le16 l_next_free_rec; /* Next unused extent slot */
271 __le16 l_reserved1;
272 __le64 l_reserved2; /* Pad to
273 sizeof(ocfs2_extent_rec) */
274/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
275};
276
277/*
278 * On disk allocation chain list for OCFS2. Note that this is
279 * contained inside ocfs2_dinode, so the offsets are relative to
280 * ocfs2_dinode.id2.i_chain.
281 */
282struct ocfs2_chain_list {
283/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
284 __le16 cl_bpc; /* Bits per cluster */
285 __le16 cl_count; /* Total chains in this list */
286 __le16 cl_next_free_rec; /* Next unused chain slot */
287 __le64 cl_reserved1;
288/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
289};
290
291/*
292 * On disk deallocation log for OCFS2. Note that this is
293 * contained inside ocfs2_dinode, so the offsets are relative to
294 * ocfs2_dinode.id2.i_dealloc.
295 */
296struct ocfs2_truncate_log {
297/*00*/ __le16 tl_count; /* Total records in this log */
298 __le16 tl_used; /* Number of records in use */
299 __le32 tl_reserved1;
300/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
301};
302
303/*
304 * On disk extent block (indirect block) for OCFS2
305 */
306struct ocfs2_extent_block
307{
308/*00*/ __u8 h_signature[8]; /* Signature for verification */
309 __le64 h_reserved1;
310/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
311 extent_header belongs to */
312 __le16 h_suballoc_bit; /* Bit offset in suballocator
313 block group */
314 __le32 h_fs_generation; /* Must match super block */
315 __le64 h_blkno; /* Offset on disk, in blocks */
316/*20*/ __le64 h_reserved3;
317 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
318 of next leaf header pointing
319 to data */
320/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
321/* Actual on-disk size is one block */
322};
323
324/*
325 * On disk superblock for OCFS2
326 * Note that it is contained inside an ocfs2_dinode, so all offsets
327 * are relative to the start of ocfs2_dinode.id2.
328 */
329struct ocfs2_super_block {
330/*00*/ __le16 s_major_rev_level;
331 __le16 s_minor_rev_level;
332 __le16 s_mnt_count;
333 __le16 s_max_mnt_count;
334 __le16 s_state; /* File system state */
335 __le16 s_errors; /* Behaviour when detecting errors */
336 __le32 s_checkinterval; /* Max time between checks */
337/*10*/ __le64 s_lastcheck; /* Time of last check */
338 __le32 s_creator_os; /* OS */
339 __le32 s_feature_compat; /* Compatible feature set */
340/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
341 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
342 __le64 s_root_blkno; /* Offset, in blocks, of root directory
343 dinode */
344/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
345 directory dinode */
346 __le32 s_blocksize_bits; /* Blocksize for this fs */
347 __le32 s_clustersize_bits; /* Clustersize for this fs */
348/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
349 before tunefs required */
350 __le16 s_reserved1;
351 __le32 s_reserved2;
352 __le64 s_first_cluster_group; /* Block offset of 1st cluster
353 * group header */
354/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
355/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
356/*A0*/
357};
358
359/*
360 * Local allocation bitmap for OCFS2 slots
361 * Note that it exists inside an ocfs2_dinode, so all offsets are
362 * relative to the start of ocfs2_dinode.id2.
363 */
364struct ocfs2_local_alloc
365{
366/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
367 __le16 la_size; /* Size of included bitmap, in bytes */
368 __le16 la_reserved1;
369 __le64 la_reserved2;
370/*10*/ __u8 la_bitmap[0];
371};
372
373/*
374 * On disk inode for OCFS2
375 */
376struct ocfs2_dinode {
377/*00*/ __u8 i_signature[8]; /* Signature for validation */
378 __le32 i_generation; /* Generation number */
379 __le16 i_suballoc_slot; /* Slot suballocator this inode
380 belongs to */
381 __le16 i_suballoc_bit; /* Bit offset in suballocator
382 block group */
383/*10*/ __le32 i_reserved0;
384 __le32 i_clusters; /* Cluster count */
385 __le32 i_uid; /* Owner UID */
386 __le32 i_gid; /* Owning GID */
387/*20*/ __le64 i_size; /* Size in bytes */
388 __le16 i_mode; /* File mode */
389 __le16 i_links_count; /* Links count */
390 __le32 i_flags; /* File flags */
391/*30*/ __le64 i_atime; /* Access time */
392 __le64 i_ctime; /* Creation time */
393/*40*/ __le64 i_mtime; /* Modification time */
394 __le64 i_dtime; /* Deletion time */
395/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
396 __le64 i_last_eb_blk; /* Pointer to last extent
397 block */
398/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
399 __le32 i_atime_nsec;
400 __le32 i_ctime_nsec;
401 __le32 i_mtime_nsec;
402/*70*/ __le64 i_reserved1[9];
403/*B8*/ union {
404 __le64 i_pad1; /* Generic way to refer to this
405 64bit union */
406 struct {
407 __le64 i_rdev; /* Device number */
408 } dev1;
409 struct { /* Info for bitmap system
410 inodes */
411 __le32 i_used; /* Bits (ie, clusters) used */
412 __le32 i_total; /* Total bits (clusters)
413 available */
414 } bitmap1;
415 struct { /* Info for journal system
416 inodes */
417 __le32 ij_flags; /* Mounted, version, etc. */
418 __le32 ij_pad;
419 } journal1;
420 } id1; /* Inode type dependant 1 */
421/*C0*/ union {
422 struct ocfs2_super_block i_super;
423 struct ocfs2_local_alloc i_lab;
424 struct ocfs2_chain_list i_chain;
425 struct ocfs2_extent_list i_list;
426 struct ocfs2_truncate_log i_dealloc;
427 __u8 i_symlink[0];
428 } id2;
429/* Actual on-disk size is one block */
430};
431
432/*
433 * On-disk directory entry structure for OCFS2
434 *
435 * Packed as this structure could be accessed unaligned on 64-bit platforms
436 */
437struct ocfs2_dir_entry {
438/*00*/ __le64 inode; /* Inode number */
439 __le16 rec_len; /* Directory entry length */
440 __u8 name_len; /* Name length */
441 __u8 file_type;
442/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
443/* Actual on-disk length specified by rec_len */
444} __attribute__ ((packed));
445
446/*
447 * On disk allocator group structure for OCFS2
448 */
449struct ocfs2_group_desc
450{
451/*00*/ __u8 bg_signature[8]; /* Signature for validation */
452 __le16 bg_size; /* Size of included bitmap in
453 bytes. */
454 __le16 bg_bits; /* Bits represented by this
455 group. */
456 __le16 bg_free_bits_count; /* Free bits count */
457 __le16 bg_chain; /* What chain I am in. */
458/*10*/ __le32 bg_generation;
459 __le32 bg_reserved1;
460 __le64 bg_next_group; /* Next group in my list, in
461 blocks */
462/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
463 blocks */
464 __le64 bg_blkno; /* Offset on disk, in blocks */
465/*30*/ __le64 bg_reserved2[2];
466/*40*/ __u8 bg_bitmap[0];
467};
468
469#ifdef __KERNEL__
470static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
471{
472 return sb->s_blocksize -
473 offsetof(struct ocfs2_dinode, id2.i_symlink);
474}
475
476static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
477{
478 int size;
479
480 size = sb->s_blocksize -
481 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
482
483 return size / sizeof(struct ocfs2_extent_rec);
484}
485
486static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
487{
488 int size;
489
490 size = sb->s_blocksize -
491 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
492
493 return size / sizeof(struct ocfs2_chain_rec);
494}
495
496static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
497{
498 int size;
499
500 size = sb->s_blocksize -
501 offsetof(struct ocfs2_extent_block, h_list.l_recs);
502
503 return size / sizeof(struct ocfs2_extent_rec);
504}
505
506static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
507{
508 u16 size;
509
510 size = sb->s_blocksize -
511 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
512
513 return size;
514}
515
516static inline int ocfs2_group_bitmap_size(struct super_block *sb)
517{
518 int size;
519
520 size = sb->s_blocksize -
521 offsetof(struct ocfs2_group_desc, bg_bitmap);
522
523 return size;
524}
525
526static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
527{
528 int size;
529
530 size = sb->s_blocksize -
531 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
532
533 return size / sizeof(struct ocfs2_truncate_rec);
534}
535#else
536static inline int ocfs2_fast_symlink_chars(int blocksize)
537{
538 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
539}
540
541static inline int ocfs2_extent_recs_per_inode(int blocksize)
542{
543 int size;
544
545 size = blocksize -
546 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
547
548 return size / sizeof(struct ocfs2_extent_rec);
549}
550
551static inline int ocfs2_chain_recs_per_inode(int blocksize)
552{
553 int size;
554
555 size = blocksize -
556 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
557
558 return size / sizeof(struct ocfs2_chain_rec);
559}
560
561static inline int ocfs2_extent_recs_per_eb(int blocksize)
562{
563 int size;
564
565 size = blocksize -
566 offsetof(struct ocfs2_extent_block, h_list.l_recs);
567
568 return size / sizeof(struct ocfs2_extent_rec);
569}
570
571static inline int ocfs2_local_alloc_size(int blocksize)
572{
573 int size;
574
575 size = blocksize -
576 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
577
578 return size;
579}
580
581static inline int ocfs2_group_bitmap_size(int blocksize)
582{
583 int size;
584
585 size = blocksize -
586 offsetof(struct ocfs2_group_desc, bg_bitmap);
587
588 return size;
589}
590
591static inline int ocfs2_truncate_recs_per_inode(int blocksize)
592{
593 int size;
594
595 size = blocksize -
596 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
597
598 return size / sizeof(struct ocfs2_truncate_rec);
599}
600#endif /* __KERNEL__ */
601
602
603static inline int ocfs2_system_inode_is_global(int type)
604{
605 return ((type >= 0) &&
606 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
607}
608
609static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
610 int type, int slot)
611{
612 int chars;
613
614 /*
615 * Global system inodes can only have one copy. Everything
616 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
617 * list has a copy per slot.
618 */
619 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
620 chars = snprintf(buf, len,
621 ocfs2_system_inodes[type].si_name);
622 else
623 chars = snprintf(buf, len,
624 ocfs2_system_inodes[type].si_name,
625 slot);
626
627 return chars;
628}
629
630static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
631 umode_t mode)
632{
633 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
634}
635
636#endif /* _OCFS2_FS_H */
637