Commit bc02e8693d875c2a9b0037cfd37fe0b726d26403

Authored by Christoph Hellwig
Committed by Ben Myers
1 parent 1813dd6405

xfs: add CRC infrastructure

- add a mount feature bit for CRC enabled filesystems
 - add some helpers for generating and verifying the CRCs
 - add a copy_uuid helper

The checksumming helpers are loosely based on similar ones in sctp,
all other bits come from Dave Chinner.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>

Showing 5 changed files with 78 additions and 0 deletions Inline Diff

1 config XFS_FS 1 config XFS_FS
2 tristate "XFS filesystem support" 2 tristate "XFS filesystem support"
3 depends on BLOCK 3 depends on BLOCK
4 select EXPORTFS 4 select EXPORTFS
5 select LIBCRC32C
5 help 6 help
6 XFS is a high performance journaling filesystem which originated 7 XFS is a high performance journaling filesystem which originated
7 on the SGI IRIX platform. It is completely multi-threaded, can 8 on the SGI IRIX platform. It is completely multi-threaded, can
8 support large files and large filesystems, extended attributes, 9 support large files and large filesystems, extended attributes,
9 variable block sizes, is extent based, and makes extensive use of 10 variable block sizes, is extent based, and makes extensive use of
10 Btrees (directories, extents, free space) to aid both performance 11 Btrees (directories, extents, free space) to aid both performance
11 and scalability. 12 and scalability.
12 13
13 Refer to the documentation at <http://oss.sgi.com/projects/xfs/> 14 Refer to the documentation at <http://oss.sgi.com/projects/xfs/>
14 for complete details. This implementation is on-disk compatible 15 for complete details. This implementation is on-disk compatible
15 with the IRIX version of XFS. 16 with the IRIX version of XFS.
16 17
17 To compile this file system support as a module, choose M here: the 18 To compile this file system support as a module, choose M here: the
18 module will be called xfs. Be aware, however, that if the file 19 module will be called xfs. Be aware, however, that if the file
19 system of your root partition is compiled as a module, you'll need 20 system of your root partition is compiled as a module, you'll need
20 to use an initial ramdisk (initrd) to boot. 21 to use an initial ramdisk (initrd) to boot.
21 22
22 config XFS_QUOTA 23 config XFS_QUOTA
23 bool "XFS Quota support" 24 bool "XFS Quota support"
24 depends on XFS_FS 25 depends on XFS_FS
25 select QUOTACTL 26 select QUOTACTL
26 help 27 help
27 If you say Y here, you will be able to set limits for disk usage on 28 If you say Y here, you will be able to set limits for disk usage on
28 a per user and/or a per group basis under XFS. XFS considers quota 29 a per user and/or a per group basis under XFS. XFS considers quota
29 information as filesystem metadata and uses journaling to provide a 30 information as filesystem metadata and uses journaling to provide a
30 higher level guarantee of consistency. The on-disk data format for 31 higher level guarantee of consistency. The on-disk data format for
31 quota is also compatible with the IRIX version of XFS, allowing a 32 quota is also compatible with the IRIX version of XFS, allowing a
32 filesystem to be migrated between Linux and IRIX without any need 33 filesystem to be migrated between Linux and IRIX without any need
33 for conversion. 34 for conversion.
34 35
35 If unsure, say N. More comprehensive documentation can be found in 36 If unsure, say N. More comprehensive documentation can be found in
36 README.quota in the xfsprogs package. XFS quota can be used either 37 README.quota in the xfsprogs package. XFS quota can be used either
37 with or without the generic quota support enabled (CONFIG_QUOTA) - 38 with or without the generic quota support enabled (CONFIG_QUOTA) -
38 they are completely independent subsystems. 39 they are completely independent subsystems.
39 40
40 config XFS_POSIX_ACL 41 config XFS_POSIX_ACL
41 bool "XFS POSIX ACL support" 42 bool "XFS POSIX ACL support"
42 depends on XFS_FS 43 depends on XFS_FS
43 select FS_POSIX_ACL 44 select FS_POSIX_ACL
44 help 45 help
45 POSIX Access Control Lists (ACLs) support permissions for users and 46 POSIX Access Control Lists (ACLs) support permissions for users and
46 groups beyond the owner/group/world scheme. 47 groups beyond the owner/group/world scheme.
47 48
48 To learn more about Access Control Lists, visit the POSIX ACLs for 49 To learn more about Access Control Lists, visit the POSIX ACLs for
49 Linux website <http://acl.bestbits.at/>. 50 Linux website <http://acl.bestbits.at/>.
50 51
51 If you don't know what Access Control Lists are, say N. 52 If you don't know what Access Control Lists are, say N.
52 53
53 config XFS_RT 54 config XFS_RT
54 bool "XFS Realtime subvolume support" 55 bool "XFS Realtime subvolume support"
55 depends on XFS_FS 56 depends on XFS_FS
56 help 57 help
57 If you say Y here you will be able to mount and use XFS filesystems 58 If you say Y here you will be able to mount and use XFS filesystems
58 which contain a realtime subvolume. The realtime subvolume is a 59 which contain a realtime subvolume. The realtime subvolume is a
59 separate area of disk space where only file data is stored. It was 60 separate area of disk space where only file data is stored. It was
60 originally designed to provide deterministic data rates suitable 61 originally designed to provide deterministic data rates suitable
61 for media streaming applications, but is also useful as a generic 62 for media streaming applications, but is also useful as a generic
62 mechanism for ensuring data and metadata/log I/Os are completely 63 mechanism for ensuring data and metadata/log I/Os are completely
63 separated. Regular file I/Os are isolated to a separate device 64 separated. Regular file I/Os are isolated to a separate device
64 from all other requests, and this can be done quite transparently 65 from all other requests, and this can be done quite transparently
65 to applications via the inherit-realtime directory inode flag. 66 to applications via the inherit-realtime directory inode flag.
66 67
67 See the xfs man page in section 5 for additional information. 68 See the xfs man page in section 5 for additional information.
68 69
69 If unsure, say N. 70 If unsure, say N.
70 71
71 config XFS_DEBUG 72 config XFS_DEBUG
72 bool "XFS Debugging support (EXPERIMENTAL)" 73 bool "XFS Debugging support (EXPERIMENTAL)"
73 depends on XFS_FS && EXPERIMENTAL 74 depends on XFS_FS && EXPERIMENTAL
74 help 75 help
75 Say Y here to get an XFS build with many debugging features, 76 Say Y here to get an XFS build with many debugging features,
76 including ASSERT checks, function wrappers around macros, 77 including ASSERT checks, function wrappers around macros,
77 and extra sanity-checking functions in various code paths. 78 and extra sanity-checking functions in various code paths.
78 79
79 Note that the resulting code will be HUGE and SLOW, and probably 80 Note that the resulting code will be HUGE and SLOW, and probably
80 not useful unless you are debugging a particular problem. 81 not useful unless you are debugging a particular problem.
81 82
82 Say N unless you are an XFS developer, or you play one on TV. 83 Say N unless you are an XFS developer, or you play one on TV.
83 84
1 /* 1 /*
2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. 2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved. 3 * All Rights Reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as 6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * This program is distributed in the hope that it would be useful, 9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation, 15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */ 17 */
18 #ifndef __XFS_SUPPORT_UUID_H__ 18 #ifndef __XFS_SUPPORT_UUID_H__
19 #define __XFS_SUPPORT_UUID_H__ 19 #define __XFS_SUPPORT_UUID_H__
20 20
21 typedef struct { 21 typedef struct {
22 unsigned char __u_bits[16]; 22 unsigned char __u_bits[16];
23 } uuid_t; 23 } uuid_t;
24 24
25 extern int uuid_is_nil(uuid_t *uuid); 25 extern int uuid_is_nil(uuid_t *uuid);
26 extern int uuid_equal(uuid_t *uuid1, uuid_t *uuid2); 26 extern int uuid_equal(uuid_t *uuid1, uuid_t *uuid2);
27 extern void uuid_getnodeuniq(uuid_t *uuid, int fsid [2]); 27 extern void uuid_getnodeuniq(uuid_t *uuid, int fsid [2]);
28 28
29 static inline void
30 uuid_copy(uuid_t *dst, uuid_t *src)
31 {
32 memcpy(dst, src, sizeof(uuid_t));
33 }
34
29 #endif /* __XFS_SUPPORT_UUID_H__ */ 35 #endif /* __XFS_SUPPORT_UUID_H__ */
30 36
File was created 1 #ifndef _XFS_CKSUM_H
2 #define _XFS_CKSUM_H 1
3
4 #define XFS_CRC_SEED (~(__uint32_t)0)
5
6 /*
7 * Calculate the intermediate checksum for a buffer that has the CRC field
8 * inside it. The offset of the 32bit crc fields is passed as the
9 * cksum_offset parameter.
10 */
11 static inline __uint32_t
12 xfs_start_cksum(char *buffer, size_t length, unsigned long cksum_offset)
13 {
14 __uint32_t zero = 0;
15 __uint32_t crc;
16
17 /* Calculate CRC up to the checksum. */
18 crc = crc32c(XFS_CRC_SEED, buffer, cksum_offset);
19
20 /* Skip checksum field */
21 crc = crc32c(crc, &zero, sizeof(__u32));
22
23 /* Calculate the rest of the CRC. */
24 return crc32c(crc, &buffer[cksum_offset + sizeof(__be32)],
25 length - (cksum_offset + sizeof(__be32)));
26 }
27
28 /*
29 * Convert the intermediate checksum to the final ondisk format.
30 *
31 * The CRC32c calculation uses LE format even on BE machines, but returns the
32 * result in host endian format. Hence we need to byte swap it back to LE format
33 * so that it is consistent on disk.
34 */
35 static inline __le32
36 xfs_end_cksum(__uint32_t crc)
37 {
38 return ~cpu_to_le32(crc);
39 }
40
41 /*
42 * Helper to generate the checksum for a buffer.
43 */
44 static inline void
45 xfs_update_cksum(char *buffer, size_t length, unsigned long cksum_offset)
46 {
47 __uint32_t crc = xfs_start_cksum(buffer, length, cksum_offset);
48
49 *(__le32 *)(buffer + cksum_offset) = xfs_end_cksum(crc);
50 }
51
52 /*
53 * Helper to verify the checksum for a buffer.
54 */
55 static inline int
56 xfs_verify_cksum(char *buffer, size_t length, unsigned long cksum_offset)
57 {
58 __uint32_t crc = xfs_start_cksum(buffer, length, cksum_offset);
59
60 return *(__le32 *)(buffer + cksum_offset) == xfs_end_cksum(crc);
61 }
62
63 #endif /* _XFS_CKSUM_H */
64
1 /* 1 /*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc. 2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved. 3 * All Rights Reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as 6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * This program is distributed in the hope that it would be useful, 9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation, 15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */ 17 */
18 #ifndef __XFS_LINUX__ 18 #ifndef __XFS_LINUX__
19 #define __XFS_LINUX__ 19 #define __XFS_LINUX__
20 20
21 #include <linux/types.h> 21 #include <linux/types.h>
22 22
23 /* 23 /*
24 * XFS_BIG_BLKNOS needs block layer disk addresses to be 64 bits. 24 * XFS_BIG_BLKNOS needs block layer disk addresses to be 64 bits.
25 * XFS_BIG_INUMS requires XFS_BIG_BLKNOS to be set. 25 * XFS_BIG_INUMS requires XFS_BIG_BLKNOS to be set.
26 */ 26 */
27 #if defined(CONFIG_LBDAF) || (BITS_PER_LONG == 64) 27 #if defined(CONFIG_LBDAF) || (BITS_PER_LONG == 64)
28 # define XFS_BIG_BLKNOS 1 28 # define XFS_BIG_BLKNOS 1
29 # define XFS_BIG_INUMS 1 29 # define XFS_BIG_INUMS 1
30 #else 30 #else
31 # define XFS_BIG_BLKNOS 0 31 # define XFS_BIG_BLKNOS 0
32 # define XFS_BIG_INUMS 0 32 # define XFS_BIG_INUMS 0
33 #endif 33 #endif
34 34
35 #include "xfs_types.h" 35 #include "xfs_types.h"
36 36
37 #include "kmem.h" 37 #include "kmem.h"
38 #include "mrlock.h" 38 #include "mrlock.h"
39 #include "time.h" 39 #include "time.h"
40 #include "uuid.h" 40 #include "uuid.h"
41 41
42 #include <linux/semaphore.h> 42 #include <linux/semaphore.h>
43 #include <linux/mm.h> 43 #include <linux/mm.h>
44 #include <linux/kernel.h> 44 #include <linux/kernel.h>
45 #include <linux/blkdev.h> 45 #include <linux/blkdev.h>
46 #include <linux/slab.h> 46 #include <linux/slab.h>
47 #include <linux/crc32c.h>
47 #include <linux/module.h> 48 #include <linux/module.h>
48 #include <linux/mutex.h> 49 #include <linux/mutex.h>
49 #include <linux/file.h> 50 #include <linux/file.h>
50 #include <linux/swap.h> 51 #include <linux/swap.h>
51 #include <linux/errno.h> 52 #include <linux/errno.h>
52 #include <linux/sched.h> 53 #include <linux/sched.h>
53 #include <linux/bitops.h> 54 #include <linux/bitops.h>
54 #include <linux/major.h> 55 #include <linux/major.h>
55 #include <linux/pagemap.h> 56 #include <linux/pagemap.h>
56 #include <linux/vfs.h> 57 #include <linux/vfs.h>
57 #include <linux/seq_file.h> 58 #include <linux/seq_file.h>
58 #include <linux/init.h> 59 #include <linux/init.h>
59 #include <linux/list.h> 60 #include <linux/list.h>
60 #include <linux/proc_fs.h> 61 #include <linux/proc_fs.h>
61 #include <linux/sort.h> 62 #include <linux/sort.h>
62 #include <linux/cpu.h> 63 #include <linux/cpu.h>
63 #include <linux/notifier.h> 64 #include <linux/notifier.h>
64 #include <linux/delay.h> 65 #include <linux/delay.h>
65 #include <linux/log2.h> 66 #include <linux/log2.h>
66 #include <linux/spinlock.h> 67 #include <linux/spinlock.h>
67 #include <linux/random.h> 68 #include <linux/random.h>
68 #include <linux/ctype.h> 69 #include <linux/ctype.h>
69 #include <linux/writeback.h> 70 #include <linux/writeback.h>
70 #include <linux/capability.h> 71 #include <linux/capability.h>
71 #include <linux/kthread.h> 72 #include <linux/kthread.h>
72 #include <linux/freezer.h> 73 #include <linux/freezer.h>
73 #include <linux/list_sort.h> 74 #include <linux/list_sort.h>
74 75
75 #include <asm/page.h> 76 #include <asm/page.h>
76 #include <asm/div64.h> 77 #include <asm/div64.h>
77 #include <asm/param.h> 78 #include <asm/param.h>
78 #include <asm/uaccess.h> 79 #include <asm/uaccess.h>
79 #include <asm/byteorder.h> 80 #include <asm/byteorder.h>
80 #include <asm/unaligned.h> 81 #include <asm/unaligned.h>
81 82
82 #include "xfs_vnode.h" 83 #include "xfs_vnode.h"
83 #include "xfs_stats.h" 84 #include "xfs_stats.h"
84 #include "xfs_sysctl.h" 85 #include "xfs_sysctl.h"
85 #include "xfs_iops.h" 86 #include "xfs_iops.h"
86 #include "xfs_aops.h" 87 #include "xfs_aops.h"
87 #include "xfs_super.h" 88 #include "xfs_super.h"
88 #include "xfs_buf.h" 89 #include "xfs_buf.h"
89 #include "xfs_message.h" 90 #include "xfs_message.h"
90 91
91 #ifdef __BIG_ENDIAN 92 #ifdef __BIG_ENDIAN
92 #define XFS_NATIVE_HOST 1 93 #define XFS_NATIVE_HOST 1
93 #else 94 #else
94 #undef XFS_NATIVE_HOST 95 #undef XFS_NATIVE_HOST
95 #endif 96 #endif
96 97
97 /* 98 /*
98 * Feature macros (disable/enable) 99 * Feature macros (disable/enable)
99 */ 100 */
100 #ifdef CONFIG_SMP 101 #ifdef CONFIG_SMP
101 #define HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */ 102 #define HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
102 #else 103 #else
103 #undef HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */ 104 #undef HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
104 #endif 105 #endif
105 106
106 #define irix_sgid_inherit xfs_params.sgid_inherit.val 107 #define irix_sgid_inherit xfs_params.sgid_inherit.val
107 #define irix_symlink_mode xfs_params.symlink_mode.val 108 #define irix_symlink_mode xfs_params.symlink_mode.val
108 #define xfs_panic_mask xfs_params.panic_mask.val 109 #define xfs_panic_mask xfs_params.panic_mask.val
109 #define xfs_error_level xfs_params.error_level.val 110 #define xfs_error_level xfs_params.error_level.val
110 #define xfs_syncd_centisecs xfs_params.syncd_timer.val 111 #define xfs_syncd_centisecs xfs_params.syncd_timer.val
111 #define xfs_stats_clear xfs_params.stats_clear.val 112 #define xfs_stats_clear xfs_params.stats_clear.val
112 #define xfs_inherit_sync xfs_params.inherit_sync.val 113 #define xfs_inherit_sync xfs_params.inherit_sync.val
113 #define xfs_inherit_nodump xfs_params.inherit_nodump.val 114 #define xfs_inherit_nodump xfs_params.inherit_nodump.val
114 #define xfs_inherit_noatime xfs_params.inherit_noatim.val 115 #define xfs_inherit_noatime xfs_params.inherit_noatim.val
115 #define xfs_buf_timer_centisecs xfs_params.xfs_buf_timer.val 116 #define xfs_buf_timer_centisecs xfs_params.xfs_buf_timer.val
116 #define xfs_buf_age_centisecs xfs_params.xfs_buf_age.val 117 #define xfs_buf_age_centisecs xfs_params.xfs_buf_age.val
117 #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val 118 #define xfs_inherit_nosymlinks xfs_params.inherit_nosym.val
118 #define xfs_rotorstep xfs_params.rotorstep.val 119 #define xfs_rotorstep xfs_params.rotorstep.val
119 #define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val 120 #define xfs_inherit_nodefrag xfs_params.inherit_nodfrg.val
120 #define xfs_fstrm_centisecs xfs_params.fstrm_timer.val 121 #define xfs_fstrm_centisecs xfs_params.fstrm_timer.val
121 #define xfs_eofb_secs xfs_params.eofb_timer.val 122 #define xfs_eofb_secs xfs_params.eofb_timer.val
122 123
123 #define current_cpu() (raw_smp_processor_id()) 124 #define current_cpu() (raw_smp_processor_id())
124 #define current_pid() (current->pid) 125 #define current_pid() (current->pid)
125 #define current_test_flags(f) (current->flags & (f)) 126 #define current_test_flags(f) (current->flags & (f))
126 #define current_set_flags_nested(sp, f) \ 127 #define current_set_flags_nested(sp, f) \
127 (*(sp) = current->flags, current->flags |= (f)) 128 (*(sp) = current->flags, current->flags |= (f))
128 #define current_clear_flags_nested(sp, f) \ 129 #define current_clear_flags_nested(sp, f) \
129 (*(sp) = current->flags, current->flags &= ~(f)) 130 (*(sp) = current->flags, current->flags &= ~(f))
130 #define current_restore_flags_nested(sp, f) \ 131 #define current_restore_flags_nested(sp, f) \
131 (current->flags = ((current->flags & ~(f)) | (*(sp) & (f)))) 132 (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
132 133
133 #define spinlock_destroy(lock) 134 #define spinlock_destroy(lock)
134 135
135 #define NBBY 8 /* number of bits per byte */ 136 #define NBBY 8 /* number of bits per byte */
136 137
137 /* 138 /*
138 * Size of block device i/o is parameterized here. 139 * Size of block device i/o is parameterized here.
139 * Currently the system supports page-sized i/o. 140 * Currently the system supports page-sized i/o.
140 */ 141 */
141 #define BLKDEV_IOSHIFT PAGE_CACHE_SHIFT 142 #define BLKDEV_IOSHIFT PAGE_CACHE_SHIFT
142 #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT) 143 #define BLKDEV_IOSIZE (1<<BLKDEV_IOSHIFT)
143 /* number of BB's per block device block */ 144 /* number of BB's per block device block */
144 #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE) 145 #define BLKDEV_BB BTOBB(BLKDEV_IOSIZE)
145 146
146 #define ENOATTR ENODATA /* Attribute not found */ 147 #define ENOATTR ENODATA /* Attribute not found */
147 #define EWRONGFS EINVAL /* Mount with wrong filesystem type */ 148 #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
148 #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ 149 #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
149 150
150 #define SYNCHRONIZE() barrier() 151 #define SYNCHRONIZE() barrier()
151 #define __return_address __builtin_return_address(0) 152 #define __return_address __builtin_return_address(0)
152 153
153 #define XFS_PROJID_DEFAULT 0 154 #define XFS_PROJID_DEFAULT 0
154 #define MAXPATHLEN 1024 155 #define MAXPATHLEN 1024
155 156
156 #define MIN(a,b) (min(a,b)) 157 #define MIN(a,b) (min(a,b))
157 #define MAX(a,b) (max(a,b)) 158 #define MAX(a,b) (max(a,b))
158 #define howmany(x, y) (((x)+((y)-1))/(y)) 159 #define howmany(x, y) (((x)+((y)-1))/(y))
159 160
160 /* 161 /*
161 * Various platform dependent calls that don't fit anywhere else 162 * Various platform dependent calls that don't fit anywhere else
162 */ 163 */
163 #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL) 164 #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL)
164 #define xfs_stack_trace() dump_stack() 165 #define xfs_stack_trace() dump_stack()
165 166
166 167
167 /* Move the kernel do_div definition off to one side */ 168 /* Move the kernel do_div definition off to one side */
168 169
169 #if defined __i386__ 170 #if defined __i386__
170 /* For ia32 we need to pull some tricks to get past various versions 171 /* For ia32 we need to pull some tricks to get past various versions
171 * of the compiler which do not like us using do_div in the middle 172 * of the compiler which do not like us using do_div in the middle
172 * of large functions. 173 * of large functions.
173 */ 174 */
174 static inline __u32 xfs_do_div(void *a, __u32 b, int n) 175 static inline __u32 xfs_do_div(void *a, __u32 b, int n)
175 { 176 {
176 __u32 mod; 177 __u32 mod;
177 178
178 switch (n) { 179 switch (n) {
179 case 4: 180 case 4:
180 mod = *(__u32 *)a % b; 181 mod = *(__u32 *)a % b;
181 *(__u32 *)a = *(__u32 *)a / b; 182 *(__u32 *)a = *(__u32 *)a / b;
182 return mod; 183 return mod;
183 case 8: 184 case 8:
184 { 185 {
185 unsigned long __upper, __low, __high, __mod; 186 unsigned long __upper, __low, __high, __mod;
186 __u64 c = *(__u64 *)a; 187 __u64 c = *(__u64 *)a;
187 __upper = __high = c >> 32; 188 __upper = __high = c >> 32;
188 __low = c; 189 __low = c;
189 if (__high) { 190 if (__high) {
190 __upper = __high % (b); 191 __upper = __high % (b);
191 __high = __high / (b); 192 __high = __high / (b);
192 } 193 }
193 asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper)); 194 asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
194 asm("":"=A" (c):"a" (__low),"d" (__high)); 195 asm("":"=A" (c):"a" (__low),"d" (__high));
195 *(__u64 *)a = c; 196 *(__u64 *)a = c;
196 return __mod; 197 return __mod;
197 } 198 }
198 } 199 }
199 200
200 /* NOTREACHED */ 201 /* NOTREACHED */
201 return 0; 202 return 0;
202 } 203 }
203 204
204 /* Side effect free 64 bit mod operation */ 205 /* Side effect free 64 bit mod operation */
205 static inline __u32 xfs_do_mod(void *a, __u32 b, int n) 206 static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
206 { 207 {
207 switch (n) { 208 switch (n) {
208 case 4: 209 case 4:
209 return *(__u32 *)a % b; 210 return *(__u32 *)a % b;
210 case 8: 211 case 8:
211 { 212 {
212 unsigned long __upper, __low, __high, __mod; 213 unsigned long __upper, __low, __high, __mod;
213 __u64 c = *(__u64 *)a; 214 __u64 c = *(__u64 *)a;
214 __upper = __high = c >> 32; 215 __upper = __high = c >> 32;
215 __low = c; 216 __low = c;
216 if (__high) { 217 if (__high) {
217 __upper = __high % (b); 218 __upper = __high % (b);
218 __high = __high / (b); 219 __high = __high / (b);
219 } 220 }
220 asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper)); 221 asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (b), "0" (__low), "1" (__upper));
221 asm("":"=A" (c):"a" (__low),"d" (__high)); 222 asm("":"=A" (c):"a" (__low),"d" (__high));
222 return __mod; 223 return __mod;
223 } 224 }
224 } 225 }
225 226
226 /* NOTREACHED */ 227 /* NOTREACHED */
227 return 0; 228 return 0;
228 } 229 }
229 #else 230 #else
230 static inline __u32 xfs_do_div(void *a, __u32 b, int n) 231 static inline __u32 xfs_do_div(void *a, __u32 b, int n)
231 { 232 {
232 __u32 mod; 233 __u32 mod;
233 234
234 switch (n) { 235 switch (n) {
235 case 4: 236 case 4:
236 mod = *(__u32 *)a % b; 237 mod = *(__u32 *)a % b;
237 *(__u32 *)a = *(__u32 *)a / b; 238 *(__u32 *)a = *(__u32 *)a / b;
238 return mod; 239 return mod;
239 case 8: 240 case 8:
240 mod = do_div(*(__u64 *)a, b); 241 mod = do_div(*(__u64 *)a, b);
241 return mod; 242 return mod;
242 } 243 }
243 244
244 /* NOTREACHED */ 245 /* NOTREACHED */
245 return 0; 246 return 0;
246 } 247 }
247 248
248 /* Side effect free 64 bit mod operation */ 249 /* Side effect free 64 bit mod operation */
249 static inline __u32 xfs_do_mod(void *a, __u32 b, int n) 250 static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
250 { 251 {
251 switch (n) { 252 switch (n) {
252 case 4: 253 case 4:
253 return *(__u32 *)a % b; 254 return *(__u32 *)a % b;
254 case 8: 255 case 8:
255 { 256 {
256 __u64 c = *(__u64 *)a; 257 __u64 c = *(__u64 *)a;
257 return do_div(c, b); 258 return do_div(c, b);
258 } 259 }
259 } 260 }
260 261
261 /* NOTREACHED */ 262 /* NOTREACHED */
262 return 0; 263 return 0;
263 } 264 }
264 #endif 265 #endif
265 266
266 #undef do_div 267 #undef do_div
267 #define do_div(a, b) xfs_do_div(&(a), (b), sizeof(a)) 268 #define do_div(a, b) xfs_do_div(&(a), (b), sizeof(a))
268 #define do_mod(a, b) xfs_do_mod(&(a), (b), sizeof(a)) 269 #define do_mod(a, b) xfs_do_mod(&(a), (b), sizeof(a))
269 270
270 static inline __uint64_t roundup_64(__uint64_t x, __uint32_t y) 271 static inline __uint64_t roundup_64(__uint64_t x, __uint32_t y)
271 { 272 {
272 x += y - 1; 273 x += y - 1;
273 do_div(x, y); 274 do_div(x, y);
274 return(x * y); 275 return(x * y);
275 } 276 }
276 277
277 static inline __uint64_t howmany_64(__uint64_t x, __uint32_t y) 278 static inline __uint64_t howmany_64(__uint64_t x, __uint32_t y)
278 { 279 {
279 x += y - 1; 280 x += y - 1;
280 do_div(x, y); 281 do_div(x, y);
281 return x; 282 return x;
282 } 283 }
283 284
284 /* ARM old ABI has some weird alignment/padding */ 285 /* ARM old ABI has some weird alignment/padding */
285 #if defined(__arm__) && !defined(__ARM_EABI__) 286 #if defined(__arm__) && !defined(__ARM_EABI__)
286 #define __arch_pack __attribute__((packed)) 287 #define __arch_pack __attribute__((packed))
287 #else 288 #else
288 #define __arch_pack 289 #define __arch_pack
289 #endif 290 #endif
290 291
291 #define ASSERT_ALWAYS(expr) \ 292 #define ASSERT_ALWAYS(expr) \
292 (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__)) 293 (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
293 294
294 #ifndef DEBUG 295 #ifndef DEBUG
295 #define ASSERT(expr) ((void)0) 296 #define ASSERT(expr) ((void)0)
296 297
297 #ifndef STATIC 298 #ifndef STATIC
298 # define STATIC static noinline 299 # define STATIC static noinline
299 #endif 300 #endif
300 301
301 #else /* DEBUG */ 302 #else /* DEBUG */
302 303
303 #define ASSERT(expr) \ 304 #define ASSERT(expr) \
304 (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__)) 305 (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
305 306
306 #ifndef STATIC 307 #ifndef STATIC
307 # define STATIC noinline 308 # define STATIC noinline
308 #endif 309 #endif
309 310
310 #endif /* DEBUG */ 311 #endif /* DEBUG */
311 312
312 #endif /* __XFS_LINUX__ */ 313 #endif /* __XFS_LINUX__ */
313 314
1 /* 1 /*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc. 2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved. 3 * All Rights Reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as 6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * This program is distributed in the hope that it would be useful, 9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation, 15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */ 17 */
18 #ifndef __XFS_SB_H__ 18 #ifndef __XFS_SB_H__
19 #define __XFS_SB_H__ 19 #define __XFS_SB_H__
20 20
21 /* 21 /*
22 * Super block 22 * Super block
23 * Fits into a sector-sized buffer at address 0 of each allocation group. 23 * Fits into a sector-sized buffer at address 0 of each allocation group.
24 * Only the first of these is ever updated except during growfs. 24 * Only the first of these is ever updated except during growfs.
25 */ 25 */
26 26
27 struct xfs_buf; 27 struct xfs_buf;
28 struct xfs_mount; 28 struct xfs_mount;
29 29
30 #define XFS_SB_MAGIC 0x58465342 /* 'XFSB' */ 30 #define XFS_SB_MAGIC 0x58465342 /* 'XFSB' */
31 #define XFS_SB_VERSION_1 1 /* 5.3, 6.0.1, 6.1 */ 31 #define XFS_SB_VERSION_1 1 /* 5.3, 6.0.1, 6.1 */
32 #define XFS_SB_VERSION_2 2 /* 6.2 - attributes */ 32 #define XFS_SB_VERSION_2 2 /* 6.2 - attributes */
33 #define XFS_SB_VERSION_3 3 /* 6.2 - new inode version */ 33 #define XFS_SB_VERSION_3 3 /* 6.2 - new inode version */
34 #define XFS_SB_VERSION_4 4 /* 6.2+ - bitmask version */ 34 #define XFS_SB_VERSION_4 4 /* 6.2+ - bitmask version */
35 #define XFS_SB_VERSION_NUMBITS 0x000f 35 #define XFS_SB_VERSION_NUMBITS 0x000f
36 #define XFS_SB_VERSION_ALLFBITS 0xfff0 36 #define XFS_SB_VERSION_ALLFBITS 0xfff0
37 #define XFS_SB_VERSION_SASHFBITS 0xf000 37 #define XFS_SB_VERSION_SASHFBITS 0xf000
38 #define XFS_SB_VERSION_REALFBITS 0x0ff0 38 #define XFS_SB_VERSION_REALFBITS 0x0ff0
39 #define XFS_SB_VERSION_ATTRBIT 0x0010 39 #define XFS_SB_VERSION_ATTRBIT 0x0010
40 #define XFS_SB_VERSION_NLINKBIT 0x0020 40 #define XFS_SB_VERSION_NLINKBIT 0x0020
41 #define XFS_SB_VERSION_QUOTABIT 0x0040 41 #define XFS_SB_VERSION_QUOTABIT 0x0040
42 #define XFS_SB_VERSION_ALIGNBIT 0x0080 42 #define XFS_SB_VERSION_ALIGNBIT 0x0080
43 #define XFS_SB_VERSION_DALIGNBIT 0x0100 43 #define XFS_SB_VERSION_DALIGNBIT 0x0100
44 #define XFS_SB_VERSION_SHAREDBIT 0x0200 44 #define XFS_SB_VERSION_SHAREDBIT 0x0200
45 #define XFS_SB_VERSION_LOGV2BIT 0x0400 45 #define XFS_SB_VERSION_LOGV2BIT 0x0400
46 #define XFS_SB_VERSION_SECTORBIT 0x0800 46 #define XFS_SB_VERSION_SECTORBIT 0x0800
47 #define XFS_SB_VERSION_EXTFLGBIT 0x1000 47 #define XFS_SB_VERSION_EXTFLGBIT 0x1000
48 #define XFS_SB_VERSION_DIRV2BIT 0x2000 48 #define XFS_SB_VERSION_DIRV2BIT 0x2000
49 #define XFS_SB_VERSION_BORGBIT 0x4000 /* ASCII only case-insens. */ 49 #define XFS_SB_VERSION_BORGBIT 0x4000 /* ASCII only case-insens. */
50 #define XFS_SB_VERSION_MOREBITSBIT 0x8000 50 #define XFS_SB_VERSION_MOREBITSBIT 0x8000
51 #define XFS_SB_VERSION_OKSASHFBITS \ 51 #define XFS_SB_VERSION_OKSASHFBITS \
52 (XFS_SB_VERSION_EXTFLGBIT | \ 52 (XFS_SB_VERSION_EXTFLGBIT | \
53 XFS_SB_VERSION_DIRV2BIT | \ 53 XFS_SB_VERSION_DIRV2BIT | \
54 XFS_SB_VERSION_BORGBIT) 54 XFS_SB_VERSION_BORGBIT)
55 #define XFS_SB_VERSION_OKREALFBITS \ 55 #define XFS_SB_VERSION_OKREALFBITS \
56 (XFS_SB_VERSION_ATTRBIT | \ 56 (XFS_SB_VERSION_ATTRBIT | \
57 XFS_SB_VERSION_NLINKBIT | \ 57 XFS_SB_VERSION_NLINKBIT | \
58 XFS_SB_VERSION_QUOTABIT | \ 58 XFS_SB_VERSION_QUOTABIT | \
59 XFS_SB_VERSION_ALIGNBIT | \ 59 XFS_SB_VERSION_ALIGNBIT | \
60 XFS_SB_VERSION_DALIGNBIT | \ 60 XFS_SB_VERSION_DALIGNBIT | \
61 XFS_SB_VERSION_SHAREDBIT | \ 61 XFS_SB_VERSION_SHAREDBIT | \
62 XFS_SB_VERSION_LOGV2BIT | \ 62 XFS_SB_VERSION_LOGV2BIT | \
63 XFS_SB_VERSION_SECTORBIT | \ 63 XFS_SB_VERSION_SECTORBIT | \
64 XFS_SB_VERSION_MOREBITSBIT) 64 XFS_SB_VERSION_MOREBITSBIT)
65 #define XFS_SB_VERSION_OKREALBITS \ 65 #define XFS_SB_VERSION_OKREALBITS \
66 (XFS_SB_VERSION_NUMBITS | \ 66 (XFS_SB_VERSION_NUMBITS | \
67 XFS_SB_VERSION_OKREALFBITS | \ 67 XFS_SB_VERSION_OKREALFBITS | \
68 XFS_SB_VERSION_OKSASHFBITS) 68 XFS_SB_VERSION_OKSASHFBITS)
69 69
70 /* 70 /*
71 * There are two words to hold XFS "feature" bits: the original 71 * There are two words to hold XFS "feature" bits: the original
72 * word, sb_versionnum, and sb_features2. Whenever a bit is set in 72 * word, sb_versionnum, and sb_features2. Whenever a bit is set in
73 * sb_features2, the feature bit XFS_SB_VERSION_MOREBITSBIT must be set. 73 * sb_features2, the feature bit XFS_SB_VERSION_MOREBITSBIT must be set.
74 * 74 *
75 * These defines represent bits in sb_features2. 75 * These defines represent bits in sb_features2.
76 */ 76 */
77 #define XFS_SB_VERSION2_REALFBITS 0x00ffffff /* Mask: features */ 77 #define XFS_SB_VERSION2_REALFBITS 0x00ffffff /* Mask: features */
78 #define XFS_SB_VERSION2_RESERVED1BIT 0x00000001 78 #define XFS_SB_VERSION2_RESERVED1BIT 0x00000001
79 #define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000002 /* Superblk counters */ 79 #define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000002 /* Superblk counters */
80 #define XFS_SB_VERSION2_RESERVED4BIT 0x00000004 80 #define XFS_SB_VERSION2_RESERVED4BIT 0x00000004
81 #define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */ 81 #define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */
82 #define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* parent pointers */ 82 #define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* parent pointers */
83 #define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32 bit project id */ 83 #define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32 bit project id */
84 #define XFS_SB_VERSION2_CRCBIT 0x00000100 /* metadata CRCs */
84 85
85 #define XFS_SB_VERSION2_OKREALFBITS \ 86 #define XFS_SB_VERSION2_OKREALFBITS \
86 (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \ 87 (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
87 XFS_SB_VERSION2_ATTR2BIT | \ 88 XFS_SB_VERSION2_ATTR2BIT | \
88 XFS_SB_VERSION2_PROJID32BIT) 89 XFS_SB_VERSION2_PROJID32BIT)
89 #define XFS_SB_VERSION2_OKSASHFBITS \ 90 #define XFS_SB_VERSION2_OKSASHFBITS \
90 (0) 91 (0)
91 #define XFS_SB_VERSION2_OKREALBITS \ 92 #define XFS_SB_VERSION2_OKREALBITS \
92 (XFS_SB_VERSION2_OKREALFBITS | \ 93 (XFS_SB_VERSION2_OKREALFBITS | \
93 XFS_SB_VERSION2_OKSASHFBITS ) 94 XFS_SB_VERSION2_OKSASHFBITS )
94 95
95 /* 96 /*
96 * Superblock - in core version. Must match the ondisk version below. 97 * Superblock - in core version. Must match the ondisk version below.
97 * Must be padded to 64 bit alignment. 98 * Must be padded to 64 bit alignment.
98 */ 99 */
99 typedef struct xfs_sb { 100 typedef struct xfs_sb {
100 __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */ 101 __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */
101 __uint32_t sb_blocksize; /* logical block size, bytes */ 102 __uint32_t sb_blocksize; /* logical block size, bytes */
102 xfs_drfsbno_t sb_dblocks; /* number of data blocks */ 103 xfs_drfsbno_t sb_dblocks; /* number of data blocks */
103 xfs_drfsbno_t sb_rblocks; /* number of realtime blocks */ 104 xfs_drfsbno_t sb_rblocks; /* number of realtime blocks */
104 xfs_drtbno_t sb_rextents; /* number of realtime extents */ 105 xfs_drtbno_t sb_rextents; /* number of realtime extents */
105 uuid_t sb_uuid; /* file system unique id */ 106 uuid_t sb_uuid; /* file system unique id */
106 xfs_dfsbno_t sb_logstart; /* starting block of log if internal */ 107 xfs_dfsbno_t sb_logstart; /* starting block of log if internal */
107 xfs_ino_t sb_rootino; /* root inode number */ 108 xfs_ino_t sb_rootino; /* root inode number */
108 xfs_ino_t sb_rbmino; /* bitmap inode for realtime extents */ 109 xfs_ino_t sb_rbmino; /* bitmap inode for realtime extents */
109 xfs_ino_t sb_rsumino; /* summary inode for rt bitmap */ 110 xfs_ino_t sb_rsumino; /* summary inode for rt bitmap */
110 xfs_agblock_t sb_rextsize; /* realtime extent size, blocks */ 111 xfs_agblock_t sb_rextsize; /* realtime extent size, blocks */
111 xfs_agblock_t sb_agblocks; /* size of an allocation group */ 112 xfs_agblock_t sb_agblocks; /* size of an allocation group */
112 xfs_agnumber_t sb_agcount; /* number of allocation groups */ 113 xfs_agnumber_t sb_agcount; /* number of allocation groups */
113 xfs_extlen_t sb_rbmblocks; /* number of rt bitmap blocks */ 114 xfs_extlen_t sb_rbmblocks; /* number of rt bitmap blocks */
114 xfs_extlen_t sb_logblocks; /* number of log blocks */ 115 xfs_extlen_t sb_logblocks; /* number of log blocks */
115 __uint16_t sb_versionnum; /* header version == XFS_SB_VERSION */ 116 __uint16_t sb_versionnum; /* header version == XFS_SB_VERSION */
116 __uint16_t sb_sectsize; /* volume sector size, bytes */ 117 __uint16_t sb_sectsize; /* volume sector size, bytes */
117 __uint16_t sb_inodesize; /* inode size, bytes */ 118 __uint16_t sb_inodesize; /* inode size, bytes */
118 __uint16_t sb_inopblock; /* inodes per block */ 119 __uint16_t sb_inopblock; /* inodes per block */
119 char sb_fname[12]; /* file system name */ 120 char sb_fname[12]; /* file system name */
120 __uint8_t sb_blocklog; /* log2 of sb_blocksize */ 121 __uint8_t sb_blocklog; /* log2 of sb_blocksize */
121 __uint8_t sb_sectlog; /* log2 of sb_sectsize */ 122 __uint8_t sb_sectlog; /* log2 of sb_sectsize */
122 __uint8_t sb_inodelog; /* log2 of sb_inodesize */ 123 __uint8_t sb_inodelog; /* log2 of sb_inodesize */
123 __uint8_t sb_inopblog; /* log2 of sb_inopblock */ 124 __uint8_t sb_inopblog; /* log2 of sb_inopblock */
124 __uint8_t sb_agblklog; /* log2 of sb_agblocks (rounded up) */ 125 __uint8_t sb_agblklog; /* log2 of sb_agblocks (rounded up) */
125 __uint8_t sb_rextslog; /* log2 of sb_rextents */ 126 __uint8_t sb_rextslog; /* log2 of sb_rextents */
126 __uint8_t sb_inprogress; /* mkfs is in progress, don't mount */ 127 __uint8_t sb_inprogress; /* mkfs is in progress, don't mount */
127 __uint8_t sb_imax_pct; /* max % of fs for inode space */ 128 __uint8_t sb_imax_pct; /* max % of fs for inode space */
128 /* statistics */ 129 /* statistics */
129 /* 130 /*
130 * These fields must remain contiguous. If you really 131 * These fields must remain contiguous. If you really
131 * want to change their layout, make sure you fix the 132 * want to change their layout, make sure you fix the
132 * code in xfs_trans_apply_sb_deltas(). 133 * code in xfs_trans_apply_sb_deltas().
133 */ 134 */
134 __uint64_t sb_icount; /* allocated inodes */ 135 __uint64_t sb_icount; /* allocated inodes */
135 __uint64_t sb_ifree; /* free inodes */ 136 __uint64_t sb_ifree; /* free inodes */
136 __uint64_t sb_fdblocks; /* free data blocks */ 137 __uint64_t sb_fdblocks; /* free data blocks */
137 __uint64_t sb_frextents; /* free realtime extents */ 138 __uint64_t sb_frextents; /* free realtime extents */
138 /* 139 /*
139 * End contiguous fields. 140 * End contiguous fields.
140 */ 141 */
141 xfs_ino_t sb_uquotino; /* user quota inode */ 142 xfs_ino_t sb_uquotino; /* user quota inode */
142 xfs_ino_t sb_gquotino; /* group quota inode */ 143 xfs_ino_t sb_gquotino; /* group quota inode */
143 __uint16_t sb_qflags; /* quota flags */ 144 __uint16_t sb_qflags; /* quota flags */
144 __uint8_t sb_flags; /* misc. flags */ 145 __uint8_t sb_flags; /* misc. flags */
145 __uint8_t sb_shared_vn; /* shared version number */ 146 __uint8_t sb_shared_vn; /* shared version number */
146 xfs_extlen_t sb_inoalignmt; /* inode chunk alignment, fsblocks */ 147 xfs_extlen_t sb_inoalignmt; /* inode chunk alignment, fsblocks */
147 __uint32_t sb_unit; /* stripe or raid unit */ 148 __uint32_t sb_unit; /* stripe or raid unit */
148 __uint32_t sb_width; /* stripe or raid width */ 149 __uint32_t sb_width; /* stripe or raid width */
149 __uint8_t sb_dirblklog; /* log2 of dir block size (fsbs) */ 150 __uint8_t sb_dirblklog; /* log2 of dir block size (fsbs) */
150 __uint8_t sb_logsectlog; /* log2 of the log sector size */ 151 __uint8_t sb_logsectlog; /* log2 of the log sector size */
151 __uint16_t sb_logsectsize; /* sector size for the log, bytes */ 152 __uint16_t sb_logsectsize; /* sector size for the log, bytes */
152 __uint32_t sb_logsunit; /* stripe unit size for the log */ 153 __uint32_t sb_logsunit; /* stripe unit size for the log */
153 __uint32_t sb_features2; /* additional feature bits */ 154 __uint32_t sb_features2; /* additional feature bits */
154 155
155 /* 156 /*
156 * bad features2 field as a result of failing to pad the sb 157 * bad features2 field as a result of failing to pad the sb
157 * structure to 64 bits. Some machines will be using this field 158 * structure to 64 bits. Some machines will be using this field
158 * for features2 bits. Easiest just to mark it bad and not use 159 * for features2 bits. Easiest just to mark it bad and not use
159 * it for anything else. 160 * it for anything else.
160 */ 161 */
161 __uint32_t sb_bad_features2; 162 __uint32_t sb_bad_features2;
162 163
163 /* must be padded to 64 bit alignment */ 164 /* must be padded to 64 bit alignment */
164 } xfs_sb_t; 165 } xfs_sb_t;
165 166
166 /* 167 /*
167 * Superblock - on disk version. Must match the in core version above. 168 * Superblock - on disk version. Must match the in core version above.
168 * Must be padded to 64 bit alignment. 169 * Must be padded to 64 bit alignment.
169 */ 170 */
170 typedef struct xfs_dsb { 171 typedef struct xfs_dsb {
171 __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */ 172 __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */
172 __be32 sb_blocksize; /* logical block size, bytes */ 173 __be32 sb_blocksize; /* logical block size, bytes */
173 __be64 sb_dblocks; /* number of data blocks */ 174 __be64 sb_dblocks; /* number of data blocks */
174 __be64 sb_rblocks; /* number of realtime blocks */ 175 __be64 sb_rblocks; /* number of realtime blocks */
175 __be64 sb_rextents; /* number of realtime extents */ 176 __be64 sb_rextents; /* number of realtime extents */
176 uuid_t sb_uuid; /* file system unique id */ 177 uuid_t sb_uuid; /* file system unique id */
177 __be64 sb_logstart; /* starting block of log if internal */ 178 __be64 sb_logstart; /* starting block of log if internal */
178 __be64 sb_rootino; /* root inode number */ 179 __be64 sb_rootino; /* root inode number */
179 __be64 sb_rbmino; /* bitmap inode for realtime extents */ 180 __be64 sb_rbmino; /* bitmap inode for realtime extents */
180 __be64 sb_rsumino; /* summary inode for rt bitmap */ 181 __be64 sb_rsumino; /* summary inode for rt bitmap */
181 __be32 sb_rextsize; /* realtime extent size, blocks */ 182 __be32 sb_rextsize; /* realtime extent size, blocks */
182 __be32 sb_agblocks; /* size of an allocation group */ 183 __be32 sb_agblocks; /* size of an allocation group */
183 __be32 sb_agcount; /* number of allocation groups */ 184 __be32 sb_agcount; /* number of allocation groups */
184 __be32 sb_rbmblocks; /* number of rt bitmap blocks */ 185 __be32 sb_rbmblocks; /* number of rt bitmap blocks */
185 __be32 sb_logblocks; /* number of log blocks */ 186 __be32 sb_logblocks; /* number of log blocks */
186 __be16 sb_versionnum; /* header version == XFS_SB_VERSION */ 187 __be16 sb_versionnum; /* header version == XFS_SB_VERSION */
187 __be16 sb_sectsize; /* volume sector size, bytes */ 188 __be16 sb_sectsize; /* volume sector size, bytes */
188 __be16 sb_inodesize; /* inode size, bytes */ 189 __be16 sb_inodesize; /* inode size, bytes */
189 __be16 sb_inopblock; /* inodes per block */ 190 __be16 sb_inopblock; /* inodes per block */
190 char sb_fname[12]; /* file system name */ 191 char sb_fname[12]; /* file system name */
191 __u8 sb_blocklog; /* log2 of sb_blocksize */ 192 __u8 sb_blocklog; /* log2 of sb_blocksize */
192 __u8 sb_sectlog; /* log2 of sb_sectsize */ 193 __u8 sb_sectlog; /* log2 of sb_sectsize */
193 __u8 sb_inodelog; /* log2 of sb_inodesize */ 194 __u8 sb_inodelog; /* log2 of sb_inodesize */
194 __u8 sb_inopblog; /* log2 of sb_inopblock */ 195 __u8 sb_inopblog; /* log2 of sb_inopblock */
195 __u8 sb_agblklog; /* log2 of sb_agblocks (rounded up) */ 196 __u8 sb_agblklog; /* log2 of sb_agblocks (rounded up) */
196 __u8 sb_rextslog; /* log2 of sb_rextents */ 197 __u8 sb_rextslog; /* log2 of sb_rextents */
197 __u8 sb_inprogress; /* mkfs is in progress, don't mount */ 198 __u8 sb_inprogress; /* mkfs is in progress, don't mount */
198 __u8 sb_imax_pct; /* max % of fs for inode space */ 199 __u8 sb_imax_pct; /* max % of fs for inode space */
199 /* statistics */ 200 /* statistics */
200 /* 201 /*
201 * These fields must remain contiguous. If you really 202 * These fields must remain contiguous. If you really
202 * want to change their layout, make sure you fix the 203 * want to change their layout, make sure you fix the
203 * code in xfs_trans_apply_sb_deltas(). 204 * code in xfs_trans_apply_sb_deltas().
204 */ 205 */
205 __be64 sb_icount; /* allocated inodes */ 206 __be64 sb_icount; /* allocated inodes */
206 __be64 sb_ifree; /* free inodes */ 207 __be64 sb_ifree; /* free inodes */
207 __be64 sb_fdblocks; /* free data blocks */ 208 __be64 sb_fdblocks; /* free data blocks */
208 __be64 sb_frextents; /* free realtime extents */ 209 __be64 sb_frextents; /* free realtime extents */
209 /* 210 /*
210 * End contiguous fields. 211 * End contiguous fields.
211 */ 212 */
212 __be64 sb_uquotino; /* user quota inode */ 213 __be64 sb_uquotino; /* user quota inode */
213 __be64 sb_gquotino; /* group quota inode */ 214 __be64 sb_gquotino; /* group quota inode */
214 __be16 sb_qflags; /* quota flags */ 215 __be16 sb_qflags; /* quota flags */
215 __u8 sb_flags; /* misc. flags */ 216 __u8 sb_flags; /* misc. flags */
216 __u8 sb_shared_vn; /* shared version number */ 217 __u8 sb_shared_vn; /* shared version number */
217 __be32 sb_inoalignmt; /* inode chunk alignment, fsblocks */ 218 __be32 sb_inoalignmt; /* inode chunk alignment, fsblocks */
218 __be32 sb_unit; /* stripe or raid unit */ 219 __be32 sb_unit; /* stripe or raid unit */
219 __be32 sb_width; /* stripe or raid width */ 220 __be32 sb_width; /* stripe or raid width */
220 __u8 sb_dirblklog; /* log2 of dir block size (fsbs) */ 221 __u8 sb_dirblklog; /* log2 of dir block size (fsbs) */
221 __u8 sb_logsectlog; /* log2 of the log sector size */ 222 __u8 sb_logsectlog; /* log2 of the log sector size */
222 __be16 sb_logsectsize; /* sector size for the log, bytes */ 223 __be16 sb_logsectsize; /* sector size for the log, bytes */
223 __be32 sb_logsunit; /* stripe unit size for the log */ 224 __be32 sb_logsunit; /* stripe unit size for the log */
224 __be32 sb_features2; /* additional feature bits */ 225 __be32 sb_features2; /* additional feature bits */
225 /* 226 /*
226 * bad features2 field as a result of failing to pad the sb 227 * bad features2 field as a result of failing to pad the sb
227 * structure to 64 bits. Some machines will be using this field 228 * structure to 64 bits. Some machines will be using this field
228 * for features2 bits. Easiest just to mark it bad and not use 229 * for features2 bits. Easiest just to mark it bad and not use
229 * it for anything else. 230 * it for anything else.
230 */ 231 */
231 __be32 sb_bad_features2; 232 __be32 sb_bad_features2;
232 233
233 /* must be padded to 64 bit alignment */ 234 /* must be padded to 64 bit alignment */
234 } xfs_dsb_t; 235 } xfs_dsb_t;
235 236
236 /* 237 /*
237 * Sequence number values for the fields. 238 * Sequence number values for the fields.
238 */ 239 */
239 typedef enum { 240 typedef enum {
240 XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS, 241 XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
241 XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO, 242 XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
242 XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS, 243 XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
243 XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS, 244 XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
244 XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE, 245 XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
245 XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG, 246 XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
246 XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG, 247 XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
247 XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT, 248 XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
248 XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO, 249 XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
249 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN, 250 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
250 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG, 251 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
251 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT, 252 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
252 XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2, 253 XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2,
253 XFS_SBS_FIELDCOUNT 254 XFS_SBS_FIELDCOUNT
254 } xfs_sb_field_t; 255 } xfs_sb_field_t;
255 256
256 /* 257 /*
257 * Mask values, defined based on the xfs_sb_field_t values. 258 * Mask values, defined based on the xfs_sb_field_t values.
258 * Only define the ones we're using. 259 * Only define the ones we're using.
259 */ 260 */
260 #define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x) 261 #define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x)
261 #define XFS_SB_UUID XFS_SB_MVAL(UUID) 262 #define XFS_SB_UUID XFS_SB_MVAL(UUID)
262 #define XFS_SB_FNAME XFS_SB_MVAL(FNAME) 263 #define XFS_SB_FNAME XFS_SB_MVAL(FNAME)
263 #define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO) 264 #define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO)
264 #define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO) 265 #define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO)
265 #define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO) 266 #define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO)
266 #define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM) 267 #define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM)
267 #define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO) 268 #define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO)
268 #define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO) 269 #define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO)
269 #define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS) 270 #define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS)
270 #define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN) 271 #define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN)
271 #define XFS_SB_UNIT XFS_SB_MVAL(UNIT) 272 #define XFS_SB_UNIT XFS_SB_MVAL(UNIT)
272 #define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH) 273 #define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH)
273 #define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT) 274 #define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT)
274 #define XFS_SB_IFREE XFS_SB_MVAL(IFREE) 275 #define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
275 #define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS) 276 #define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
276 #define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2) 277 #define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2)
277 #define XFS_SB_BAD_FEATURES2 XFS_SB_MVAL(BAD_FEATURES2) 278 #define XFS_SB_BAD_FEATURES2 XFS_SB_MVAL(BAD_FEATURES2)
278 #define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT) 279 #define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
279 #define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1) 280 #define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
280 #define XFS_SB_MOD_BITS \ 281 #define XFS_SB_MOD_BITS \
281 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \ 282 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
282 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \ 283 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
283 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \ 284 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
284 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \ 285 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \
285 XFS_SB_BAD_FEATURES2) 286 XFS_SB_BAD_FEATURES2)
286 287
287 288
288 /* 289 /*
289 * Misc. Flags - warning - these will be cleared by xfs_repair unless 290 * Misc. Flags - warning - these will be cleared by xfs_repair unless
290 * a feature bit is set when the flag is used. 291 * a feature bit is set when the flag is used.
291 */ 292 */
292 #define XFS_SBF_NOFLAGS 0x00 /* no flags set */ 293 #define XFS_SBF_NOFLAGS 0x00 /* no flags set */
293 #define XFS_SBF_READONLY 0x01 /* only read-only mounts allowed */ 294 #define XFS_SBF_READONLY 0x01 /* only read-only mounts allowed */
294 295
295 /* 296 /*
296 * define max. shared version we can interoperate with 297 * define max. shared version we can interoperate with
297 */ 298 */
298 #define XFS_SB_MAX_SHARED_VN 0 299 #define XFS_SB_MAX_SHARED_VN 0
299 300
300 #define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS) 301 #define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
301 302
302 static inline int xfs_sb_good_version(xfs_sb_t *sbp) 303 static inline int xfs_sb_good_version(xfs_sb_t *sbp)
303 { 304 {
304 /* We always support version 1-3 */ 305 /* We always support version 1-3 */
305 if (sbp->sb_versionnum >= XFS_SB_VERSION_1 && 306 if (sbp->sb_versionnum >= XFS_SB_VERSION_1 &&
306 sbp->sb_versionnum <= XFS_SB_VERSION_3) 307 sbp->sb_versionnum <= XFS_SB_VERSION_3)
307 return 1; 308 return 1;
308 309
309 /* We support version 4 if all feature bits are supported */ 310 /* We support version 4 if all feature bits are supported */
310 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) { 311 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) {
311 if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) || 312 if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) ||
312 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) && 313 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
313 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS))) 314 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS)))
314 return 0; 315 return 0;
315 316
316 #ifdef __KERNEL__ 317 #ifdef __KERNEL__
317 if (sbp->sb_shared_vn > XFS_SB_MAX_SHARED_VN) 318 if (sbp->sb_shared_vn > XFS_SB_MAX_SHARED_VN)
318 return 0; 319 return 0;
319 #else 320 #else
320 if ((sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) && 321 if ((sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) &&
321 sbp->sb_shared_vn > XFS_SB_MAX_SHARED_VN) 322 sbp->sb_shared_vn > XFS_SB_MAX_SHARED_VN)
322 return 0; 323 return 0;
323 #endif 324 #endif
324 325
325 return 1; 326 return 1;
326 } 327 }
327 328
328 return 0; 329 return 0;
329 } 330 }
330 331
331 /* 332 /*
332 * Detect a mismatched features2 field. Older kernels read/wrote 333 * Detect a mismatched features2 field. Older kernels read/wrote
333 * this into the wrong slot, so to be safe we keep them in sync. 334 * this into the wrong slot, so to be safe we keep them in sync.
334 */ 335 */
335 static inline int xfs_sb_has_mismatched_features2(xfs_sb_t *sbp) 336 static inline int xfs_sb_has_mismatched_features2(xfs_sb_t *sbp)
336 { 337 {
337 return (sbp->sb_bad_features2 != sbp->sb_features2); 338 return (sbp->sb_bad_features2 != sbp->sb_features2);
338 } 339 }
339 340
340 static inline unsigned xfs_sb_version_tonew(unsigned v) 341 static inline unsigned xfs_sb_version_tonew(unsigned v)
341 { 342 {
342 if (v == XFS_SB_VERSION_1) 343 if (v == XFS_SB_VERSION_1)
343 return XFS_SB_VERSION_4; 344 return XFS_SB_VERSION_4;
344 345
345 if (v == XFS_SB_VERSION_2) 346 if (v == XFS_SB_VERSION_2)
346 return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT; 347 return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT;
347 348
348 return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT | 349 return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT |
349 XFS_SB_VERSION_NLINKBIT; 350 XFS_SB_VERSION_NLINKBIT;
350 } 351 }
351 352
352 static inline unsigned xfs_sb_version_toold(unsigned v) 353 static inline unsigned xfs_sb_version_toold(unsigned v)
353 { 354 {
354 if (v & (XFS_SB_VERSION_QUOTABIT | XFS_SB_VERSION_ALIGNBIT)) 355 if (v & (XFS_SB_VERSION_QUOTABIT | XFS_SB_VERSION_ALIGNBIT))
355 return 0; 356 return 0;
356 if (v & XFS_SB_VERSION_NLINKBIT) 357 if (v & XFS_SB_VERSION_NLINKBIT)
357 return XFS_SB_VERSION_3; 358 return XFS_SB_VERSION_3;
358 if (v & XFS_SB_VERSION_ATTRBIT) 359 if (v & XFS_SB_VERSION_ATTRBIT)
359 return XFS_SB_VERSION_2; 360 return XFS_SB_VERSION_2;
360 return XFS_SB_VERSION_1; 361 return XFS_SB_VERSION_1;
361 } 362 }
362 363
363 static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp) 364 static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp)
364 { 365 {
365 return sbp->sb_versionnum == XFS_SB_VERSION_2 || 366 return sbp->sb_versionnum == XFS_SB_VERSION_2 ||
366 sbp->sb_versionnum == XFS_SB_VERSION_3 || 367 sbp->sb_versionnum == XFS_SB_VERSION_3 ||
367 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 368 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
368 (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT)); 369 (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT));
369 } 370 }
370 371
371 static inline void xfs_sb_version_addattr(xfs_sb_t *sbp) 372 static inline void xfs_sb_version_addattr(xfs_sb_t *sbp)
372 { 373 {
373 if (sbp->sb_versionnum == XFS_SB_VERSION_1) 374 if (sbp->sb_versionnum == XFS_SB_VERSION_1)
374 sbp->sb_versionnum = XFS_SB_VERSION_2; 375 sbp->sb_versionnum = XFS_SB_VERSION_2;
375 else if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) 376 else if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
376 sbp->sb_versionnum |= XFS_SB_VERSION_ATTRBIT; 377 sbp->sb_versionnum |= XFS_SB_VERSION_ATTRBIT;
377 else 378 else
378 sbp->sb_versionnum = XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT; 379 sbp->sb_versionnum = XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT;
379 } 380 }
380 381
381 static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp) 382 static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp)
382 { 383 {
383 return sbp->sb_versionnum == XFS_SB_VERSION_3 || 384 return sbp->sb_versionnum == XFS_SB_VERSION_3 ||
384 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 385 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
385 (sbp->sb_versionnum & XFS_SB_VERSION_NLINKBIT)); 386 (sbp->sb_versionnum & XFS_SB_VERSION_NLINKBIT));
386 } 387 }
387 388
388 static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp) 389 static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp)
389 { 390 {
390 if (sbp->sb_versionnum <= XFS_SB_VERSION_2) 391 if (sbp->sb_versionnum <= XFS_SB_VERSION_2)
391 sbp->sb_versionnum = XFS_SB_VERSION_3; 392 sbp->sb_versionnum = XFS_SB_VERSION_3;
392 else 393 else
393 sbp->sb_versionnum |= XFS_SB_VERSION_NLINKBIT; 394 sbp->sb_versionnum |= XFS_SB_VERSION_NLINKBIT;
394 } 395 }
395 396
396 static inline int xfs_sb_version_hasquota(xfs_sb_t *sbp) 397 static inline int xfs_sb_version_hasquota(xfs_sb_t *sbp)
397 { 398 {
398 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 399 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
399 (sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT); 400 (sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
400 } 401 }
401 402
402 static inline void xfs_sb_version_addquota(xfs_sb_t *sbp) 403 static inline void xfs_sb_version_addquota(xfs_sb_t *sbp)
403 { 404 {
404 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) 405 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
405 sbp->sb_versionnum |= XFS_SB_VERSION_QUOTABIT; 406 sbp->sb_versionnum |= XFS_SB_VERSION_QUOTABIT;
406 else 407 else
407 sbp->sb_versionnum = xfs_sb_version_tonew(sbp->sb_versionnum) | 408 sbp->sb_versionnum = xfs_sb_version_tonew(sbp->sb_versionnum) |
408 XFS_SB_VERSION_QUOTABIT; 409 XFS_SB_VERSION_QUOTABIT;
409 } 410 }
410 411
411 static inline int xfs_sb_version_hasalign(xfs_sb_t *sbp) 412 static inline int xfs_sb_version_hasalign(xfs_sb_t *sbp)
412 { 413 {
413 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 414 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
414 (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT); 415 (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT);
415 } 416 }
416 417
417 static inline int xfs_sb_version_hasdalign(xfs_sb_t *sbp) 418 static inline int xfs_sb_version_hasdalign(xfs_sb_t *sbp)
418 { 419 {
419 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 420 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
420 (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT); 421 (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
421 } 422 }
422 423
423 static inline int xfs_sb_version_hasshared(xfs_sb_t *sbp) 424 static inline int xfs_sb_version_hasshared(xfs_sb_t *sbp)
424 { 425 {
425 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 426 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
426 (sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT); 427 (sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT);
427 } 428 }
428 429
429 static inline int xfs_sb_version_hasdirv2(xfs_sb_t *sbp) 430 static inline int xfs_sb_version_hasdirv2(xfs_sb_t *sbp)
430 { 431 {
431 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 432 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
432 (sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT); 433 (sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT);
433 } 434 }
434 435
435 static inline int xfs_sb_version_haslogv2(xfs_sb_t *sbp) 436 static inline int xfs_sb_version_haslogv2(xfs_sb_t *sbp)
436 { 437 {
437 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 438 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
438 (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT); 439 (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
439 } 440 }
440 441
441 static inline int xfs_sb_version_hasextflgbit(xfs_sb_t *sbp) 442 static inline int xfs_sb_version_hasextflgbit(xfs_sb_t *sbp)
442 { 443 {
443 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 444 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
444 (sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT); 445 (sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT);
445 } 446 }
446 447
447 static inline int xfs_sb_version_hassector(xfs_sb_t *sbp) 448 static inline int xfs_sb_version_hassector(xfs_sb_t *sbp)
448 { 449 {
449 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 450 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
450 (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT); 451 (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
451 } 452 }
452 453
453 static inline int xfs_sb_version_hasasciici(xfs_sb_t *sbp) 454 static inline int xfs_sb_version_hasasciici(xfs_sb_t *sbp)
454 { 455 {
455 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 456 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
456 (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT); 457 (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT);
457 } 458 }
458 459
459 static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp) 460 static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp)
460 { 461 {
461 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 && 462 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
462 (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT); 463 (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
463 } 464 }
464 465
465 /* 466 /*
466 * sb_features2 bit version macros. 467 * sb_features2 bit version macros.
467 * 468 *
468 * For example, for a bit defined as XFS_SB_VERSION2_FUNBIT, has a macro: 469 * For example, for a bit defined as XFS_SB_VERSION2_FUNBIT, has a macro:
469 * 470 *
470 * SB_VERSION_HASFUNBIT(xfs_sb_t *sbp) 471 * SB_VERSION_HASFUNBIT(xfs_sb_t *sbp)
471 * ((xfs_sb_version_hasmorebits(sbp) && 472 * ((xfs_sb_version_hasmorebits(sbp) &&
472 * ((sbp)->sb_features2 & XFS_SB_VERSION2_FUNBIT) 473 * ((sbp)->sb_features2 & XFS_SB_VERSION2_FUNBIT)
473 */ 474 */
474 475
475 static inline int xfs_sb_version_haslazysbcount(xfs_sb_t *sbp) 476 static inline int xfs_sb_version_haslazysbcount(xfs_sb_t *sbp)
476 { 477 {
477 return xfs_sb_version_hasmorebits(sbp) && 478 return xfs_sb_version_hasmorebits(sbp) &&
478 (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT); 479 (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT);
479 } 480 }
480 481
481 static inline int xfs_sb_version_hasattr2(xfs_sb_t *sbp) 482 static inline int xfs_sb_version_hasattr2(xfs_sb_t *sbp)
482 { 483 {
483 return xfs_sb_version_hasmorebits(sbp) && 484 return xfs_sb_version_hasmorebits(sbp) &&
484 (sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT); 485 (sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT);
485 } 486 }
486 487
487 static inline void xfs_sb_version_addattr2(xfs_sb_t *sbp) 488 static inline void xfs_sb_version_addattr2(xfs_sb_t *sbp)
488 { 489 {
489 sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT; 490 sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
490 sbp->sb_features2 |= XFS_SB_VERSION2_ATTR2BIT; 491 sbp->sb_features2 |= XFS_SB_VERSION2_ATTR2BIT;
491 } 492 }
492 493
493 static inline void xfs_sb_version_removeattr2(xfs_sb_t *sbp) 494 static inline void xfs_sb_version_removeattr2(xfs_sb_t *sbp)
494 { 495 {
495 sbp->sb_features2 &= ~XFS_SB_VERSION2_ATTR2BIT; 496 sbp->sb_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
496 if (!sbp->sb_features2) 497 if (!sbp->sb_features2)
497 sbp->sb_versionnum &= ~XFS_SB_VERSION_MOREBITSBIT; 498 sbp->sb_versionnum &= ~XFS_SB_VERSION_MOREBITSBIT;
498 } 499 }
499 500
500 static inline int xfs_sb_version_hasprojid32bit(xfs_sb_t *sbp) 501 static inline int xfs_sb_version_hasprojid32bit(xfs_sb_t *sbp)
501 { 502 {
502 return xfs_sb_version_hasmorebits(sbp) && 503 return xfs_sb_version_hasmorebits(sbp) &&
503 (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT); 504 (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT);
505 }
506
507 static inline int xfs_sb_version_hascrc(xfs_sb_t *sbp)
508 {
509 return (xfs_sb_version_hasmorebits(sbp) &&
510 (sbp->sb_features2 & XFS_SB_VERSION2_CRCBIT));
504 } 511 }
505 512
506 /* 513 /*
507 * end of superblock version macros 514 * end of superblock version macros
508 */ 515 */
509 516
510 #define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */ 517 #define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
511 #define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR) 518 #define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
512 #define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)((bp)->b_addr)) 519 #define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)((bp)->b_addr))
513 520
514 #define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d)) 521 #define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
515 #define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \ 522 #define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
516 xfs_daddr_to_agno(mp,d), xfs_daddr_to_agbno(mp,d)) 523 xfs_daddr_to_agno(mp,d), xfs_daddr_to_agbno(mp,d))
517 #define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \ 524 #define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \
518 XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno)) 525 XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
519 526
520 /* 527 /*
521 * File system sector to basic block conversions. 528 * File system sector to basic block conversions.
522 */ 529 */
523 #define XFS_FSS_TO_BB(mp,sec) ((sec) << (mp)->m_sectbb_log) 530 #define XFS_FSS_TO_BB(mp,sec) ((sec) << (mp)->m_sectbb_log)
524 531
525 /* 532 /*
526 * File system block to basic block conversions. 533 * File system block to basic block conversions.
527 */ 534 */
528 #define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log) 535 #define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log)
529 #define XFS_BB_TO_FSB(mp,bb) \ 536 #define XFS_BB_TO_FSB(mp,bb) \
530 (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log) 537 (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
531 #define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log) 538 #define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log)
532 539
533 /* 540 /*
534 * File system block to byte conversions. 541 * File system block to byte conversions.
535 */ 542 */
536 #define XFS_FSB_TO_B(mp,fsbno) ((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog) 543 #define XFS_FSB_TO_B(mp,fsbno) ((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
537 #define XFS_B_TO_FSB(mp,b) \ 544 #define XFS_B_TO_FSB(mp,b) \
538 ((((__uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog) 545 ((((__uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
539 #define XFS_B_TO_FSBT(mp,b) (((__uint64_t)(b)) >> (mp)->m_sb.sb_blocklog) 546 #define XFS_B_TO_FSBT(mp,b) (((__uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
540 #define XFS_B_FSB_OFFSET(mp,b) ((b) & (mp)->m_blockmask) 547 #define XFS_B_FSB_OFFSET(mp,b) ((b) & (mp)->m_blockmask)
541 548
542 #endif /* __XFS_SB_H__ */ 549 #endif /* __XFS_SB_H__ */
543 550