From nobody Sat Jun 18 14:17:50 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id A686986AFDD; Sat, 18 Jun 2022 14:17:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LQJ0G4Cxxz3rvw; Sat, 18 Jun 2022 14:17:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655561870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=M+722d/Dw7jG/4E9Y2rZoNYmfxGwl6bTiDa13quMD+s=; b=XCPLP1USOYK8Tf3L3h1cdXGsXAqs+e1fUnEQLC0Ez80e6pdA/QTTmbziI74Zo1GOmW2HHT xVJYygYwd+iNWCndJuw44rF5mES0YO/7LzXOa+tYwXg/74lapO64RAI2VwAtKplXRbprhy 5UzZ/w501o2mzZ3kyF6Fhzx1oSWWNLaqwYJmSDW5krxi2k0CTg66rXi9AUtEDYsjXwLcuT QZPdEF70JrY4n7Em9eisA0Pz4I/weU88gg6dVtAJIS9IlusexkTPYxkR9ZeE+qZeD0z+Dp uYj3Bs+yw/PgxP4Bj3ZpfIBwPP6R0SdQEFxBdIuD8shKqAbQqjjOwwala6xriw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7158A16187; Sat, 18 Jun 2022 14:17:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25IEHohr035079; Sat, 18 Jun 2022 14:17:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25IEHodm035078; Sat, 18 Jun 2022 14:17:50 GMT (envelope-from git) Date: Sat, 18 Jun 2022 14:17:50 GMT Message-Id: <202206181417.25IEHodm035078@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: 1a2920e96aac - stable/13 - makefs: fix calculation of file sizes List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1a2920e96aacc253b4f65405640074bf595c431d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655561870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=M+722d/Dw7jG/4E9Y2rZoNYmfxGwl6bTiDa13quMD+s=; b=jljFzp0nBuZdBiaC0vidiBzaVF5uDfU43Q7+3ZR6zFGUJciag9T5kWvlJh9SzldgIyOkxe mMJJ9twnS51HtZ+4XpeBRna0jFq56PDO2Wo+l0MxzoSJr2cvE5Dx9P+Qyhoy/PEkseKj9W FVkmvPez573U9nNLmGFDozaDlp8W1FYydGjaK37EEsuaPLembjy8XEHRf6vVGaS8Ixq7Oy 2b0Pqh5Cr8trJyAhM3DnMXa2QcTJWn0lneeFW/Cbr6lLwfEyVIX5U0MtLn5FEiKMdDfPWn 2EPkn87yjuzfX10DHFZA2rKnBkgbq9gqsF1OtRlAf4fJA/yiN3+7pCb8cdq4TA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655561870; a=rsa-sha256; cv=none; b=bXVzR+i6RKFyHQOLJAruv8PnXejeG2IZlvtvuQcInHUOlH8ZTbBf692XXtEIginVj1pRx2 BqTJh3ZHwf7OwTmdDpkj9u284Rbw44OLLPXyXHe+Lcy+r69cUrjaOyvYb7J4i0zowZPRB6 T2xy/0u3zTQotIvxe5nqreZkFpNoxdHY7wBcIxpYL7nbX6V4fyc8kwbFZ+A6+l1KD1PMqX AjRGtdZ3iDi/dFjTMwFLplk4SAr4CxIh9JjMU3c4uXr/cCp8QzTtR3kYx5TkXDxAaiunZb 9DwpBdNy6y4qjP7byXMLYx+A11GTjAFoNkCo2tCS75v7Cf6W1PIeDzLOz39OzQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=1a2920e96aacc253b4f65405640074bf595c431d commit 1a2920e96aacc253b4f65405640074bf595c431d Author: Alan Somers AuthorDate: 2022-05-16 22:32:10 +0000 Commit: Alan Somers CommitDate: 2022-06-18 14:17:23 +0000 makefs: fix calculation of file sizes When a new FS image is created we need to calculate how much space each file is going to consume. Fix two bugs in that logic: 1) Count the space needed for indirect blocks for large files. 1) Normally the trailing data of a file is written to a block of frag size, 4 kB by default. However for files that use indirect blocks a full block is allocated, 32kB by default. Take that into account. Adjust size calculations to match what is done in ffs_mkfs routine: * Depending on the UFS version the superblock is stored at a different offset. Take that into account. * Add the cylinder group block size. * All of the above has to be aligned to the block size. Finally, Remove "ncg" variable. It's always 1 and it was used to multiply stuff. PR: 229929 Reviewed by: mckusick Sponsored by: Semihalf Submitted by: Kornel Dulęba Differential Revision: https://reviews.freebsd.org/D35131 Differential Revision: https://reviews.freebsd.org/D35132 (cherry picked from commit ecdc04d006de93eb343ce3b77208abd937d4f8ac) --- usr.sbin/makefs/ffs.c | 50 ++++++++++++++++++------------- usr.sbin/makefs/tests/makefs_ffs_tests.sh | 1 - 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c index 6429c54e8a9f..29972317c80b 100644 --- a/usr.sbin/makefs/ffs.c +++ b/usr.sbin/makefs/ffs.c @@ -324,7 +324,6 @@ ffs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) static void ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts) { - int32_t ncg = 1; #ifdef notyet int32_t spc, nspf, ncyl, fssize; #endif @@ -395,22 +394,26 @@ ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts) fsopts->size = fsopts->size * (100 + fsopts->freeblockpc) / 100; - /* add space needed for superblocks */ /* - * The old SBOFF (SBLOCK_UFS1) is used here because makefs is - * typically used for small filesystems where space matters. - * XXX make this an option. + * Add space needed for superblock, cylblock and to store inodes. + * All of those segments are aligned to the block size. + * XXX: This has to match calculations done in ffs_mkfs. */ - fsopts->size += (SBLOCK_UFS1 + SBLOCKSIZE) * ncg; - /* add space needed to store inodes, x3 for blockmaps, etc */ - if (ffs_opts->version == 1) - fsopts->size += ncg * DINODE1_SIZE * - roundup(fsopts->inodes / ncg, - ffs_opts->bsize / DINODE1_SIZE); - else - fsopts->size += ncg * DINODE2_SIZE * - roundup(fsopts->inodes / ncg, - ffs_opts->bsize / DINODE2_SIZE); + if (ffs_opts->version == 1) { + fsopts->size += + roundup(SBLOCK_UFS1 + SBLOCKSIZE, ffs_opts->bsize); + fsopts->size += roundup(SBLOCKSIZE, ffs_opts->bsize); + fsopts->size += ffs_opts->bsize; + fsopts->size += DINODE1_SIZE * + roundup(fsopts->inodes, ffs_opts->bsize / DINODE1_SIZE); + } else { + fsopts->size += + roundup(SBLOCK_UFS2 + SBLOCKSIZE, ffs_opts->bsize); + fsopts->size += roundup(SBLOCKSIZE, ffs_opts->bsize); + fsopts->size += ffs_opts->bsize; + fsopts->size += DINODE2_SIZE * + roundup(fsopts->inodes, ffs_opts->bsize / DINODE2_SIZE); + } /* add minfree */ if (ffs_opts->minfree > 0) @@ -620,12 +623,19 @@ ffs_size_dir(fsnode *root, fsinfo_t *fsopts) e, tmpdir.d_namlen, this, curdirsize); \ } while (0); - /* - * XXX this needs to take into account extra space consumed - * by indirect blocks, etc. - */ #define ADDSIZE(x) do { \ - fsopts->size += roundup((x), ffs_opts->fsize); \ + if ((size_t)(x) < UFS_NDADDR * (size_t)ffs_opts->bsize) { \ + fsopts->size += roundup((x), ffs_opts->fsize); \ + } else { \ + /* Count space consumed by indirecttion blocks. */ \ + fsopts->size += ffs_opts->bsize * \ + (howmany((x), UFS_NDADDR * ffs_opts->bsize) - 1); \ + /* \ + * If the file is big enough to use indirect blocks, \ + * we allocate bsize block for trailing data. \ + */ \ + fsopts->size += roundup((x), ffs_opts->bsize); \ + } \ } while (0); curdirsize = 0; diff --git a/usr.sbin/makefs/tests/makefs_ffs_tests.sh b/usr.sbin/makefs/tests/makefs_ffs_tests.sh index 55be19f099eb..1a415cb5f518 100644 --- a/usr.sbin/makefs/tests/makefs_ffs_tests.sh +++ b/usr.sbin/makefs/tests/makefs_ffs_tests.sh @@ -57,7 +57,6 @@ check_ffs_image_contents() atf_test_case autocalculate_image_size cleanup autocalculate_image_size_body() { - atf_expect_fail "PR 229929 makefs(8) can underestimate image size" create_test_inputs atf_check -e empty -o save:$TEST_SPEC_FILE -s exit:0 \