| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: setup.c,v 1.102 2018/10/05 09:49:23 hannken Exp $ */ | | 1 | /* $NetBSD: setup.c,v 1.103 2020/04/17 09:42:27 jdolecek Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1980, 1986, 1993 | | 4 | * Copyright (c) 1980, 1986, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -24,27 +24,27 @@ | | | @@ -24,27 +24,27 @@ |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | #if 0 | | 34 | #if 0 |
35 | static char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95"; | | 35 | static char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95"; |
36 | #else | | 36 | #else |
37 | __RCSID("$NetBSD: setup.c,v 1.102 2018/10/05 09:49:23 hannken Exp $"); | | 37 | __RCSID("$NetBSD: setup.c,v 1.103 2020/04/17 09:42:27 jdolecek Exp $"); |
38 | #endif | | 38 | #endif |
39 | #endif /* not lint */ | | 39 | #endif /* not lint */ |
40 | | | 40 | |
41 | #include <sys/param.h> | | 41 | #include <sys/param.h> |
42 | #include <sys/time.h> | | 42 | #include <sys/time.h> |
43 | #include <sys/stat.h> | | 43 | #include <sys/stat.h> |
44 | #include <sys/ioctl.h> | | 44 | #include <sys/ioctl.h> |
45 | #include <sys/file.h> | | 45 | #include <sys/file.h> |
46 | #include <sys/disk.h> | | 46 | #include <sys/disk.h> |
47 | | | 47 | |
48 | #include <ufs/ufs/dinode.h> | | 48 | #include <ufs/ufs/dinode.h> |
49 | #include <ufs/ufs/dir.h> | | 49 | #include <ufs/ufs/dir.h> |
50 | #include <ufs/ufs/ufs_bswap.h> | | 50 | #include <ufs/ufs/ufs_bswap.h> |
| @@ -116,30 +116,30 @@ setup(const char *dev, const char *origd | | | @@ -116,30 +116,30 @@ setup(const char *dev, const char *origd |
116 | if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) { | | 116 | if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) { |
117 | fswritefd = -1; | | 117 | fswritefd = -1; |
118 | if (preen) | | 118 | if (preen) |
119 | pfatal("NO WRITE ACCESS"); | | 119 | pfatal("NO WRITE ACCESS"); |
120 | printf("** %s (NO WRITE)\n", dev); | | 120 | printf("** %s (NO WRITE)\n", dev); |
121 | quiet = 0; | | 121 | quiet = 0; |
122 | } else | | 122 | } else |
123 | if (!preen && !quiet) | | 123 | if (!preen && !quiet) |
124 | printf("** %s\n", dev); | | 124 | printf("** %s\n", dev); |
125 | fsmodified = 0; | | 125 | fsmodified = 0; |
126 | lfdir = 0; | | 126 | lfdir = 0; |
127 | initbarea(&sblk); | | 127 | initbarea(&sblk); |
128 | initbarea(&asblk); | | 128 | initbarea(&asblk); |
129 | sblk.b_un.b_buf = malloc(SBLOCKSIZE); | | 129 | sblk.b_un.b_buf = aligned_alloc(DEV_BSIZE, SBLOCKSIZE); |
130 | sblock = malloc(SBLOCKSIZE); | | 130 | sblock = aligned_alloc(DEV_BSIZE, SBLOCKSIZE); |
131 | asblk.b_un.b_buf = malloc(SBLOCKSIZE); | | 131 | asblk.b_un.b_buf = aligned_alloc(DEV_BSIZE, SBLOCKSIZE); |
132 | altsblock = malloc(SBLOCKSIZE); | | 132 | altsblock = aligned_alloc(DEV_BSIZE, SBLOCKSIZE); |
133 | if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL || | | 133 | if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL || |
134 | sblock == NULL || altsblock == NULL) | | 134 | sblock == NULL || altsblock == NULL) |
135 | errexit("Cannot allocate space for superblock"); | | 135 | errexit("Cannot allocate space for superblock"); |
136 | if (strcmp(dev, origdev) && !forceimage) { | | 136 | if (strcmp(dev, origdev) && !forceimage) { |
137 | /* | | 137 | /* |
138 | * dev isn't the original fs (for example it's a snapshot) | | 138 | * dev isn't the original fs (for example it's a snapshot) |
139 | * do getdiskinfo on the original device | | 139 | * do getdiskinfo on the original device |
140 | */ | | 140 | */ |
141 | fd = open(origdev, O_RDONLY); | | 141 | fd = open(origdev, O_RDONLY); |
142 | if (fd < 0) { | | 142 | if (fd < 0) { |
143 | warn("Can't open %s", origdev); | | 143 | warn("Can't open %s", origdev); |
144 | return (0); | | 144 | return (0); |
145 | } | | 145 | } |
| @@ -448,32 +448,34 @@ setup(const char *dev, const char *origd | | | @@ -448,32 +448,34 @@ setup(const char *dev, const char *origd |
448 | } | | 448 | } |
449 | if (asblk.b_dirty && !bflag) { | | 449 | if (asblk.b_dirty && !bflag) { |
450 | memmove(sblk.b_un.b_fs, sblock, SBLOCKSIZE); | | 450 | memmove(sblk.b_un.b_fs, sblock, SBLOCKSIZE); |
451 | sb_oldfscompat_write(sblk.b_un.b_fs, sblocksave); | | 451 | sb_oldfscompat_write(sblk.b_un.b_fs, sblocksave); |
452 | if (needswap) | | 452 | if (needswap) |
453 | ffs_sb_swap(sblk.b_un.b_fs, sblk.b_un.b_fs); | | 453 | ffs_sb_swap(sblk.b_un.b_fs, sblk.b_un.b_fs); |
454 | memmove(asblk.b_un.b_fs, sblk.b_un.b_fs, (size_t)sblock->fs_sbsize); | | 454 | memmove(asblk.b_un.b_fs, sblk.b_un.b_fs, (size_t)sblock->fs_sbsize); |
455 | flush(fswritefd, &asblk); | | 455 | flush(fswritefd, &asblk); |
456 | } | | 456 | } |
457 | /* | | 457 | /* |
458 | * read in the summary info. | | 458 | * read in the summary info. |
459 | */ | | 459 | */ |
460 | asked = 0; | | 460 | asked = 0; |
461 | sblock->fs_csp = (struct csum *)calloc(1, sblock->fs_cssize); | | 461 | sblock->fs_csp = (struct csum *)aligned_alloc(DEV_BSIZE, |
| | | 462 | sblock->fs_cssize); |
462 | if (sblock->fs_csp == NULL) { | | 463 | if (sblock->fs_csp == NULL) { |
463 | pwarn("cannot alloc %u bytes for summary info\n", | | 464 | pwarn("cannot alloc %u bytes for summary info\n", |
464 | sblock->fs_cssize); | | 465 | sblock->fs_cssize); |
465 | goto badsblabel; | | 466 | goto badsblabel; |
466 | } | | 467 | } |
| | | 468 | memset(sblock->fs_csp, 0, sblock->fs_cssize); |
467 | for (i = 0, j = 0; i < sblock->fs_cssize; i += sblock->fs_bsize, j++) { | | 469 | for (i = 0, j = 0; i < sblock->fs_cssize; i += sblock->fs_bsize, j++) { |
468 | size = sblock->fs_cssize - i < sblock->fs_bsize ? | | 470 | size = sblock->fs_cssize - i < sblock->fs_bsize ? |
469 | sblock->fs_cssize - i : sblock->fs_bsize; | | 471 | sblock->fs_cssize - i : sblock->fs_bsize; |
470 | ccsp = (struct csum *)((char *)sblock->fs_csp + i); | | 472 | ccsp = (struct csum *)((char *)sblock->fs_csp + i); |
471 | if (bread(fsreadfd, (char *)ccsp, | | 473 | if (bread(fsreadfd, (char *)ccsp, |
472 | FFS_FSBTODB(sblock, sblock->fs_csaddr + j * sblock->fs_frag), | | 474 | FFS_FSBTODB(sblock, sblock->fs_csaddr + j * sblock->fs_frag), |
473 | size) != 0 && !asked) { | | 475 | size) != 0 && !asked) { |
474 | pfatal("BAD SUMMARY INFORMATION"); | | 476 | pfatal("BAD SUMMARY INFORMATION"); |
475 | if (reply("CONTINUE") == 0) { | | 477 | if (reply("CONTINUE") == 0) { |
476 | markclean = 0; | | 478 | markclean = 0; |
477 | exit(FSCK_EXIT_CHECK_FAILED); | | 479 | exit(FSCK_EXIT_CHECK_FAILED); |
478 | } | | 480 | } |
479 | asked++; | | 481 | asked++; |
| @@ -482,32 +484,33 @@ setup(const char *dev, const char *origd | | | @@ -482,32 +484,33 @@ setup(const char *dev, const char *origd |
482 | ffs_csum_swap(ccsp, ccsp, size); | | 484 | ffs_csum_swap(ccsp, ccsp, size); |
483 | bwrite(fswritefd, (char *)ccsp, | | 485 | bwrite(fswritefd, (char *)ccsp, |
484 | FFS_FSBTODB(sblock, | | 486 | FFS_FSBTODB(sblock, |
485 | sblock->fs_csaddr + j * sblock->fs_frag), | | 487 | sblock->fs_csaddr + j * sblock->fs_frag), |
486 | size); | | 488 | size); |
487 | } | | 489 | } |
488 | if (needswap) | | 490 | if (needswap) |
489 | ffs_csum_swap(ccsp, ccsp, size); | | 491 | ffs_csum_swap(ccsp, ccsp, size); |
490 | } | | 492 | } |
491 | /* | | 493 | /* |
492 | * allocate and initialize the necessary maps | | 494 | * allocate and initialize the necessary maps |
493 | */ | | 495 | */ |
494 | bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t)); | | 496 | bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t)); |
495 | blockmap = calloc((unsigned)bmapsize, sizeof (char)); | | 497 | blockmap = aligned_alloc(DEV_BSIZE, (unsigned)bmapsize); |
496 | if (blockmap == NULL) { | | 498 | if (blockmap == NULL) { |
497 | pwarn("cannot alloc %u bytes for blockmap\n", | | 499 | pwarn("cannot alloc %u bytes for blockmap\n", |
498 | (unsigned)bmapsize); | | 500 | (unsigned)bmapsize); |
499 | goto badsblabel; | | 501 | goto badsblabel; |
500 | } | | 502 | } |
| | | 503 | memset(blockmap, 0, bmapsize); |
501 | inostathead = calloc((unsigned)(sblock->fs_ncg), | | 504 | inostathead = calloc((unsigned)(sblock->fs_ncg), |
502 | sizeof(struct inostatlist)); | | 505 | sizeof(struct inostatlist)); |
503 | if (inostathead == NULL) { | | 506 | if (inostathead == NULL) { |
504 | pwarn("cannot alloc %u bytes for inostathead\n", | | 507 | pwarn("cannot alloc %u bytes for inostathead\n", |
505 | (unsigned)(sizeof(struct inostatlist) * (sblock->fs_ncg))); | | 508 | (unsigned)(sizeof(struct inostatlist) * (sblock->fs_ncg))); |
506 | goto badsblabel; | | 509 | goto badsblabel; |
507 | } | | 510 | } |
508 | /* | | 511 | /* |
509 | * cs_ndir may be inaccurate, particularly if we're using the -b | | 512 | * cs_ndir may be inaccurate, particularly if we're using the -b |
510 | * option, so set a minimum to prevent bogus subdirectory reconnects | | 513 | * option, so set a minimum to prevent bogus subdirectory reconnects |
511 | * and really inefficient directory scans. | | 514 | * and really inefficient directory scans. |
512 | * Also set a maximum in case the value is too large. | | 515 | * Also set a maximum in case the value is too large. |
513 | */ | | 516 | */ |
| @@ -516,27 +519,27 @@ setup(const char *dev, const char *origd | | | @@ -516,27 +519,27 @@ setup(const char *dev, const char *origd |
516 | numdirs = 1024; | | 519 | numdirs = 1024; |
517 | if ((ino_t)numdirs > maxino + 1) | | 520 | if ((ino_t)numdirs > maxino + 1) |
518 | numdirs = maxino + 1; | | 521 | numdirs = maxino + 1; |
519 | dirhash = numdirs; | | 522 | dirhash = numdirs; |
520 | inplast = 0; | | 523 | inplast = 0; |
521 | listmax = numdirs + 10; | | 524 | listmax = numdirs + 10; |
522 | inpsort = calloc((unsigned)listmax, sizeof(*inpsort)); | | 525 | inpsort = calloc((unsigned)listmax, sizeof(*inpsort)); |
523 | inphead = calloc((unsigned)numdirs, sizeof(*inphead)); | | 526 | inphead = calloc((unsigned)numdirs, sizeof(*inphead)); |
524 | if (inpsort == NULL || inphead == NULL) { | | 527 | if (inpsort == NULL || inphead == NULL) { |
525 | pwarn("cannot alloc %u bytes for inphead\n", | | 528 | pwarn("cannot alloc %u bytes for inphead\n", |
526 | (unsigned)(numdirs * sizeof(struct inoinfo *))); | | 529 | (unsigned)(numdirs * sizeof(struct inoinfo *))); |
527 | goto badsblabel; | | 530 | goto badsblabel; |
528 | } | | 531 | } |
529 | cgrp = malloc(sblock->fs_cgsize); | | 532 | cgrp = aligned_alloc(DEV_BSIZE, sblock->fs_cgsize); |
530 | if (cgrp == NULL) { | | 533 | if (cgrp == NULL) { |
531 | pwarn("cannot alloc %u bytes for cylinder group\n", | | 534 | pwarn("cannot alloc %u bytes for cylinder group\n", |
532 | sblock->fs_cgsize); | | 535 | sblock->fs_cgsize); |
533 | goto badsblabel; | | 536 | goto badsblabel; |
534 | } | | 537 | } |
535 | bufinit(); | | 538 | bufinit(); |
536 | if (sblock->fs_flags & FS_DOSOFTDEP) | | 539 | if (sblock->fs_flags & FS_DOSOFTDEP) |
537 | usedsoftdep = 1; | | 540 | usedsoftdep = 1; |
538 | else | | 541 | else |
539 | usedsoftdep = 0; | | 542 | usedsoftdep = 0; |
540 | | | 543 | |
541 | #ifndef NO_APPLE_UFS | | 544 | #ifndef NO_APPLE_UFS |
542 | if (!forceimage && dkw.dkw_parent[0]) | | 545 | if (!forceimage && dkw.dkw_parent[0]) |