]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - mkfs/maxtrres.c
fc24eac1aa61ac7a1ac2f237c8ca4197d7b96894
[thirdparty/xfsprogs-dev.git] / mkfs / maxtrres.c
1 /*
2 * Copyright (c) 2000-2001,2004-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
19 /*
20 * maxtrres.c
21 *
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.
25 */
26
27 #include "libxfs.h"
28 #include "xfs_multidisk.h"
29
30 int
31 max_trans_res(
32 unsigned long agsize,
33 int crcs_enabled,
34 int dirversion,
35 int sectorlog,
36 int blocklog,
37 int inodelog,
38 int dirblocklog,
39 int logversion,
40 int log_sunit,
41 int finobt,
42 int rmapbt)
43 {
44 xfs_sb_t *sbp;
45 xfs_mount_t mount;
46 int maxfsb;
47
48 memset(&mount, 0, sizeof(mount));
49 sbp = &mount.m_sb;
50 sbp->sb_magicnum = XFS_SB_MAGIC;
51 sbp->sb_sectlog = sectorlog;
52 sbp->sb_sectsize = 1 << sbp->sb_sectlog;
53 sbp->sb_blocklog = blocklog;
54 sbp->sb_blocksize = 1 << blocklog;
55 sbp->sb_agblocks = agsize;
56 sbp->sb_inodelog = inodelog;
57 sbp->sb_inopblog = blocklog - inodelog;
58 sbp->sb_inodesize = 1 << inodelog;
59 sbp->sb_inopblock = 1 << (blocklog - inodelog);
60 sbp->sb_dirblklog = dirblocklog - blocklog;
61
62 if (log_sunit > 0) {
63 log_sunit <<= blocklog;
64 logversion = 2;
65 } else
66 log_sunit = 1;
67 sbp->sb_logsunit = log_sunit;
68
69 sbp->sb_versionnum =
70 (crcs_enabled ? XFS_SB_VERSION_5 : XFS_SB_VERSION_4) |
71 (dirversion == 2 ? XFS_SB_VERSION_DIRV2BIT : 0) |
72 (logversion > 1 ? XFS_SB_VERSION_LOGV2BIT : 0) |
73 XFS_DFL_SB_VERSION_BITS;
74 if (finobt)
75 sbp->sb_features_ro_compat |= XFS_SB_FEAT_RO_COMPAT_FINOBT;
76 if (rmapbt)
77 sbp->sb_features_ro_compat |= XFS_SB_FEAT_RO_COMPAT_RMAPBT;
78
79 libxfs_mount(&mount, sbp, 0,0,0,0);
80 maxfsb = xfs_log_calc_minimum_size(&mount);
81 libxfs_umount(&mount);
82
83 #if 0
84 printf("#define\tMAXTRRES_S%d_B%d_I%d_D%d_V%d_LSU%d\t%d\n",
85 sectorlog, blocklog, inodelog, dirblocklog, dirversion,
86 log_sunit, maxfsb);
87 #endif
88
89 return maxfsb;
90 }