Bug Summary

File:src/usr.sbin/makefs/ffs/mkfs.c
Warning:line 732, column 26
Division by zero

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name mkfs.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/usr.sbin/makefs/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/usr.sbin/makefs -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.sbin/makefs/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/usr.sbin/makefs/ffs/mkfs.c
1/* $OpenBSD: mkfs.c,v 1.14 2021/10/06 00:40:41 deraadt Exp $ */
2/* $NetBSD: mkfs.c,v 1.34 2016/06/24 19:24:11 christos Exp $ */
3
4/*
5 * Copyright (c) 2002 Networks Associates Technology, Inc.
6 * All rights reserved.
7 *
8 * This software was developed for the FreeBSD Project by Marshall
9 * Kirk McKusick and Network Associates Laboratories, the Security
10 * Research Division of Network Associates, Inc. under DARPA/SPAWAR
11 * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
12 * research program
13 *
14 * Copyright (c) 1980, 1989, 1993
15 * The Regents of the University of California. All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 */
41
42#include <sys/param.h> /* roundup howmany setbit */
43#include <sys/time.h>
44#include <sys/resource.h>
45
46#include <stdio.h>
47#include <stdlib.h>
48#include <limits.h>
49#include <string.h>
50#include <unistd.h>
51#include <errno(*__errno()).h>
52#include <util.h>
53
54#include <ufs/ufs/dinode.h>
55#include <ufs/ffs/fs.h>
56
57#include "ffs/ufs_inode.h"
58#include "ffs/ffs_extern.h"
59
60#include "makefs.h"
61#include "ffs.h"
62#include "ffs/newfs_extern.h"
63
64static void initcg(int, time_t, const fsinfo_t *);
65static int ilog2(int);
66
67static int count_digits(int);
68
69/*
70 * make file system for cylinder-group style file systems
71 */
72#define UMASK0755 0755
73#define POWEROF2(num)(((num) & ((num) - 1)) == 0) (((num) & ((num) - 1)) == 0)
74
75union {
76 struct fs fs;
77 char pad[SBLOCKSIZE8192];
78} fsun;
79#define sblockfsun.fs fsun.fs
80struct csum *fscs;
81
82union {
83 struct cg cg;
84 char pad[FFS_MAXBSIZE65536];
85} cgun;
86#define acgcgun.cg cgun.cg
87
88char *iobuf;
89int iobufsize;
90
91char writebuf[FFS_MAXBSIZE65536];
92
93static int Oflag; /* format as an 4.3BSD file system */
94static int64_t fssize; /* file system size */
95static int sectorsize; /* bytes/sector */
96static int fsize; /* fragment size */
97static int bsize; /* block size */
98static int maxbsize; /* maximum clustering */
99static int maxblkspercg;
100static int minfree; /* free space threshold */
101static int opt; /* optimization preference (space or time) */
102static int density; /* number of bytes per inode */
103static int maxcontig; /* max contiguous blocks to allocate */
104static int maxbpg; /* maximum blocks per file in a cyl group */
105static int bbsize; /* boot block size */
106static int avgfilesize; /* expected average file size */
107static int avgfpdir; /* expected number of files per directory */
108
109struct fs *
110ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp)
111{
112 int fragsperinode, optimalfpg, origdensity, minfpg, lastminfpg;
113 int32_t cylno, i, csfrags;
114 long long sizepb;
115 void *space;
116 int size;
117 int nprintcols, printcolwidth;
118 ffs_opt_t *ffs_opts = fsopts->fs_specific;
119
120 Oflag = ffs_opts->version;
121 fssize = fsopts->size / fsopts->sectorsize;
122 sectorsize = fsopts->sectorsize;
123 fsize = ffs_opts->fsize;
124 bsize = ffs_opts->bsize;
125 maxbsize = ffs_opts->maxbsize;
126 maxblkspercg = ffs_opts->maxblkspercg;
127 minfree = ffs_opts->minfree;
128 opt = ffs_opts->optimization;
129 density = ffs_opts->density;
130 maxcontig = MAXIMUM(1, MINIMUM(MAXBSIZE, FFS_MAXBSIZE) / bsize)(((1) > (((((64 * 1024)) < (65536)) ? ((64 * 1024)) : (
65536)) / bsize)) ? (1) : (((((64 * 1024)) < (65536)) ? ((
64 * 1024)) : (65536)) / bsize))
;
1
'?' condition is false
2
Assuming the condition is false
3
'?' condition is false
4
'?' condition is false
131 maxbpg = ffs_opts->maxbpg;
132 avgfilesize = ffs_opts->avgfilesize;
133 avgfpdir = ffs_opts->avgfpdir;
134 bbsize = BBSIZE8192;
135
136 strlcpy((char *)sblockfsun.fs.fs_volname, ffs_opts->label,
137 sizeof(sblockfsun.fs.fs_volname));
138
139 sblockfsun.fs.fs_inodefmt = FS_44INODEFMT2;
140 sblockfsun.fs.fs_maxsymlinklen = (Oflag == 1 ? MAXSYMLINKLEN_UFS1((12 + 3) * sizeof(int32_t)) :
5
Assuming 'Oflag' is not equal to 1
6
'?' condition is false
141 MAXSYMLINKLEN_UFS2((12 + 3) * sizeof(int64_t)));
142 sblockfsun.fs.fs_ffs1_flags = FS_FLAGS_UPDATED0x80;
143 sblockfsun.fs.fs_flags = 0;
144
145 /*
146 * Validate the given file system size.
147 * Verify that its last block can actually be accessed.
148 * Convert to file system fragment sized units.
149 */
150 if (fssize <= 0) {
7
Assuming 'fssize' is > 0
8
Taking false branch
151 printf("preposterous size %lld\n", (long long)fssize);
152 exit(13);
153 }
154 ffs_wtfs(fssize - 1, sectorsize, (char *)&sblockfsun.fs, fsopts);
155
156 /*
157 * collect and verify the filesystem density info
158 */
159 sblockfsun.fs.fs_avgfilesize = avgfilesize;
160 sblockfsun.fs.fs_avgfpdir = avgfpdir;
161 if (sblockfsun.fs.fs_avgfilesize <= 0)
9
Assuming field 'fs_avgfilesize' is > 0
10
Taking false branch
162 printf("illegal expected average file size %d\n",
163 sblockfsun.fs.fs_avgfilesize), exit(14);
164 if (sblockfsun.fs.fs_avgfpdir <= 0)
11
Assuming field 'fs_avgfpdir' is > 0
12
Taking false branch
165 printf("illegal expected number of files per directory %d\n",
166 sblockfsun.fs.fs_avgfpdir), exit(15);
167 /*
168 * collect and verify the block and fragment sizes
169 */
170 sblockfsun.fs.fs_bsize = bsize;
171 sblockfsun.fs.fs_fsize = fsize;
172 if (!POWEROF2(sblock.fs_bsize)(((fsun.fs.fs_bsize) & ((fsun.fs.fs_bsize) - 1)) == 0)) {
13
Assuming the condition is true
14
Taking false branch
173 printf("block size must be a power of 2, not %d\n",
174 sblockfsun.fs.fs_bsize);
175 exit(16);
176 }
177 if (!POWEROF2(sblock.fs_fsize)(((fsun.fs.fs_fsize) & ((fsun.fs.fs_fsize) - 1)) == 0)) {
15
Assuming the condition is true
16
Taking false branch
178 printf("fragment size must be a power of 2, not %d\n",
179 sblockfsun.fs.fs_fsize);
180 exit(17);
181 }
182 if (sblockfsun.fs.fs_fsize < sectorsize) {
17
Assuming 'sectorsize' is <= field 'fs_fsize'
18
Taking false branch
183 printf("fragment size %d is too small, minimum is %d\n",
184 sblockfsun.fs.fs_fsize, sectorsize);
185 exit(18);
186 }
187 if (sblockfsun.fs.fs_bsize < MINBSIZE4096) {
19
Assuming field 'fs_bsize' is >= MINBSIZE
20
Taking false branch
188 printf("block size %d is too small, minimum is %d\n",
189 sblockfsun.fs.fs_bsize, MINBSIZE4096);
190 exit(19);
191 }
192 if (sblockfsun.fs.fs_bsize > FFS_MAXBSIZE65536) {
21
Assuming field 'fs_bsize' is <= FFS_MAXBSIZE
22
Taking false branch
193 printf("block size %d is too large, maximum is %d\n",
194 sblockfsun.fs.fs_bsize, FFS_MAXBSIZE65536);
195 exit(19);
196 }
197 if (sblockfsun.fs.fs_bsize < sblockfsun.fs.fs_fsize) {
23
Assuming field 'fs_bsize' is >= field 'fs_fsize'
24
Taking false branch
198 printf("block size (%d) cannot be smaller than fragment size (%d)\n",
199 sblockfsun.fs.fs_bsize, sblockfsun.fs.fs_fsize);
200 exit(20);
201 }
202
203 if (maxbsize < bsize || !POWEROF2(maxbsize)(((maxbsize) & ((maxbsize) - 1)) == 0)) {
25
Assuming 'maxbsize' is >= 'bsize'
26
Assuming the condition is false
27
Taking true branch
204 sblockfsun.fs.fs_maxbsize = sblockfsun.fs.fs_bsize;
205 printf("Extent size set to %d\n", sblockfsun.fs.fs_maxbsize);
206 } else if (sblockfsun.fs.fs_maxbsize > FS_MAXCONTIG16 * sblockfsun.fs.fs_bsize) {
207 sblockfsun.fs.fs_maxbsize = FS_MAXCONTIG16 * sblockfsun.fs.fs_bsize;
208 printf("Extent size reduced to %d\n", sblockfsun.fs.fs_maxbsize);
209 } else {
210 sblockfsun.fs.fs_maxbsize = maxbsize;
211 }
212 sblockfsun.fs.fs_maxcontig = maxcontig;
213 if (sblockfsun.fs.fs_maxcontig < sblockfsun.fs.fs_maxbsize / sblockfsun.fs.fs_bsize) {
28
Assuming the condition is false
29
Taking false branch
214 sblockfsun.fs.fs_maxcontig = sblockfsun.fs.fs_maxbsize / sblockfsun.fs.fs_bsize;
215 printf("Maxcontig raised to %d\n", sblockfsun.fs.fs_maxbsize);
216 }
217
218 if (sblockfsun.fs.fs_maxcontig > 1)
30
Assuming field 'fs_maxcontig' is <= 1
31
Taking false branch
219 sblockfsun.fs.fs_contigsumsize = MINIMUM(sblock.fs_maxcontig,FS_MAXCONTIG)(((fsun.fs.fs_maxcontig) < (16)) ? (fsun.fs.fs_maxcontig) :
(16))
;
220
221 sblockfsun.fs.fs_bmask = ~(sblockfsun.fs.fs_bsize - 1);
222 sblockfsun.fs.fs_fmask = ~(sblockfsun.fs.fs_fsize - 1);
223 sblockfsun.fs.fs_qbmask = ~sblockfsun.fs.fs_bmask;
224 sblockfsun.fs.fs_qfmask = ~sblockfsun.fs.fs_fmask;
225 for (sblockfsun.fs.fs_bshift = 0, i = sblockfsun.fs.fs_bsize; i
31.1
'i' is > 1
> 1
; i >>= 1)
32
Loop condition is true. Entering loop body
33
Assuming 'i' is <= 1
34
Loop condition is false. Execution continues on line 227
226 sblockfsun.fs.fs_bshift++;
227 for (sblockfsun.fs.fs_fshift = 0, i = sblockfsun.fs.fs_fsize; i > 1; i >>= 1)
35
Assuming 'i' is > 1
36
Loop condition is true. Entering loop body
37
Assuming 'i' is <= 1
38
Loop condition is false. Execution continues on line 229
228 sblockfsun.fs.fs_fshift++;
229 sblockfsun.fs.fs_frag = numfrags(&sblock, sblock.fs_bsize)((fsun.fs.fs_bsize) >> (&fsun.fs)->fs_fshift);
230 for (sblockfsun.fs.fs_fragshift = 0, i = sblockfsun.fs.fs_frag; i > 1; i >>= 1)
39
Assuming 'i' is <= 1
40
Loop condition is false. Execution continues on line 232
231 sblockfsun.fs.fs_fragshift++;
232 if (sblockfsun.fs.fs_frag
40.1
Field 'fs_frag' is <= MAXFRAG
> MAXFRAG8) {
41
Taking false branch
233 printf("fragment size %d is too small, "
234 "minimum with block size %d is %d\n",
235 sblockfsun.fs.fs_fsize, sblockfsun.fs.fs_bsize,
236 sblockfsun.fs.fs_bsize / MAXFRAG8);
237 exit(21);
238 }
239 sblockfsun.fs.fs_fsbtodb = ilog2(sblockfsun.fs.fs_fsize / sectorsize);
240 sblockfsun.fs.fs_size = fssize = dbtofsb(&sblock, fssize)((fssize) >> (&fsun.fs)->fs_fsbtodb);
241
242 if (Oflag <= 1) {
42
Assuming 'Oflag' is > 1
43
Taking false branch
243 sblockfsun.fs.fs_magic = FS_UFS1_MAGIC0x011954;
244 sblockfsun.fs.fs_sblockloc = SBLOCK_UFS18192;
245 sblockfsun.fs.fs_nindir = sblockfsun.fs.fs_bsize / sizeof(int32_t);
246 sblockfsun.fs.fs_inopb = sblockfsun.fs.fs_bsize / sizeof(struct ufs1_dinode);
247 sblockfsun.fs.fs_maxsymlinklen = (NDADDR12 + NIADDR3) * sizeof (int32_t);
248 sblockfsun.fs.fs_inodefmt = FS_44INODEFMT2;
249 sblockfsun.fs.fs_cgoffset = 0;
250 sblockfsun.fs.fs_cgmask = 0xffffffff;
251 sblockfsun.fs.fs_ffs1_size = sblockfsun.fs.fs_size;
252 sblockfsun.fs.fs_rotdelay = 0;
253 sblockfsun.fs.fs_rps = 60;
254 sblockfsun.fs.fs_nspf = sblockfsun.fs.fs_fsize / sectorsize;
255 sblockfsun.fs.fs_cpg = 1;
256 sblockfsun.fs.fs_interleave = 1;
257 sblockfsun.fs.fs_trackskew = 0;
258 sblockfsun.fs.fs_cpc = 0;
259 sblockfsun.fs.fs_postblformat = 1;
260 sblockfsun.fs.fs_nrpos = 1;
261 } else {
262 sblockfsun.fs.fs_magic = FS_UFS2_MAGIC0x19540119;
263#if 0 /* XXX makefs is used for small filesystems. */
264 sblockfsun.fs.fs_sblockloc = SBLOCK_UFS265536;
265#else
266 sblockfsun.fs.fs_sblockloc = SBLOCK_UFS18192;
267#endif
268 sblockfsun.fs.fs_nindir = sblockfsun.fs.fs_bsize / sizeof(int64_t);
269 sblockfsun.fs.fs_inopb = sblockfsun.fs.fs_bsize / sizeof(struct ufs2_dinode);
270 sblockfsun.fs.fs_maxsymlinklen = (NDADDR12 + NIADDR3) * sizeof (int64_t);
271 }
272
273 sblockfsun.fs.fs_sblkno =
274 roundup(howmany(sblock.fs_sblockloc + SBLOCKSIZE, sblock.fs_fsize),(((((((fsun.fs.fs_sblockloc + 8192) + ((fsun.fs.fs_fsize) - 1
)) / (fsun.fs.fs_fsize)))+((fsun.fs.fs_frag)-1))/(fsun.fs.fs_frag
))*(fsun.fs.fs_frag))
275 sblock.fs_frag)(((((((fsun.fs.fs_sblockloc + 8192) + ((fsun.fs.fs_fsize) - 1
)) / (fsun.fs.fs_fsize)))+((fsun.fs.fs_frag)-1))/(fsun.fs.fs_frag
))*(fsun.fs.fs_frag))
;
276 sblockfsun.fs.fs_cblkno = (daddr_t)(sblockfsun.fs.fs_sblkno +
277 roundup(howmany(SBLOCKSIZE, sblock.fs_fsize), sblock.fs_frag)(((((((8192) + ((fsun.fs.fs_fsize) - 1)) / (fsun.fs.fs_fsize)
))+((fsun.fs.fs_frag)-1))/(fsun.fs.fs_frag))*(fsun.fs.fs_frag
))
);
278 sblockfsun.fs.fs_iblkno = sblockfsun.fs.fs_cblkno + sblockfsun.fs.fs_frag;
279 sblockfsun.fs.fs_maxfilesize = sblockfsun.fs.fs_bsize * NDADDR12 - 1;
280 for (sizepb = sblockfsun.fs.fs_bsize, i = 0; i < NIADDR3; i++) {
44
Loop condition is true. Entering loop body
45
Loop condition is true. Entering loop body
46
Loop condition is true. Entering loop body
47
Loop condition is false. Execution continues on line 299
281 sizepb *= NINDIR(&sblock)((&fsun.fs)->fs_nindir);
282 sblockfsun.fs.fs_maxfilesize += sizepb;
283 }
284
285 /*
286 * Calculate the number of blocks to put into each cylinder group.
287 *
288 * This algorithm selects the number of blocks per cylinder
289 * group. The first goal is to have at least enough data blocks
290 * in each cylinder group to meet the density requirement. Once
291 * this goal is achieved we try to expand to have at least
292 * 1 cylinder group. Once this goal is achieved, we pack as
293 * many blocks into each cylinder group map as will fit.
294 *
295 * We start by calculating the smallest number of blocks that we
296 * can put into each cylinder group. If this is too big, we reduce
297 * the density until it fits.
298 */
299 origdensity = density;
300 for (;;) {
48
Loop condition is true. Entering loop body
301 fragsperinode = MAXIMUM(numfrags(&sblock, density), 1)(((((density) >> (&fsun.fs)->fs_fshift)) > (1
)) ? (((density) >> (&fsun.fs)->fs_fshift)) : (1
))
;
49
Assuming the condition is false
50
'?' condition is false
302 minfpg = fragsperinode * INOPB(&sblock)((&fsun.fs)->fs_inopb);
303 if (minfpg > sblockfsun.fs.fs_size)
51
Assuming 'minfpg' is <= field 'fs_size'
52
Taking false branch
304 minfpg = sblockfsun.fs.fs_size;
305 sblockfsun.fs.fs_ipg = INOPB(&sblock)((&fsun.fs)->fs_inopb);
306 sblockfsun.fs.fs_fpg = roundup(sblock.fs_iblkno +((((fsun.fs.fs_iblkno + fsun.fs.fs_ipg / ((&fsun.fs)->
fs_inopb >> (&fsun.fs)->fs_fragshift))+((fsun.fs
.fs_frag)-1))/(fsun.fs.fs_frag))*(fsun.fs.fs_frag))
307 sblock.fs_ipg / INOPF(&sblock), sblock.fs_frag)((((fsun.fs.fs_iblkno + fsun.fs.fs_ipg / ((&fsun.fs)->
fs_inopb >> (&fsun.fs)->fs_fragshift))+((fsun.fs
.fs_frag)-1))/(fsun.fs.fs_frag))*(fsun.fs.fs_frag))
;
308 if (sblockfsun.fs.fs_fpg < minfpg)
53
Assuming 'minfpg' is <= field 'fs_fpg'
54
Taking false branch
309 sblockfsun.fs.fs_fpg = minfpg;
310 sblockfsun.fs.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),(((((((fsun.fs.fs_fpg) + ((fragsperinode) - 1)) / (fragsperinode
)))+((((&fsun.fs)->fs_inopb))-1))/(((&fsun.fs)->
fs_inopb)))*(((&fsun.fs)->fs_inopb)))
311 INOPB(&sblock))(((((((fsun.fs.fs_fpg) + ((fragsperinode) - 1)) / (fragsperinode
)))+((((&fsun.fs)->fs_inopb))-1))/(((&fsun.fs)->
fs_inopb)))*(((&fsun.fs)->fs_inopb)))
;
312 sblockfsun.fs.fs_fpg = roundup(sblock.fs_iblkno +((((fsun.fs.fs_iblkno + fsun.fs.fs_ipg / ((&fsun.fs)->
fs_inopb >> (&fsun.fs)->fs_fragshift))+((fsun.fs
.fs_frag)-1))/(fsun.fs.fs_frag))*(fsun.fs.fs_frag))
313 sblock.fs_ipg / INOPF(&sblock), sblock.fs_frag)((((fsun.fs.fs_iblkno + fsun.fs.fs_ipg / ((&fsun.fs)->
fs_inopb >> (&fsun.fs)->fs_fragshift))+((fsun.fs
.fs_frag)-1))/(fsun.fs.fs_frag))*(fsun.fs.fs_frag))
;
314 if (sblockfsun.fs.fs_fpg < minfpg)
55
Assuming 'minfpg' is <= field 'fs_fpg'
56
Taking false branch
315 sblockfsun.fs.fs_fpg = minfpg;
316 sblockfsun.fs.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),(((((((fsun.fs.fs_fpg) + ((fragsperinode) - 1)) / (fragsperinode
)))+((((&fsun.fs)->fs_inopb))-1))/(((&fsun.fs)->
fs_inopb)))*(((&fsun.fs)->fs_inopb)))
317 INOPB(&sblock))(((((((fsun.fs.fs_fpg) + ((fragsperinode) - 1)) / (fragsperinode
)))+((((&fsun.fs)->fs_inopb))-1))/(((&fsun.fs)->
fs_inopb)))*(((&fsun.fs)->fs_inopb)))
;
318 if (CGSIZE(&sblock)(sizeof(struct cg) + sizeof(int32_t) + (&fsun.fs)->fs_cpg
* sizeof(int32_t) + (&fsun.fs)->fs_cpg * (&fsun.fs
)->fs_nrpos * sizeof(int16_t) + ((((&fsun.fs)->fs_ipg
) + ((8) - 1)) / (8)) + ((((&fsun.fs)->fs_fpg) + ((8) -
1)) / (8)) + ((&fsun.fs)->fs_contigsumsize <= 0 ? 0
: (&fsun.fs)->fs_contigsumsize * sizeof(int32_t) + ((
((((&fsun.fs)->fs_fpg) >> (&fsun.fs)->fs_fragshift
)) + ((8) - 1)) / (8))))
< (unsigned long)sblockfsun.fs.fs_bsize
)
57
Assuming field 'fs_contigsumsize' is <= 0
58
'?' condition is true
59
Assuming the condition is true
60
Taking true branch
319 break;
61
Execution continues on line 322
320 density -= sblockfsun.fs.fs_fsize;
321 }
322 if (density
61.1
'density' is equal to 'origdensity'
!= origdensity)
62
Taking false branch
323 printf("density reduced from %d to %d\n", origdensity, density);
324
325 if (maxblkspercg <= 0 || maxblkspercg >= fssize)
63
Assuming 'maxblkspercg' is > 0
64
Assuming 'maxblkspercg' is < 'fssize'
65
Taking false branch
326 maxblkspercg = fssize - 1;
327 /*
328 * Start packing more blocks into the cylinder group until
329 * it cannot grow any larger, the number of cylinder groups
330 * drops below 1, or we reach the size requested.
331 */
332 for ( ; sblockfsun.fs.fs_fpg < maxblkspercg; sblockfsun.fs.fs_fpg += sblockfsun.fs.fs_frag) {
66
Assuming 'maxblkspercg' is <= field 'fs_fpg'
67
Loop condition is false. Execution continues on line 352
333 sblockfsun.fs.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),(((((((fsun.fs.fs_fpg) + ((fragsperinode) - 1)) / (fragsperinode
)))+((((&fsun.fs)->fs_inopb))-1))/(((&fsun.fs)->
fs_inopb)))*(((&fsun.fs)->fs_inopb)))
334 INOPB(&sblock))(((((((fsun.fs.fs_fpg) + ((fragsperinode) - 1)) / (fragsperinode
)))+((((&fsun.fs)->fs_inopb))-1))/(((&fsun.fs)->
fs_inopb)))*(((&fsun.fs)->fs_inopb)))
;
335 if (sblockfsun.fs.fs_size / sblockfsun.fs.fs_fpg < 1)
336 break;
337 if (CGSIZE(&sblock)(sizeof(struct cg) + sizeof(int32_t) + (&fsun.fs)->fs_cpg
* sizeof(int32_t) + (&fsun.fs)->fs_cpg * (&fsun.fs
)->fs_nrpos * sizeof(int16_t) + ((((&fsun.fs)->fs_ipg
) + ((8) - 1)) / (8)) + ((((&fsun.fs)->fs_fpg) + ((8) -
1)) / (8)) + ((&fsun.fs)->fs_contigsumsize <= 0 ? 0
: (&fsun.fs)->fs_contigsumsize * sizeof(int32_t) + ((
((((&fsun.fs)->fs_fpg) >> (&fsun.fs)->fs_fragshift
)) + ((8) - 1)) / (8))))
< (unsigned long)sblockfsun.fs.fs_bsize)
338 continue;
339 if (CGSIZE(&sblock)(sizeof(struct cg) + sizeof(int32_t) + (&fsun.fs)->fs_cpg
* sizeof(int32_t) + (&fsun.fs)->fs_cpg * (&fsun.fs
)->fs_nrpos * sizeof(int16_t) + ((((&fsun.fs)->fs_ipg
) + ((8) - 1)) / (8)) + ((((&fsun.fs)->fs_fpg) + ((8) -
1)) / (8)) + ((&fsun.fs)->fs_contigsumsize <= 0 ? 0
: (&fsun.fs)->fs_contigsumsize * sizeof(int32_t) + ((
((((&fsun.fs)->fs_fpg) >> (&fsun.fs)->fs_fragshift
)) + ((8) - 1)) / (8))))
== (unsigned long)sblockfsun.fs.fs_bsize)
340 break;
341 sblockfsun.fs.fs_fpg -= sblockfsun.fs.fs_frag;
342 sblockfsun.fs.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),(((((((fsun.fs.fs_fpg) + ((fragsperinode) - 1)) / (fragsperinode
)))+((((&fsun.fs)->fs_inopb))-1))/(((&fsun.fs)->
fs_inopb)))*(((&fsun.fs)->fs_inopb)))
343 INOPB(&sblock))(((((((fsun.fs.fs_fpg) + ((fragsperinode) - 1)) / (fragsperinode
)))+((((&fsun.fs)->fs_inopb))-1))/(((&fsun.fs)->
fs_inopb)))*(((&fsun.fs)->fs_inopb)))
;
344 break;
345 }
346 /*
347 * Check to be sure that the last cylinder group has enough blocks
348 * to be viable. If it is too small, reduce the number of blocks
349 * per cylinder group which will have the effect of moving more
350 * blocks into the last cylinder group.
351 */
352 optimalfpg = sblockfsun.fs.fs_fpg;
353 for (;;) {
68
Loop condition is true. Entering loop body
354 sblockfsun.fs.fs_ncg = howmany(sblock.fs_size, sblock.fs_fpg)(((fsun.fs.fs_size) + ((fsun.fs.fs_fpg) - 1)) / (fsun.fs.fs_fpg
))
;
355 lastminfpg = roundup(sblock.fs_iblkno +((((fsun.fs.fs_iblkno + fsun.fs.fs_ipg / ((&fsun.fs)->
fs_inopb >> (&fsun.fs)->fs_fragshift))+((fsun.fs
.fs_frag)-1))/(fsun.fs.fs_frag))*(fsun.fs.fs_frag))
356 sblock.fs_ipg / INOPF(&sblock), sblock.fs_frag)((((fsun.fs.fs_iblkno + fsun.fs.fs_ipg / ((&fsun.fs)->
fs_inopb >> (&fsun.fs)->fs_fragshift))+((fsun.fs
.fs_frag)-1))/(fsun.fs.fs_frag))*(fsun.fs.fs_frag))
;
357 if (sblockfsun.fs.fs_size < lastminfpg) {
69
Assuming 'lastminfpg' is <= field 'fs_size'
70
Taking false branch
358 printf("Filesystem size %lld < minimum size of %d\n",
359 (long long)sblockfsun.fs.fs_size, lastminfpg);
360 exit(28);
361 }
362 if (sblockfsun.fs.fs_size % sblockfsun.fs.fs_fpg >= lastminfpg ||
71
Assuming the condition is true
363 sblockfsun.fs.fs_size % sblockfsun.fs.fs_fpg == 0)
364 break;
72
Execution continues on line 369
365 sblockfsun.fs.fs_fpg -= sblockfsun.fs.fs_frag;
366 sblockfsun.fs.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),(((((((fsun.fs.fs_fpg) + ((fragsperinode) - 1)) / (fragsperinode
)))+((((&fsun.fs)->fs_inopb))-1))/(((&fsun.fs)->
fs_inopb)))*(((&fsun.fs)->fs_inopb)))
367 INOPB(&sblock))(((((((fsun.fs.fs_fpg) + ((fragsperinode) - 1)) / (fragsperinode
)))+((((&fsun.fs)->fs_inopb))-1))/(((&fsun.fs)->
fs_inopb)))*(((&fsun.fs)->fs_inopb)))
;
368 }
369 if (optimalfpg
72.1
'optimalfpg' is equal to field 'fs_fpg'
!= sblockfsun.fs.fs_fpg)
73
Taking false branch
370 printf("Reduced frags per cylinder group from %d to %d %s\n",
371 optimalfpg, sblockfsun.fs.fs_fpg, "to enlarge last cyl group");
372 sblockfsun.fs.fs_cgsize = fragroundup(&sblock, CGSIZE(&sblock))((((sizeof(struct cg) + sizeof(int32_t) + (&fsun.fs)->
fs_cpg * sizeof(int32_t) + (&fsun.fs)->fs_cpg * (&
fsun.fs)->fs_nrpos * sizeof(int16_t) + ((((&fsun.fs)->
fs_ipg) + ((8) - 1)) / (8)) + ((((&fsun.fs)->fs_fpg) +
((8) - 1)) / (8)) + ((&fsun.fs)->fs_contigsumsize <=
0 ? 0 : (&fsun.fs)->fs_contigsumsize * sizeof(int32_t
) + ((((((&fsun.fs)->fs_fpg) >> (&fsun.fs)->
fs_fragshift)) + ((8) - 1)) / (8))))) + (&fsun.fs)->fs_qfmask
) & (&fsun.fs)->fs_fmask)
;
74
Assuming field 'fs_contigsumsize' is <= 0
75
'?' condition is true
373 sblockfsun.fs.fs_dblkno = sblockfsun.fs.fs_iblkno + sblockfsun.fs.fs_ipg / INOPF(&sblock)((&fsun.fs)->fs_inopb >> (&fsun.fs)->fs_fragshift
)
;
374 if (Oflag
75.1
'Oflag' is > 1
<= 1) {
76
Taking false branch
375 sblockfsun.fs.fs_spc = sblockfsun.fs.fs_fpg * sblockfsun.fs.fs_nspf;
376 sblockfsun.fs.fs_nsect = sblockfsun.fs.fs_spc;
377 sblockfsun.fs.fs_npsect = sblockfsun.fs.fs_spc;
378 sblockfsun.fs.fs_ncyl = sblockfsun.fs.fs_ncg;
379 }
380
381 /*
382 * fill in remaining fields of the super block
383 */
384 sblockfsun.fs.fs_csaddr = cgdmin(&sblock, 0)((((daddr_t)(&fsun.fs)->fs_fpg * (0)) + (&fsun.fs)
->fs_cgoffset * ((0) & ~((&fsun.fs)->fs_cgmask)
)) + (&fsun.fs)->fs_dblkno)
;
385 sblockfsun.fs.fs_cssize =
386 fragroundup(&sblock, sblock.fs_ncg * sizeof(struct csum))(((fsun.fs.fs_ncg * sizeof(struct csum)) + (&fsun.fs)->
fs_qfmask) & (&fsun.fs)->fs_fmask)
;
387
388 /*
389 * Setup memory for temporary in-core cylgroup summaries.
390 * Cribbed from ffs_mountfs().
391 */
392 size = sblockfsun.fs.fs_cssize;
393 if (sblockfsun.fs.fs_contigsumsize > 0)
77
Assuming field 'fs_contigsumsize' is <= 0
78
Taking false branch
394 size += sblockfsun.fs.fs_ncg * sizeof(int32_t);
395 space = ecalloc(1, size);
396 sblockfsun.fs.fs_csp = space;
397 space = (char *)space + sblockfsun.fs.fs_cssize;
398 if (sblockfsun.fs.fs_contigsumsize > 0) {
79
Assuming field 'fs_contigsumsize' is <= 0
80
Taking false branch
399 int32_t *lp;
400
401 sblockfsun.fs.fs_maxcluster = lp = space;
402 for (i = 0; i < sblockfsun.fs.fs_ncg; i++)
403 *lp++ = sblockfsun.fs.fs_contigsumsize;
404 }
405
406 sblockfsun.fs.fs_sbsize = fragroundup(&sblock, sizeof(struct fs))(((sizeof(struct fs)) + (&fsun.fs)->fs_qfmask) & (
&fsun.fs)->fs_fmask)
;
407 if (sblockfsun.fs.fs_sbsize > SBLOCKSIZE8192)
81
Assuming field 'fs_sbsize' is <= SBLOCKSIZE
82
Taking false branch
408 sblockfsun.fs.fs_sbsize = SBLOCKSIZE8192;
409 sblockfsun.fs.fs_minfree = minfree;
410 sblockfsun.fs.fs_maxcontig = maxcontig;
411 sblockfsun.fs.fs_maxbpg = maxbpg;
412 sblockfsun.fs.fs_optim = opt;
413 sblockfsun.fs.fs_cgrotor = 0;
414 sblockfsun.fs.fs_pendingblocks = 0;
415 sblockfsun.fs.fs_pendinginodes = 0;
416 sblockfsun.fs.fs_cstotal.cs_ndir = 0;
417 sblockfsun.fs.fs_cstotal.cs_nbfree = 0;
418 sblockfsun.fs.fs_cstotal.cs_nifree = 0;
419 sblockfsun.fs.fs_cstotal.cs_nffree = 0;
420 sblockfsun.fs.fs_fmod = 0;
421 sblockfsun.fs.fs_ronly = 0;
422 sblockfsun.fs.fs_state = 0;
423 sblockfsun.fs.fs_clean = FS_ISCLEAN0x01;
424 sblockfsun.fs.fs_ronly = 0;
425 sblockfsun.fs.fs_id[0] = tstamp;
426 sblockfsun.fs.fs_id[1] = random();
427 sblockfsun.fs.fs_fsmnt[0] = '\0';
428 csfrags = howmany(sblock.fs_cssize, sblock.fs_fsize)(((fsun.fs.fs_cssize) + ((fsun.fs.fs_fsize) - 1)) / (fsun.fs.
fs_fsize))
;
429 sblockfsun.fs.fs_dsize = sblockfsun.fs.fs_size - sblockfsun.fs.fs_sblkno -
430 sblockfsun.fs.fs_ncg * (sblockfsun.fs.fs_dblkno - sblockfsun.fs.fs_sblkno);
431 sblockfsun.fs.fs_cstotal.cs_nbfree =
432 fragstoblks(&sblock, sblock.fs_dsize)((fsun.fs.fs_dsize) >> (&fsun.fs)->fs_fragshift) -
433 howmany(csfrags, sblock.fs_frag)(((csfrags) + ((fsun.fs.fs_frag) - 1)) / (fsun.fs.fs_frag));
434 sblockfsun.fs.fs_cstotal.cs_nffree =
435 fragnum(&sblock, sblock.fs_size)((fsun.fs.fs_size) & ((&fsun.fs)->fs_frag - 1)) +
436 (fragnum(&sblock, csfrags)((csfrags) & ((&fsun.fs)->fs_frag - 1)) > 0 ?
83
Assuming the condition is false
84
'?' condition is false
437 sblockfsun.fs.fs_frag - fragnum(&sblock, csfrags)((csfrags) & ((&fsun.fs)->fs_frag - 1)) : 0);
438 sblockfsun.fs.fs_cstotal.cs_nifree = sblockfsun.fs.fs_ncg * sblockfsun.fs.fs_ipg - ROOTINO((ufsino_t)2);
439 sblockfsun.fs.fs_cstotal.cs_ndir = 0;
440 sblockfsun.fs.fs_dsize -= csfrags;
441 sblockfsun.fs.fs_time = tstamp;
442 if (Oflag <= 1) {
85
Assuming 'Oflag' is > 1
86
Taking false branch
443 sblockfsun.fs.fs_ffs1_time = tstamp;
444 sblockfsun.fs.fs_ffs1_dsize = sblockfsun.fs.fs_dsize;
445 sblockfsun.fs.fs_ffs1_csaddr = sblockfsun.fs.fs_csaddr;
446 sblockfsun.fs.fs_ffs1_cstotal.cs_ndir = sblockfsun.fs.fs_cstotal.cs_ndir;
447 sblockfsun.fs.fs_ffs1_cstotal.cs_nbfree = sblockfsun.fs.fs_cstotal.cs_nbfree;
448 sblockfsun.fs.fs_ffs1_cstotal.cs_nifree = sblockfsun.fs.fs_cstotal.cs_nifree;
449 sblockfsun.fs.fs_ffs1_cstotal.cs_nffree = sblockfsun.fs.fs_cstotal.cs_nffree;
450 }
451 /*
452 * Dump out summary information about file system.
453 */
454#define B2MBFACTOR (1 / (1024.0 * 1024.0))
455 printf("%s: %.1fMB (%lld sectors) block size %d, "
456 "fragment size %d\n",
457 fsys, (float)sblockfsun.fs.fs_size * sblockfsun.fs.fs_fsize * B2MBFACTOR,
458 (long long)fsbtodb(&sblock, sblock.fs_size)((fsun.fs.fs_size) << (&fsun.fs)->fs_fsbtodb),
459 sblockfsun.fs.fs_bsize, sblockfsun.fs.fs_fsize);
460 printf("\tusing %d cylinder groups of %.2fMB, %d blks, "
461 "%d inodes.\n",
462 sblockfsun.fs.fs_ncg,
463 (float)sblockfsun.fs.fs_fpg * sblockfsun.fs.fs_fsize * B2MBFACTOR,
464 sblockfsun.fs.fs_fpg / sblockfsun.fs.fs_frag, sblockfsun.fs.fs_ipg);
465#undef B2MBFACTOR
466 /*
467 * Now determine how wide each column will be, and calculate how
468 * many columns will fit in a 76 char line. 76 is the width of the
469 * subwindows in sysinst.
470 */
471 printcolwidth = count_digits(
472 fsbtodb(&sblock, cgsblock(&sblock, sblock.fs_ncg -1))((((((daddr_t)(&fsun.fs)->fs_fpg * (fsun.fs.fs_ncg -1)
) + (&fsun.fs)->fs_cgoffset * ((fsun.fs.fs_ncg -1) &
~((&fsun.fs)->fs_cgmask))) + (&fsun.fs)->fs_sblkno
)) << (&fsun.fs)->fs_fsbtodb)
);
473 nprintcols = 76 / (printcolwidth + 2);
474
475 /*
476 * allocate space for superblock, cylinder group map, and
477 * two sets of inode blocks.
478 */
479 if (sblockfsun.fs.fs_bsize < SBLOCKSIZE8192)
87
Assuming field 'fs_bsize' is >= SBLOCKSIZE
88
Taking false branch
480 iobufsize = SBLOCKSIZE8192 + 3 * sblockfsun.fs.fs_bsize;
481 else
482 iobufsize = 4 * sblockfsun.fs.fs_bsize;
483 iobuf = ecalloc(1, iobufsize);
484 /*
485 * Make a copy of the superblock into the buffer that we will be
486 * writing out in each cylinder group.
487 */
488 memcpy(writebuf, &sblockfsun.fs, SBLOCKSIZE8192);
489 memcpy(iobuf, writebuf, SBLOCKSIZE8192);
490
491 printf("super-block backups (for fsck -b #) at:");
492 for (cylno = 0; cylno < sblockfsun.fs.fs_ncg; cylno++) {
89
Assuming 'cylno' is < field 'fs_ncg'
90
Loop condition is true. Entering loop body
493 initcg(cylno, tstamp, fsopts);
91
Calling 'initcg'
494 if (cylno % nprintcols == 0)
495 printf("\n");
496 printf(" %*lld,", printcolwidth,
497 (long long)fsbtodb(&sblock, cgsblock(&sblock, cylno))((((((daddr_t)(&fsun.fs)->fs_fpg * (cylno)) + (&fsun
.fs)->fs_cgoffset * ((cylno) & ~((&fsun.fs)->fs_cgmask
))) + (&fsun.fs)->fs_sblkno)) << (&fsun.fs)->
fs_fsbtodb)
);
498 fflush(stdout(&__sF[1]));
499 }
500 printf("\n");
501
502 /*
503 * Now construct the initial file system,
504 * then write out the super-block.
505 */
506 sblockfsun.fs.fs_time = tstamp;
507 if (Oflag <= 1) {
508 sblockfsun.fs.fs_ffs1_cstotal.cs_ndir = sblockfsun.fs.fs_cstotal.cs_ndir;
509 sblockfsun.fs.fs_ffs1_cstotal.cs_nbfree = sblockfsun.fs.fs_cstotal.cs_nbfree;
510 sblockfsun.fs.fs_ffs1_cstotal.cs_nifree = sblockfsun.fs.fs_cstotal.cs_nifree;
511 sblockfsun.fs.fs_ffs1_cstotal.cs_nffree = sblockfsun.fs.fs_cstotal.cs_nffree;
512 }
513 ffs_write_superblock(&sblockfsun.fs, fsopts);
514 return (&sblockfsun.fs);
515}
516
517/*
518 * Write out the superblock and its duplicates,
519 * and the cylinder group summaries
520 */
521void
522ffs_write_superblock(struct fs *fs, const fsinfo_t *fsopts)
523{
524 int cylno, size, blks, i;
525 struct fs *fsdup;
526 void *space;
527 char *wrbuf;
528
529 memcpy(writebuf, fs, SBLOCKSIZE8192);
530
531 fsdup = (struct fs *)writebuf;
532 fsdup->fs_csp = NULL((void*)0);
533 fsdup->fs_maxcluster = NULL((void*)0);
534
535 ffs_wtfs(fs->fs_sblockloc / sectorsize, SBLOCKSIZE8192, writebuf, fsopts);
536
537 /* Write out the duplicate super blocks */
538 for (cylno = 0; cylno < fs->fs_ncg; cylno++)
539 ffs_wtfs(fsbtodb(fs, cgsblock(fs, cylno))((((((daddr_t)(fs)->fs_fpg * (cylno)) + (fs)->fs_cgoffset
* ((cylno) & ~((fs)->fs_cgmask))) + (fs)->fs_sblkno
)) << (fs)->fs_fsbtodb)
,
540 SBLOCKSIZE8192, writebuf, fsopts);
541
542 /* Write out the cylinder group summaries */
543 size = fs->fs_cssize;
544 blks = howmany(size, fs->fs_fsize)(((size) + ((fs->fs_fsize) - 1)) / (fs->fs_fsize));
545 space = (void *)fs->fs_csp;
546 wrbuf = emalloc(size);
547 for (i = 0; i < blks; i+= fs->fs_frag) {
548 size = fs->fs_bsize;
549 if (i + fs->fs_frag > blks)
550 size = (blks - i) * fs->fs_fsize;
551 memcpy(wrbuf, space, (u_int)size);
552 ffs_wtfs(fsbtodb(fs, fs->fs_csaddr + i)((fs->fs_csaddr + i) << (fs)->fs_fsbtodb), size, wrbuf, fsopts);
553 space = (char *)space + size;
554 }
555 free(wrbuf);
556}
557
558/*
559 * Initialize a cylinder group.
560 */
561static void
562initcg(int cylno, time_t utime, const fsinfo_t *fsopts)
563{
564 daddr_t cbase, dmax;
565 int i, j, d, dlower, dupper, blkno;
566 struct ufs1_dinode *dp1;
567 struct ufs2_dinode *dp2;
568 int start;
569
570 /*
571 * Determine block bounds for cylinder group.
572 * Allow space for super block summary information in first
573 * cylinder group.
574 */
575 cbase = cgbase(&sblock, cylno)((daddr_t)(&fsun.fs)->fs_fpg * (cylno));
576 dmax = cbase + sblockfsun.fs.fs_fpg;
577 if (dmax > sblockfsun.fs.fs_size)
92
Assuming 'dmax' is <= field 'fs_size'
93
Taking false branch
578 dmax = sblockfsun.fs.fs_size;
579 dlower = cgsblock(&sblock, cylno)((((daddr_t)(&fsun.fs)->fs_fpg * (cylno)) + (&fsun
.fs)->fs_cgoffset * ((cylno) & ~((&fsun.fs)->fs_cgmask
))) + (&fsun.fs)->fs_sblkno)
- cbase;
580 dupper = cgdmin(&sblock, cylno)((((daddr_t)(&fsun.fs)->fs_fpg * (cylno)) + (&fsun
.fs)->fs_cgoffset * ((cylno) & ~((&fsun.fs)->fs_cgmask
))) + (&fsun.fs)->fs_dblkno)
- cbase;
581 if (cylno
93.1
'cylno' is equal to 0
== 0)
94
Taking true branch
582 dupper += howmany(sblock.fs_cssize, sblock.fs_fsize)(((fsun.fs.fs_cssize) + ((fsun.fs.fs_fsize) - 1)) / (fsun.fs.
fs_fsize))
;
583 memset(&acgcgun.cg, 0, sblockfsun.fs.fs_cgsize);
584 acgcgun.cg.cg_ffs2_time = utime;
585 acgcgun.cg.cg_magic = CG_MAGIC0x090255;
586 acgcgun.cg.cg_cgx = cylno;
587 acgcgun.cg.cg_ffs2_niblk = sblockfsun.fs.fs_ipg;
588 acgcgun.cg.cg_initediblk = sblockfsun.fs.fs_ipg < 2 * INOPB(&sblock)((&fsun.fs)->fs_inopb) ?
95
Assuming the condition is false
96
'?' condition is false
589 sblockfsun.fs.fs_ipg : 2 * INOPB(&sblock)((&fsun.fs)->fs_inopb);
590 acgcgun.cg.cg_ndblk = dmax - cbase;
591 if (sblockfsun.fs.fs_contigsumsize > 0)
97
Assuming field 'fs_contigsumsize' is <= 0
98
Taking false branch
592 acgcgun.cg.cg_nclusterblks = acgcgun.cg.cg_ndblk >> sblockfsun.fs.fs_fragshift;
593 start = sizeof(struct cg);
594 if (Oflag == 2) {
99
Assuming 'Oflag' is equal to 2
100
Taking true branch
595 acgcgun.cg.cg_iusedoff = start;
596 } else {
597 if (cylno == sblockfsun.fs.fs_ncg - 1)
598 acgcgun.cg.cg_ncyl = howmany(acg.cg_ndblk,(((cgun.cg.cg_ndblk) + ((fsun.fs.fs_fpg / fsun.fs.fs_cpg) - 1
)) / (fsun.fs.fs_fpg / fsun.fs.fs_cpg))
599 sblock.fs_fpg / sblock.fs_cpg)(((cgun.cg.cg_ndblk) + ((fsun.fs.fs_fpg / fsun.fs.fs_cpg) - 1
)) / (fsun.fs.fs_fpg / fsun.fs.fs_cpg))
;
600 else
601 acgcgun.cg.cg_ncyl = sblockfsun.fs.fs_cpg;
602 acgcgun.cg.cg_time = acgcgun.cg.cg_ffs2_time;
603 acgcgun.cg.cg_ffs2_time = 0;
604 acgcgun.cg.cg_niblk = acgcgun.cg.cg_ffs2_niblk;
605 acgcgun.cg.cg_ffs2_niblk = 0;
606 acgcgun.cg.cg_initediblk = 0;
607 acgcgun.cg.cg_btotoff = start;
608 acgcgun.cg.cg_boff = acgcgun.cg.cg_btotoff + sblockfsun.fs.fs_cpg * sizeof(int32_t);
609 acgcgun.cg.cg_iusedoff = acgcgun.cg.cg_boff +
610 sblockfsun.fs.fs_cpg * sizeof(u_int16_t);
611 }
612 acgcgun.cg.cg_freeoff = acgcgun.cg.cg_iusedoff + howmany(sblock.fs_ipg, CHAR_BIT)(((fsun.fs.fs_ipg) + ((8) - 1)) / (8));
613 if (sblockfsun.fs.fs_contigsumsize
100.1
Field 'fs_contigsumsize' is <= 0
<= 0) {
101
Taking true branch
614 acgcgun.cg.cg_nextfreeoff = acgcgun.cg.cg_freeoff +
615 howmany(sblock.fs_fpg, CHAR_BIT)(((fsun.fs.fs_fpg) + ((8) - 1)) / (8));
616 } else {
617 acgcgun.cg.cg_clustersumoff = acgcgun.cg.cg_freeoff +
618 howmany(sblock.fs_fpg, CHAR_BIT)(((fsun.fs.fs_fpg) + ((8) - 1)) / (8)) - sizeof(int32_t);
619 acgcgun.cg.cg_clustersumoff =
620 roundup(acg.cg_clustersumoff, sizeof(int32_t))((((cgun.cg.cg_clustersumoff)+((sizeof(int32_t))-1))/(sizeof(
int32_t)))*(sizeof(int32_t)))
;
621 acgcgun.cg.cg_clusteroff = acgcgun.cg.cg_clustersumoff +
622 (sblockfsun.fs.fs_contigsumsize + 1) * sizeof(int32_t);
623 acgcgun.cg.cg_nextfreeoff = acgcgun.cg.cg_clusteroff +
624 howmany(fragstoblks(&sblock, sblock.fs_fpg), CHAR_BIT)(((((fsun.fs.fs_fpg) >> (&fsun.fs)->fs_fragshift
)) + ((8) - 1)) / (8))
;
625 }
626 if (acgcgun.cg.cg_nextfreeoff > sblockfsun.fs.fs_cgsize) {
102
Assuming field 'cg_nextfreeoff' is <= field 'fs_cgsize'
103
Taking false branch
627 printf("Panic: cylinder group too big\n");
628 exit(37);
629 }
630 acgcgun.cg.cg_cs.cs_nifree += sblockfsun.fs.fs_ipg;
631 if (cylno
103.1
'cylno' is equal to 0
== 0) {
104
Taking true branch
632 size_t r;
633
634 for (r = 0; r < ROOTINO((ufsino_t)2); r++) {
105
Loop condition is true. Entering loop body
107
Loop condition is true. Entering loop body
110
Loop condition is false. Execution continues on line 639
635 setbit(cg_inosused(&acg), r)(((((&cgun.cg)->cg_magic != 0x090255) ? (((struct ocg *
)(&cgun.cg))->cg_iused) : ((u_int8_t *)((u_int8_t *)(&
cgun.cg) + (&cgun.cg)->cg_iusedoff))))[(r)>>3] |=
1<<((r)&(8 -1)))
;
106
'?' condition is false
108
Assuming field 'cg_magic' is not equal to 590421
109
'?' condition is true
636 acgcgun.cg.cg_cs.cs_nifree--;
637 }
638 }
639 if (cylno
110.1
'cylno' is <= 0
> 0) {
111
Taking false branch
640 /*
641 * In cylno 0, beginning space is reserved
642 * for boot and super blocks.
643 */
644 for (d = 0, blkno = 0; d < dlower;) {
645 ffs_setblock(&sblockfsun.fs, cg_blksfree(&acg)(((&cgun.cg)->cg_magic != 0x090255) ? (((struct ocg *)
(&cgun.cg))->cg_free) : ((u_int8_t *)((u_int8_t *)(&
cgun.cg) + (&cgun.cg)->cg_freeoff)))
, blkno);
646 if (sblockfsun.fs.fs_contigsumsize > 0)
647 setbit(cg_clustersfree(&acg), blkno)((((u_int8_t *)((u_int8_t *)(&cgun.cg) + (&cgun.cg)->
cg_clusteroff)))[(blkno)>>3] |= 1<<((blkno)&(
8 -1)))
;
648 acgcgun.cg.cg_cs.cs_nbfree++;
649 d += sblockfsun.fs.fs_frag;
650 blkno++;
651 }
652 }
653 if ((i = (dupper & (sblockfsun.fs.fs_frag - 1))) != 0) {
112
Assuming the condition is false
113
Taking false branch
654 acgcgun.cg.cg_frsum[sblockfsun.fs.fs_frag - i]++;
655 for (d = dupper + sblockfsun.fs.fs_frag - i; dupper < d; dupper++) {
656 setbit(cg_blksfree(&acg), dupper)(((((&cgun.cg)->cg_magic != 0x090255) ? (((struct ocg *
)(&cgun.cg))->cg_free) : ((u_int8_t *)((u_int8_t *)(&
cgun.cg) + (&cgun.cg)->cg_freeoff))))[(dupper)>>
3] |= 1<<((dupper)&(8 -1)))
;
657 acgcgun.cg.cg_cs.cs_nffree++;
658 }
659 }
660 for (d = dupper, blkno = dupper >> sblockfsun.fs.fs_fragshift;
114
Loop condition is true. Entering loop body
119
Loop condition is false. Execution continues on line 669
661 d + sblockfsun.fs.fs_frag <= acgcgun.cg.cg_ndblk; ) {
662 ffs_setblock(&sblockfsun.fs, cg_blksfree(&acg)(((&cgun.cg)->cg_magic != 0x090255) ? (((struct ocg *)
(&cgun.cg))->cg_free) : ((u_int8_t *)((u_int8_t *)(&
cgun.cg) + (&cgun.cg)->cg_freeoff)))
, blkno);
115
Assuming field 'cg_magic' is not equal to 590421
116
'?' condition is true
663 if (sblockfsun.fs.fs_contigsumsize > 0)
117
Assuming field 'fs_contigsumsize' is <= 0
118
Taking false branch
664 setbit(cg_clustersfree(&acg), blkno)((((u_int8_t *)((u_int8_t *)(&cgun.cg) + (&cgun.cg)->
cg_clusteroff)))[(blkno)>>3] |= 1<<((blkno)&(
8 -1)))
;
665 acgcgun.cg.cg_cs.cs_nbfree++;
666 d += sblockfsun.fs.fs_frag;
667 blkno++;
668 }
669 if (d < acgcgun.cg.cg_ndblk) {
120
Assuming 'd' is >= field 'cg_ndblk'
121
Taking false branch
670 acgcgun.cg.cg_frsum[acgcgun.cg.cg_ndblk - d]++;
671 for (; d < acgcgun.cg.cg_ndblk; d++) {
672 setbit(cg_blksfree(&acg), d)(((((&cgun.cg)->cg_magic != 0x090255) ? (((struct ocg *
)(&cgun.cg))->cg_free) : ((u_int8_t *)((u_int8_t *)(&
cgun.cg) + (&cgun.cg)->cg_freeoff))))[(d)>>3] |=
1<<((d)&(8 -1)))
;
673 acgcgun.cg.cg_cs.cs_nffree++;
674 }
675 }
676 if (sblockfsun.fs.fs_contigsumsize
121.1
Field 'fs_contigsumsize' is <= 0
> 0) {
122
Taking false branch
677 int32_t *sump = cg_clustersum(&acg)((int32_t *)((u_int8_t *)(&cgun.cg) + (&cgun.cg)->
cg_clustersumoff))
;
678 u_char *mapp = cg_clustersfree(&acg)((u_int8_t *)((u_int8_t *)(&cgun.cg) + (&cgun.cg)->
cg_clusteroff))
;
679 int map = *mapp++;
680 int bit = 1;
681 int run = 0;
682
683 for (i = 0; i < acgcgun.cg.cg_nclusterblks; i++) {
684 if ((map & bit) != 0) {
685 run++;
686 } else if (run != 0) {
687 if (run > sblockfsun.fs.fs_contigsumsize)
688 run = sblockfsun.fs.fs_contigsumsize;
689 sump[run]++;
690 run = 0;
691 }
692 if ((i & (CHAR_BIT8 - 1)) != (CHAR_BIT8 - 1)) {
693 bit <<= 1;
694 } else {
695 map = *mapp++;
696 bit = 1;
697 }
698 }
699 if (run != 0) {
700 if (run > sblockfsun.fs.fs_contigsumsize)
701 run = sblockfsun.fs.fs_contigsumsize;
702 sump[run]++;
703 }
704 }
705 sblockfsun.fs.fs_cs(&sblock, cylno)fs_csp[cylno] = acgcgun.cg.cg_cs;
706 /*
707 * Write out the duplicate super block, the cylinder group map
708 * and two blocks worth of inodes in a single write.
709 */
710 start = sblockfsun.fs.fs_bsize > SBLOCKSIZE8192 ? sblockfsun.fs.fs_bsize : SBLOCKSIZE8192;
123
Assuming field 'fs_bsize' is <= SBLOCKSIZE
124
'?' condition is false
711 memcpy(&iobuf[start], &acgcgun.cg, sblockfsun.fs.fs_cgsize);
712 start += sblockfsun.fs.fs_bsize;
713 dp1 = (struct ufs1_dinode *)(&iobuf[start]);
714 dp2 = (struct ufs2_dinode *)(&iobuf[start]);
715 for (i = 0; i < acgcgun.cg.cg_initediblk; i++) {
125
Loop condition is false. Execution continues on line 725
716 if (sblockfsun.fs.fs_magic == FS_UFS1_MAGIC0x011954) {
717 /* No need to swap, it'll stay random */
718 dp1->di_gen = random();
719 dp1++;
720 } else {
721 dp2->di_gen = random();
722 dp2++;
723 }
724 }
725 ffs_wtfs(fsbtodb(&sblock, cgsblock(&sblock, cylno))((((((daddr_t)(&fsun.fs)->fs_fpg * (cylno)) + (&fsun
.fs)->fs_cgoffset * ((cylno) & ~((&fsun.fs)->fs_cgmask
))) + (&fsun.fs)->fs_sblkno)) << (&fsun.fs)->
fs_fsbtodb)
, iobufsize, iobuf,
726 fsopts);
727 /*
728 * For the old file system, we have to initialize all the inodes.
729 */
730 if (Oflag <= 1) {
126
Assuming 'Oflag' is <= 1
127
Taking true branch
731 for (i = 2 * sblockfsun.fs.fs_frag;
129
Loop condition is true. Entering loop body
732 i < sblockfsun.fs.fs_ipg / INOPF(&sblock)((&fsun.fs)->fs_inopb >> (&fsun.fs)->fs_fragshift
)
;
128
Assuming the condition is true
132
Division by zero
733 i += sblockfsun.fs.fs_frag) {
734 dp1 = (struct ufs1_dinode *)(&iobuf[start]);
735 for (j = 0; j < INOPB(&sblock)((&fsun.fs)->fs_inopb); j++) {
130
Assuming 'j' is >= field 'fs_inopb'
131
Loop condition is false. Execution continues on line 739
736 dp1->di_gen = random();
737 dp1++;
738 }
739 ffs_wtfs(fsbtodb(&sblock, cgimin(&sblock, cylno) + i)((((((daddr_t)(&fsun.fs)->fs_fpg * (cylno)) + (&fsun
.fs)->fs_cgoffset * ((cylno) & ~((&fsun.fs)->fs_cgmask
))) + (&fsun.fs)->fs_iblkno) + i) << (&fsun.
fs)->fs_fsbtodb)
,
740 sblockfsun.fs.fs_bsize, &iobuf[start], fsopts);
741 }
742 }
743}
744
745/*
746 * read a block from the file system
747 */
748void
749ffs_rdfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts)
750{
751 int n;
752 off_t offset;
753
754 offset = bno * fsopts->sectorsize + fsopts->offset;
755 if (lseek(fsopts->fd, offset, SEEK_SET0) < 0)
756 err(1, "%s: seek error for sector %lld", __func__,
757 (long long)bno);
758 n = read(fsopts->fd, bf, size);
759 if (n == -1) {
760 err(1, "%s: read error bno %lld size %d", __func__,
761 (long long)bno, size);
762 }
763 else if (n != size)
764 errx(1, "%s: short read error for sector %lld", __func__,
765 (long long)bno);
766}
767
768/*
769 * write a block to the file system
770 */
771void
772ffs_wtfs(daddr_t bno, int size, void *bf, const fsinfo_t *fsopts)
773{
774 int n;
775 off_t offset;
776
777 offset = bno * fsopts->sectorsize + fsopts->offset;
778 if (lseek(fsopts->fd, offset, SEEK_SET0) == -1)
779 err(1, "%s: seek error for sector %lld", __func__,
780 (long long)bno);
781 n = write(fsopts->fd, bf, size);
782 if (n == -1)
783 err(1, "%s: write error for sector %lld", __func__,
784 (long long)bno);
785 else if (n != size)
786 errx(1, "%s: short write error for sector %lld", __func__,
787 (long long)bno);
788}
789
790
791/* Determine how many digits are needed to print a given integer */
792static int
793count_digits(int num)
794{
795 int ndig;
796
797 for(ndig = 1; num > 9; num /=10, ndig++);
798
799 return (ndig);
800}
801
802static int
803ilog2(int val)
804{
805 u_int n;
806
807 for (n = 0; n < sizeof(n) * CHAR_BIT8; n++)
808 if (1 << n == val)
809 return (n);
810 errx(1, "%s: %d is not a power of 2", __func__, val);
811}