]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/xfs_mount.c
2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 * Mount initialization code establishing various mount
37 * fields from the superblock associated with the given
41 xfs_mount_common(xfs_mount_t
*mp
, xfs_sb_t
*sbp
)
45 mp
->m_agfrotor
= mp
->m_agirotor
= 0;
46 mp
->m_maxagi
= mp
->m_sb
.sb_agcount
;
47 mp
->m_blkbit_log
= sbp
->sb_blocklog
+ XFS_NBBYLOG
;
48 mp
->m_blkbb_log
= sbp
->sb_blocklog
- BBSHIFT
;
49 mp
->m_agno_log
= xfs_highbit32(sbp
->sb_agcount
- 1) + 1;
50 mp
->m_agino_log
= sbp
->sb_inopblog
+ sbp
->sb_agblklog
;
51 mp
->m_litino
= sbp
->sb_inodesize
-
52 ((uint
)sizeof(xfs_dinode_core_t
) + (uint
)sizeof(xfs_agino_t
));
53 mp
->m_blockmask
= sbp
->sb_blocksize
- 1;
54 mp
->m_blockwsize
= sbp
->sb_blocksize
>> XFS_WORDLOG
;
55 mp
->m_blockwmask
= mp
->m_blockwsize
- 1;
58 if (XFS_SB_VERSION_HASLOGV2(sbp
)) {
59 if (sbp
->sb_logsunit
<= 1) {
60 mp
->m_lstripemask
= 1;
63 1 << xfs_highbit32(sbp
->sb_logsunit
>> BBSHIFT
);
68 * Setup for attributes, in case they get created.
69 * This value is for inodes getting attributes for the first time,
70 * the per-inode value is for old attribute values.
72 ASSERT(sbp
->sb_inodesize
>= 256 && sbp
->sb_inodesize
<= 2048);
73 switch (sbp
->sb_inodesize
) {
75 mp
->m_attroffset
= XFS_LITINO(mp
) - XFS_BMDR_SPACE_CALC(2);
80 mp
->m_attroffset
= XFS_BMDR_SPACE_CALC(12);
85 ASSERT(mp
->m_attroffset
< XFS_LITINO(mp
));
87 for (i
= 0; i
< 2; i
++) {
88 mp
->m_alloc_mxr
[i
] = XFS_BTREE_BLOCK_MAXRECS(sbp
->sb_blocksize
,
90 mp
->m_alloc_mnr
[i
] = XFS_BTREE_BLOCK_MINRECS(sbp
->sb_blocksize
,
93 for (i
= 0; i
< 2; i
++) {
94 mp
->m_bmap_dmxr
[i
] = XFS_BTREE_BLOCK_MAXRECS(sbp
->sb_blocksize
,
96 mp
->m_bmap_dmnr
[i
] = XFS_BTREE_BLOCK_MINRECS(sbp
->sb_blocksize
,
99 for (i
= 0; i
< 2; i
++) {
100 mp
->m_inobt_mxr
[i
] = XFS_BTREE_BLOCK_MAXRECS(sbp
->sb_blocksize
,
102 mp
->m_inobt_mnr
[i
] = XFS_BTREE_BLOCK_MINRECS(sbp
->sb_blocksize
,
106 mp
->m_bsize
= XFS_FSB_TO_BB(mp
, 1);
107 mp
->m_ialloc_inos
= (int)MAX((__uint16_t
)XFS_INODES_PER_CHUNK
,
109 mp
->m_ialloc_blks
= mp
->m_ialloc_inos
>> sbp
->sb_inopblog
;
114 short type
; /* 0 = integer
115 * 1 = binary / string (no translation)
118 { offsetof(xfs_sb_t
, sb_magicnum
), 0 },
119 { offsetof(xfs_sb_t
, sb_blocksize
), 0 },
120 { offsetof(xfs_sb_t
, sb_dblocks
), 0 },
121 { offsetof(xfs_sb_t
, sb_rblocks
), 0 },
122 { offsetof(xfs_sb_t
, sb_rextents
), 0 },
123 { offsetof(xfs_sb_t
, sb_uuid
), 1 },
124 { offsetof(xfs_sb_t
, sb_logstart
), 0 },
125 { offsetof(xfs_sb_t
, sb_rootino
), 0 },
126 { offsetof(xfs_sb_t
, sb_rbmino
), 0 },
127 { offsetof(xfs_sb_t
, sb_rsumino
), 0 },
128 { offsetof(xfs_sb_t
, sb_rextsize
), 0 },
129 { offsetof(xfs_sb_t
, sb_agblocks
), 0 },
130 { offsetof(xfs_sb_t
, sb_agcount
), 0 },
131 { offsetof(xfs_sb_t
, sb_rbmblocks
), 0 },
132 { offsetof(xfs_sb_t
, sb_logblocks
), 0 },
133 { offsetof(xfs_sb_t
, sb_versionnum
), 0 },
134 { offsetof(xfs_sb_t
, sb_sectsize
), 0 },
135 { offsetof(xfs_sb_t
, sb_inodesize
), 0 },
136 { offsetof(xfs_sb_t
, sb_inopblock
), 0 },
137 { offsetof(xfs_sb_t
, sb_fname
[0]), 1 },
138 { offsetof(xfs_sb_t
, sb_blocklog
), 0 },
139 { offsetof(xfs_sb_t
, sb_sectlog
), 0 },
140 { offsetof(xfs_sb_t
, sb_inodelog
), 0 },
141 { offsetof(xfs_sb_t
, sb_inopblog
), 0 },
142 { offsetof(xfs_sb_t
, sb_agblklog
), 0 },
143 { offsetof(xfs_sb_t
, sb_rextslog
), 0 },
144 { offsetof(xfs_sb_t
, sb_inprogress
), 0 },
145 { offsetof(xfs_sb_t
, sb_imax_pct
), 0 },
146 { offsetof(xfs_sb_t
, sb_icount
), 0 },
147 { offsetof(xfs_sb_t
, sb_ifree
), 0 },
148 { offsetof(xfs_sb_t
, sb_fdblocks
), 0 },
149 { offsetof(xfs_sb_t
, sb_frextents
), 0 },
150 { offsetof(xfs_sb_t
, sb_uquotino
), 0 },
151 { offsetof(xfs_sb_t
, sb_gquotino
), 0 },
152 { offsetof(xfs_sb_t
, sb_qflags
), 0 },
153 { offsetof(xfs_sb_t
, sb_flags
), 0 },
154 { offsetof(xfs_sb_t
, sb_shared_vn
), 0 },
155 { offsetof(xfs_sb_t
, sb_inoalignmt
), 0 },
156 { offsetof(xfs_sb_t
, sb_unit
), 0 },
157 { offsetof(xfs_sb_t
, sb_width
), 0 },
158 { offsetof(xfs_sb_t
, sb_dirblklog
), 0 },
159 { offsetof(xfs_sb_t
, sb_dummy
), 1 },
160 { offsetof(xfs_sb_t
, sb_logsunit
), 0 },
161 { sizeof(xfs_sb_t
), 0 }
166 * data - on disk version of sb
168 * dir - conversion direction: <0 - convert sb to buf
169 * >0 - convert buf to sb
170 * arch - architecture to read/write from/to buf
171 * fields - which fields to copy (bitmask)
193 buf_ptr
= (xfs_caddr_t
)data
;
194 mem_ptr
= (xfs_caddr_t
)sb
;
197 f
= (xfs_sb_field_t
)xfs_lowbit64((__uint64_t
)fields
);
198 first
= xfs_sb_info
[f
].offset
;
199 size
= xfs_sb_info
[f
+ 1].offset
- first
;
201 ASSERT(xfs_sb_info
[f
].type
== 0 || xfs_sb_info
[f
].type
== 1);
203 if (arch
== ARCH_NOCONVERT
||
205 xfs_sb_info
[f
].type
== 1) {
207 memcpy(mem_ptr
+ first
, buf_ptr
+ first
, size
);
209 memcpy(buf_ptr
+ first
, mem_ptr
+ first
, size
);
214 INT_XLATE(*(__uint16_t
*)(buf_ptr
+first
),
215 *(__uint16_t
*)(mem_ptr
+first
),
219 INT_XLATE(*(__uint32_t
*)(buf_ptr
+first
),
220 *(__uint32_t
*)(mem_ptr
+first
),
224 INT_XLATE(*(__uint64_t
*)(buf_ptr
+first
),
225 *(__uint64_t
*)(mem_ptr
+first
), dir
, arch
);
232 fields
&= ~(1LL << f
);
237 xfs_initialize_perag(xfs_mount_t
*mp
, int agcount
)
239 int index
, max_metadata
;
243 xfs_sb_t
*sbp
= &mp
->m_sb
;
244 xfs_ino_t max_inum
= XFS_MAXINUMBER_32
;
246 /* Check to see if the filesystem can overflow 32 bit inodes */
247 agino
= XFS_OFFBNO_TO_AGINO(mp
, sbp
->sb_agblocks
- 1, 0);
248 ino
= XFS_AGINO_TO_INO(mp
, agcount
- 1, agino
);
250 /* Clear the mount flag if no inode can overflow 32 bits
251 * on this filesystem.
253 if (ino
<= max_inum
) {
254 mp
->m_flags
&= ~XFS_MOUNT_32BITINODES
;
257 /* If we can overflow then setup the ag headers accordingly */
258 if (mp
->m_flags
& XFS_MOUNT_32BITINODES
) {
259 /* Calculate how much should be reserved for inodes to
260 * meet the max inode percentage.
262 if (mp
->m_maxicount
) {
265 icount
= sbp
->sb_dblocks
* sbp
->sb_imax_pct
;
267 icount
+= sbp
->sb_agblocks
- 1;
268 do_div(icount
, mp
->m_ialloc_blks
);
269 max_metadata
= icount
;
271 max_metadata
= agcount
;
273 for (index
= 0; index
< agcount
; index
++) {
274 ino
= XFS_AGINO_TO_INO(mp
, index
, agino
);
275 if (ino
> max_inum
) {
280 /* This ag is prefered for inodes */
281 pag
= &mp
->m_perag
[index
];
282 pag
->pagi_inodeok
= 1;
283 if (index
< max_metadata
)
284 pag
->pagf_metadata
= 1;
287 /* Setup default behavior for smaller filesystems */
288 for (index
= 0; index
< agcount
; index
++) {
289 pag
= &mp
->m_perag
[index
];
290 pag
->pagi_inodeok
= 1;
293 mp
->m_maxagi
= index
;