Deleted Added
full compact
ffs.c (186341) ffs.c (214921)
1/* $NetBSD: ffs.c,v 1.30 2004/06/24 22:30:13 lukem Exp $ */
1/* $NetBSD: ffs.c,v 1.44 2009/04/28 22:49:26 joerg Exp $ */
2
3/*
4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Luke Mewburn for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without

--- 51 unchanged lines hidden (view full) ---

61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 * @(#)ffs_alloc.c 8.19 (Berkeley) 7/13/95
66 */
67
68#include <sys/cdefs.h>
2
3/*
4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Luke Mewburn for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without

--- 51 unchanged lines hidden (view full) ---

61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 * @(#)ffs_alloc.c 8.19 (Berkeley) 7/13/95
66 */
67
68#include <sys/cdefs.h>
69__FBSDID("$FreeBSD: head/usr.sbin/makefs/ffs.c 186341 2008-12-19 22:58:39Z sam $");
69__FBSDID("$FreeBSD: head/usr.sbin/makefs/ffs.c 214921 2010-11-07 16:05:04Z cognet $");
70
71#include <sys/param.h>
72
73#include <sys/mount.h>
74
75#include <assert.h>
76#include <errno.h>
77#include <fcntl.h>
78#include <stdarg.h>
70
71#include <sys/param.h>
72
73#include <sys/mount.h>
74
75#include <assert.h>
76#include <errno.h>
77#include <fcntl.h>
78#include <stdarg.h>
79#include <stdint.h>
79#include <stdio.h>
80#include <stdlib.h>
81#include <string.h>
82#include <unistd.h>
83
84#include "makefs.h"
80#include <stdio.h>
81#include <stdlib.h>
82#include <string.h>
83#include <unistd.h>
84
85#include "makefs.h"
86#include "ffs.h"
85
87
88#if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS
89#include <sys/statvfs.h>
90#endif
91
86#include <ufs/ufs/dinode.h>
87#include <ufs/ufs/dir.h>
88#include <ufs/ffs/fs.h>
89
92#include <ufs/ufs/dinode.h>
93#include <ufs/ufs/dir.h>
94#include <ufs/ffs/fs.h>
95
96
90#include "ffs/ufs_bswap.h"
91#include "ffs/ufs_inode.h"
92#include "ffs/newfs_extern.h"
93#include "ffs/ffs_extern.h"
94
95#undef DIP
96#define DIP(dp, field) \
97#include "ffs/ufs_bswap.h"
98#include "ffs/ufs_inode.h"
99#include "ffs/newfs_extern.h"
100#include "ffs/ffs_extern.h"
101
102#undef DIP
103#define DIP(dp, field) \
97 ((fsopts->version == 1) ? \
104 ((ffs_opts->version == 1) ? \
98 (dp)->ffs1_din.di_##field : (dp)->ffs2_din.di_##field)
99
100/*
101 * Various file system defaults (cribbed from newfs(8)).
102 */
103#define DFL_FRAGSIZE 1024 /* fragment size */
104#define DFL_BLKSIZE 8192 /* block size */
105#define DFL_SECSIZE 512 /* sector size */

--- 28 unchanged lines hidden (view full) ---

134 fsnode *, fsinfo_t *);
135
136
137
138int sectorsize; /* XXX: for buf.c::getblk() */
139
140 /* publically visible functions */
141
105 (dp)->ffs1_din.di_##field : (dp)->ffs2_din.di_##field)
106
107/*
108 * Various file system defaults (cribbed from newfs(8)).
109 */
110#define DFL_FRAGSIZE 1024 /* fragment size */
111#define DFL_BLKSIZE 8192 /* block size */
112#define DFL_SECSIZE 512 /* sector size */

--- 28 unchanged lines hidden (view full) ---

141 fsnode *, fsinfo_t *);
142
143
144
145int sectorsize; /* XXX: for buf.c::getblk() */
146
147 /* publically visible functions */
148
149void
150ffs_prep_opts(fsinfo_t *fsopts)
151{
152 ffs_opt_t *ffs_opts;
153
154 if ((ffs_opts = calloc(1, sizeof(ffs_opt_t))) == NULL)
155 err(1, "Allocating memory for ffs_options");
156
157 fsopts->fs_specific = ffs_opts;
158
159 ffs_opts->bsize= -1;
160 ffs_opts->fsize= -1;
161 ffs_opts->cpg= -1;
162 ffs_opts->density= -1;
163 ffs_opts->minfree= -1;
164 ffs_opts->optimization= -1;
165 ffs_opts->maxcontig= -1;
166 ffs_opts->maxbpg= -1;
167 ffs_opts->avgfilesize= -1;
168 ffs_opts->avgfpdir= -1;
169 ffs_opts->version = 1;
170}
171
172void
173ffs_cleanup_opts(fsinfo_t *fsopts)
174{
175 if (fsopts->fs_specific)
176 free(fsopts->fs_specific);
177}
178
142int
143ffs_parse_opts(const char *option, fsinfo_t *fsopts)
144{
179int
180ffs_parse_opts(const char *option, fsinfo_t *fsopts)
181{
182 ffs_opt_t *ffs_opts = fsopts->fs_specific;
183
145 option_t ffs_options[] = {
184 option_t ffs_options[] = {
146 { "bsize", &fsopts->bsize, 1, INT_MAX,
185 { "bsize", &ffs_opts->bsize, 1, INT_MAX,
147 "block size" },
186 "block size" },
148 { "fsize", &fsopts->fsize, 1, INT_MAX,
187 { "fsize", &ffs_opts->fsize, 1, INT_MAX,
149 "fragment size" },
188 "fragment size" },
150 { "density", &fsopts->density, 1, INT_MAX,
189 { "density", &ffs_opts->density, 1, INT_MAX,
151 "bytes per inode" },
190 "bytes per inode" },
152 { "minfree", &fsopts->minfree, 0, 99,
191 { "minfree", &ffs_opts->minfree, 0, 99,
153 "minfree" },
192 "minfree" },
154 { "maxbpf", &fsopts->maxbpg, 1, INT_MAX,
193 { "maxbpf", &ffs_opts->maxbpg, 1, INT_MAX,
155 "max blocks per file in a cg" },
194 "max blocks per file in a cg" },
156 { "avgfilesize", &fsopts->avgfilesize, 1, INT_MAX,
195 { "avgfilesize", &ffs_opts->avgfilesize,1, INT_MAX,
157 "expected average file size" },
196 "expected average file size" },
158 { "avgfpdir", &fsopts->avgfpdir, 1, INT_MAX,
197 { "avgfpdir", &ffs_opts->avgfpdir, 1, INT_MAX,
159 "expected # of files per directory" },
198 "expected # of files per directory" },
160 { "extent", &fsopts->maxbsize, 1, INT_MAX,
199 { "extent", &ffs_opts->maxbsize, 1, INT_MAX,
161 "maximum # extent size" },
200 "maximum # extent size" },
162 { "maxbpcg", &fsopts->maxblkspercg, 1, INT_MAX,
201 { "maxbpcg", &ffs_opts->maxblkspercg,1, INT_MAX,
163 "max # of blocks per group" },
202 "max # of blocks per group" },
164 { "version", &fsopts->version, 1, 2,
203 { "version", &ffs_opts->version, 1, 2,
165 "UFS version" },
204 "UFS version" },
166 { NULL }
205 { .name = NULL }
167 };
168
169 char *var, *val;
170 int rv;
171
206 };
207
208 char *var, *val;
209 int rv;
210
172 (void)&ffs_options;
173 assert(option != NULL);
174 assert(fsopts != NULL);
211 assert(option != NULL);
212 assert(fsopts != NULL);
213 assert(ffs_opts != NULL);
175
176 if (debug & DEBUG_FS_PARSE_OPTS)
177 printf("ffs_parse_opts: got `%s'\n", option);
178
179 if ((var = strdup(option)) == NULL)
180 err(1, "Allocating memory for copy of option string");
181 rv = 0;
182
183 if ((val = strchr(var, '=')) == NULL) {
184 warnx("Option `%s' doesn't contain a value", var);
185 goto leave_ffs_parse_opts;
186 }
187 *val++ = '\0';
188
189 if (strcmp(var, "optimization") == 0) {
190 if (strcmp(val, "time") == 0) {
214
215 if (debug & DEBUG_FS_PARSE_OPTS)
216 printf("ffs_parse_opts: got `%s'\n", option);
217
218 if ((var = strdup(option)) == NULL)
219 err(1, "Allocating memory for copy of option string");
220 rv = 0;
221
222 if ((val = strchr(var, '=')) == NULL) {
223 warnx("Option `%s' doesn't contain a value", var);
224 goto leave_ffs_parse_opts;
225 }
226 *val++ = '\0';
227
228 if (strcmp(var, "optimization") == 0) {
229 if (strcmp(val, "time") == 0) {
191 fsopts->optimization = FS_OPTTIME;
230 ffs_opts->optimization = FS_OPTTIME;
192 } else if (strcmp(val, "space") == 0) {
231 } else if (strcmp(val, "space") == 0) {
193 fsopts->optimization = FS_OPTSPACE;
232 ffs_opts->optimization = FS_OPTSPACE;
194 } else {
195 warnx("Invalid optimization `%s'", val);
196 goto leave_ffs_parse_opts;
197 }
198 rv = 1;
199 } else
200 rv = set_option(ffs_options, var, val);
201

--- 70 unchanged lines hidden (view full) ---

272
273static void
274ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts)
275{
276 int32_t ncg = 1;
277#if notyet
278 int32_t spc, nspf, ncyl, fssize;
279#endif
233 } else {
234 warnx("Invalid optimization `%s'", val);
235 goto leave_ffs_parse_opts;
236 }
237 rv = 1;
238 } else
239 rv = set_option(ffs_options, var, val);
240

--- 70 unchanged lines hidden (view full) ---

311
312static void
313ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts)
314{
315 int32_t ncg = 1;
316#if notyet
317 int32_t spc, nspf, ncyl, fssize;
318#endif
280 off_t size;
319 ffs_opt_t *ffs_opts = fsopts->fs_specific;
281
282 assert(dir != NULL);
283 assert(root != NULL);
284 assert(fsopts != NULL);
320
321 assert(dir != NULL);
322 assert(root != NULL);
323 assert(fsopts != NULL);
324 assert(ffs_opts != NULL);
285
286 if (debug & DEBUG_FS_VALIDATE) {
287 printf("ffs_validate: before defaults set:\n");
288 ffs_dump_fsinfo(fsopts);
289 }
290
291 /* set FFS defaults */
292 if (fsopts->sectorsize == -1)
293 fsopts->sectorsize = DFL_SECSIZE;
325
326 if (debug & DEBUG_FS_VALIDATE) {
327 printf("ffs_validate: before defaults set:\n");
328 ffs_dump_fsinfo(fsopts);
329 }
330
331 /* set FFS defaults */
332 if (fsopts->sectorsize == -1)
333 fsopts->sectorsize = DFL_SECSIZE;
294 if (fsopts->fsize == -1)
295 fsopts->fsize = MAX(DFL_FRAGSIZE, fsopts->sectorsize);
296 if (fsopts->bsize == -1)
297 fsopts->bsize = MIN(DFL_BLKSIZE, 8 * fsopts->fsize);
298 if (fsopts->cpg == -1)
299 fsopts->cpg = DFL_CYLSPERGROUP;
334 if (ffs_opts->fsize == -1)
335 ffs_opts->fsize = MAX(DFL_FRAGSIZE, fsopts->sectorsize);
336 if (ffs_opts->bsize == -1)
337 ffs_opts->bsize = MIN(DFL_BLKSIZE, 8 * ffs_opts->fsize);
338 if (ffs_opts->cpg == -1)
339 ffs_opts->cpg = DFL_CYLSPERGROUP;
300 else
340 else
301 fsopts->cpgflg = 1;
341 ffs_opts->cpgflg = 1;
302 /* fsopts->density is set below */
342 /* fsopts->density is set below */
303 if (fsopts->nsectors == -1)
304 fsopts->nsectors = DFL_NSECTORS;
305 if (fsopts->minfree == -1)
306 fsopts->minfree = MINFREE;
307 if (fsopts->optimization == -1)
308 fsopts->optimization = DEFAULTOPT;
309 if (fsopts->maxcontig == -1)
310 fsopts->maxcontig =
311 MAX(1, MIN(MAXPHYS, FFS_MAXBSIZE) / fsopts->bsize);
343 if (ffs_opts->nsectors == -1)
344 ffs_opts->nsectors = DFL_NSECTORS;
345 if (ffs_opts->minfree == -1)
346 ffs_opts->minfree = MINFREE;
347 if (ffs_opts->optimization == -1)
348 ffs_opts->optimization = DEFAULTOPT;
349 if (ffs_opts->maxcontig == -1)
350 ffs_opts->maxcontig =
351 MAX(1, MIN(MAXPHYS, FFS_MAXBSIZE) / ffs_opts->bsize);
312 /* XXX ondisk32 */
352 /* XXX ondisk32 */
313 if (fsopts->maxbpg == -1)
314 fsopts->maxbpg = fsopts->bsize / sizeof(int32_t);
315 if (fsopts->avgfilesize == -1)
316 fsopts->avgfilesize = AVFILESIZ;
317 if (fsopts->avgfpdir == -1)
318 fsopts->avgfpdir = AFPDIR;
353 if (ffs_opts->maxbpg == -1)
354 ffs_opts->maxbpg = ffs_opts->bsize / sizeof(int32_t);
355 if (ffs_opts->avgfilesize == -1)
356 ffs_opts->avgfilesize = AVFILESIZ;
357 if (ffs_opts->avgfpdir == -1)
358 ffs_opts->avgfpdir = AFPDIR;
319
320 /* calculate size of tree */
321 ffs_size_dir(root, fsopts);
322 fsopts->inodes += ROOTINO; /* include first two inodes */
323
324 if (debug & DEBUG_FS_VALIDATE)
325 printf("ffs_validate: size of tree: %lld bytes, %lld inodes\n",
326 (long long)fsopts->size, (long long)fsopts->inodes);

--- 11 unchanged lines hidden (view full) ---

338 /* add space needed for superblocks */
339 /*
340 * The old SBOFF (SBLOCK_UFS1) is used here because makefs is
341 * typically used for small filesystems where space matters.
342 * XXX make this an option.
343 */
344 fsopts->size += (SBLOCK_UFS1 + SBLOCKSIZE) * ncg;
345 /* add space needed to store inodes, x3 for blockmaps, etc */
359
360 /* calculate size of tree */
361 ffs_size_dir(root, fsopts);
362 fsopts->inodes += ROOTINO; /* include first two inodes */
363
364 if (debug & DEBUG_FS_VALIDATE)
365 printf("ffs_validate: size of tree: %lld bytes, %lld inodes\n",
366 (long long)fsopts->size, (long long)fsopts->inodes);

--- 11 unchanged lines hidden (view full) ---

378 /* add space needed for superblocks */
379 /*
380 * The old SBOFF (SBLOCK_UFS1) is used here because makefs is
381 * typically used for small filesystems where space matters.
382 * XXX make this an option.
383 */
384 fsopts->size += (SBLOCK_UFS1 + SBLOCKSIZE) * ncg;
385 /* add space needed to store inodes, x3 for blockmaps, etc */
346 if (fsopts->version == 1)
386 if (ffs_opts->version == 1)
347 fsopts->size += ncg * DINODE1_SIZE *
387 fsopts->size += ncg * DINODE1_SIZE *
348 roundup(fsopts->inodes / ncg, fsopts->bsize / DINODE1_SIZE);
388 roundup(fsopts->inodes / ncg,
389 ffs_opts->bsize / DINODE1_SIZE);
349 else
350 fsopts->size += ncg * DINODE2_SIZE *
390 else
391 fsopts->size += ncg * DINODE2_SIZE *
351 roundup(fsopts->inodes / ncg, fsopts->bsize / DINODE2_SIZE);
392 roundup(fsopts->inodes / ncg,
393 ffs_opts->bsize / DINODE2_SIZE);
352
353 /* add minfree */
394
395 /* add minfree */
354 if (fsopts->minfree > 0)
396 if (ffs_opts->minfree > 0)
355 fsopts->size =
397 fsopts->size =
356 fsopts->size * (100 + fsopts->minfree) / 100;
398 fsopts->size * (100 + ffs_opts->minfree) / 100;
357 /*
358 * XXX any other fs slop to add, such as csum's, bitmaps, etc ??
359 */
360
361 if (fsopts->size < fsopts->minsize) /* ensure meets minimum size */
362 fsopts->size = fsopts->minsize;
363
364 /* round up to the next block */
399 /*
400 * XXX any other fs slop to add, such as csum's, bitmaps, etc ??
401 */
402
403 if (fsopts->size < fsopts->minsize) /* ensure meets minimum size */
404 fsopts->size = fsopts->minsize;
405
406 /* round up to the next block */
365 size = roundup(fsopts->size, fsopts->bsize);
407 fsopts->size = roundup(fsopts->size, ffs_opts->bsize);
366
408
367 /* now check calculated sizes vs requested sizes */
368 if (fsopts->maxsize > 0 && size > fsopts->maxsize) {
369 if (debug & DEBUG_FS_VALIDATE) {
370 printf("%s: `%s' size of %lld is larger than the "
371 "maxsize of %lld; rounding down to %lld.",
372 __func__, dir, (long long)size,
373 (long long)fsopts->maxsize,
374 (long long) rounddown(fsopts->size, fsopts->bsize));
375 }
376 size = rounddown(fsopts->size, fsopts->bsize);
377 }
378 fsopts->size = size;
379
380 /* calculate density if necessary */
409 /* calculate density if necessary */
381 if (fsopts->density == -1)
382 fsopts->density = fsopts->size / fsopts->inodes + 1;
410 if (ffs_opts->density == -1)
411 ffs_opts->density = fsopts->size / fsopts->inodes + 1;
383
384 if (debug & DEBUG_FS_VALIDATE) {
385 printf("ffs_validate: after defaults set:\n");
386 ffs_dump_fsinfo(fsopts);
387 printf("ffs_validate: dir %s; %lld bytes, %lld inodes\n",
388 dir, (long long)fsopts->size, (long long)fsopts->inodes);
389 }
390 sectorsize = fsopts->sectorsize; /* XXX - see earlier */
412
413 if (debug & DEBUG_FS_VALIDATE) {
414 printf("ffs_validate: after defaults set:\n");
415 ffs_dump_fsinfo(fsopts);
416 printf("ffs_validate: dir %s; %lld bytes, %lld inodes\n",
417 dir, (long long)fsopts->size, (long long)fsopts->inodes);
418 }
419 sectorsize = fsopts->sectorsize; /* XXX - see earlier */
420
421 /* now check calculated sizes vs requested sizes */
422 if (fsopts->maxsize > 0 && fsopts->size > fsopts->maxsize) {
423 errx(1, "`%s' size of %lld is larger than the maxsize of %lld.",
424 dir, (long long)fsopts->size, (long long)fsopts->maxsize);
425 }
391}
392
393
394static void
395ffs_dump_fsinfo(fsinfo_t *f)
396{
397
426}
427
428
429static void
430ffs_dump_fsinfo(fsinfo_t *f)
431{
432
433 ffs_opt_t *fs = f->fs_specific;
434
398 printf("fsopts at %p\n", f);
399
400 printf("\tsize %lld, inodes %lld, curinode %u\n",
401 (long long)f->size, (long long)f->inodes, f->curinode);
402
403 printf("\tminsize %lld, maxsize %lld\n",
404 (long long)f->minsize, (long long)f->maxsize);
405 printf("\tfree files %lld, freefile %% %d\n",
406 (long long)f->freefiles, f->freefilepc);
407 printf("\tfree blocks %lld, freeblock %% %d\n",
408 (long long)f->freeblocks, f->freeblockpc);
409 printf("\tneedswap %d, sectorsize %d\n", f->needswap, f->sectorsize);
410
411 printf("\tbsize %d, fsize %d, cpg %d, density %d\n",
435 printf("fsopts at %p\n", f);
436
437 printf("\tsize %lld, inodes %lld, curinode %u\n",
438 (long long)f->size, (long long)f->inodes, f->curinode);
439
440 printf("\tminsize %lld, maxsize %lld\n",
441 (long long)f->minsize, (long long)f->maxsize);
442 printf("\tfree files %lld, freefile %% %d\n",
443 (long long)f->freefiles, f->freefilepc);
444 printf("\tfree blocks %lld, freeblock %% %d\n",
445 (long long)f->freeblocks, f->freeblockpc);
446 printf("\tneedswap %d, sectorsize %d\n", f->needswap, f->sectorsize);
447
448 printf("\tbsize %d, fsize %d, cpg %d, density %d\n",
412 f->bsize, f->fsize, f->cpg, f->density);
449 fs->bsize, fs->fsize, fs->cpg, fs->density);
413 printf("\tnsectors %d, rpm %d, minfree %d\n",
450 printf("\tnsectors %d, rpm %d, minfree %d\n",
414 f->nsectors, f->rpm, f->minfree);
451 fs->nsectors, fs->rpm, fs->minfree);
415 printf("\tmaxcontig %d, maxbpg %d\n",
452 printf("\tmaxcontig %d, maxbpg %d\n",
416 f->maxcontig, f->maxbpg);
453 fs->maxcontig, fs->maxbpg);
417 printf("\toptimization %s\n",
454 printf("\toptimization %s\n",
418 f->optimization == FS_OPTSPACE ? "space" : "time");
455 fs->optimization == FS_OPTSPACE ? "space" : "time");
419}
420
421
422static int
423ffs_create_image(const char *image, fsinfo_t *fsopts)
424{
456}
457
458
459static int
460ffs_create_image(const char *image, fsinfo_t *fsopts)
461{
425#if HAVE_STRUCT_STATVFS_F_IOSIZE
462#if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS
426 struct statvfs sfs;
427#endif
428 struct fs *fs;
429 char *buf;
430 int i, bufsize;
431 off_t bufrem;
432
433 assert (image != NULL);
434 assert (fsopts != NULL);
435
436 /* create image */
463 struct statvfs sfs;
464#endif
465 struct fs *fs;
466 char *buf;
467 int i, bufsize;
468 off_t bufrem;
469
470 assert (image != NULL);
471 assert (fsopts != NULL);
472
473 /* create image */
437 if ((fsopts->fd = open(image, O_RDWR | O_CREAT | O_TRUNC, 0777))
474 if ((fsopts->fd = open(image, O_RDWR | O_CREAT | O_TRUNC, 0666))
438 == -1) {
439 warn("Can't open `%s' for writing", image);
440 return (-1);
441 }
442
443 /* zero image */
475 == -1) {
476 warn("Can't open `%s' for writing", image);
477 return (-1);
478 }
479
480 /* zero image */
444#if HAVE_STRUCT_STATVFS_F_IOSIZE
481#if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS
445 if (fstatvfs(fsopts->fd, &sfs) == -1) {
446#endif
447 bufsize = 8192;
482 if (fstatvfs(fsopts->fd, &sfs) == -1) {
483#endif
484 bufsize = 8192;
448#if HAVE_STRUCT_STATVFS_F_IOSIZE
485#if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS
449 warn("can't fstatvfs `%s', using default %d byte chunk",
450 image, bufsize);
451 } else
452 bufsize = sfs.f_iosize;
453#endif
454 bufrem = fsopts->size;
455 if (debug & DEBUG_FS_CREATE_IMAGE)
456 printf(
457 "zero-ing image `%s', %lld sectors, using %d byte chunks\n",
458 image, (long long)bufrem, bufsize);
459 if ((buf = calloc(1, bufsize)) == NULL) {
460 warn("Can't create buffer for sector");
461 return (-1);
462 }
463 while (bufrem > 0) {
464 i = write(fsopts->fd, buf, MIN(bufsize, bufrem));
465 if (i == -1) {
466 warn("zeroing image, %lld bytes to go",
467 (long long)bufrem);
486 warn("can't fstatvfs `%s', using default %d byte chunk",
487 image, bufsize);
488 } else
489 bufsize = sfs.f_iosize;
490#endif
491 bufrem = fsopts->size;
492 if (debug & DEBUG_FS_CREATE_IMAGE)
493 printf(
494 "zero-ing image `%s', %lld sectors, using %d byte chunks\n",
495 image, (long long)bufrem, bufsize);
496 if ((buf = calloc(1, bufsize)) == NULL) {
497 warn("Can't create buffer for sector");
498 return (-1);
499 }
500 while (bufrem > 0) {
501 i = write(fsopts->fd, buf, MIN(bufsize, bufrem));
502 if (i == -1) {
503 warn("zeroing image, %lld bytes to go",
504 (long long)bufrem);
505 free(buf);
468 return (-1);
469 }
470 bufrem -= i;
471 }
506 return (-1);
507 }
508 bufrem -= i;
509 }
510 free(buf);
472
473 /* make the file system */
474 if (debug & DEBUG_FS_CREATE_IMAGE)
475 printf("calling mkfs(\"%s\", ...)\n", image);
476 fs = ffs_mkfs(image, fsopts);
477 fsopts->superblock = (void *)fs;
478 if (debug & DEBUG_FS_CREATE_IMAGE) {
479 time_t t;

--- 7 unchanged lines hidden (view full) ---

487 (long long)fs->fs_cstotal.cs_nifree,
488 (long long)fs->fs_cstotal.cs_ndir);
489 }
490
491 if (fs->fs_cstotal.cs_nifree + ROOTINO < fsopts->inodes) {
492 warnx(
493 "Image file `%s' has %lld free inodes; %lld are required.",
494 image,
511
512 /* make the file system */
513 if (debug & DEBUG_FS_CREATE_IMAGE)
514 printf("calling mkfs(\"%s\", ...)\n", image);
515 fs = ffs_mkfs(image, fsopts);
516 fsopts->superblock = (void *)fs;
517 if (debug & DEBUG_FS_CREATE_IMAGE) {
518 time_t t;

--- 7 unchanged lines hidden (view full) ---

526 (long long)fs->fs_cstotal.cs_nifree,
527 (long long)fs->fs_cstotal.cs_ndir);
528 }
529
530 if (fs->fs_cstotal.cs_nifree + ROOTINO < fsopts->inodes) {
531 warnx(
532 "Image file `%s' has %lld free inodes; %lld are required.",
533 image,
495 (long long)fs->fs_cstotal.cs_nifree + ROOTINO,
534 (long long)(fs->fs_cstotal.cs_nifree + ROOTINO),
496 (long long)fsopts->inodes);
497 return (-1);
498 }
499 return (fsopts->fd);
500}
501
502
503static void
504ffs_size_dir(fsnode *root, fsinfo_t *fsopts)
505{
506 struct direct tmpdir;
507 fsnode * node;
508 int curdirsize, this;
535 (long long)fsopts->inodes);
536 return (-1);
537 }
538 return (fsopts->fd);
539}
540
541
542static void
543ffs_size_dir(fsnode *root, fsinfo_t *fsopts)
544{
545 struct direct tmpdir;
546 fsnode * node;
547 int curdirsize, this;
548 ffs_opt_t *ffs_opts = fsopts->fs_specific;
509
510 /* node may be NULL (empty directory) */
511 assert(fsopts != NULL);
549
550 /* node may be NULL (empty directory) */
551 assert(fsopts != NULL);
552 assert(ffs_opts != NULL);
512
513 if (debug & DEBUG_FS_SIZE_DIR)
514 printf("ffs_size_dir: entry: bytes %lld inodes %lld\n",
515 (long long)fsopts->size, (long long)fsopts->inodes);
516
517#define ADDDIRENT(e) do { \
518 tmpdir.d_namlen = strlen((e)); \
553
554 if (debug & DEBUG_FS_SIZE_DIR)
555 printf("ffs_size_dir: entry: bytes %lld inodes %lld\n",
556 (long long)fsopts->size, (long long)fsopts->inodes);
557
558#define ADDDIRENT(e) do { \
559 tmpdir.d_namlen = strlen((e)); \
519 this = DIRSIZ_SWAP(0, &tmpdir, 0); \
560 this = DIRSIZ_SWAP(0, &tmpdir, 0); \
520 if (debug & DEBUG_FS_SIZE_DIR_ADD_DIRENT) \
521 printf("ADDDIRENT: was: %s (%d) this %d cur %d\n", \
522 e, tmpdir.d_namlen, this, curdirsize); \
523 if (this + curdirsize > roundup(curdirsize, DIRBLKSIZ)) \
524 curdirsize = roundup(curdirsize, DIRBLKSIZ); \
525 curdirsize += this; \
526 if (debug & DEBUG_FS_SIZE_DIR_ADD_DIRENT) \
527 printf("ADDDIRENT: now: %s (%d) this %d cur %d\n", \
528 e, tmpdir.d_namlen, this, curdirsize); \
529} while (0);
530
531 /*
532 * XXX this needs to take into account extra space consumed
533 * by indirect blocks, etc.
534 */
535#define ADDSIZE(x) do { \
561 if (debug & DEBUG_FS_SIZE_DIR_ADD_DIRENT) \
562 printf("ADDDIRENT: was: %s (%d) this %d cur %d\n", \
563 e, tmpdir.d_namlen, this, curdirsize); \
564 if (this + curdirsize > roundup(curdirsize, DIRBLKSIZ)) \
565 curdirsize = roundup(curdirsize, DIRBLKSIZ); \
566 curdirsize += this; \
567 if (debug & DEBUG_FS_SIZE_DIR_ADD_DIRENT) \
568 printf("ADDDIRENT: now: %s (%d) this %d cur %d\n", \
569 e, tmpdir.d_namlen, this, curdirsize); \
570} while (0);
571
572 /*
573 * XXX this needs to take into account extra space consumed
574 * by indirect blocks, etc.
575 */
576#define ADDSIZE(x) do { \
536 fsopts->size += roundup((x), fsopts->fsize); \
577 fsopts->size += roundup((x), ffs_opts->fsize); \
537} while (0);
538
539 curdirsize = 0;
540 for (node = root; node != NULL; node = node->next) {
541 ADDDIRENT(node->name);
578} while (0);
579
580 curdirsize = 0;
581 for (node = root; node != NULL; node = node->next) {
582 ADDDIRENT(node->name);
542 if (FSNODE_EXCLUDE_P(fsopts, node))
543 continue;
544 if (node == root) { /* we're at "." */
545 assert(strcmp(node->name, ".") == 0);
546 ADDDIRENT("..");
547 } else if ((node->inode->flags & FI_SIZED) == 0) {
548 /* don't count duplicate names */
549 node->inode->flags |= FI_SIZED;
550 if (debug & DEBUG_FS_SIZE_DIR_NODE)
551 printf("ffs_size_dir: `%s' size %lld\n",
552 node->name,
553 (long long)node->inode->st.st_size);
554 fsopts->inodes++;
555 if (node->type == S_IFREG)
556 ADDSIZE(node->inode->st.st_size);
557 if (node->type == S_IFLNK) {
558 int slen;
559
560 slen = strlen(node->symlink) + 1;
583 if (node == root) { /* we're at "." */
584 assert(strcmp(node->name, ".") == 0);
585 ADDDIRENT("..");
586 } else if ((node->inode->flags & FI_SIZED) == 0) {
587 /* don't count duplicate names */
588 node->inode->flags |= FI_SIZED;
589 if (debug & DEBUG_FS_SIZE_DIR_NODE)
590 printf("ffs_size_dir: `%s' size %lld\n",
591 node->name,
592 (long long)node->inode->st.st_size);
593 fsopts->inodes++;
594 if (node->type == S_IFREG)
595 ADDSIZE(node->inode->st.st_size);
596 if (node->type == S_IFLNK) {
597 int slen;
598
599 slen = strlen(node->symlink) + 1;
561 if (slen >= (fsopts->version == 1 ?
600 if (slen >= (ffs_opts->version == 1 ?
562 MAXSYMLINKLEN_UFS1 :
563 MAXSYMLINKLEN_UFS2))
564 ADDSIZE(slen);
565 }
566 }
567 if (node->type == S_IFDIR)
568 ffs_size_dir(node->child, fsopts);
569 }

--- 107 unchanged lines hidden (view full) ---

677static int
678ffs_populate_dir(const char *dir, fsnode *root, fsinfo_t *fsopts)
679{
680 fsnode *cur;
681 dirbuf_t dirbuf;
682 union dinode din;
683 void *membuf;
684 char path[MAXPATHLEN + 1];
601 MAXSYMLINKLEN_UFS1 :
602 MAXSYMLINKLEN_UFS2))
603 ADDSIZE(slen);
604 }
605 }
606 if (node->type == S_IFDIR)
607 ffs_size_dir(node->child, fsopts);
608 }

--- 107 unchanged lines hidden (view full) ---

716static int
717ffs_populate_dir(const char *dir, fsnode *root, fsinfo_t *fsopts)
718{
719 fsnode *cur;
720 dirbuf_t dirbuf;
721 union dinode din;
722 void *membuf;
723 char path[MAXPATHLEN + 1];
724 ffs_opt_t *ffs_opts = fsopts->fs_specific;
685
686 assert(dir != NULL);
687 assert(root != NULL);
688 assert(fsopts != NULL);
725
726 assert(dir != NULL);
727 assert(root != NULL);
728 assert(fsopts != NULL);
729 assert(ffs_opts != NULL);
689
690 (void)memset(&dirbuf, 0, sizeof(dirbuf));
691
692 if (debug & DEBUG_FS_POPULATE)
693 printf("ffs_populate_dir: PASS 1 dir %s node %p\n", dir, root);
694
695 /*
696 * pass 1: allocate inode numbers, build directory `file'
697 */
698 for (cur = root; cur != NULL; cur = cur->next) {
730
731 (void)memset(&dirbuf, 0, sizeof(dirbuf));
732
733 if (debug & DEBUG_FS_POPULATE)
734 printf("ffs_populate_dir: PASS 1 dir %s node %p\n", dir, root);
735
736 /*
737 * pass 1: allocate inode numbers, build directory `file'
738 */
739 for (cur = root; cur != NULL; cur = cur->next) {
699 if (FSNODE_EXCLUDE_P(fsopts, cur))
700 continue;
701 if ((cur->inode->flags & FI_ALLOCATED) == 0) {
702 cur->inode->flags |= FI_ALLOCATED;
703 if (cur == root && cur->parent != NULL)
704 cur->inode->ino = cur->parent->inode->ino;
705 else {
706 cur->inode->ino = fsopts->curinode;
707 fsopts->curinode++;
708 }

--- 18 unchanged lines hidden (view full) ---

727 ffs_dump_dirbuf(&dirbuf, dir, fsopts->needswap);
728
729 /*
730 * pass 2: write out dirbuf, then non-directories at this level
731 */
732 if (debug & DEBUG_FS_POPULATE)
733 printf("ffs_populate_dir: PASS 2 dir %s\n", dir);
734 for (cur = root; cur != NULL; cur = cur->next) {
740 if ((cur->inode->flags & FI_ALLOCATED) == 0) {
741 cur->inode->flags |= FI_ALLOCATED;
742 if (cur == root && cur->parent != NULL)
743 cur->inode->ino = cur->parent->inode->ino;
744 else {
745 cur->inode->ino = fsopts->curinode;
746 fsopts->curinode++;
747 }

--- 18 unchanged lines hidden (view full) ---

766 ffs_dump_dirbuf(&dirbuf, dir, fsopts->needswap);
767
768 /*
769 * pass 2: write out dirbuf, then non-directories at this level
770 */
771 if (debug & DEBUG_FS_POPULATE)
772 printf("ffs_populate_dir: PASS 2 dir %s\n", dir);
773 for (cur = root; cur != NULL; cur = cur->next) {
735 if (FSNODE_EXCLUDE_P(fsopts, cur))
736 continue;
737 if (cur->inode->flags & FI_WRITTEN)
738 continue; /* skip hard-linked entries */
739 cur->inode->flags |= FI_WRITTEN;
740
741 if (snprintf(path, sizeof(path), "%s/%s", dir, cur->name)
742 >= sizeof(path))
743 errx(1, "Pathname too long.");
744
745 if (cur->child != NULL)
746 continue; /* child creates own inode */
747
748 /* build on-disk inode */
774 if (cur->inode->flags & FI_WRITTEN)
775 continue; /* skip hard-linked entries */
776 cur->inode->flags |= FI_WRITTEN;
777
778 if (snprintf(path, sizeof(path), "%s/%s", dir, cur->name)
779 >= sizeof(path))
780 errx(1, "Pathname too long.");
781
782 if (cur->child != NULL)
783 continue; /* child creates own inode */
784
785 /* build on-disk inode */
749 if (fsopts->version == 1)
786 if (ffs_opts->version == 1)
750 membuf = ffs_build_dinode1(&din.ffs1_din, &dirbuf, cur,
751 root, fsopts);
752 else
753 membuf = ffs_build_dinode2(&din.ffs2_din, &dirbuf, cur,
754 root, fsopts);
755
756 if (debug & DEBUG_FS_POPULATE_NODE) {
757 printf("ffs_populate_dir: writing ino %d, %s",

--- 14 unchanged lines hidden (view full) ---

772 }
773
774 /*
775 * pass 3: write out sub-directories
776 */
777 if (debug & DEBUG_FS_POPULATE)
778 printf("ffs_populate_dir: PASS 3 dir %s\n", dir);
779 for (cur = root; cur != NULL; cur = cur->next) {
787 membuf = ffs_build_dinode1(&din.ffs1_din, &dirbuf, cur,
788 root, fsopts);
789 else
790 membuf = ffs_build_dinode2(&din.ffs2_din, &dirbuf, cur,
791 root, fsopts);
792
793 if (debug & DEBUG_FS_POPULATE_NODE) {
794 printf("ffs_populate_dir: writing ino %d, %s",

--- 14 unchanged lines hidden (view full) ---

809 }
810
811 /*
812 * pass 3: write out sub-directories
813 */
814 if (debug & DEBUG_FS_POPULATE)
815 printf("ffs_populate_dir: PASS 3 dir %s\n", dir);
816 for (cur = root; cur != NULL; cur = cur->next) {
780 if (FSNODE_EXCLUDE_P(fsopts, cur))
781 continue;
782 if (cur->child == NULL)
783 continue;
784 if (snprintf(path, sizeof(path), "%s/%s", dir, cur->name)
785 >= sizeof(path))
786 errx(1, "Pathname too long.");
787 if (! ffs_populate_dir(path, cur->child, fsopts))
788 return (0);
789 }

--- 9 unchanged lines hidden (view full) ---

799
800
801static void
802ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts)
803{
804 int isfile, ffd;
805 char *fbuf, *p;
806 off_t bufleft, chunk, offset;
817 if (cur->child == NULL)
818 continue;
819 if (snprintf(path, sizeof(path), "%s/%s", dir, cur->name)
820 >= sizeof(path))
821 errx(1, "Pathname too long.");
822 if (! ffs_populate_dir(path, cur->child, fsopts))
823 return (0);
824 }

--- 9 unchanged lines hidden (view full) ---

834
835
836static void
837ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts)
838{
839 int isfile, ffd;
840 char *fbuf, *p;
841 off_t bufleft, chunk, offset;
842 ssize_t nread;
807 struct inode in;
808 struct buf * bp;
843 struct inode in;
844 struct buf * bp;
845 ffs_opt_t *ffs_opts = fsopts->fs_specific;
809
810 assert (din != NULL);
811 assert (buf != NULL);
812 assert (fsopts != NULL);
846
847 assert (din != NULL);
848 assert (buf != NULL);
849 assert (fsopts != NULL);
850 assert (ffs_opts != NULL);
813
814 isfile = S_ISREG(DIP(din, mode));
815 fbuf = NULL;
816 ffd = -1;
851
852 isfile = S_ISREG(DIP(din, mode));
853 fbuf = NULL;
854 ffd = -1;
855 p = NULL;
817
818 in.i_fs = (struct fs *)fsopts->superblock;
819
820 if (debug & DEBUG_FS_WRITE_FILE) {
821 printf(
822 "ffs_write_file: ino %u, din %p, isfile %d, %s, size %lld",
823 ino, din, isfile, inode_type(DIP(din, mode) & S_IFMT),
824 (long long)DIP(din, size));
825 if (isfile)
826 printf(", file '%s'\n", (char *)buf);
827 else
828 printf(", buffer %p\n", buf);
829 }
830
831 in.i_number = ino;
832 in.i_size = DIP(din, size);
856
857 in.i_fs = (struct fs *)fsopts->superblock;
858
859 if (debug & DEBUG_FS_WRITE_FILE) {
860 printf(
861 "ffs_write_file: ino %u, din %p, isfile %d, %s, size %lld",
862 ino, din, isfile, inode_type(DIP(din, mode) & S_IFMT),
863 (long long)DIP(din, size));
864 if (isfile)
865 printf(", file '%s'\n", (char *)buf);
866 else
867 printf(", buffer %p\n", buf);
868 }
869
870 in.i_number = ino;
871 in.i_size = DIP(din, size);
833 if (fsopts->version == 1)
872 if (ffs_opts->version == 1)
834 memcpy(&in.i_din.ffs1_din, &din->ffs1_din,
835 sizeof(in.i_din.ffs1_din));
836 else
837 memcpy(&in.i_din.ffs2_din, &din->ffs2_din,
838 sizeof(in.i_din.ffs2_din));
839 in.i_fd = fsopts->fd;
840
841 if (DIP(din, size) == 0)
842 goto write_inode_and_leave; /* mmm, cheating */
843
844 if (isfile) {
873 memcpy(&in.i_din.ffs1_din, &din->ffs1_din,
874 sizeof(in.i_din.ffs1_din));
875 else
876 memcpy(&in.i_din.ffs2_din, &din->ffs2_din,
877 sizeof(in.i_din.ffs2_din));
878 in.i_fd = fsopts->fd;
879
880 if (DIP(din, size) == 0)
881 goto write_inode_and_leave; /* mmm, cheating */
882
883 if (isfile) {
845 if ((fbuf = malloc(fsopts->bsize)) == NULL)
884 if ((fbuf = malloc(ffs_opts->bsize)) == NULL)
846 err(1, "Allocating memory for write buffer");
847 if ((ffd = open((char *)buf, O_RDONLY, 0444)) == -1) {
848 warn("Can't open `%s' for reading", (char *)buf);
849 goto leave_ffs_write_file;
850 }
851 } else {
852 p = buf;
853 }
854
855 chunk = 0;
856 for (bufleft = DIP(din, size); bufleft > 0; bufleft -= chunk) {
885 err(1, "Allocating memory for write buffer");
886 if ((ffd = open((char *)buf, O_RDONLY, 0444)) == -1) {
887 warn("Can't open `%s' for reading", (char *)buf);
888 goto leave_ffs_write_file;
889 }
890 } else {
891 p = buf;
892 }
893
894 chunk = 0;
895 for (bufleft = DIP(din, size); bufleft > 0; bufleft -= chunk) {
857 chunk = MIN(bufleft, fsopts->bsize);
858 if (isfile) {
859 if (read(ffd, fbuf, chunk) != chunk)
860 err(1, "Reading `%s', %lld bytes to go",
861 (char *)buf, (long long)bufleft);
896 chunk = MIN(bufleft, ffs_opts->bsize);
897 if (!isfile)
898 ;
899 else if ((nread = read(ffd, fbuf, chunk)) == -1)
900 err(EXIT_FAILURE, "Reading `%s', %lld bytes to go",
901 (char *)buf, (long long)bufleft);
902 else if (nread != chunk)
903 errx(EXIT_FAILURE, "Reading `%s', %lld bytes to go, "
904 "read %zd bytes, expected %ju bytes, does "
905 "metalog size= attribute mismatch source size?",
906 (char *)buf, (long long)bufleft, nread,
907 (uintmax_t)chunk);
908 else
862 p = fbuf;
909 p = fbuf;
863 }
864 offset = DIP(din, size) - bufleft;
865 if (debug & DEBUG_FS_WRITE_FILE_BLOCK)
866 printf(
867 "ffs_write_file: write %p offset %lld size %lld left %lld\n",
868 p, (long long)offset,
869 (long long)chunk, (long long)bufleft);
870 /*
871 * XXX if holey support is desired, do the check here

--- 55 unchanged lines hidden (view full) ---

927 }
928}
929
930static void
931ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node, int needswap)
932{
933 struct direct de, *dp;
934 uint16_t llen, reclen;
910 offset = DIP(din, size) - bufleft;
911 if (debug & DEBUG_FS_WRITE_FILE_BLOCK)
912 printf(
913 "ffs_write_file: write %p offset %lld size %lld left %lld\n",
914 p, (long long)offset,
915 (long long)chunk, (long long)bufleft);
916 /*
917 * XXX if holey support is desired, do the check here

--- 55 unchanged lines hidden (view full) ---

973 }
974}
975
976static void
977ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node, int needswap)
978{
979 struct direct de, *dp;
980 uint16_t llen, reclen;
935 char *newbuf;
981 u_char *newbuf;
936
937 assert (dbuf != NULL);
938 assert (name != NULL);
939 assert (node != NULL);
940 /* create direct entry */
941 (void)memset(&de, 0, sizeof(de));
942 de.d_ino = ufs_rw32(node->inode->ino, needswap);
943 de.d_type = IFTODT(node->type);

--- 20 unchanged lines hidden (view full) ---

964 printf("ffs_make_dirbuf: growing buf to %d\n",
965 dbuf->size + DIRBLKSIZ);
966 if ((newbuf = realloc(dbuf->buf, dbuf->size + DIRBLKSIZ)) == NULL)
967 err(1, "Allocating memory for directory buffer");
968 dbuf->buf = newbuf;
969 dbuf->size += DIRBLKSIZ;
970 memset(dbuf->buf + dbuf->size - DIRBLKSIZ, 0, DIRBLKSIZ);
971 dbuf->cur = dbuf->size - DIRBLKSIZ;
982
983 assert (dbuf != NULL);
984 assert (name != NULL);
985 assert (node != NULL);
986 /* create direct entry */
987 (void)memset(&de, 0, sizeof(de));
988 de.d_ino = ufs_rw32(node->inode->ino, needswap);
989 de.d_type = IFTODT(node->type);

--- 20 unchanged lines hidden (view full) ---

1010 printf("ffs_make_dirbuf: growing buf to %d\n",
1011 dbuf->size + DIRBLKSIZ);
1012 if ((newbuf = realloc(dbuf->buf, dbuf->size + DIRBLKSIZ)) == NULL)
1013 err(1, "Allocating memory for directory buffer");
1014 dbuf->buf = newbuf;
1015 dbuf->size += DIRBLKSIZ;
1016 memset(dbuf->buf + dbuf->size - DIRBLKSIZ, 0, DIRBLKSIZ);
1017 dbuf->cur = dbuf->size - DIRBLKSIZ;
972 } else { /* shrink end of previous */
1018 } else if (dp) { /* shrink end of previous */
973 dp->d_reclen = ufs_rw16(llen,needswap);
974 dbuf->cur += llen;
975 }
976 dp = (struct direct *)(dbuf->buf + dbuf->cur);
977 memcpy(dp, &de, reclen);
978 dp->d_reclen = ufs_rw16(dbuf->size - dbuf->cur, needswap);
979}
980

--- 7 unchanged lines hidden (view full) ---

988 struct ufs1_dinode *dp1;
989 struct ufs2_dinode *dp2, *dip;
990 struct cg *cgp;
991 struct fs *fs;
992 int cg, cgino, i;
993 daddr_t d;
994 char sbbuf[FFS_MAXBSIZE];
995 int32_t initediblk;
1019 dp->d_reclen = ufs_rw16(llen,needswap);
1020 dbuf->cur += llen;
1021 }
1022 dp = (struct direct *)(dbuf->buf + dbuf->cur);
1023 memcpy(dp, &de, reclen);
1024 dp->d_reclen = ufs_rw16(dbuf->size - dbuf->cur, needswap);
1025}
1026

--- 7 unchanged lines hidden (view full) ---

1034 struct ufs1_dinode *dp1;
1035 struct ufs2_dinode *dp2, *dip;
1036 struct cg *cgp;
1037 struct fs *fs;
1038 int cg, cgino, i;
1039 daddr_t d;
1040 char sbbuf[FFS_MAXBSIZE];
1041 int32_t initediblk;
1042 ffs_opt_t *ffs_opts = fsopts->fs_specific;
996
997 assert (dp != NULL);
998 assert (ino > 0);
999 assert (fsopts != NULL);
1043
1044 assert (dp != NULL);
1045 assert (ino > 0);
1046 assert (fsopts != NULL);
1047 assert (ffs_opts != NULL);
1000
1001 fs = (struct fs *)fsopts->superblock;
1002 cg = ino_to_cg(fs, ino);
1003 cgino = ino % fs->fs_ipg;
1004 if (debug & DEBUG_FS_WRITE_INODE)
1005 printf("ffs_write_inode: din %p ino %u cg %d cgino %d\n",
1006 dp, ino, cg, cgino);
1007

--- 28 unchanged lines hidden (view full) ---

1036 fs->fs_cstotal.cs_ndir++;
1037 fs->fs_cs(fs, cg).cs_ndir++;
1038 }
1039
1040 /*
1041 * Initialize inode blocks on the fly for UFS2.
1042 */
1043 initediblk = ufs_rw32(cgp->cg_initediblk, fsopts->needswap);
1048
1049 fs = (struct fs *)fsopts->superblock;
1050 cg = ino_to_cg(fs, ino);
1051 cgino = ino % fs->fs_ipg;
1052 if (debug & DEBUG_FS_WRITE_INODE)
1053 printf("ffs_write_inode: din %p ino %u cg %d cgino %d\n",
1054 dp, ino, cg, cgino);
1055

--- 28 unchanged lines hidden (view full) ---

1084 fs->fs_cstotal.cs_ndir++;
1085 fs->fs_cs(fs, cg).cs_ndir++;
1086 }
1087
1088 /*
1089 * Initialize inode blocks on the fly for UFS2.
1090 */
1091 initediblk = ufs_rw32(cgp->cg_initediblk, fsopts->needswap);
1044 if (fsopts->version == 2 && cgino + INOPB(fs) > initediblk &&
1092 if (ffs_opts->version == 2 && cgino + INOPB(fs) > initediblk &&
1045 initediblk < ufs_rw32(cgp->cg_niblk, fsopts->needswap)) {
1046 memset(buf, 0, fs->fs_bsize);
1047 dip = (struct ufs2_dinode *)buf;
1048 srandom(time(NULL));
1049 for (i = 0; i < INOPB(fs); i++) {
1050 dip->di_gen = random() / 2 + 1;
1051 dip++;
1052 }

--- 7 unchanged lines hidden (view full) ---

1060
1061 ffs_wtfs(fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, &sbbuf,
1062 fsopts);
1063
1064 /* now write inode */
1065 d = fsbtodb(fs, ino_to_fsba(fs, ino));
1066 ffs_rdfs(d, fs->fs_bsize, buf, fsopts);
1067 if (fsopts->needswap) {
1093 initediblk < ufs_rw32(cgp->cg_niblk, fsopts->needswap)) {
1094 memset(buf, 0, fs->fs_bsize);
1095 dip = (struct ufs2_dinode *)buf;
1096 srandom(time(NULL));
1097 for (i = 0; i < INOPB(fs); i++) {
1098 dip->di_gen = random() / 2 + 1;
1099 dip++;
1100 }

--- 7 unchanged lines hidden (view full) ---

1108
1109 ffs_wtfs(fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, &sbbuf,
1110 fsopts);
1111
1112 /* now write inode */
1113 d = fsbtodb(fs, ino_to_fsba(fs, ino));
1114 ffs_rdfs(d, fs->fs_bsize, buf, fsopts);
1115 if (fsopts->needswap) {
1068 if (fsopts->version == 1)
1116 if (ffs_opts->version == 1)
1069 ffs_dinode1_swap(&dp->ffs1_din,
1070 &dp1[ino_to_fsbo(fs, ino)]);
1071 else
1072 ffs_dinode2_swap(&dp->ffs2_din,
1073 &dp2[ino_to_fsbo(fs, ino)]);
1074 } else {
1117 ffs_dinode1_swap(&dp->ffs1_din,
1118 &dp1[ino_to_fsbo(fs, ino)]);
1119 else
1120 ffs_dinode2_swap(&dp->ffs2_din,
1121 &dp2[ino_to_fsbo(fs, ino)]);
1122 } else {
1075 if (fsopts->version == 1)
1123 if (ffs_opts->version == 1)
1076 dp1[ino_to_fsbo(fs, ino)] = dp->ffs1_din;
1077 else
1078 dp2[ino_to_fsbo(fs, ino)] = dp->ffs2_din;
1079 }
1080 ffs_wtfs(d, fs->fs_bsize, buf, fsopts);
1081 free(buf);
1082}
1083
1084void
1085panic(const char *fmt, ...)
1086{
1087 va_list ap;
1088
1089 va_start(ap, fmt);
1090 vwarnx(fmt, ap);
1091 va_end(ap);
1092 exit(1);
1093}
1124 dp1[ino_to_fsbo(fs, ino)] = dp->ffs1_din;
1125 else
1126 dp2[ino_to_fsbo(fs, ino)] = dp->ffs2_din;
1127 }
1128 ffs_wtfs(d, fs->fs_bsize, buf, fsopts);
1129 free(buf);
1130}
1131
1132void
1133panic(const char *fmt, ...)
1134{
1135 va_list ap;
1136
1137 va_start(ap, fmt);
1138 vwarnx(fmt, ap);
1139 va_end(ap);
1140 exit(1);
1141}