fs: copy BTRFS_IOC_[SG]ET_FSLABEL to vfs
[linux-2.6-block.git] / fs / xfs / libxfs / xfs_sb.c
CommitLineData
ff55068c
DC
1/*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18#include "xfs.h"
19#include "xfs_fs.h"
632b89e8 20#include "xfs_shared.h"
ff55068c 21#include "xfs_format.h"
239880ef
DC
22#include "xfs_log_format.h"
23#include "xfs_trans_resv.h"
ff55068c 24#include "xfs_bit.h"
ff55068c 25#include "xfs_sb.h"
ff55068c 26#include "xfs_mount.h"
3ab78df2 27#include "xfs_defer.h"
ff55068c 28#include "xfs_inode.h"
ff55068c
DC
29#include "xfs_ialloc.h"
30#include "xfs_alloc.h"
ff55068c 31#include "xfs_error.h"
ff55068c
DC
32#include "xfs_trace.h"
33#include "xfs_cksum.h"
239880ef 34#include "xfs_trans.h"
ff55068c 35#include "xfs_buf_item.h"
a4fbe6ab
DC
36#include "xfs_bmap_btree.h"
37#include "xfs_alloc_btree.h"
38#include "xfs_ialloc_btree.h"
a45086e2 39#include "xfs_log.h"
035e00ac 40#include "xfs_rmap_btree.h"
1946b91c
DW
41#include "xfs_bmap.h"
42#include "xfs_refcount_btree.h"
c368ebcd
DW
43#include "xfs_da_format.h"
44#include "xfs_da_btree.h"
ff55068c
DC
45
46/*
47 * Physical superblock buffer manipulations. Shared with libxfs in userspace.
48 */
49
ff55068c
DC
50/*
51 * Reference counting access wrappers to the perag structures.
52 * Because we never free per-ag structures, the only thing we
53 * have to protect against changes is the tree structure itself.
54 */
55struct xfs_perag *
56xfs_perag_get(
57 struct xfs_mount *mp,
58 xfs_agnumber_t agno)
59{
60 struct xfs_perag *pag;
61 int ref = 0;
62
63 rcu_read_lock();
64 pag = radix_tree_lookup(&mp->m_perag_tree, agno);
65 if (pag) {
66 ASSERT(atomic_read(&pag->pag_ref) >= 0);
67 ref = atomic_inc_return(&pag->pag_ref);
68 }
69 rcu_read_unlock();
70 trace_xfs_perag_get(mp, agno, ref, _RET_IP_);
71 return pag;
72}
73
74/*
75 * search from @first to find the next perag with the given tag set.
76 */
77struct xfs_perag *
78xfs_perag_get_tag(
79 struct xfs_mount *mp,
80 xfs_agnumber_t first,
81 int tag)
82{
83 struct xfs_perag *pag;
84 int found;
85 int ref;
86
87 rcu_read_lock();
88 found = radix_tree_gang_lookup_tag(&mp->m_perag_tree,
89 (void **)&pag, first, 1, tag);
90 if (found <= 0) {
91 rcu_read_unlock();
92 return NULL;
93 }
94 ref = atomic_inc_return(&pag->pag_ref);
95 rcu_read_unlock();
96 trace_xfs_perag_get_tag(mp, pag->pag_agno, ref, _RET_IP_);
97 return pag;
98}
99
100void
101xfs_perag_put(
102 struct xfs_perag *pag)
103{
104 int ref;
105
106 ASSERT(atomic_read(&pag->pag_ref) > 0);
107 ref = atomic_dec_return(&pag->pag_ref);
108 trace_xfs_perag_put(pag->pag_mount, pag->pag_agno, ref, _RET_IP_);
109}
110
111/*
112 * Check the validity of the SB found.
113 */
114STATIC int
115xfs_mount_validate_sb(
116 xfs_mount_t *mp,
117 xfs_sb_t *sbp,
118 bool check_inprogress,
119 bool check_version)
120{
131fa58d
DW
121 uint32_t agcount = 0;
122 uint32_t rem;
4bb73d01 123
ff55068c
DC
124 if (sbp->sb_magicnum != XFS_SB_MAGIC) {
125 xfs_warn(mp, "bad magic number");
2451337d 126 return -EWRONGFS;
ff55068c
DC
127 }
128
129
130 if (!xfs_sb_good_version(sbp)) {
131 xfs_warn(mp, "bad version");
2451337d 132 return -EWRONGFS;
ff55068c
DC
133 }
134
135 /*
136 * Version 5 superblock feature mask validation. Reject combinations the
137 * kernel cannot support up front before checking anything else. For
138 * write validation, we don't need to check feature masks.
139 */
140 if (check_version && XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) {
ff55068c
DC
141 if (xfs_sb_has_compat_feature(sbp,
142 XFS_SB_FEAT_COMPAT_UNKNOWN)) {
143 xfs_warn(mp,
f41febd2 144"Superblock has unknown compatible features (0x%x) enabled.",
ff55068c
DC
145 (sbp->sb_features_compat &
146 XFS_SB_FEAT_COMPAT_UNKNOWN));
f41febd2
JP
147 xfs_warn(mp,
148"Using a more recent kernel is recommended.");
ff55068c
DC
149 }
150
151 if (xfs_sb_has_ro_compat_feature(sbp,
152 XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
153 xfs_alert(mp,
154"Superblock has unknown read-only compatible features (0x%x) enabled.",
155 (sbp->sb_features_ro_compat &
156 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
157 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
158 xfs_warn(mp,
f41febd2
JP
159"Attempted to mount read-only compatible filesystem read-write.");
160 xfs_warn(mp,
ff55068c 161"Filesystem can only be safely mounted read only.");
f41febd2 162
2451337d 163 return -EINVAL;
ff55068c
DC
164 }
165 }
166 if (xfs_sb_has_incompat_feature(sbp,
167 XFS_SB_FEAT_INCOMPAT_UNKNOWN)) {
168 xfs_warn(mp,
f41febd2 169"Superblock has unknown incompatible features (0x%x) enabled.",
ff55068c
DC
170 (sbp->sb_features_incompat &
171 XFS_SB_FEAT_INCOMPAT_UNKNOWN));
f41febd2
JP
172 xfs_warn(mp,
173"Filesystem can not be safely mounted by this kernel.");
2451337d 174 return -EINVAL;
ff55068c 175 }
a45086e2
BF
176 } else if (xfs_sb_version_hascrc(sbp)) {
177 /*
178 * We can't read verify the sb LSN because the read verifier is
179 * called before the log is allocated and processed. We know the
180 * log is set up before write verifier (!check_version) calls,
181 * so just check it here.
182 */
183 if (!xfs_log_check_lsn(mp, sbp->sb_lsn))
184 return -EFSCORRUPTED;
ff55068c
DC
185 }
186
187 if (xfs_sb_version_has_pquotino(sbp)) {
188 if (sbp->sb_qflags & (XFS_OQUOTA_ENFD | XFS_OQUOTA_CHKD)) {
189 xfs_notice(mp,
08e96e1a 190 "Version 5 of Super block has XFS_OQUOTA bits.");
2451337d 191 return -EFSCORRUPTED;
ff55068c
DC
192 }
193 } else if (sbp->sb_qflags & (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD |
194 XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD)) {
195 xfs_notice(mp,
08e96e1a 196"Superblock earlier than Version 5 has XFS_[PQ]UOTA_{ENFD|CHKD} bits.");
2451337d 197 return -EFSCORRUPTED;
ff55068c
DC
198 }
199
e5376fc1
BF
200 /*
201 * Full inode chunks must be aligned to inode chunk size when
202 * sparse inodes are enabled to support the sparse chunk
203 * allocation algorithm and prevent overlapping inode records.
204 */
205 if (xfs_sb_version_hassparseinodes(sbp)) {
206 uint32_t align;
207
e5376fc1
BF
208 align = XFS_INODES_PER_CHUNK * sbp->sb_inodesize
209 >> sbp->sb_blocklog;
210 if (sbp->sb_inoalignmt != align) {
211 xfs_warn(mp,
212"Inode block alignment (%u) must match chunk size (%u) for sparse inodes.",
213 sbp->sb_inoalignmt, align);
214 return -EINVAL;
215 }
216 }
217
ff55068c
DC
218 if (unlikely(
219 sbp->sb_logstart == 0 && mp->m_logdev_targp == mp->m_ddev_targp)) {
220 xfs_warn(mp,
221 "filesystem is marked as having an external log; "
222 "specify logdev on the mount command line.");
2451337d 223 return -EINVAL;
ff55068c
DC
224 }
225
226 if (unlikely(
227 sbp->sb_logstart != 0 && mp->m_logdev_targp != mp->m_ddev_targp)) {
228 xfs_warn(mp,
229 "filesystem is marked as having an internal log; "
230 "do not specify logdev on the mount command line.");
2451337d 231 return -EINVAL;
ff55068c
DC
232 }
233
4bb73d01
DW
234 /* Compute agcount for this number of dblocks and agblocks */
235 if (sbp->sb_agblocks) {
236 agcount = div_u64_rem(sbp->sb_dblocks, sbp->sb_agblocks, &rem);
237 if (rem)
238 agcount++;
239 }
240
ff55068c
DC
241 /*
242 * More sanity checking. Most of these were stolen directly from
243 * xfs_repair.
244 */
245 if (unlikely(
246 sbp->sb_agcount <= 0 ||
247 sbp->sb_sectsize < XFS_MIN_SECTORSIZE ||
248 sbp->sb_sectsize > XFS_MAX_SECTORSIZE ||
249 sbp->sb_sectlog < XFS_MIN_SECTORSIZE_LOG ||
250 sbp->sb_sectlog > XFS_MAX_SECTORSIZE_LOG ||
251 sbp->sb_sectsize != (1 << sbp->sb_sectlog) ||
252 sbp->sb_blocksize < XFS_MIN_BLOCKSIZE ||
253 sbp->sb_blocksize > XFS_MAX_BLOCKSIZE ||
254 sbp->sb_blocklog < XFS_MIN_BLOCKSIZE_LOG ||
255 sbp->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG ||
256 sbp->sb_blocksize != (1 << sbp->sb_blocklog) ||
83d230eb 257 sbp->sb_dirblklog + sbp->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG ||
ff55068c
DC
258 sbp->sb_inodesize < XFS_DINODE_MIN_SIZE ||
259 sbp->sb_inodesize > XFS_DINODE_MAX_SIZE ||
260 sbp->sb_inodelog < XFS_DINODE_MIN_LOG ||
261 sbp->sb_inodelog > XFS_DINODE_MAX_LOG ||
262 sbp->sb_inodesize != (1 << sbp->sb_inodelog) ||
e1b05723 263 sbp->sb_logsunit > XLOG_MAX_RECORD_BSIZE ||
392c6de9 264 sbp->sb_inopblock != howmany(sbp->sb_blocksize,sbp->sb_inodesize) ||
4bb73d01
DW
265 XFS_FSB_TO_B(mp, sbp->sb_agblocks) < XFS_MIN_AG_BYTES ||
266 XFS_FSB_TO_B(mp, sbp->sb_agblocks) > XFS_MAX_AG_BYTES ||
267 sbp->sb_agblklog != xfs_highbit32(sbp->sb_agblocks - 1) + 1 ||
268 agcount == 0 || agcount != sbp->sb_agcount ||
ff55068c
DC
269 (sbp->sb_blocklog - sbp->sb_inodelog != sbp->sb_inopblog) ||
270 (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE) ||
271 (sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE) ||
272 (sbp->sb_imax_pct > 100 /* zero sb_imax_pct is valid */) ||
273 sbp->sb_dblocks == 0 ||
274 sbp->sb_dblocks > XFS_MAX_DBLOCKS(sbp) ||
ab3e57b5
DC
275 sbp->sb_dblocks < XFS_MIN_DBLOCKS(sbp) ||
276 sbp->sb_shared_vn != 0)) {
5ef11eb0 277 xfs_notice(mp, "SB sanity check failed");
2451337d 278 return -EFSCORRUPTED;
bec9d48d
DW
279 }
280
281 if (xfs_sb_version_hascrc(&mp->m_sb) &&
282 sbp->sb_blocksize < XFS_MIN_CRC_BLOCKSIZE) {
283 xfs_notice(mp, "v5 SB sanity check failed");
284 return -EFSCORRUPTED;
ff55068c
DC
285 }
286
287 /*
288 * Until this is fixed only page-sized or smaller data blocks work.
289 */
290 if (unlikely(sbp->sb_blocksize > PAGE_SIZE)) {
291 xfs_warn(mp,
292 "File system with blocksize %d bytes. "
293 "Only pagesize (%ld) or less will currently work.",
294 sbp->sb_blocksize, PAGE_SIZE);
2451337d 295 return -ENOSYS;
ff55068c
DC
296 }
297
298 /*
299 * Currently only very few inode sizes are supported.
300 */
301 switch (sbp->sb_inodesize) {
302 case 256:
303 case 512:
304 case 1024:
305 case 2048:
306 break;
307 default:
308 xfs_warn(mp, "inode size of %d bytes not supported",
309 sbp->sb_inodesize);
2451337d 310 return -ENOSYS;
ff55068c
DC
311 }
312
313 if (xfs_sb_validate_fsb_count(sbp, sbp->sb_dblocks) ||
314 xfs_sb_validate_fsb_count(sbp, sbp->sb_rblocks)) {
315 xfs_warn(mp,
316 "file system too large to be mounted on this system.");
2451337d 317 return -EFBIG;
ff55068c
DC
318 }
319
320 if (check_inprogress && sbp->sb_inprogress) {
321 xfs_warn(mp, "Offline file system operation in progress!");
2451337d 322 return -EFSCORRUPTED;
ff55068c 323 }
ff55068c
DC
324 return 0;
325}
326
327void
328xfs_sb_quota_from_disk(struct xfs_sb *sbp)
329{
330 /*
331 * older mkfs doesn't initialize quota inodes to NULLFSINO. This
332 * leads to in-core values having two different values for a quota
333 * inode to be invalid: 0 and NULLFSINO. Change it to a single value
334 * NULLFSINO.
335 *
336 * Note that this change affect only the in-core values. These
337 * values are not written back to disk unless any quota information
338 * is written to the disk. Even in that case, sb_pquotino field is
339 * not written to disk unless the superblock supports pquotino.
340 */
341 if (sbp->sb_uquotino == 0)
342 sbp->sb_uquotino = NULLFSINO;
343 if (sbp->sb_gquotino == 0)
344 sbp->sb_gquotino = NULLFSINO;
345 if (sbp->sb_pquotino == 0)
346 sbp->sb_pquotino = NULLFSINO;
347
348 /*
349 * We need to do these manipilations only if we are working
350 * with an older version of on-disk superblock.
351 */
352 if (xfs_sb_version_has_pquotino(sbp))
353 return;
354
355 if (sbp->sb_qflags & XFS_OQUOTA_ENFD)
356 sbp->sb_qflags |= (sbp->sb_qflags & XFS_PQUOTA_ACCT) ?
357 XFS_PQUOTA_ENFD : XFS_GQUOTA_ENFD;
358 if (sbp->sb_qflags & XFS_OQUOTA_CHKD)
359 sbp->sb_qflags |= (sbp->sb_qflags & XFS_PQUOTA_ACCT) ?
360 XFS_PQUOTA_CHKD : XFS_GQUOTA_CHKD;
361 sbp->sb_qflags &= ~(XFS_OQUOTA_ENFD | XFS_OQUOTA_CHKD);
362
e6fc6fcf
ES
363 if (sbp->sb_qflags & XFS_PQUOTA_ACCT &&
364 sbp->sb_gquotino != NULLFSINO) {
ff55068c
DC
365 /*
366 * In older version of superblock, on-disk superblock only
367 * has sb_gquotino, and in-core superblock has both sb_gquotino
368 * and sb_pquotino. But, only one of them is supported at any
369 * point of time. So, if PQUOTA is set in disk superblock,
e6fc6fcf
ES
370 * copy over sb_gquotino to sb_pquotino. The NULLFSINO test
371 * above is to make sure we don't do this twice and wipe them
372 * both out!
ff55068c
DC
373 */
374 sbp->sb_pquotino = sbp->sb_gquotino;
375 sbp->sb_gquotino = NULLFSINO;
376 }
377}
378
5ef828c4
ES
379static void
380__xfs_sb_from_disk(
ff55068c 381 struct xfs_sb *to,
5ef828c4
ES
382 xfs_dsb_t *from,
383 bool convert_xquota)
ff55068c
DC
384{
385 to->sb_magicnum = be32_to_cpu(from->sb_magicnum);
386 to->sb_blocksize = be32_to_cpu(from->sb_blocksize);
387 to->sb_dblocks = be64_to_cpu(from->sb_dblocks);
388 to->sb_rblocks = be64_to_cpu(from->sb_rblocks);
389 to->sb_rextents = be64_to_cpu(from->sb_rextents);
390 memcpy(&to->sb_uuid, &from->sb_uuid, sizeof(to->sb_uuid));
391 to->sb_logstart = be64_to_cpu(from->sb_logstart);
392 to->sb_rootino = be64_to_cpu(from->sb_rootino);
393 to->sb_rbmino = be64_to_cpu(from->sb_rbmino);
394 to->sb_rsumino = be64_to_cpu(from->sb_rsumino);
395 to->sb_rextsize = be32_to_cpu(from->sb_rextsize);
396 to->sb_agblocks = be32_to_cpu(from->sb_agblocks);
397 to->sb_agcount = be32_to_cpu(from->sb_agcount);
398 to->sb_rbmblocks = be32_to_cpu(from->sb_rbmblocks);
399 to->sb_logblocks = be32_to_cpu(from->sb_logblocks);
400 to->sb_versionnum = be16_to_cpu(from->sb_versionnum);
401 to->sb_sectsize = be16_to_cpu(from->sb_sectsize);
402 to->sb_inodesize = be16_to_cpu(from->sb_inodesize);
403 to->sb_inopblock = be16_to_cpu(from->sb_inopblock);
404 memcpy(&to->sb_fname, &from->sb_fname, sizeof(to->sb_fname));
405 to->sb_blocklog = from->sb_blocklog;
406 to->sb_sectlog = from->sb_sectlog;
407 to->sb_inodelog = from->sb_inodelog;
408 to->sb_inopblog = from->sb_inopblog;
409 to->sb_agblklog = from->sb_agblklog;
410 to->sb_rextslog = from->sb_rextslog;
411 to->sb_inprogress = from->sb_inprogress;
412 to->sb_imax_pct = from->sb_imax_pct;
413 to->sb_icount = be64_to_cpu(from->sb_icount);
414 to->sb_ifree = be64_to_cpu(from->sb_ifree);
415 to->sb_fdblocks = be64_to_cpu(from->sb_fdblocks);
416 to->sb_frextents = be64_to_cpu(from->sb_frextents);
417 to->sb_uquotino = be64_to_cpu(from->sb_uquotino);
418 to->sb_gquotino = be64_to_cpu(from->sb_gquotino);
419 to->sb_qflags = be16_to_cpu(from->sb_qflags);
420 to->sb_flags = from->sb_flags;
421 to->sb_shared_vn = from->sb_shared_vn;
422 to->sb_inoalignmt = be32_to_cpu(from->sb_inoalignmt);
423 to->sb_unit = be32_to_cpu(from->sb_unit);
424 to->sb_width = be32_to_cpu(from->sb_width);
425 to->sb_dirblklog = from->sb_dirblklog;
426 to->sb_logsectlog = from->sb_logsectlog;
427 to->sb_logsectsize = be16_to_cpu(from->sb_logsectsize);
428 to->sb_logsunit = be32_to_cpu(from->sb_logsunit);
429 to->sb_features2 = be32_to_cpu(from->sb_features2);
430 to->sb_bad_features2 = be32_to_cpu(from->sb_bad_features2);
431 to->sb_features_compat = be32_to_cpu(from->sb_features_compat);
432 to->sb_features_ro_compat = be32_to_cpu(from->sb_features_ro_compat);
433 to->sb_features_incompat = be32_to_cpu(from->sb_features_incompat);
434 to->sb_features_log_incompat =
435 be32_to_cpu(from->sb_features_log_incompat);
04dd1a0d
ES
436 /* crc is only used on disk, not in memory; just init to 0 here. */
437 to->sb_crc = 0;
fb4f2b4e 438 to->sb_spino_align = be32_to_cpu(from->sb_spino_align);
ff55068c
DC
439 to->sb_pquotino = be64_to_cpu(from->sb_pquotino);
440 to->sb_lsn = be64_to_cpu(from->sb_lsn);
ce748eaa
ES
441 /*
442 * sb_meta_uuid is only on disk if it differs from sb_uuid and the
443 * feature flag is set; if not set we keep it only in memory.
444 */
445 if (xfs_sb_version_hasmetauuid(to))
446 uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
447 else
448 uuid_copy(&to->sb_meta_uuid, &from->sb_uuid);
5ef828c4
ES
449 /* Convert on-disk flags to in-memory flags? */
450 if (convert_xquota)
451 xfs_sb_quota_from_disk(to);
452}
453
454void
455xfs_sb_from_disk(
456 struct xfs_sb *to,
457 xfs_dsb_t *from)
458{
459 __xfs_sb_from_disk(to, from, true);
ff55068c
DC
460}
461
4d11a402 462static void
ff55068c 463xfs_sb_quota_to_disk(
4d11a402
DC
464 struct xfs_dsb *to,
465 struct xfs_sb *from)
ff55068c 466{
c8ce540d 467 uint16_t qflags = from->sb_qflags;
ff55068c 468
4d11a402
DC
469 to->sb_uquotino = cpu_to_be64(from->sb_uquotino);
470 if (xfs_sb_version_has_pquotino(from)) {
471 to->sb_qflags = cpu_to_be16(from->sb_qflags);
472 to->sb_gquotino = cpu_to_be64(from->sb_gquotino);
473 to->sb_pquotino = cpu_to_be64(from->sb_pquotino);
474 return;
475 }
476
ff55068c 477 /*
4d11a402
DC
478 * The in-core version of sb_qflags do not have XFS_OQUOTA_*
479 * flags, whereas the on-disk version does. So, convert incore
480 * XFS_{PG}QUOTA_* flags to on-disk XFS_OQUOTA_* flags.
ff55068c 481 */
4d11a402
DC
482 qflags &= ~(XFS_PQUOTA_ENFD | XFS_PQUOTA_CHKD |
483 XFS_GQUOTA_ENFD | XFS_GQUOTA_CHKD);
ff55068c 484
4d11a402
DC
485 if (from->sb_qflags &
486 (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD))
487 qflags |= XFS_OQUOTA_ENFD;
488 if (from->sb_qflags &
489 (XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD))
490 qflags |= XFS_OQUOTA_CHKD;
491 to->sb_qflags = cpu_to_be16(qflags);
ff55068c
DC
492
493 /*
4d11a402
DC
494 * GQUOTINO and PQUOTINO cannot be used together in versions
495 * of superblock that do not have pquotino. from->sb_flags
496 * tells us which quota is active and should be copied to
497 * disk. If neither are active, we should NULL the inode.
03e01349 498 *
4d11a402
DC
499 * In all cases, the separate pquotino must remain 0 because it
500 * it beyond the "end" of the valid non-pquotino superblock.
ff55068c 501 */
4d11a402 502 if (from->sb_qflags & XFS_GQUOTA_ACCT)
ff55068c 503 to->sb_gquotino = cpu_to_be64(from->sb_gquotino);
4d11a402 504 else if (from->sb_qflags & XFS_PQUOTA_ACCT)
ff55068c 505 to->sb_gquotino = cpu_to_be64(from->sb_pquotino);
03e01349
DC
506 else {
507 /*
508 * We can't rely on just the fields being logged to tell us
509 * that it is safe to write NULLFSINO - we should only do that
510 * if quotas are not actually enabled. Hence only write
511 * NULLFSINO if both in-core quota inodes are NULL.
512 */
513 if (from->sb_gquotino == NULLFSINO &&
514 from->sb_pquotino == NULLFSINO)
515 to->sb_gquotino = cpu_to_be64(NULLFSINO);
516 }
ff55068c 517
4d11a402 518 to->sb_pquotino = 0;
ff55068c
DC
519}
520
ff55068c
DC
521void
522xfs_sb_to_disk(
4d11a402
DC
523 struct xfs_dsb *to,
524 struct xfs_sb *from)
ff55068c 525{
4d11a402
DC
526 xfs_sb_quota_to_disk(to, from);
527
528 to->sb_magicnum = cpu_to_be32(from->sb_magicnum);
529 to->sb_blocksize = cpu_to_be32(from->sb_blocksize);
530 to->sb_dblocks = cpu_to_be64(from->sb_dblocks);
531 to->sb_rblocks = cpu_to_be64(from->sb_rblocks);
532 to->sb_rextents = cpu_to_be64(from->sb_rextents);
533 memcpy(&to->sb_uuid, &from->sb_uuid, sizeof(to->sb_uuid));
534 to->sb_logstart = cpu_to_be64(from->sb_logstart);
535 to->sb_rootino = cpu_to_be64(from->sb_rootino);
536 to->sb_rbmino = cpu_to_be64(from->sb_rbmino);
537 to->sb_rsumino = cpu_to_be64(from->sb_rsumino);
538 to->sb_rextsize = cpu_to_be32(from->sb_rextsize);
539 to->sb_agblocks = cpu_to_be32(from->sb_agblocks);
540 to->sb_agcount = cpu_to_be32(from->sb_agcount);
541 to->sb_rbmblocks = cpu_to_be32(from->sb_rbmblocks);
542 to->sb_logblocks = cpu_to_be32(from->sb_logblocks);
543 to->sb_versionnum = cpu_to_be16(from->sb_versionnum);
544 to->sb_sectsize = cpu_to_be16(from->sb_sectsize);
545 to->sb_inodesize = cpu_to_be16(from->sb_inodesize);
546 to->sb_inopblock = cpu_to_be16(from->sb_inopblock);
547 memcpy(&to->sb_fname, &from->sb_fname, sizeof(to->sb_fname));
548 to->sb_blocklog = from->sb_blocklog;
549 to->sb_sectlog = from->sb_sectlog;
550 to->sb_inodelog = from->sb_inodelog;
551 to->sb_inopblog = from->sb_inopblog;
552 to->sb_agblklog = from->sb_agblklog;
553 to->sb_rextslog = from->sb_rextslog;
554 to->sb_inprogress = from->sb_inprogress;
555 to->sb_imax_pct = from->sb_imax_pct;
556 to->sb_icount = cpu_to_be64(from->sb_icount);
557 to->sb_ifree = cpu_to_be64(from->sb_ifree);
558 to->sb_fdblocks = cpu_to_be64(from->sb_fdblocks);
559 to->sb_frextents = cpu_to_be64(from->sb_frextents);
ff55068c 560
4d11a402
DC
561 to->sb_flags = from->sb_flags;
562 to->sb_shared_vn = from->sb_shared_vn;
563 to->sb_inoalignmt = cpu_to_be32(from->sb_inoalignmt);
564 to->sb_unit = cpu_to_be32(from->sb_unit);
565 to->sb_width = cpu_to_be32(from->sb_width);
566 to->sb_dirblklog = from->sb_dirblklog;
567 to->sb_logsectlog = from->sb_logsectlog;
568 to->sb_logsectsize = cpu_to_be16(from->sb_logsectsize);
569 to->sb_logsunit = cpu_to_be32(from->sb_logsunit);
074e427b
DC
570
571 /*
572 * We need to ensure that bad_features2 always matches features2.
573 * Hence we enforce that here rather than having to remember to do it
574 * everywhere else that updates features2.
575 */
576 from->sb_bad_features2 = from->sb_features2;
4d11a402
DC
577 to->sb_features2 = cpu_to_be32(from->sb_features2);
578 to->sb_bad_features2 = cpu_to_be32(from->sb_bad_features2);
579
580 if (xfs_sb_version_hascrc(from)) {
581 to->sb_features_compat = cpu_to_be32(from->sb_features_compat);
582 to->sb_features_ro_compat =
583 cpu_to_be32(from->sb_features_ro_compat);
584 to->sb_features_incompat =
585 cpu_to_be32(from->sb_features_incompat);
586 to->sb_features_log_incompat =
587 cpu_to_be32(from->sb_features_log_incompat);
fb4f2b4e 588 to->sb_spino_align = cpu_to_be32(from->sb_spino_align);
4d11a402 589 to->sb_lsn = cpu_to_be64(from->sb_lsn);
ce748eaa
ES
590 if (xfs_sb_version_hasmetauuid(from))
591 uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
ff55068c
DC
592 }
593}
594
595static int
596xfs_sb_verify(
597 struct xfs_buf *bp,
598 bool check_version)
599{
600 struct xfs_mount *mp = bp->b_target->bt_mount;
601 struct xfs_sb sb;
602
5ef828c4
ES
603 /*
604 * Use call variant which doesn't convert quota flags from disk
605 * format, because xfs_mount_validate_sb checks the on-disk flags.
606 */
607 __xfs_sb_from_disk(&sb, XFS_BUF_TO_SBP(bp), false);
ff55068c
DC
608
609 /*
610 * Only check the in progress field for the primary superblock as
611 * mkfs.xfs doesn't clear it from secondary superblocks.
612 */
f3d7ebde
DC
613 return xfs_mount_validate_sb(mp, &sb,
614 bp->b_maps[0].bm_bn == XFS_SB_DADDR,
ff55068c
DC
615 check_version);
616}
617
618/*
619 * If the superblock has the CRC feature bit set or the CRC field is non-null,
620 * check that the CRC is valid. We check the CRC field is non-null because a
621 * single bit error could clear the feature bit and unused parts of the
622 * superblock are supposed to be zero. Hence a non-null crc field indicates that
623 * we've potentially lost a feature bit and we should check it anyway.
10e6e65d
ES
624 *
625 * However, past bugs (i.e. in growfs) left non-zeroed regions beyond the
626 * last field in V4 secondary superblocks. So for secondary superblocks,
627 * we are more forgiving, and ignore CRC failures if the primary doesn't
628 * indicate that the fs version is V5.
ff55068c
DC
629 */
630static void
631xfs_sb_read_verify(
632 struct xfs_buf *bp)
633{
634 struct xfs_mount *mp = bp->b_target->bt_mount;
635 struct xfs_dsb *dsb = XFS_BUF_TO_SBP(bp);
636 int error;
637
638 /*
639 * open code the version check to avoid needing to convert the entire
640 * superblock from disk order just to check the version number
641 */
642 if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC) &&
643 (((be16_to_cpu(dsb->sb_versionnum) & XFS_SB_VERSION_NUMBITS) ==
644 XFS_SB_VERSION_5) ||
645 dsb->sb_crc != 0)) {
646
51582170 647 if (!xfs_buf_verify_cksum(bp, XFS_SB_CRC_OFF)) {
10e6e65d 648 /* Only fail bad secondaries on a known V5 filesystem */
7a01e707 649 if (bp->b_bn == XFS_SB_DADDR ||
10e6e65d 650 xfs_sb_version_hascrc(&mp->m_sb)) {
2451337d 651 error = -EFSBADCRC;
10e6e65d
ES
652 goto out_error;
653 }
ff55068c
DC
654 }
655 }
656 error = xfs_sb_verify(bp, true);
657
658out_error:
31ca03c9 659 if (error == -EFSCORRUPTED || error == -EFSBADCRC)
bc1a09b8 660 xfs_verifier_error(bp, error, __this_address);
31ca03c9 661 else if (error)
ff55068c 662 xfs_buf_ioerror(bp, error);
ff55068c
DC
663}
664
665/*
666 * We may be probed for a filesystem match, so we may not want to emit
667 * messages when the superblock buffer is not actually an XFS superblock.
2533787a 668 * If we find an XFS superblock, then run a normal, noisy mount because we are
ff55068c
DC
669 * really going to mount it and want to know about errors.
670 */
671static void
672xfs_sb_quiet_read_verify(
673 struct xfs_buf *bp)
674{
675 struct xfs_dsb *dsb = XFS_BUF_TO_SBP(bp);
676
ff55068c
DC
677 if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC)) {
678 /* XFS filesystem, verify noisily! */
679 xfs_sb_read_verify(bp);
680 return;
681 }
682 /* quietly fail */
2451337d 683 xfs_buf_ioerror(bp, -EWRONGFS);
ff55068c
DC
684}
685
686static void
687xfs_sb_write_verify(
688 struct xfs_buf *bp)
689{
690 struct xfs_mount *mp = bp->b_target->bt_mount;
fb1755a6 691 struct xfs_buf_log_item *bip = bp->b_log_item;
ff55068c
DC
692 int error;
693
694 error = xfs_sb_verify(bp, false);
695 if (error) {
bc1a09b8 696 xfs_verifier_error(bp, error, __this_address);
ff55068c
DC
697 return;
698 }
699
700 if (!xfs_sb_version_hascrc(&mp->m_sb))
701 return;
702
703 if (bip)
704 XFS_BUF_TO_SBP(bp)->sb_lsn = cpu_to_be64(bip->bli_item.li_lsn);
705
f1dbcd7e 706 xfs_buf_update_cksum(bp, XFS_SB_CRC_OFF);
ff55068c
DC
707}
708
709const struct xfs_buf_ops xfs_sb_buf_ops = {
233135b7 710 .name = "xfs_sb",
ff55068c
DC
711 .verify_read = xfs_sb_read_verify,
712 .verify_write = xfs_sb_write_verify,
713};
714
715const struct xfs_buf_ops xfs_sb_quiet_buf_ops = {
233135b7 716 .name = "xfs_sb_quiet",
ff55068c
DC
717 .verify_read = xfs_sb_quiet_read_verify,
718 .verify_write = xfs_sb_write_verify,
719};
720
721/*
722 * xfs_mount_common
723 *
724 * Mount initialization code establishing various mount
725 * fields from the superblock associated with the given
726 * mount structure
727 */
728void
729xfs_sb_mount_common(
730 struct xfs_mount *mp,
731 struct xfs_sb *sbp)
732{
733 mp->m_agfrotor = mp->m_agirotor = 0;
ff55068c
DC
734 mp->m_maxagi = mp->m_sb.sb_agcount;
735 mp->m_blkbit_log = sbp->sb_blocklog + XFS_NBBYLOG;
736 mp->m_blkbb_log = sbp->sb_blocklog - BBSHIFT;
737 mp->m_sectbb_log = sbp->sb_sectlog - BBSHIFT;
738 mp->m_agno_log = xfs_highbit32(sbp->sb_agcount - 1) + 1;
739 mp->m_agino_log = sbp->sb_inopblog + sbp->sb_agblklog;
740 mp->m_blockmask = sbp->sb_blocksize - 1;
741 mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG;
742 mp->m_blockwmask = mp->m_blockwsize - 1;
743
744 mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1);
745 mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0);
746 mp->m_alloc_mnr[0] = mp->m_alloc_mxr[0] / 2;
747 mp->m_alloc_mnr[1] = mp->m_alloc_mxr[1] / 2;
748
749 mp->m_inobt_mxr[0] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, 1);
750 mp->m_inobt_mxr[1] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, 0);
751 mp->m_inobt_mnr[0] = mp->m_inobt_mxr[0] / 2;
752 mp->m_inobt_mnr[1] = mp->m_inobt_mxr[1] / 2;
753
754 mp->m_bmap_dmxr[0] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 1);
755 mp->m_bmap_dmxr[1] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 0);
756 mp->m_bmap_dmnr[0] = mp->m_bmap_dmxr[0] / 2;
757 mp->m_bmap_dmnr[1] = mp->m_bmap_dmxr[1] / 2;
758
a1f69417
ES
759 mp->m_rmap_mxr[0] = xfs_rmapbt_maxrecs(sbp->sb_blocksize, 1);
760 mp->m_rmap_mxr[1] = xfs_rmapbt_maxrecs(sbp->sb_blocksize, 0);
035e00ac
DW
761 mp->m_rmap_mnr[0] = mp->m_rmap_mxr[0] / 2;
762 mp->m_rmap_mnr[1] = mp->m_rmap_mxr[1] / 2;
763
a1f69417
ES
764 mp->m_refc_mxr[0] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, true);
765 mp->m_refc_mxr[1] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, false);
1946b91c
DW
766 mp->m_refc_mnr[0] = mp->m_refc_mxr[0] / 2;
767 mp->m_refc_mnr[1] = mp->m_refc_mxr[1] / 2;
768
ff55068c 769 mp->m_bsize = XFS_FSB_TO_BB(mp, 1);
c8ce540d 770 mp->m_ialloc_inos = (int)MAX((uint16_t)XFS_INODES_PER_CHUNK,
ff55068c
DC
771 sbp->sb_inopblock);
772 mp->m_ialloc_blks = mp->m_ialloc_inos >> sbp->sb_inopblog;
066a1884
BF
773
774 if (sbp->sb_spino_align)
775 mp->m_ialloc_min_blks = sbp->sb_spino_align;
776 else
777 mp->m_ialloc_min_blks = mp->m_ialloc_blks;
52548852
DW
778 mp->m_alloc_set_aside = xfs_alloc_set_aside(mp);
779 mp->m_ag_max_usable = xfs_alloc_ag_max_usable(mp);
ff55068c
DC
780}
781
782/*
783 * xfs_initialize_perag_data
784 *
785 * Read in each per-ag structure so we can count up the number of
786 * allocated inodes, free inodes and used filesystem blocks as this
787 * information is no longer persistent in the superblock. Once we have
788 * this information, write it into the in-core superblock structure.
789 */
790int
791xfs_initialize_perag_data(
792 struct xfs_mount *mp,
793 xfs_agnumber_t agcount)
794{
795 xfs_agnumber_t index;
796 xfs_perag_t *pag;
797 xfs_sb_t *sbp = &mp->m_sb;
798 uint64_t ifree = 0;
799 uint64_t ialloc = 0;
800 uint64_t bfree = 0;
801 uint64_t bfreelst = 0;
802 uint64_t btree = 0;
803 int error;
804
805 for (index = 0; index < agcount; index++) {
806 /*
807 * read the agf, then the agi. This gets us
808 * all the information we need and populates the
809 * per-ag structures for us.
810 */
811 error = xfs_alloc_pagf_init(mp, NULL, index, 0);
812 if (error)
813 return error;
814
815 error = xfs_ialloc_pagi_init(mp, NULL, index);
816 if (error)
817 return error;
818 pag = xfs_perag_get(mp, index);
819 ifree += pag->pagi_freecount;
820 ialloc += pag->pagi_count;
821 bfree += pag->pagf_freeblks;
822 bfreelst += pag->pagf_flcount;
823 btree += pag->pagf_btreeblks;
824 xfs_perag_put(pag);
825 }
5681ca40
DC
826
827 /* Overwrite incore superblock counters with just-read data */
ff55068c
DC
828 spin_lock(&mp->m_sb_lock);
829 sbp->sb_ifree = ifree;
830 sbp->sb_icount = ialloc;
831 sbp->sb_fdblocks = bfree + bfreelst + btree;
832 spin_unlock(&mp->m_sb_lock);
833
5681ca40 834 xfs_reinit_percpu_counters(mp);
ff55068c
DC
835
836 return 0;
837}
838
839/*
61e63ecb
DC
840 * xfs_log_sb() can be used to copy arbitrary changes to the in-core superblock
841 * into the superblock buffer to be logged. It does not provide the higher
842 * level of locking that is needed to protect the in-core superblock from
843 * concurrent access.
ff55068c
DC
844 */
845void
61e63ecb 846xfs_log_sb(
4d11a402 847 struct xfs_trans *tp)
ff55068c 848{
4d11a402
DC
849 struct xfs_mount *mp = tp->t_mountp;
850 struct xfs_buf *bp = xfs_trans_getsb(tp, mp, 0);
ff55068c 851
501ab323 852 mp->m_sb.sb_icount = percpu_counter_sum(&mp->m_icount);
e88b64ea 853 mp->m_sb.sb_ifree = percpu_counter_sum(&mp->m_ifree);
0d485ada 854 mp->m_sb.sb_fdblocks = percpu_counter_sum(&mp->m_fdblocks);
501ab323 855
4d11a402 856 xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb);
ff55068c 857 xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF);
4d11a402 858 xfs_trans_log_buf(tp, bp, 0, sizeof(struct xfs_dsb));
ff55068c 859}
61e63ecb
DC
860
861/*
862 * xfs_sync_sb
863 *
864 * Sync the superblock to disk.
865 *
866 * Note that the caller is responsible for checking the frozen state of the
867 * filesystem. This procedure uses the non-blocking transaction allocator and
868 * thus will allow modifications to a frozen fs. This is required because this
869 * code can be called during the process of freezing where use of the high-level
870 * allocator would deadlock.
871 */
872int
873xfs_sync_sb(
874 struct xfs_mount *mp,
875 bool wait)
876{
877 struct xfs_trans *tp;
878 int error;
879
253f4911
CH
880 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0,
881 XFS_TRANS_NO_WRITECOUNT, &tp);
882 if (error)
61e63ecb 883 return error;
61e63ecb
DC
884
885 xfs_log_sb(tp);
886 if (wait)
887 xfs_trans_set_sync(tp);
70393313 888 return xfs_trans_commit(tp);
61e63ecb 889}
c368ebcd 890
b16817b6
DC
891/*
892 * Update all the secondary superblocks to match the new state of the primary.
893 * Because we are completely overwriting all the existing fields in the
894 * secondary superblock buffers, there is no need to read them in from disk.
895 * Just get a new buffer, stamp it and write it.
896 *
897 * The sb buffers need to be cached here so that we serialise against other
898 * operations that access the secondary superblocks, but we don't want to keep
899 * them in memory once it is written so we mark it as a one-shot buffer.
900 */
901int
902xfs_update_secondary_sbs(
903 struct xfs_mount *mp)
904{
905 xfs_agnumber_t agno;
906 int saved_error = 0;
907 int error = 0;
908 LIST_HEAD (buffer_list);
909
910 /* update secondary superblocks. */
911 for (agno = 1; agno < mp->m_sb.sb_agcount; agno++) {
912 struct xfs_buf *bp;
913
914 bp = xfs_buf_get(mp->m_ddev_targp,
915 XFS_AG_DADDR(mp, agno, XFS_SB_DADDR),
916 XFS_FSS_TO_BB(mp, 1), 0);
917 /*
918 * If we get an error reading or writing alternate superblocks,
919 * continue. xfs_repair chooses the "best" superblock based
920 * on most matches; if we break early, we'll leave more
921 * superblocks un-updated than updated, and xfs_repair may
922 * pick them over the properly-updated primary.
923 */
924 if (!bp) {
925 xfs_warn(mp,
926 "error allocating secondary superblock for ag %d",
927 agno);
928 if (!saved_error)
929 saved_error = -ENOMEM;
930 continue;
931 }
932
933 bp->b_ops = &xfs_sb_buf_ops;
934 xfs_buf_oneshot(bp);
935 xfs_buf_zero(bp, 0, BBTOB(bp->b_length));
936 xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb);
937 xfs_buf_delwri_queue(bp, &buffer_list);
938 xfs_buf_relse(bp);
939
940 /* don't hold too many buffers at once */
941 if (agno % 16)
942 continue;
943
944 error = xfs_buf_delwri_submit(&buffer_list);
945 if (error) {
946 xfs_warn(mp,
947 "write error %d updating a secondary superblock near ag %d",
948 error, agno);
949 if (!saved_error)
950 saved_error = error;
951 continue;
952 }
953 }
954 error = xfs_buf_delwri_submit(&buffer_list);
955 if (error) {
956 xfs_warn(mp,
957 "write error %d updating a secondary superblock near ag %d",
958 error, agno);
959 }
960
961 return saved_error ? saved_error : error;
962}
963
c368ebcd
DW
964int
965xfs_fs_geometry(
ac503a4c
DW
966 struct xfs_sb *sbp,
967 struct xfs_fsop_geom *geo,
968 int struct_version)
c368ebcd 969{
ac503a4c
DW
970 memset(geo, 0, sizeof(struct xfs_fsop_geom));
971
972 geo->blocksize = sbp->sb_blocksize;
973 geo->rtextsize = sbp->sb_rextsize;
974 geo->agblocks = sbp->sb_agblocks;
975 geo->agcount = sbp->sb_agcount;
976 geo->logblocks = sbp->sb_logblocks;
977 geo->sectsize = sbp->sb_sectsize;
978 geo->inodesize = sbp->sb_inodesize;
979 geo->imaxpct = sbp->sb_imax_pct;
980 geo->datablocks = sbp->sb_dblocks;
981 geo->rtblocks = sbp->sb_rblocks;
982 geo->rtextents = sbp->sb_rextents;
983 geo->logstart = sbp->sb_logstart;
984 BUILD_BUG_ON(sizeof(geo->uuid) != sizeof(sbp->sb_uuid));
985 memcpy(geo->uuid, &sbp->sb_uuid, sizeof(sbp->sb_uuid));
986
987 if (struct_version < 2)
988 return 0;
989
990 geo->sunit = sbp->sb_unit;
991 geo->swidth = sbp->sb_width;
992
993 if (struct_version < 3)
994 return 0;
995
996 geo->version = XFS_FSOP_GEOM_VERSION;
997 geo->flags = XFS_FSOP_GEOM_FLAGS_NLINK |
998 XFS_FSOP_GEOM_FLAGS_DIRV2;
999 if (xfs_sb_version_hasattr(sbp))
1000 geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR;
1001 if (xfs_sb_version_hasquota(sbp))
1002 geo->flags |= XFS_FSOP_GEOM_FLAGS_QUOTA;
1003 if (xfs_sb_version_hasalign(sbp))
1004 geo->flags |= XFS_FSOP_GEOM_FLAGS_IALIGN;
1005 if (xfs_sb_version_hasdalign(sbp))
1006 geo->flags |= XFS_FSOP_GEOM_FLAGS_DALIGN;
1007 if (xfs_sb_version_hasextflgbit(sbp))
1008 geo->flags |= XFS_FSOP_GEOM_FLAGS_EXTFLG;
1009 if (xfs_sb_version_hassector(sbp))
1010 geo->flags |= XFS_FSOP_GEOM_FLAGS_SECTOR;
1011 if (xfs_sb_version_hasasciici(sbp))
1012 geo->flags |= XFS_FSOP_GEOM_FLAGS_DIRV2CI;
1013 if (xfs_sb_version_haslazysbcount(sbp))
1014 geo->flags |= XFS_FSOP_GEOM_FLAGS_LAZYSB;
1015 if (xfs_sb_version_hasattr2(sbp))
1016 geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR2;
1017 if (xfs_sb_version_hasprojid32bit(sbp))
1018 geo->flags |= XFS_FSOP_GEOM_FLAGS_PROJID32;
1019 if (xfs_sb_version_hascrc(sbp))
1020 geo->flags |= XFS_FSOP_GEOM_FLAGS_V5SB;
1021 if (xfs_sb_version_hasftype(sbp))
1022 geo->flags |= XFS_FSOP_GEOM_FLAGS_FTYPE;
1023 if (xfs_sb_version_hasfinobt(sbp))
1024 geo->flags |= XFS_FSOP_GEOM_FLAGS_FINOBT;
1025 if (xfs_sb_version_hassparseinodes(sbp))
1026 geo->flags |= XFS_FSOP_GEOM_FLAGS_SPINODES;
1027 if (xfs_sb_version_hasrmapbt(sbp))
1028 geo->flags |= XFS_FSOP_GEOM_FLAGS_RMAPBT;
1029 if (xfs_sb_version_hasreflink(sbp))
1030 geo->flags |= XFS_FSOP_GEOM_FLAGS_REFLINK;
1031 if (xfs_sb_version_hassector(sbp))
1032 geo->logsectsize = sbp->sb_logsectsize;
1033 else
1034 geo->logsectsize = BBSIZE;
1035 geo->rtsectsize = sbp->sb_blocksize;
1036 geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp);
1037
a8789a5a 1038 if (struct_version < 4)
ac503a4c
DW
1039 return 0;
1040
1041 if (xfs_sb_version_haslogv2(sbp))
1042 geo->flags |= XFS_FSOP_GEOM_FLAGS_LOGV2;
1043
1044 geo->logsunit = sbp->sb_logsunit;
c368ebcd 1045
c368ebcd
DW
1046 return 0;
1047}
689e11c8
DW
1048
1049/* Read a secondary superblock. */
1050int
1051xfs_sb_read_secondary(
1052 struct xfs_mount *mp,
1053 struct xfs_trans *tp,
1054 xfs_agnumber_t agno,
1055 struct xfs_buf **bpp)
1056{
1057 struct xfs_buf *bp;
1058 int error;
1059
1060 ASSERT(agno != 0 && agno != NULLAGNUMBER);
1061 error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
1062 XFS_AG_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
1063 XFS_FSS_TO_BB(mp, 1), 0, &bp, &xfs_sb_buf_ops);
1064 if (error)
1065 return error;
1066 xfs_buf_set_ref(bp, XFS_SSB_REF);
1067 *bpp = bp;
1068 return 0;
1069}