Fri Apr 17 09:42:27 2020 UTC ()
align buffers used for I/O to DEV_BSIZE so it's executed more optimally
when run for xbd(4) raw (character) device


(jdolecek)
diff -r1.72 -r1.73 src/sbin/fsck_ffs/inode.c
diff -r1.102 -r1.103 src/sbin/fsck_ffs/setup.c
diff -r1.65 -r1.66 src/sbin/fsck_ffs/utilities.c

cvs diff -r1.72 -r1.73 src/sbin/fsck_ffs/inode.c (expand / switch to unified diff)

--- src/sbin/fsck_ffs/inode.c 2017/02/08 16:11:40 1.72
+++ src/sbin/fsck_ffs/inode.c 2020/04/17 09:42:27 1.73
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: inode.c,v 1.72 2017/02/08 16:11:40 rin Exp $ */ 1/* $NetBSD: inode.c,v 1.73 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
35static char sccsid[] = "@(#)inode.c 8.8 (Berkeley) 4/28/95"; 35static char sccsid[] = "@(#)inode.c 8.8 (Berkeley) 4/28/95";
36#else 36#else
37__RCSID("$NetBSD: inode.c,v 1.72 2017/02/08 16:11:40 rin Exp $"); 37__RCSID("$NetBSD: inode.c,v 1.73 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 44
45#include <ufs/ufs/dinode.h> 45#include <ufs/ufs/dinode.h>
46#include <ufs/ufs/dir.h> 46#include <ufs/ufs/dir.h>
47#include <ufs/ffs/fs.h> 47#include <ufs/ffs/fs.h>
48#include <ufs/ffs/ffs_extern.h> 48#include <ufs/ffs/ffs_extern.h>
49#include <ufs/ufs/ufs_bswap.h> 49#include <ufs/ufs/ufs_bswap.h>
50 50
@@ -453,27 +453,27 @@ setinodebuf(ino_t inum) @@ -453,27 +453,27 @@ setinodebuf(ino_t inum)
453 return; 453 return;
454 inobufsize = ffs_blkroundup(sblock, INOBUFSIZE); 454 inobufsize = ffs_blkroundup(sblock, INOBUFSIZE);
455 fullcnt = inobufsize / (is_ufs2 ? DINODE2_SIZE : DINODE1_SIZE); 455 fullcnt = inobufsize / (is_ufs2 ? DINODE2_SIZE : DINODE1_SIZE);
456 readpercg = sblock->fs_ipg / fullcnt; 456 readpercg = sblock->fs_ipg / fullcnt;
457 partialcnt = sblock->fs_ipg % fullcnt; 457 partialcnt = sblock->fs_ipg % fullcnt;
458 partialsize = partialcnt * (is_ufs2 ? DINODE2_SIZE : DINODE1_SIZE); 458 partialsize = partialcnt * (is_ufs2 ? DINODE2_SIZE : DINODE1_SIZE);
459 if (partialcnt != 0) { 459 if (partialcnt != 0) {
460 readpercg++; 460 readpercg++;
461 } else { 461 } else {
462 partialcnt = fullcnt; 462 partialcnt = fullcnt;
463 partialsize = inobufsize; 463 partialsize = inobufsize;
464 } 464 }
465 if (inodebuf == NULL && 465 if (inodebuf == NULL &&
466 (inodebuf = malloc((unsigned)inobufsize)) == NULL) 466 (inodebuf = aligned_alloc(DEV_BSIZE, (unsigned)inobufsize)) == NULL)
467 errexit("Cannot allocate space for inode buffer"); 467 errexit("Cannot allocate space for inode buffer");
468} 468}
469 469
470void 470void
471freeinodebuf(void) 471freeinodebuf(void)
472{ 472{
473 473
474 if (inodebuf != NULL) 474 if (inodebuf != NULL)
475 free((char *)inodebuf); 475 free((char *)inodebuf);
476 inodebuf = NULL; 476 inodebuf = NULL;
477} 477}
478 478
479/* 479/*

cvs diff -r1.102 -r1.103 src/sbin/fsck_ffs/setup.c (expand / switch to unified diff)

--- src/sbin/fsck_ffs/setup.c 2018/10/05 09:49:23 1.102
+++ src/sbin/fsck_ffs/setup.c 2020/04/17 09:42:27 1.103
@@ -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
35static char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95"; 35static 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])

cvs diff -r1.65 -r1.66 src/sbin/fsck_ffs/utilities.c (expand / switch to unified diff)

--- src/sbin/fsck_ffs/utilities.c 2017/02/08 16:11:40 1.65
+++ src/sbin/fsck_ffs/utilities.c 2020/04/17 09:42:27 1.66
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: utilities.c,v 1.65 2017/02/08 16:11:40 rin Exp $ */ 1/* $NetBSD: utilities.c,v 1.66 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
35static char sccsid[] = "@(#)utilities.c 8.6 (Berkeley) 5/19/95"; 35static char sccsid[] = "@(#)utilities.c 8.6 (Berkeley) 5/19/95";
36#else 36#else
37__RCSID("$NetBSD: utilities.c,v 1.65 2017/02/08 16:11:40 rin Exp $"); 37__RCSID("$NetBSD: utilities.c,v 1.66 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 43
44#include <ufs/ufs/dinode.h> 44#include <ufs/ufs/dinode.h>
45#include <ufs/ufs/dir.h> 45#include <ufs/ufs/dir.h>
46#include <ufs/ffs/fs.h> 46#include <ufs/ffs/fs.h>
47#include <ufs/ffs/ffs_extern.h> 47#include <ufs/ffs/ffs_extern.h>
48#include <ufs/ufs/ufs_bswap.h> 48#include <ufs/ufs/ufs_bswap.h>
49#include <ufs/ufs/quota2.h> 49#include <ufs/ufs/quota2.h>
50 50
@@ -125,45 +125,45 @@ reply(const char *question) @@ -125,45 +125,45 @@ reply(const char *question)
125} 125}
126 126
127/* 127/*
128 * Malloc buffers and set up cache. 128 * Malloc buffers and set up cache.
129 */ 129 */
130void 130void
131bufinit(void) 131bufinit(void)
132{ 132{
133 struct bufarea *bp; 133 struct bufarea *bp;
134 long bufcnt, i; 134 long bufcnt, i;
135 char *bufp; 135 char *bufp;
136 136
137 pbp = pdirbp = (struct bufarea *)0; 137 pbp = pdirbp = (struct bufarea *)0;
138 bufp = malloc((unsigned int)sblock->fs_bsize); 138 bufp = aligned_alloc(DEV_BSIZE, (unsigned int)sblock->fs_bsize);
139 if (bufp == 0) 139 if (bufp == 0)
140 errexit("cannot allocate buffer pool"); 140 errexit("cannot allocate buffer pool");
141 cgblk.b_un.b_buf = bufp; 141 cgblk.b_un.b_buf = bufp;
142 initbarea(&cgblk); 142 initbarea(&cgblk);
143#ifndef NO_APPLE_UFS 143#ifndef NO_APPLE_UFS
144 bufp = malloc((unsigned int)APPLEUFS_LABEL_SIZE); 144 bufp = aligned_alloc(DEV_BSIZE, (unsigned int)APPLEUFS_LABEL_SIZE);
145 if (bufp == 0) 145 if (bufp == 0)
146 errexit("cannot allocate buffer pool"); 146 errexit("cannot allocate buffer pool");
147 appleufsblk.b_un.b_buf = bufp; 147 appleufsblk.b_un.b_buf = bufp;
148 initbarea(&appleufsblk); 148 initbarea(&appleufsblk);
149#endif 149#endif
150 bufhead.b_next = bufhead.b_prev = &bufhead; 150 bufhead.b_next = bufhead.b_prev = &bufhead;
151 bufcnt = MAXBUFSPACE / sblock->fs_bsize; 151 bufcnt = MAXBUFSPACE / sblock->fs_bsize;
152 if (bufcnt < MINBUFS) 152 if (bufcnt < MINBUFS)
153 bufcnt = MINBUFS; 153 bufcnt = MINBUFS;
154 for (i = 0; i < bufcnt; i++) { 154 for (i = 0; i < bufcnt; i++) {
155 bp = malloc(sizeof(struct bufarea)); 155 bp = malloc(sizeof(struct bufarea));
156 bufp = malloc((unsigned int)sblock->fs_bsize); 156 bufp = aligned_alloc(DEV_BSIZE, (unsigned int)sblock->fs_bsize);
157 if (bp == NULL || bufp == NULL) { 157 if (bp == NULL || bufp == NULL) {
158 if (i >= MINBUFS) { 158 if (i >= MINBUFS) {
159 if (bp) 159 if (bp)
160 free(bp); 160 free(bp);
161 if (bufp) 161 if (bufp)
162 free(bufp); 162 free(bufp);
163 break; 163 break;
164 } 164 }
165 errexit("cannot allocate buffer pool"); 165 errexit("cannot allocate buffer pool");
166 } 166 }
167 bp->b_un.b_buf = bufp; 167 bp->b_un.b_buf = bufp;
168 bp->b_prev = &bufhead; 168 bp->b_prev = &bufhead;
169 bp->b_next = bufhead.b_next; 169 bp->b_next = bufhead.b_next;