blob: 2e90e89f1602f835205329ebe00e51ed29ddf54f [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
Sunil Mushranc271c5c2006-12-05 17:56:35 -080089#define OCFS2_FEATURE_INCOMPAT_SUPP OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT
Mark Fashehccd979b2005-12-15 14:31:24 -080090#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
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800100/* Used to denote a non-clustered volume */
101#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
102
Mark Fashehccd979b2005-12-15 14:31:24 -0800103/*
104 * Flags on ocfs2_dinode.i_flags
105 */
106#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
107#define OCFS2_UNUSED2_FL (0x00000002)
108#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
109#define OCFS2_UNUSED3_FL (0x00000008)
110/* System inode flags */
111#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
112#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
113#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
114#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
115#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
116#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
117#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
118#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
119
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700120/* Inode attributes, keep in sync with EXT2 */
121#define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
122#define OCFS2_UNRM_FL (0x00000002) /* Undelete */
123#define OCFS2_COMPR_FL (0x00000004) /* Compress file */
124#define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
125#define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
126#define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
127#define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
128#define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
129#define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
130
131#define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
132#define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
133
134/*
135 * ioctl commands
136 */
137#define OCFS2_IOC_GETFLAGS _IOR('f', 1, long)
138#define OCFS2_IOC_SETFLAGS _IOW('f', 2, long)
139
Mark Fashehccd979b2005-12-15 14:31:24 -0800140/*
141 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
142 */
143#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
144
145/*
146 * superblock s_state flags
147 */
148#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
149
150/* Limit of space in ocfs2_dir_entry */
151#define OCFS2_MAX_FILENAME_LEN 255
152
153/* Maximum slots on an ocfs2 file system */
154#define OCFS2_MAX_SLOTS 255
155
156/* Slot map indicator for an empty slot */
157#define OCFS2_INVALID_SLOT -1
158
159#define OCFS2_VOL_UUID_LEN 16
160#define OCFS2_MAX_VOL_LABEL_LEN 64
161
162/* Journal limits (in bytes) */
163#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800164
165struct ocfs2_system_inode_info {
166 char *si_name;
167 int si_iflags;
168 int si_mode;
169};
170
171/* System file index */
172enum {
173 BAD_BLOCK_SYSTEM_INODE = 0,
174 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
175 SLOT_MAP_SYSTEM_INODE,
176#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
177 HEARTBEAT_SYSTEM_INODE,
178 GLOBAL_BITMAP_SYSTEM_INODE,
179#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE
180 ORPHAN_DIR_SYSTEM_INODE,
181 EXTENT_ALLOC_SYSTEM_INODE,
182 INODE_ALLOC_SYSTEM_INODE,
183 JOURNAL_SYSTEM_INODE,
184 LOCAL_ALLOC_SYSTEM_INODE,
185 TRUNCATE_LOG_SYSTEM_INODE,
186 NUM_SYSTEM_INODES
187};
188
189static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
190 /* Global system inodes (single copy) */
191 /* The first two are only used from userspace mfks/tunefs */
192 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
193 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
194
195 /* These are used by the running filesystem */
196 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
197 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
198 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
199
200 /* Slot-specific system inodes (one copy per slot) */
201 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
202 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
203 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
204 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
205 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
206 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }
207};
208
209/* Parameter passed from mount.ocfs2 to module */
210#define OCFS2_HB_NONE "heartbeat=none"
211#define OCFS2_HB_LOCAL "heartbeat=local"
212
213/*
214 * OCFS2 directory file types. Only the low 3 bits are used. The
215 * other bits are reserved for now.
216 */
217#define OCFS2_FT_UNKNOWN 0
218#define OCFS2_FT_REG_FILE 1
219#define OCFS2_FT_DIR 2
220#define OCFS2_FT_CHRDEV 3
221#define OCFS2_FT_BLKDEV 4
222#define OCFS2_FT_FIFO 5
223#define OCFS2_FT_SOCK 6
224#define OCFS2_FT_SYMLINK 7
225
226#define OCFS2_FT_MAX 8
227
228/*
229 * OCFS2_DIR_PAD defines the directory entries boundaries
230 *
231 * NOTE: It must be a multiple of 4
232 */
233#define OCFS2_DIR_PAD 4
234#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
235#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
236#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
237 OCFS2_DIR_ROUND) & \
238 ~OCFS2_DIR_ROUND)
239
240#define OCFS2_LINK_MAX 32000
241
242#define S_SHIFT 12
243static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
244 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
245 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
246 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
247 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
248 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
249 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
250 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
251};
252
253
254/*
255 * Convenience casts
256 */
257#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
258
259/*
260 * On disk extent record for OCFS2
261 * It describes a range of clusters on disk.
262 */
263struct ocfs2_extent_rec {
264/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
265 __le32 e_clusters; /* Clusters covered by this extent */
266 __le64 e_blkno; /* Physical disk offset, in blocks */
267/*10*/
268};
269
270struct ocfs2_chain_rec {
271 __le32 c_free; /* Number of free bits in this chain. */
272 __le32 c_total; /* Number of total bits in this chain */
273 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
274};
275
276struct ocfs2_truncate_rec {
277 __le32 t_start; /* 1st cluster in this log */
278 __le32 t_clusters; /* Number of total clusters covered */
279};
280
281/*
282 * On disk extent list for OCFS2 (node in the tree). Note that this
283 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
284 * offsets are relative to ocfs2_dinode.id2.i_list or
285 * ocfs2_extent_block.h_list, respectively.
286 */
287struct ocfs2_extent_list {
288/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
289 point. 0 means data extents
290 hang directly off this
291 header (a leaf) */
292 __le16 l_count; /* Number of extent records */
293 __le16 l_next_free_rec; /* Next unused extent slot */
294 __le16 l_reserved1;
295 __le64 l_reserved2; /* Pad to
296 sizeof(ocfs2_extent_rec) */
297/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
298};
299
300/*
301 * On disk allocation chain list for OCFS2. Note that this is
302 * contained inside ocfs2_dinode, so the offsets are relative to
303 * ocfs2_dinode.id2.i_chain.
304 */
305struct ocfs2_chain_list {
306/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
307 __le16 cl_bpc; /* Bits per cluster */
308 __le16 cl_count; /* Total chains in this list */
309 __le16 cl_next_free_rec; /* Next unused chain slot */
310 __le64 cl_reserved1;
311/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
312};
313
314/*
315 * On disk deallocation log for OCFS2. Note that this is
316 * contained inside ocfs2_dinode, so the offsets are relative to
317 * ocfs2_dinode.id2.i_dealloc.
318 */
319struct ocfs2_truncate_log {
320/*00*/ __le16 tl_count; /* Total records in this log */
321 __le16 tl_used; /* Number of records in use */
322 __le32 tl_reserved1;
323/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
324};
325
326/*
327 * On disk extent block (indirect block) for OCFS2
328 */
329struct ocfs2_extent_block
330{
331/*00*/ __u8 h_signature[8]; /* Signature for verification */
332 __le64 h_reserved1;
333/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
334 extent_header belongs to */
335 __le16 h_suballoc_bit; /* Bit offset in suballocator
336 block group */
337 __le32 h_fs_generation; /* Must match super block */
338 __le64 h_blkno; /* Offset on disk, in blocks */
339/*20*/ __le64 h_reserved3;
340 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
341 of next leaf header pointing
342 to data */
343/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
344/* Actual on-disk size is one block */
345};
346
347/*
348 * On disk superblock for OCFS2
349 * Note that it is contained inside an ocfs2_dinode, so all offsets
350 * are relative to the start of ocfs2_dinode.id2.
351 */
352struct ocfs2_super_block {
353/*00*/ __le16 s_major_rev_level;
354 __le16 s_minor_rev_level;
355 __le16 s_mnt_count;
356 __le16 s_max_mnt_count;
357 __le16 s_state; /* File system state */
358 __le16 s_errors; /* Behaviour when detecting errors */
359 __le32 s_checkinterval; /* Max time between checks */
360/*10*/ __le64 s_lastcheck; /* Time of last check */
361 __le32 s_creator_os; /* OS */
362 __le32 s_feature_compat; /* Compatible feature set */
363/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
364 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
365 __le64 s_root_blkno; /* Offset, in blocks, of root directory
366 dinode */
367/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
368 directory dinode */
369 __le32 s_blocksize_bits; /* Blocksize for this fs */
370 __le32 s_clustersize_bits; /* Clustersize for this fs */
371/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
372 before tunefs required */
373 __le16 s_reserved1;
374 __le32 s_reserved2;
375 __le64 s_first_cluster_group; /* Block offset of 1st cluster
376 * group header */
377/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
378/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
379/*A0*/
380};
381
382/*
383 * Local allocation bitmap for OCFS2 slots
384 * Note that it exists inside an ocfs2_dinode, so all offsets are
385 * relative to the start of ocfs2_dinode.id2.
386 */
387struct ocfs2_local_alloc
388{
389/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
390 __le16 la_size; /* Size of included bitmap, in bytes */
391 __le16 la_reserved1;
392 __le64 la_reserved2;
393/*10*/ __u8 la_bitmap[0];
394};
395
396/*
397 * On disk inode for OCFS2
398 */
399struct ocfs2_dinode {
400/*00*/ __u8 i_signature[8]; /* Signature for validation */
401 __le32 i_generation; /* Generation number */
402 __le16 i_suballoc_slot; /* Slot suballocator this inode
403 belongs to */
404 __le16 i_suballoc_bit; /* Bit offset in suballocator
405 block group */
406/*10*/ __le32 i_reserved0;
407 __le32 i_clusters; /* Cluster count */
408 __le32 i_uid; /* Owner UID */
409 __le32 i_gid; /* Owning GID */
410/*20*/ __le64 i_size; /* Size in bytes */
411 __le16 i_mode; /* File mode */
412 __le16 i_links_count; /* Links count */
413 __le32 i_flags; /* File flags */
414/*30*/ __le64 i_atime; /* Access time */
415 __le64 i_ctime; /* Creation time */
416/*40*/ __le64 i_mtime; /* Modification time */
417 __le64 i_dtime; /* Deletion time */
418/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
419 __le64 i_last_eb_blk; /* Pointer to last extent
420 block */
421/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
422 __le32 i_atime_nsec;
423 __le32 i_ctime_nsec;
424 __le32 i_mtime_nsec;
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700425 __le32 i_attr;
426 __le32 i_reserved1;
427/*70*/ __le64 i_reserved2[8];
Mark Fashehccd979b2005-12-15 14:31:24 -0800428/*B8*/ union {
429 __le64 i_pad1; /* Generic way to refer to this
430 64bit union */
431 struct {
432 __le64 i_rdev; /* Device number */
433 } dev1;
434 struct { /* Info for bitmap system
435 inodes */
436 __le32 i_used; /* Bits (ie, clusters) used */
437 __le32 i_total; /* Total bits (clusters)
438 available */
439 } bitmap1;
440 struct { /* Info for journal system
441 inodes */
442 __le32 ij_flags; /* Mounted, version, etc. */
443 __le32 ij_pad;
444 } journal1;
445 } id1; /* Inode type dependant 1 */
446/*C0*/ union {
447 struct ocfs2_super_block i_super;
448 struct ocfs2_local_alloc i_lab;
449 struct ocfs2_chain_list i_chain;
450 struct ocfs2_extent_list i_list;
451 struct ocfs2_truncate_log i_dealloc;
452 __u8 i_symlink[0];
453 } id2;
454/* Actual on-disk size is one block */
455};
456
457/*
458 * On-disk directory entry structure for OCFS2
459 *
460 * Packed as this structure could be accessed unaligned on 64-bit platforms
461 */
462struct ocfs2_dir_entry {
463/*00*/ __le64 inode; /* Inode number */
464 __le16 rec_len; /* Directory entry length */
465 __u8 name_len; /* Name length */
466 __u8 file_type;
467/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
468/* Actual on-disk length specified by rec_len */
469} __attribute__ ((packed));
470
471/*
472 * On disk allocator group structure for OCFS2
473 */
474struct ocfs2_group_desc
475{
476/*00*/ __u8 bg_signature[8]; /* Signature for validation */
477 __le16 bg_size; /* Size of included bitmap in
478 bytes. */
479 __le16 bg_bits; /* Bits represented by this
480 group. */
481 __le16 bg_free_bits_count; /* Free bits count */
482 __le16 bg_chain; /* What chain I am in. */
483/*10*/ __le32 bg_generation;
484 __le32 bg_reserved1;
485 __le64 bg_next_group; /* Next group in my list, in
486 blocks */
487/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
488 blocks */
489 __le64 bg_blkno; /* Offset on disk, in blocks */
490/*30*/ __le64 bg_reserved2[2];
491/*40*/ __u8 bg_bitmap[0];
492};
493
494#ifdef __KERNEL__
495static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
496{
497 return sb->s_blocksize -
498 offsetof(struct ocfs2_dinode, id2.i_symlink);
499}
500
501static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
502{
503 int size;
504
505 size = sb->s_blocksize -
506 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
507
508 return size / sizeof(struct ocfs2_extent_rec);
509}
510
511static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
512{
513 int size;
514
515 size = sb->s_blocksize -
516 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
517
518 return size / sizeof(struct ocfs2_chain_rec);
519}
520
521static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
522{
523 int size;
524
525 size = sb->s_blocksize -
526 offsetof(struct ocfs2_extent_block, h_list.l_recs);
527
528 return size / sizeof(struct ocfs2_extent_rec);
529}
530
531static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
532{
533 u16 size;
534
535 size = sb->s_blocksize -
536 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
537
538 return size;
539}
540
541static inline int ocfs2_group_bitmap_size(struct super_block *sb)
542{
543 int size;
544
545 size = sb->s_blocksize -
546 offsetof(struct ocfs2_group_desc, bg_bitmap);
547
548 return size;
549}
550
551static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
552{
553 int size;
554
555 size = sb->s_blocksize -
556 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
557
558 return size / sizeof(struct ocfs2_truncate_rec);
559}
560#else
561static inline int ocfs2_fast_symlink_chars(int blocksize)
562{
563 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
564}
565
566static inline int ocfs2_extent_recs_per_inode(int blocksize)
567{
568 int size;
569
570 size = blocksize -
571 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
572
573 return size / sizeof(struct ocfs2_extent_rec);
574}
575
576static inline int ocfs2_chain_recs_per_inode(int blocksize)
577{
578 int size;
579
580 size = blocksize -
581 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
582
583 return size / sizeof(struct ocfs2_chain_rec);
584}
585
586static inline int ocfs2_extent_recs_per_eb(int blocksize)
587{
588 int size;
589
590 size = blocksize -
591 offsetof(struct ocfs2_extent_block, h_list.l_recs);
592
593 return size / sizeof(struct ocfs2_extent_rec);
594}
595
596static inline int ocfs2_local_alloc_size(int blocksize)
597{
598 int size;
599
600 size = blocksize -
601 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
602
603 return size;
604}
605
606static inline int ocfs2_group_bitmap_size(int blocksize)
607{
608 int size;
609
610 size = blocksize -
611 offsetof(struct ocfs2_group_desc, bg_bitmap);
612
613 return size;
614}
615
616static inline int ocfs2_truncate_recs_per_inode(int blocksize)
617{
618 int size;
619
620 size = blocksize -
621 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
622
623 return size / sizeof(struct ocfs2_truncate_rec);
624}
625#endif /* __KERNEL__ */
626
627
628static inline int ocfs2_system_inode_is_global(int type)
629{
630 return ((type >= 0) &&
631 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
632}
633
634static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
635 int type, int slot)
636{
637 int chars;
638
639 /*
640 * Global system inodes can only have one copy. Everything
641 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
642 * list has a copy per slot.
643 */
644 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
645 chars = snprintf(buf, len,
646 ocfs2_system_inodes[type].si_name);
647 else
648 chars = snprintf(buf, len,
649 ocfs2_system_inodes[type].si_name,
650 slot);
651
652 return chars;
653}
654
655static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
656 umode_t mode)
657{
658 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
659}
660
661#endif /* _OCFS2_FS_H */
662