]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/xfs_mount.c
cmd/xfs/bmap/Makefile 1.8 Renamed to cmd/xfsprogs/bmap/Makefile
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_mount.c
1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
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.
7 *
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.
11 *
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.
18 *
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.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include <xfs.h>
34
35 /*
36 * Mount initialization code establishing various mount
37 * fields from the superblock associated with the given
38 * mount structure.
39 */
40 void
41 xfs_mount_common(xfs_mount_t *mp, xfs_sb_t *sbp)
42 {
43 int i;
44
45 mp->m_agfrotor = mp->m_agirotor = 0;
46 mp->m_blkbit_log = sbp->sb_blocklog + XFS_NBBYLOG;
47 mp->m_blkbb_log = sbp->sb_blocklog - BBSHIFT;
48 mp->m_agno_log = xfs_highbit32(sbp->sb_agcount - 1) + 1;
49 mp->m_agino_log = sbp->sb_inopblog + sbp->sb_agblklog;
50 mp->m_litino = sbp->sb_inodesize -
51 ((uint)sizeof(xfs_dinode_core_t) + (uint)sizeof(xfs_agino_t));
52 mp->m_blockmask = sbp->sb_blocksize - 1;
53 mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG;
54 mp->m_blockwmask = mp->m_blockwsize - 1;
55
56 /*
57 * Setup for attributes, in case they get created.
58 * This value is for inodes getting attributes for the first time,
59 * the per-inode value is for old attribute values.
60 */
61 ASSERT(sbp->sb_inodesize >= 256 && sbp->sb_inodesize <= 2048);
62 switch (sbp->sb_inodesize) {
63 case 256:
64 mp->m_attroffset = XFS_LITINO(mp) - XFS_BMDR_SPACE_CALC(2);
65 break;
66 case 512:
67 case 1024:
68 case 2048:
69 mp->m_attroffset = XFS_BMDR_SPACE_CALC(12);
70 break;
71 default:
72 ASSERT(0);
73 }
74 ASSERT(mp->m_attroffset < XFS_LITINO(mp));
75
76 for (i = 0; i < 2; i++) {
77 mp->m_alloc_mxr[i] = XFS_BTREE_BLOCK_MAXRECS(sbp->sb_blocksize,
78 xfs_alloc, i == 0);
79 mp->m_alloc_mnr[i] = XFS_BTREE_BLOCK_MINRECS(sbp->sb_blocksize,
80 xfs_alloc, i == 0);
81 }
82 for (i = 0; i < 2; i++) {
83 mp->m_bmap_dmxr[i] = XFS_BTREE_BLOCK_MAXRECS(sbp->sb_blocksize,
84 xfs_bmbt, i == 0);
85 mp->m_bmap_dmnr[i] = XFS_BTREE_BLOCK_MINRECS(sbp->sb_blocksize,
86 xfs_bmbt, i == 0);
87 }
88 for (i = 0; i < 2; i++) {
89 mp->m_inobt_mxr[i] = XFS_BTREE_BLOCK_MAXRECS(sbp->sb_blocksize,
90 xfs_inobt, i == 0);
91 mp->m_inobt_mnr[i] = XFS_BTREE_BLOCK_MINRECS(sbp->sb_blocksize,
92 xfs_inobt, i == 0);
93 }
94
95 mp->m_bsize = XFS_FSB_TO_BB(mp, 1);
96 mp->m_ialloc_inos = (int)MAX(XFS_INODES_PER_CHUNK, sbp->sb_inopblock);
97 mp->m_ialloc_blks = mp->m_ialloc_inos >> sbp->sb_inopblog;
98 }
99
100 static struct {
101 short offset;
102 short type; /* 0 = integer
103 * 1 = binary / string (no translation)
104 */
105 } xfs_sb_info[] = {
106 { offsetof(xfs_sb_t, sb_magicnum), 0 },
107 { offsetof(xfs_sb_t, sb_blocksize), 0 },
108 { offsetof(xfs_sb_t, sb_dblocks), 0 },
109 { offsetof(xfs_sb_t, sb_rblocks), 0 },
110 { offsetof(xfs_sb_t, sb_rextents), 0 },
111 { offsetof(xfs_sb_t, sb_uuid), 1 },
112 { offsetof(xfs_sb_t, sb_logstart), 0 },
113 { offsetof(xfs_sb_t, sb_rootino), 0 },
114 { offsetof(xfs_sb_t, sb_rbmino), 0 },
115 { offsetof(xfs_sb_t, sb_rsumino), 0 },
116 { offsetof(xfs_sb_t, sb_rextsize), 0 },
117 { offsetof(xfs_sb_t, sb_agblocks), 0 },
118 { offsetof(xfs_sb_t, sb_agcount), 0 },
119 { offsetof(xfs_sb_t, sb_rbmblocks), 0 },
120 { offsetof(xfs_sb_t, sb_logblocks), 0 },
121 { offsetof(xfs_sb_t, sb_versionnum), 0 },
122 { offsetof(xfs_sb_t, sb_sectsize), 0 },
123 { offsetof(xfs_sb_t, sb_inodesize), 0 },
124 { offsetof(xfs_sb_t, sb_inopblock), 0 },
125 { offsetof(xfs_sb_t, sb_fname[0]), 1 },
126 { offsetof(xfs_sb_t, sb_blocklog), 0 },
127 { offsetof(xfs_sb_t, sb_sectlog), 0 },
128 { offsetof(xfs_sb_t, sb_inodelog), 0 },
129 { offsetof(xfs_sb_t, sb_inopblog), 0 },
130 { offsetof(xfs_sb_t, sb_agblklog), 0 },
131 { offsetof(xfs_sb_t, sb_rextslog), 0 },
132 { offsetof(xfs_sb_t, sb_inprogress), 0 },
133 { offsetof(xfs_sb_t, sb_imax_pct), 0 },
134 { offsetof(xfs_sb_t, sb_icount), 0 },
135 { offsetof(xfs_sb_t, sb_ifree), 0 },
136 { offsetof(xfs_sb_t, sb_fdblocks), 0 },
137 { offsetof(xfs_sb_t, sb_frextents), 0 },
138 { offsetof(xfs_sb_t, sb_uquotino), 0 },
139 { offsetof(xfs_sb_t, sb_pquotino), 0 },
140 { offsetof(xfs_sb_t, sb_qflags), 0 },
141 { offsetof(xfs_sb_t, sb_flags), 0 },
142 { offsetof(xfs_sb_t, sb_shared_vn), 0 },
143 { offsetof(xfs_sb_t, sb_inoalignmt), 0 },
144 { offsetof(xfs_sb_t, sb_unit), 0 },
145 { offsetof(xfs_sb_t, sb_width), 0 },
146 { offsetof(xfs_sb_t, sb_dirblklog), 0 },
147 { offsetof(xfs_sb_t, sb_dummy), 1 },
148 { sizeof(xfs_sb_t), 0 }
149 };
150
151 /*
152 * xfs_xlatesb
153 * data - on disk version of sb
154 * sb - a superblock
155 * dir - conversion direction: <0 - convert sb to buf
156 * >0 - convert buf to sb
157 * arch - architecture to read/write from/to buf
158 * fields - which fields to copy (bitmask)
159 */
160 void
161 xfs_xlatesb(void *data, xfs_sb_t *sb, int dir, xfs_arch_t arch,
162 __int64_t fields)
163 {
164 xfs_caddr_t buf_ptr;
165 xfs_caddr_t mem_ptr;
166
167 ASSERT(dir);
168 ASSERT(fields);
169
170 if (!fields)
171 return;
172
173 buf_ptr=(xfs_caddr_t)data;
174 mem_ptr=(xfs_caddr_t)sb;
175
176 while (fields) {
177 xfs_sb_field_t f;
178 int first;
179 int size;
180
181 f = (xfs_sb_field_t)xfs_lowbit64((__uint64_t)fields);
182 first = xfs_sb_info[f].offset;
183 size = xfs_sb_info[f + 1].offset - first;
184
185 ASSERT(xfs_sb_info[f].type==0 || xfs_sb_info[f].type==1);
186
187 if (arch == ARCH_NOCONVERT || size==1 || xfs_sb_info[f].type==1) {
188 if (dir>0) {
189 bcopy(buf_ptr + first, mem_ptr + first, size);
190 } else {
191 bcopy(mem_ptr + first, buf_ptr + first, size);
192 }
193 } else {
194 switch (size) {
195 case 2:
196 INT_XLATE(*(__uint16_t*)(buf_ptr+first),
197 *(__uint16_t*)(mem_ptr+first), dir, arch);
198 break;
199 case 4:
200 INT_XLATE(*(__uint32_t*)(buf_ptr+first),
201 *(__uint32_t*)(mem_ptr+first), dir, arch);
202 break;
203 case 8:
204 INT_XLATE(*(__uint64_t*)(buf_ptr+first),
205 *(__uint64_t*)(mem_ptr+first), dir, arch);
206 break;
207 default:
208 ASSERT(0);
209 }
210 }
211 fields &= ~(1LL << f);
212 }
213
214 }