1 /* $NetBSD: ffs.c,v 1.45 2011/10/09 22:49:26 christos 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 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 /* 38 * Copyright (c) 1982, 1986, 1989, 1993 39 * The Regents of the University of California. All rights reserved. 40 * 41 * Redistribution and use in source and binary forms, with or without 42 * modification, are permitted provided that the following conditions 43 * are met: 44 * 1. Redistributions of source code must retain the above copyright 45 * notice, this list of conditions and the following disclaimer. 46 * 2. Redistributions in binary form must reproduce the above copyright 47 * notice, this list of conditions and the following disclaimer in the 48 * documentation and/or other materials provided with the distribution. 49 * 3. Neither the name of the University nor the names of its contributors 50 * may be used to endorse or promote products derived from this software 51 * without specific prior written permission. 52 * 53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 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$"); 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> 80 #include <stdio.h> 81 #include <stdlib.h> 82 #include <string.h> 83 #include <time.h> 84 #include <unistd.h> 85 #include <util.h> 86 87 #include "makefs.h" 88 #include "ffs.h" 89 90 #if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS 91 #include <sys/statvfs.h> 92 #endif 93 94 #include <ufs/ufs/dinode.h> 95 #include <ufs/ufs/dir.h> 96 #include <ufs/ffs/fs.h> 97 98 99 #include "ffs/ufs_bswap.h" 100 #include "ffs/ufs_inode.h" 101 #include "ffs/newfs_extern.h" 102 #include "ffs/ffs_extern.h" 103 104 #undef DIP 105 #define DIP(dp, field) \ 106 ((ffs_opts->version == 1) ? \ 107 (dp)->ffs1_din.di_##field : (dp)->ffs2_din.di_##field) 108 109 /* 110 * Various file system defaults (cribbed from newfs(8)). 111 */ 112 #define DFL_FRAGSIZE 1024 /* fragment size */ 113 #define DFL_BLKSIZE 8192 /* block size */ 114 #define DFL_SECSIZE 512 /* sector size */ 115 #define DFL_CYLSPERGROUP 65536 /* cylinders per group */ 116 #define DFL_FRAGSPERINODE 4 /* fragments per inode */ 117 #define DFL_ROTDELAY 0 /* rotational delay */ 118 #define DFL_NRPOS 1 /* rotational positions */ 119 #define DFL_RPM 3600 /* rpm of disk */ 120 #define DFL_NSECTORS 64 /* # of sectors */ 121 #define DFL_NTRACKS 16 /* # of tracks */ 122 123 124 typedef struct { 125 u_char *buf; /* buf for directory */ 126 doff_t size; /* full size of buf */ 127 doff_t cur; /* offset of current entry */ 128 } dirbuf_t; 129 130 131 static int ffs_create_image(const char *, fsinfo_t *); 132 static void ffs_dump_fsinfo(fsinfo_t *); 133 static void ffs_dump_dirbuf(dirbuf_t *, const char *, int); 134 static void ffs_make_dirbuf(dirbuf_t *, const char *, fsnode *, int); 135 static int ffs_populate_dir(const char *, fsnode *, fsinfo_t *); 136 static void ffs_size_dir(fsnode *, fsinfo_t *); 137 static void ffs_validate(const char *, fsnode *, fsinfo_t *); 138 static void ffs_write_file(union dinode *, uint32_t, void *, fsinfo_t *); 139 static void ffs_write_inode(union dinode *, uint32_t, const fsinfo_t *); 140 static void *ffs_build_dinode1(struct ufs1_dinode *, dirbuf_t *, fsnode *, 141 fsnode *, fsinfo_t *); 142 static void *ffs_build_dinode2(struct ufs2_dinode *, dirbuf_t *, fsnode *, 143 fsnode *, fsinfo_t *); 144 145 146 int sectorsize; /* XXX: for buf.c::getblk() */ 147 /* publicly visible functions */ 148 149 void 150 ffs_prep_opts(fsinfo_t *fsopts) 151 { 152 ffs_opt_t *ffs_opts = ecalloc(1, sizeof(*ffs_opts)); 153 154 const option_t ffs_options[] = { 155 { 'b', "bsize", &ffs_opts->bsize, OPT_INT32, 156 1, INT_MAX, "block size" }, 157 { 'f', "fsize", &ffs_opts->fsize, OPT_INT32, 158 1, INT_MAX, "fragment size" }, 159 { 'd', "density", &ffs_opts->density, OPT_INT32, 160 1, INT_MAX, "bytes per inode" }, 161 { 'm', "minfree", &ffs_opts->minfree, OPT_INT32, 162 0, 99, "minfree" }, 163 { 'M', "maxbpg", &ffs_opts->maxbpg, OPT_INT32, 164 1, INT_MAX, "max blocks per file in a cg" }, 165 { 'a', "avgfilesize", &ffs_opts->avgfilesize, OPT_INT32, 166 1, INT_MAX, "expected average file size" }, 167 { 'n', "avgfpdir", &ffs_opts->avgfpdir, OPT_INT32, 168 1, INT_MAX, "expected # of files per directory" }, 169 { 'x', "extent", &ffs_opts->maxbsize, OPT_INT32, 170 1, INT_MAX, "maximum # extent size" }, 171 { 'g', "maxbpcg", &ffs_opts->maxblkspercg, OPT_INT32, 172 1, INT_MAX, "max # of blocks per group" }, 173 { 'v', "version", &ffs_opts->version, OPT_INT32, 174 1, 2, "UFS version" }, 175 { 'o', "optimization", NULL, OPT_STRBUF, 176 0, 0, "Optimization (time|space)" }, 177 { 'l', "label", ffs_opts->label, OPT_STRARRAY, 178 1, sizeof(ffs_opts->label), "UFS label" }, 179 { 's', "softupdates", &ffs_opts->softupdates, OPT_INT32, 180 0, 1, "enable softupdates" }, 181 { .name = NULL } 182 }; 183 184 ffs_opts->bsize= -1; 185 ffs_opts->fsize= -1; 186 ffs_opts->cpg= -1; 187 ffs_opts->density= -1; 188 ffs_opts->minfree= -1; 189 ffs_opts->optimization= -1; 190 ffs_opts->maxcontig= -1; 191 ffs_opts->maxbpg= -1; 192 ffs_opts->avgfilesize= -1; 193 ffs_opts->avgfpdir= -1; 194 ffs_opts->version = 1; 195 ffs_opts->softupdates = 0; 196 197 fsopts->fs_specific = ffs_opts; 198 fsopts->fs_options = copy_opts(ffs_options); 199 } 200 201 void 202 ffs_cleanup_opts(fsinfo_t *fsopts) 203 { 204 free(fsopts->fs_specific); 205 free(fsopts->fs_options); 206 } 207 208 int 209 ffs_parse_opts(const char *option, fsinfo_t *fsopts) 210 { 211 ffs_opt_t *ffs_opts = fsopts->fs_specific; 212 option_t *ffs_options = fsopts->fs_options; 213 char buf[1024]; 214 215 int rv; 216 217 assert(option != NULL); 218 assert(fsopts != NULL); 219 assert(ffs_opts != NULL); 220 221 if (debug & DEBUG_FS_PARSE_OPTS) 222 printf("ffs_parse_opts: got `%s'\n", option); 223 224 rv = set_option(ffs_options, option, buf, sizeof(buf)); 225 if (rv == -1) 226 return 0; 227 228 if (ffs_options[rv].name == NULL) 229 abort(); 230 231 switch (ffs_options[rv].letter) { 232 case 'o': 233 if (strcmp(buf, "time") == 0) { 234 ffs_opts->optimization = FS_OPTTIME; 235 } else if (strcmp(buf, "space") == 0) { 236 ffs_opts->optimization = FS_OPTSPACE; 237 } else { 238 warnx("Invalid optimization `%s'", buf); 239 return 0; 240 } 241 break; 242 default: 243 break; 244 } 245 return 1; 246 } 247 248 249 void 250 ffs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) 251 { 252 struct fs *superblock; 253 struct timeval start; 254 255 assert(image != NULL); 256 assert(dir != NULL); 257 assert(root != NULL); 258 assert(fsopts != NULL); 259 260 if (debug & DEBUG_FS_MAKEFS) 261 printf("ffs_makefs: image %s directory %s root %p\n", 262 image, dir, root); 263 264 /* validate tree and options */ 265 TIMER_START(start); 266 ffs_validate(dir, root, fsopts); 267 TIMER_RESULTS(start, "ffs_validate"); 268 269 printf("Calculated size of `%s': %lld bytes, %lld inodes\n", 270 image, (long long)fsopts->size, (long long)fsopts->inodes); 271 272 /* create image */ 273 TIMER_START(start); 274 if (ffs_create_image(image, fsopts) == -1) 275 errx(1, "Image file `%s' not created.", image); 276 TIMER_RESULTS(start, "ffs_create_image"); 277 278 fsopts->curinode = UFS_ROOTINO; 279 280 if (debug & DEBUG_FS_MAKEFS) 281 putchar('\n'); 282 283 /* populate image */ 284 printf("Populating `%s'\n", image); 285 TIMER_START(start); 286 if (! ffs_populate_dir(dir, root, fsopts)) 287 errx(1, "Image file `%s' not populated.", image); 288 TIMER_RESULTS(start, "ffs_populate_dir"); 289 290 /* ensure no outstanding buffers remain */ 291 if (debug & DEBUG_FS_MAKEFS) 292 bcleanup(); 293 294 /* update various superblock parameters */ 295 superblock = fsopts->superblock; 296 superblock->fs_fmod = 0; 297 superblock->fs_old_cstotal.cs_ndir = superblock->fs_cstotal.cs_ndir; 298 superblock->fs_old_cstotal.cs_nbfree = superblock->fs_cstotal.cs_nbfree; 299 superblock->fs_old_cstotal.cs_nifree = superblock->fs_cstotal.cs_nifree; 300 superblock->fs_old_cstotal.cs_nffree = superblock->fs_cstotal.cs_nffree; 301 302 /* write out superblock; image is now complete */ 303 ffs_write_superblock(fsopts->superblock, fsopts); 304 if (close(fsopts->fd) == -1) 305 err(1, "Closing `%s'", image); 306 fsopts->fd = -1; 307 printf("Image `%s' complete\n", image); 308 } 309 310 /* end of public functions */ 311 312 313 static void 314 ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts) 315 { 316 int32_t ncg = 1; 317 #if notyet 318 int32_t spc, nspf, ncyl, fssize; 319 #endif 320 ffs_opt_t *ffs_opts = fsopts->fs_specific; 321 322 assert(dir != NULL); 323 assert(root != NULL); 324 assert(fsopts != NULL); 325 assert(ffs_opts != NULL); 326 327 if (debug & DEBUG_FS_VALIDATE) { 328 printf("ffs_validate: before defaults set:\n"); 329 ffs_dump_fsinfo(fsopts); 330 } 331 332 /* set FFS defaults */ 333 if (fsopts->sectorsize == -1) 334 fsopts->sectorsize = DFL_SECSIZE; 335 if (ffs_opts->fsize == -1) 336 ffs_opts->fsize = MAX(DFL_FRAGSIZE, fsopts->sectorsize); 337 if (ffs_opts->bsize == -1) 338 ffs_opts->bsize = MIN(DFL_BLKSIZE, 8 * ffs_opts->fsize); 339 if (ffs_opts->cpg == -1) 340 ffs_opts->cpg = DFL_CYLSPERGROUP; 341 else 342 ffs_opts->cpgflg = 1; 343 /* fsopts->density is set below */ 344 if (ffs_opts->nsectors == -1) 345 ffs_opts->nsectors = DFL_NSECTORS; 346 if (ffs_opts->minfree == -1) 347 ffs_opts->minfree = MINFREE; 348 if (ffs_opts->optimization == -1) 349 ffs_opts->optimization = DEFAULTOPT; 350 if (ffs_opts->maxcontig == -1) 351 ffs_opts->maxcontig = 352 MAX(1, MIN(MAXPHYS, FFS_MAXBSIZE) / ffs_opts->bsize); 353 /* XXX ondisk32 */ 354 if (ffs_opts->maxbpg == -1) 355 ffs_opts->maxbpg = ffs_opts->bsize / sizeof(int32_t); 356 if (ffs_opts->avgfilesize == -1) 357 ffs_opts->avgfilesize = AVFILESIZ; 358 if (ffs_opts->avgfpdir == -1) 359 ffs_opts->avgfpdir = AFPDIR; 360 361 if (fsopts->maxsize > 0 && 362 roundup(fsopts->minsize, ffs_opts->bsize) > fsopts->maxsize) 363 errx(1, "`%s' minsize of %lld rounded up to ffs bsize of %d " 364 "exceeds maxsize %lld. Lower bsize, or round the minimum " 365 "and maximum sizes to bsize.", dir, 366 (long long)fsopts->minsize, ffs_opts->bsize, 367 (long long)fsopts->maxsize); 368 369 /* calculate size of tree */ 370 ffs_size_dir(root, fsopts); 371 fsopts->inodes += UFS_ROOTINO; /* include first two inodes */ 372 373 if (debug & DEBUG_FS_VALIDATE) 374 printf("ffs_validate: size of tree: %lld bytes, %lld inodes\n", 375 (long long)fsopts->size, (long long)fsopts->inodes); 376 377 /* add requested slop */ 378 fsopts->size += fsopts->freeblocks; 379 fsopts->inodes += fsopts->freefiles; 380 if (fsopts->freefilepc > 0) 381 fsopts->inodes = 382 fsopts->inodes * (100 + fsopts->freefilepc) / 100; 383 if (fsopts->freeblockpc > 0) 384 fsopts->size = 385 fsopts->size * (100 + fsopts->freeblockpc) / 100; 386 387 /* add space needed for superblocks */ 388 /* 389 * The old SBOFF (SBLOCK_UFS1) is used here because makefs is 390 * typically used for small filesystems where space matters. 391 * XXX make this an option. 392 */ 393 fsopts->size += (SBLOCK_UFS1 + SBLOCKSIZE) * ncg; 394 /* add space needed to store inodes, x3 for blockmaps, etc */ 395 if (ffs_opts->version == 1) 396 fsopts->size += ncg * DINODE1_SIZE * 397 roundup(fsopts->inodes / ncg, 398 ffs_opts->bsize / DINODE1_SIZE); 399 else 400 fsopts->size += ncg * DINODE2_SIZE * 401 roundup(fsopts->inodes / ncg, 402 ffs_opts->bsize / DINODE2_SIZE); 403 404 /* add minfree */ 405 if (ffs_opts->minfree > 0) 406 fsopts->size = 407 fsopts->size * (100 + ffs_opts->minfree) / 100; 408 /* 409 * XXX any other fs slop to add, such as csum's, bitmaps, etc ?? 410 */ 411 412 if (fsopts->size < fsopts->minsize) /* ensure meets minimum size */ 413 fsopts->size = fsopts->minsize; 414 415 /* round up to the next block */ 416 fsopts->size = roundup(fsopts->size, ffs_opts->bsize); 417 418 /* round up to requested block size, if any */ 419 if (fsopts->roundup > 0) 420 fsopts->size = roundup(fsopts->size, fsopts->roundup); 421 422 /* calculate density if necessary */ 423 if (ffs_opts->density == -1) 424 ffs_opts->density = fsopts->size / fsopts->inodes + 1; 425 426 if (debug & DEBUG_FS_VALIDATE) { 427 printf("ffs_validate: after defaults set:\n"); 428 ffs_dump_fsinfo(fsopts); 429 printf("ffs_validate: dir %s; %lld bytes, %lld inodes\n", 430 dir, (long long)fsopts->size, (long long)fsopts->inodes); 431 } 432 sectorsize = fsopts->sectorsize; /* XXX - see earlier */ 433 434 /* now check calculated sizes vs requested sizes */ 435 if (fsopts->maxsize > 0 && fsopts->size > fsopts->maxsize) { 436 errx(1, "`%s' size of %lld is larger than the maxsize of %lld.", 437 dir, (long long)fsopts->size, (long long)fsopts->maxsize); 438 } 439 } 440 441 442 static void 443 ffs_dump_fsinfo(fsinfo_t *f) 444 { 445 446 ffs_opt_t *fs = f->fs_specific; 447 448 printf("fsopts at %p\n", f); 449 450 printf("\tsize %lld, inodes %lld, curinode %u\n", 451 (long long)f->size, (long long)f->inodes, f->curinode); 452 453 printf("\tminsize %lld, maxsize %lld\n", 454 (long long)f->minsize, (long long)f->maxsize); 455 printf("\tfree files %lld, freefile %% %d\n", 456 (long long)f->freefiles, f->freefilepc); 457 printf("\tfree blocks %lld, freeblock %% %d\n", 458 (long long)f->freeblocks, f->freeblockpc); 459 printf("\tneedswap %d, sectorsize %d\n", f->needswap, f->sectorsize); 460 461 printf("\tbsize %d, fsize %d, cpg %d, density %d\n", 462 fs->bsize, fs->fsize, fs->cpg, fs->density); 463 printf("\tnsectors %d, rpm %d, minfree %d\n", 464 fs->nsectors, fs->rpm, fs->minfree); 465 printf("\tmaxcontig %d, maxbpg %d\n", 466 fs->maxcontig, fs->maxbpg); 467 printf("\toptimization %s\n", 468 fs->optimization == FS_OPTSPACE ? "space" : "time"); 469 } 470 471 472 static int 473 ffs_create_image(const char *image, fsinfo_t *fsopts) 474 { 475 #if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS 476 struct statvfs sfs; 477 #endif 478 struct fs *fs; 479 char *buf; 480 int i, bufsize; 481 off_t bufrem; 482 time_t tstamp; 483 484 assert (image != NULL); 485 assert (fsopts != NULL); 486 487 /* create image */ 488 if ((fsopts->fd = open(image, O_RDWR | O_CREAT | O_TRUNC, 0666)) 489 == -1) { 490 warn("Can't open `%s' for writing", image); 491 return (-1); 492 } 493 494 /* zero image */ 495 #if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS 496 if (fstatvfs(fsopts->fd, &sfs) == -1) { 497 #endif 498 bufsize = 8192; 499 #if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS 500 warn("can't fstatvfs `%s', using default %d byte chunk", 501 image, bufsize); 502 } else 503 bufsize = sfs.f_iosize; 504 #endif 505 bufrem = fsopts->size; 506 if (fsopts->sparse) { 507 if (ftruncate(fsopts->fd, bufrem) == -1) { 508 warn("sparse option disabled."); 509 fsopts->sparse = 0; 510 } 511 } 512 if (fsopts->sparse) { 513 /* File truncated at bufrem. Remaining is 0 */ 514 bufrem = 0; 515 buf = NULL; 516 } else { 517 if (debug & DEBUG_FS_CREATE_IMAGE) 518 printf("zero-ing image `%s', %lld sectors, " 519 "using %d byte chunks\n", image, (long long)bufrem, 520 bufsize); 521 buf = ecalloc(1, bufsize); 522 } 523 while (bufrem > 0) { 524 i = write(fsopts->fd, buf, MIN(bufsize, bufrem)); 525 if (i == -1) { 526 warn("zeroing image, %lld bytes to go", 527 (long long)bufrem); 528 free(buf); 529 return (-1); 530 } 531 bufrem -= i; 532 } 533 if (buf) 534 free(buf); 535 536 /* make the file system */ 537 if (debug & DEBUG_FS_CREATE_IMAGE) 538 printf("calling mkfs(\"%s\", ...)\n", image); 539 540 if (stampst.st_ino != 0) 541 tstamp = stampst.st_ctime; 542 else 543 tstamp = start_time.tv_sec; 544 545 srandom(tstamp); 546 547 fs = ffs_mkfs(image, fsopts, tstamp); 548 fsopts->superblock = (void *)fs; 549 if (debug & DEBUG_FS_CREATE_IMAGE) { 550 time_t t; 551 552 t = (time_t)((struct fs *)fsopts->superblock)->fs_time; 553 printf("mkfs returned %p; fs_time %s", 554 fsopts->superblock, ctime(&t)); 555 printf("fs totals: nbfree %lld, nffree %lld, nifree %lld, ndir %lld\n", 556 (long long)fs->fs_cstotal.cs_nbfree, 557 (long long)fs->fs_cstotal.cs_nffree, 558 (long long)fs->fs_cstotal.cs_nifree, 559 (long long)fs->fs_cstotal.cs_ndir); 560 } 561 562 if (fs->fs_cstotal.cs_nifree + UFS_ROOTINO < fsopts->inodes) { 563 warnx( 564 "Image file `%s' has %lld free inodes; %lld are required.", 565 image, 566 (long long)(fs->fs_cstotal.cs_nifree + UFS_ROOTINO), 567 (long long)fsopts->inodes); 568 return (-1); 569 } 570 return (fsopts->fd); 571 } 572 573 574 static void 575 ffs_size_dir(fsnode *root, fsinfo_t *fsopts) 576 { 577 struct direct tmpdir; 578 fsnode * node; 579 int curdirsize, this; 580 ffs_opt_t *ffs_opts = fsopts->fs_specific; 581 582 /* node may be NULL (empty directory) */ 583 assert(fsopts != NULL); 584 assert(ffs_opts != NULL); 585 586 if (debug & DEBUG_FS_SIZE_DIR) 587 printf("ffs_size_dir: entry: bytes %lld inodes %lld\n", 588 (long long)fsopts->size, (long long)fsopts->inodes); 589 590 #define ADDDIRENT(e) do { \ 591 tmpdir.d_namlen = strlen((e)); \ 592 this = DIRSIZ_SWAP(0, &tmpdir, 0); \ 593 if (debug & DEBUG_FS_SIZE_DIR_ADD_DIRENT) \ 594 printf("ADDDIRENT: was: %s (%d) this %d cur %d\n", \ 595 e, tmpdir.d_namlen, this, curdirsize); \ 596 if (this + curdirsize > roundup(curdirsize, DIRBLKSIZ)) \ 597 curdirsize = roundup(curdirsize, DIRBLKSIZ); \ 598 curdirsize += this; \ 599 if (debug & DEBUG_FS_SIZE_DIR_ADD_DIRENT) \ 600 printf("ADDDIRENT: now: %s (%d) this %d cur %d\n", \ 601 e, tmpdir.d_namlen, this, curdirsize); \ 602 } while (0); 603 604 /* 605 * XXX this needs to take into account extra space consumed 606 * by indirect blocks, etc. 607 */ 608 #define ADDSIZE(x) do { \ 609 fsopts->size += roundup((x), ffs_opts->fsize); \ 610 } while (0); 611 612 curdirsize = 0; 613 for (node = root; node != NULL; node = node->next) { 614 ADDDIRENT(node->name); 615 if (node == root) { /* we're at "." */ 616 assert(strcmp(node->name, ".") == 0); 617 ADDDIRENT(".."); 618 } else if ((node->inode->flags & FI_SIZED) == 0) { 619 /* don't count duplicate names */ 620 node->inode->flags |= FI_SIZED; 621 if (debug & DEBUG_FS_SIZE_DIR_NODE) 622 printf("ffs_size_dir: `%s' size %lld\n", 623 node->name, 624 (long long)node->inode->st.st_size); 625 fsopts->inodes++; 626 if (node->type == S_IFREG) 627 ADDSIZE(node->inode->st.st_size); 628 if (node->type == S_IFLNK) { 629 size_t slen; 630 631 slen = strlen(node->symlink) + 1; 632 if (slen >= (ffs_opts->version == 1 ? 633 UFS1_MAXSYMLINKLEN : 634 UFS2_MAXSYMLINKLEN)) 635 ADDSIZE(slen); 636 } 637 } 638 if (node->type == S_IFDIR) 639 ffs_size_dir(node->child, fsopts); 640 } 641 ADDSIZE(curdirsize); 642 643 if (debug & DEBUG_FS_SIZE_DIR) 644 printf("ffs_size_dir: exit: size %lld inodes %lld\n", 645 (long long)fsopts->size, (long long)fsopts->inodes); 646 } 647 648 static void * 649 ffs_build_dinode1(struct ufs1_dinode *dinp, dirbuf_t *dbufp, fsnode *cur, 650 fsnode *root, fsinfo_t *fsopts) 651 { 652 size_t slen; 653 void *membuf; 654 struct stat *st = stampst.st_ino != 0 ? &stampst : &cur->inode->st; 655 656 memset(dinp, 0, sizeof(*dinp)); 657 dinp->di_mode = cur->inode->st.st_mode; 658 dinp->di_nlink = cur->inode->nlink; 659 dinp->di_size = cur->inode->st.st_size; 660 #if HAVE_STRUCT_STAT_ST_FLAGS 661 dinp->di_flags = cur->inode->st.st_flags; 662 #endif 663 dinp->di_gen = random(); 664 dinp->di_uid = cur->inode->st.st_uid; 665 dinp->di_gid = cur->inode->st.st_gid; 666 667 dinp->di_atime = st->st_atime; 668 dinp->di_mtime = st->st_mtime; 669 dinp->di_ctime = st->st_ctime; 670 #if HAVE_STRUCT_STAT_ST_MTIMENSEC 671 dinp->di_atimensec = st->st_atimensec; 672 dinp->di_mtimensec = st->st_mtimensec; 673 dinp->di_ctimensec = st->st_ctimensec; 674 #endif 675 /* not set: di_db, di_ib, di_blocks, di_spare */ 676 677 membuf = NULL; 678 if (cur == root) { /* "."; write dirbuf */ 679 membuf = dbufp->buf; 680 dinp->di_size = dbufp->size; 681 } else if (S_ISBLK(cur->type) || S_ISCHR(cur->type)) { 682 dinp->di_size = 0; /* a device */ 683 dinp->di_rdev = 684 ufs_rw32(cur->inode->st.st_rdev, fsopts->needswap); 685 } else if (S_ISLNK(cur->type)) { /* symlink */ 686 slen = strlen(cur->symlink); 687 if (slen < UFS1_MAXSYMLINKLEN) { /* short link */ 688 memcpy(dinp->di_db, cur->symlink, slen); 689 } else 690 membuf = cur->symlink; 691 dinp->di_size = slen; 692 } 693 return membuf; 694 } 695 696 static void * 697 ffs_build_dinode2(struct ufs2_dinode *dinp, dirbuf_t *dbufp, fsnode *cur, 698 fsnode *root, fsinfo_t *fsopts) 699 { 700 size_t slen; 701 void *membuf; 702 struct stat *st = stampst.st_ino != 0 ? &stampst : &cur->inode->st; 703 704 memset(dinp, 0, sizeof(*dinp)); 705 dinp->di_mode = cur->inode->st.st_mode; 706 dinp->di_nlink = cur->inode->nlink; 707 dinp->di_size = cur->inode->st.st_size; 708 #if HAVE_STRUCT_STAT_ST_FLAGS 709 dinp->di_flags = cur->inode->st.st_flags; 710 #endif 711 dinp->di_gen = random(); 712 dinp->di_uid = cur->inode->st.st_uid; 713 dinp->di_gid = cur->inode->st.st_gid; 714 715 dinp->di_atime = st->st_atime; 716 dinp->di_mtime = st->st_mtime; 717 dinp->di_ctime = st->st_ctime; 718 #if HAVE_STRUCT_STAT_ST_MTIMENSEC 719 dinp->di_atimensec = st->st_atimensec; 720 dinp->di_mtimensec = st->st_mtimensec; 721 dinp->di_ctimensec = st->st_ctimensec; 722 #endif 723 #if HAVE_STRUCT_STAT_BIRTHTIME 724 dinp->di_birthtime = st->st_birthtime; 725 dinp->di_birthnsec = st->st_birthtimensec; 726 #endif 727 /* not set: di_db, di_ib, di_blocks, di_spare */ 728 729 membuf = NULL; 730 if (cur == root) { /* "."; write dirbuf */ 731 membuf = dbufp->buf; 732 dinp->di_size = dbufp->size; 733 } else if (S_ISBLK(cur->type) || S_ISCHR(cur->type)) { 734 dinp->di_size = 0; /* a device */ 735 dinp->di_rdev = 736 ufs_rw64(cur->inode->st.st_rdev, fsopts->needswap); 737 } else if (S_ISLNK(cur->type)) { /* symlink */ 738 slen = strlen(cur->symlink); 739 if (slen < UFS2_MAXSYMLINKLEN) { /* short link */ 740 memcpy(dinp->di_db, cur->symlink, slen); 741 } else 742 membuf = cur->symlink; 743 dinp->di_size = slen; 744 } 745 return membuf; 746 } 747 748 static int 749 ffs_populate_dir(const char *dir, fsnode *root, fsinfo_t *fsopts) 750 { 751 fsnode *cur; 752 dirbuf_t dirbuf; 753 union dinode din; 754 void *membuf; 755 char path[MAXPATHLEN + 1]; 756 ffs_opt_t *ffs_opts = fsopts->fs_specific; 757 758 assert(dir != NULL); 759 assert(root != NULL); 760 assert(fsopts != NULL); 761 assert(ffs_opts != NULL); 762 763 (void)memset(&dirbuf, 0, sizeof(dirbuf)); 764 765 if (debug & DEBUG_FS_POPULATE) 766 printf("ffs_populate_dir: PASS 1 dir %s node %p\n", dir, root); 767 768 /* 769 * pass 1: allocate inode numbers, build directory `file' 770 */ 771 for (cur = root; cur != NULL; cur = cur->next) { 772 if ((cur->inode->flags & FI_ALLOCATED) == 0) { 773 cur->inode->flags |= FI_ALLOCATED; 774 if (cur == root && cur->parent != NULL) 775 cur->inode->ino = cur->parent->inode->ino; 776 else { 777 cur->inode->ino = fsopts->curinode; 778 fsopts->curinode++; 779 } 780 } 781 ffs_make_dirbuf(&dirbuf, cur->name, cur, fsopts->needswap); 782 if (cur == root) { /* we're at "."; add ".." */ 783 ffs_make_dirbuf(&dirbuf, "..", 784 cur->parent == NULL ? cur : cur->parent->first, 785 fsopts->needswap); 786 root->inode->nlink++; /* count my parent's link */ 787 } else if (cur->child != NULL) 788 root->inode->nlink++; /* count my child's link */ 789 790 /* 791 * XXX possibly write file and long symlinks here, 792 * ensuring that blocks get written before inodes? 793 * otoh, this isn't a real filesystem, so who 794 * cares about ordering? :-) 795 */ 796 } 797 if (debug & DEBUG_FS_POPULATE_DIRBUF) 798 ffs_dump_dirbuf(&dirbuf, dir, fsopts->needswap); 799 800 /* 801 * pass 2: write out dirbuf, then non-directories at this level 802 */ 803 if (debug & DEBUG_FS_POPULATE) 804 printf("ffs_populate_dir: PASS 2 dir %s\n", dir); 805 for (cur = root; cur != NULL; cur = cur->next) { 806 if (cur->inode->flags & FI_WRITTEN) 807 continue; /* skip hard-linked entries */ 808 cur->inode->flags |= FI_WRITTEN; 809 810 if (cur->contents == NULL) { 811 if (snprintf(path, sizeof(path), "%s/%s/%s", cur->root, 812 cur->path, cur->name) >= (int)sizeof(path)) 813 errx(1, "Pathname too long."); 814 } 815 816 if (cur->child != NULL) 817 continue; /* child creates own inode */ 818 819 /* build on-disk inode */ 820 if (ffs_opts->version == 1) 821 membuf = ffs_build_dinode1(&din.ffs1_din, &dirbuf, cur, 822 root, fsopts); 823 else 824 membuf = ffs_build_dinode2(&din.ffs2_din, &dirbuf, cur, 825 root, fsopts); 826 827 if (debug & DEBUG_FS_POPULATE_NODE) { 828 printf("ffs_populate_dir: writing ino %d, %s", 829 cur->inode->ino, inode_type(cur->type)); 830 if (cur->inode->nlink > 1) 831 printf(", nlink %d", cur->inode->nlink); 832 putchar('\n'); 833 } 834 835 if (membuf != NULL) { 836 ffs_write_file(&din, cur->inode->ino, membuf, fsopts); 837 } else if (S_ISREG(cur->type)) { 838 ffs_write_file(&din, cur->inode->ino, 839 (cur->contents) ? cur->contents : path, fsopts); 840 } else { 841 assert (! S_ISDIR(cur->type)); 842 ffs_write_inode(&din, cur->inode->ino, fsopts); 843 } 844 } 845 846 /* 847 * pass 3: write out sub-directories 848 */ 849 if (debug & DEBUG_FS_POPULATE) 850 printf("ffs_populate_dir: PASS 3 dir %s\n", dir); 851 for (cur = root; cur != NULL; cur = cur->next) { 852 if (cur->child == NULL) 853 continue; 854 if ((size_t)snprintf(path, sizeof(path), "%s/%s", dir, 855 cur->name) >= sizeof(path)) 856 errx(1, "Pathname too long."); 857 if (! ffs_populate_dir(path, cur->child, fsopts)) 858 return (0); 859 } 860 861 if (debug & DEBUG_FS_POPULATE) 862 printf("ffs_populate_dir: DONE dir %s\n", dir); 863 864 /* cleanup */ 865 if (dirbuf.buf != NULL) 866 free(dirbuf.buf); 867 return (1); 868 } 869 870 871 static void 872 ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts) 873 { 874 int isfile, ffd; 875 char *fbuf, *p; 876 off_t bufleft, chunk, offset; 877 ssize_t nread; 878 struct inode in; 879 struct buf * bp; 880 ffs_opt_t *ffs_opts = fsopts->fs_specific; 881 882 assert (din != NULL); 883 assert (buf != NULL); 884 assert (fsopts != NULL); 885 assert (ffs_opts != NULL); 886 887 isfile = S_ISREG(DIP(din, mode)); 888 fbuf = NULL; 889 ffd = -1; 890 p = NULL; 891 892 in.i_fs = (struct fs *)fsopts->superblock; 893 894 if (debug & DEBUG_FS_WRITE_FILE) { 895 printf( 896 "ffs_write_file: ino %u, din %p, isfile %d, %s, size %lld", 897 ino, din, isfile, inode_type(DIP(din, mode) & S_IFMT), 898 (long long)DIP(din, size)); 899 if (isfile) 900 printf(", file '%s'\n", (char *)buf); 901 else 902 printf(", buffer %p\n", buf); 903 } 904 905 in.i_number = ino; 906 in.i_size = DIP(din, size); 907 if (ffs_opts->version == 1) 908 memcpy(&in.i_din.ffs1_din, &din->ffs1_din, 909 sizeof(in.i_din.ffs1_din)); 910 else 911 memcpy(&in.i_din.ffs2_din, &din->ffs2_din, 912 sizeof(in.i_din.ffs2_din)); 913 in.i_fd = fsopts->fd; 914 915 if (DIP(din, size) == 0) 916 goto write_inode_and_leave; /* mmm, cheating */ 917 918 if (isfile) { 919 fbuf = emalloc(ffs_opts->bsize); 920 if ((ffd = open((char *)buf, O_RDONLY, 0444)) == -1) { 921 warn("Can't open `%s' for reading", (char *)buf); 922 goto leave_ffs_write_file; 923 } 924 } else { 925 p = buf; 926 } 927 928 chunk = 0; 929 for (bufleft = DIP(din, size); bufleft > 0; bufleft -= chunk) { 930 chunk = MIN(bufleft, ffs_opts->bsize); 931 if (!isfile) 932 ; 933 else if ((nread = read(ffd, fbuf, chunk)) == -1) 934 err(EXIT_FAILURE, "Reading `%s', %lld bytes to go", 935 (char *)buf, (long long)bufleft); 936 else if (nread != chunk) 937 errx(EXIT_FAILURE, "Reading `%s', %lld bytes to go, " 938 "read %zd bytes, expected %ju bytes, does " 939 "metalog size= attribute mismatch source size?", 940 (char *)buf, (long long)bufleft, nread, 941 (uintmax_t)chunk); 942 else 943 p = fbuf; 944 offset = DIP(din, size) - bufleft; 945 if (debug & DEBUG_FS_WRITE_FILE_BLOCK) 946 printf( 947 "ffs_write_file: write %p offset %lld size %lld left %lld\n", 948 p, (long long)offset, 949 (long long)chunk, (long long)bufleft); 950 /* 951 * XXX if holey support is desired, do the check here 952 * 953 * XXX might need to write out last bit in fragroundup 954 * sized chunk. however, ffs_balloc() handles this for us 955 */ 956 errno = ffs_balloc(&in, offset, chunk, &bp); 957 bad_ffs_write_file: 958 if (errno != 0) 959 err(1, 960 "Writing inode %d (%s), bytes %lld + %lld", 961 ino, 962 isfile ? (char *)buf : 963 inode_type(DIP(din, mode) & S_IFMT), 964 (long long)offset, (long long)chunk); 965 memcpy(bp->b_data, p, chunk); 966 errno = bwrite(bp); 967 if (errno != 0) 968 goto bad_ffs_write_file; 969 brelse(bp, 0); 970 if (!isfile) 971 p += chunk; 972 } 973 974 write_inode_and_leave: 975 ffs_write_inode(&in.i_din, in.i_number, fsopts); 976 977 leave_ffs_write_file: 978 if (fbuf) 979 free(fbuf); 980 if (ffd != -1) 981 close(ffd); 982 } 983 984 985 static void 986 ffs_dump_dirbuf(dirbuf_t *dbuf, const char *dir, int needswap) 987 { 988 doff_t i; 989 struct direct *de; 990 uint16_t reclen; 991 992 assert (dbuf != NULL); 993 assert (dir != NULL); 994 printf("ffs_dump_dirbuf: dir %s size %d cur %d\n", 995 dir, dbuf->size, dbuf->cur); 996 997 for (i = 0; i < dbuf->size; ) { 998 de = (struct direct *)(dbuf->buf + i); 999 reclen = ufs_rw16(de->d_reclen, needswap); 1000 printf( 1001 " inode %4d %7s offset %4d reclen %3d namlen %3d name %s\n", 1002 ufs_rw32(de->d_ino, needswap), 1003 inode_type(DTTOIF(de->d_type)), i, reclen, 1004 de->d_namlen, de->d_name); 1005 i += reclen; 1006 assert(reclen > 0); 1007 } 1008 } 1009 1010 static void 1011 ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node, int needswap) 1012 { 1013 struct direct de, *dp; 1014 uint16_t llen, reclen; 1015 u_char *newbuf; 1016 1017 assert (dbuf != NULL); 1018 assert (name != NULL); 1019 assert (node != NULL); 1020 /* create direct entry */ 1021 (void)memset(&de, 0, sizeof(de)); 1022 de.d_ino = ufs_rw32(node->inode->ino, needswap); 1023 de.d_type = IFTODT(node->type); 1024 de.d_namlen = (uint8_t)strlen(name); 1025 strcpy(de.d_name, name); 1026 reclen = DIRSIZ_SWAP(0, &de, needswap); 1027 de.d_reclen = ufs_rw16(reclen, needswap); 1028 1029 dp = (struct direct *)(dbuf->buf + dbuf->cur); 1030 llen = 0; 1031 if (dp != NULL) 1032 llen = DIRSIZ_SWAP(0, dp, needswap); 1033 1034 if (debug & DEBUG_FS_MAKE_DIRBUF) 1035 printf( 1036 "ffs_make_dirbuf: dbuf siz %d cur %d lastlen %d\n" 1037 " ino %d type %d reclen %d namlen %d name %.30s\n", 1038 dbuf->size, dbuf->cur, llen, 1039 ufs_rw32(de.d_ino, needswap), de.d_type, reclen, 1040 de.d_namlen, de.d_name); 1041 1042 if (reclen + dbuf->cur + llen > roundup(dbuf->size, DIRBLKSIZ)) { 1043 if (debug & DEBUG_FS_MAKE_DIRBUF) 1044 printf("ffs_make_dirbuf: growing buf to %d\n", 1045 dbuf->size + DIRBLKSIZ); 1046 newbuf = erealloc(dbuf->buf, dbuf->size + DIRBLKSIZ); 1047 dbuf->buf = newbuf; 1048 dbuf->size += DIRBLKSIZ; 1049 memset(dbuf->buf + dbuf->size - DIRBLKSIZ, 0, DIRBLKSIZ); 1050 dbuf->cur = dbuf->size - DIRBLKSIZ; 1051 } else if (dp) { /* shrink end of previous */ 1052 dp->d_reclen = ufs_rw16(llen,needswap); 1053 dbuf->cur += llen; 1054 } 1055 dp = (struct direct *)(dbuf->buf + dbuf->cur); 1056 memcpy(dp, &de, reclen); 1057 dp->d_reclen = ufs_rw16(dbuf->size - dbuf->cur, needswap); 1058 } 1059 1060 /* 1061 * cribbed from sys/ufs/ffs/ffs_alloc.c 1062 */ 1063 static void 1064 ffs_write_inode(union dinode *dp, uint32_t ino, const fsinfo_t *fsopts) 1065 { 1066 char *buf; 1067 struct ufs1_dinode *dp1; 1068 struct ufs2_dinode *dp2, *dip; 1069 struct cg *cgp; 1070 struct fs *fs; 1071 int cg, cgino; 1072 uint32_t i; 1073 daddr_t d; 1074 char sbbuf[FFS_MAXBSIZE]; 1075 uint32_t initediblk; 1076 ffs_opt_t *ffs_opts = fsopts->fs_specific; 1077 1078 assert (dp != NULL); 1079 assert (ino > 0); 1080 assert (fsopts != NULL); 1081 assert (ffs_opts != NULL); 1082 1083 fs = (struct fs *)fsopts->superblock; 1084 cg = ino_to_cg(fs, ino); 1085 cgino = ino % fs->fs_ipg; 1086 if (debug & DEBUG_FS_WRITE_INODE) 1087 printf("ffs_write_inode: din %p ino %u cg %d cgino %d\n", 1088 dp, ino, cg, cgino); 1089 1090 ffs_rdfs(fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, &sbbuf, 1091 fsopts); 1092 cgp = (struct cg *)sbbuf; 1093 if (!cg_chkmagic_swap(cgp, fsopts->needswap)) 1094 errx(1, "ffs_write_inode: cg %d: bad magic number", cg); 1095 1096 assert (isclr(cg_inosused_swap(cgp, fsopts->needswap), cgino)); 1097 1098 buf = emalloc(fs->fs_bsize); 1099 dp1 = (struct ufs1_dinode *)buf; 1100 dp2 = (struct ufs2_dinode *)buf; 1101 1102 if (fs->fs_cstotal.cs_nifree == 0) 1103 errx(1, "ffs_write_inode: fs out of inodes for ino %u", 1104 ino); 1105 if (fs->fs_cs(fs, cg).cs_nifree == 0) 1106 errx(1, 1107 "ffs_write_inode: cg %d out of inodes for ino %u", 1108 cg, ino); 1109 setbit(cg_inosused_swap(cgp, fsopts->needswap), cgino); 1110 ufs_add32(cgp->cg_cs.cs_nifree, -1, fsopts->needswap); 1111 fs->fs_cstotal.cs_nifree--; 1112 fs->fs_cs(fs, cg).cs_nifree--; 1113 if (S_ISDIR(DIP(dp, mode))) { 1114 ufs_add32(cgp->cg_cs.cs_ndir, 1, fsopts->needswap); 1115 fs->fs_cstotal.cs_ndir++; 1116 fs->fs_cs(fs, cg).cs_ndir++; 1117 } 1118 1119 /* 1120 * Initialize inode blocks on the fly for UFS2. 1121 */ 1122 initediblk = ufs_rw32(cgp->cg_initediblk, fsopts->needswap); 1123 if (ffs_opts->version == 2 && cgino + INOPB(fs) > initediblk && 1124 initediblk < ufs_rw32(cgp->cg_niblk, fsopts->needswap)) { 1125 memset(buf, 0, fs->fs_bsize); 1126 dip = (struct ufs2_dinode *)buf; 1127 for (i = 0; i < INOPB(fs); i++) { 1128 dip->di_gen = random(); 1129 dip++; 1130 } 1131 ffs_wtfs(fsbtodb(fs, ino_to_fsba(fs, 1132 cg * fs->fs_ipg + initediblk)), 1133 fs->fs_bsize, buf, fsopts); 1134 initediblk += INOPB(fs); 1135 cgp->cg_initediblk = ufs_rw32(initediblk, fsopts->needswap); 1136 } 1137 1138 1139 ffs_wtfs(fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, &sbbuf, 1140 fsopts); 1141 1142 /* now write inode */ 1143 d = fsbtodb(fs, ino_to_fsba(fs, ino)); 1144 ffs_rdfs(d, fs->fs_bsize, buf, fsopts); 1145 if (fsopts->needswap) { 1146 if (ffs_opts->version == 1) 1147 ffs_dinode1_swap(&dp->ffs1_din, 1148 &dp1[ino_to_fsbo(fs, ino)]); 1149 else 1150 ffs_dinode2_swap(&dp->ffs2_din, 1151 &dp2[ino_to_fsbo(fs, ino)]); 1152 } else { 1153 if (ffs_opts->version == 1) 1154 dp1[ino_to_fsbo(fs, ino)] = dp->ffs1_din; 1155 else 1156 dp2[ino_to_fsbo(fs, ino)] = dp->ffs2_din; 1157 } 1158 ffs_wtfs(d, fs->fs_bsize, buf, fsopts); 1159 free(buf); 1160 } 1161 1162 void 1163 panic(const char *fmt, ...) 1164 { 1165 va_list ap; 1166 1167 va_start(ap, fmt); 1168 vwarnx(fmt, ap); 1169 va_end(ap); 1170 exit(1); 1171 } 1172