]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - mkfs/maxtrres.c
mkfs: factor block subopts parser
[thirdparty/xfsprogs-dev.git] / mkfs / maxtrres.c
CommitLineData
2bd0ea18 1/*
ca86e759
NS
2 * Copyright (c) 2000-2001,2004-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
da23017d
NS
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
2bd0ea18 7 * published by the Free Software Foundation.
ca86e759 8 *
da23017d
NS
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.
ca86e759 13 *
da23017d
NS
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
2bd0ea18
NS
17 */
18
19/*
cfd4ac07 20 * maxtrres.c
ca86e759 21 *
cfd4ac07
NS
22 * Compute the maximum transaction reservation for a legal combination
23 * of sector size, block size, inode size, directory version, and
24 * directory block size.
2bd0ea18 25 */
24f4f998 26#include "libfrog.h"
6b803e5a 27#include "libxfs.h"
4a32b9e9 28#include "xfs_multidisk.h"
2bd0ea18 29
2bd0ea18 30int
cfd4ac07 31max_trans_res(
e5cc9d56 32 unsigned long agsize,
f7b80291 33 int crcs_enabled,
cfd4ac07
NS
34 int dirversion,
35 int sectorlog,
36 int blocklog,
37 int inodelog,
88cd79be
DC
38 int dirblocklog,
39 int logversion,
e50c6371 40 int log_sunit,
c563396a 41 int finobt,
a5132d9b 42 int rmapbt,
2a3145a8
DW
43 int reflink,
44 int inode_align)
2bd0ea18 45{
2bd0ea18 46 xfs_sb_t *sbp;
cfd4ac07 47 xfs_mount_t mount;
88cd79be 48 int maxfsb;
2bd0ea18 49
cfd4ac07
NS
50 memset(&mount, 0, sizeof(mount));
51 sbp = &mount.m_sb;
2bd0ea18 52 sbp->sb_magicnum = XFS_SB_MAGIC;
cfd4ac07
NS
53 sbp->sb_sectlog = sectorlog;
54 sbp->sb_sectsize = 1 << sbp->sb_sectlog;
55 sbp->sb_blocklog = blocklog;
56 sbp->sb_blocksize = 1 << blocklog;
e5cc9d56 57 sbp->sb_agblocks = agsize;
24f4f998 58 sbp->sb_agblklog = (uint8_t)log2_roundup((unsigned int)agsize);
cfd4ac07
NS
59 sbp->sb_inodelog = inodelog;
60 sbp->sb_inopblog = blocklog - inodelog;
61 sbp->sb_inodesize = 1 << inodelog;
62 sbp->sb_inopblock = 1 << (blocklog - inodelog);
63 sbp->sb_dirblklog = dirblocklog - blocklog;
88cd79be 64
2a3145a8
DW
65 if (inode_align) {
66 int cluster_size = XFS_INODE_BIG_CLUSTER_SIZE;
67 if (crcs_enabled)
68 cluster_size *= sbp->sb_inodesize / XFS_DINODE_MIN_SIZE;
69 sbp->sb_inoalignmt = cluster_size >> blocklog;
70 }
71
88cd79be
DC
72 if (log_sunit > 0) {
73 log_sunit <<= blocklog;
74 logversion = 2;
75 } else
76 log_sunit = 1;
77 sbp->sb_logsunit = log_sunit;
78
f7b80291
DC
79 sbp->sb_versionnum =
80 (crcs_enabled ? XFS_SB_VERSION_5 : XFS_SB_VERSION_4) |
88cd79be 81 (dirversion == 2 ? XFS_SB_VERSION_DIRV2BIT : 0) |
ff105f75
DC
82 (logversion > 1 ? XFS_SB_VERSION_LOGV2BIT : 0) |
83 XFS_DFL_SB_VERSION_BITS;
e50c6371
DW
84 if (finobt)
85 sbp->sb_features_ro_compat |= XFS_SB_FEAT_RO_COMPAT_FINOBT;
c563396a
DW
86 if (rmapbt)
87 sbp->sb_features_ro_compat |= XFS_SB_FEAT_RO_COMPAT_RMAPBT;
a5132d9b
DW
88 if (reflink)
89 sbp->sb_features_ro_compat |= XFS_SB_FEAT_RO_COMPAT_REFLINK;
9440d84d 90
cfd4ac07 91 libxfs_mount(&mount, sbp, 0,0,0,0);
e2f60652 92 maxfsb = libxfs_log_calc_minimum_size(&mount);
cfd4ac07 93 libxfs_umount(&mount);
9440d84d 94
cfd4ac07 95#if 0
88cd79be
DC
96 printf("#define\tMAXTRRES_S%d_B%d_I%d_D%d_V%d_LSU%d\t%d\n",
97 sectorlog, blocklog, inodelog, dirblocklog, dirversion,
98 log_sunit, maxfsb);
cfd4ac07 99#endif
9440d84d 100
cfd4ac07 101 return maxfsb;
2bd0ea18 102}