From nobody Mon May 16 22:36:00 2022 X-Original-To: dev-commits-src-main@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 311CF1B35840; Mon, 16 May 2022 22:36:01 +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 4L2DcK0lGWz3P8L; Mon, 16 May 2022 22:36:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652740561; 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=tpfHl6coIt01jFqKPL6B1jFgQbbQVZOsv2/GKJSoOWE=; b=SuxUsCSpuRfcqm1R3Qi1t40diWdxS2LWbuCypMG6NxQzF/2lI6y9VVIou8jbVgcvs8kha4 ubxN8jLi8T3+q9PrzYTr27iInxBvgOKx8eP3nOR4FbnGZzr8UlNEuHhaerBMQGPT3hrXUD ym9mNqgxvgoEjTTQFFIyaIyrfPvTPPG6SEAYOy4hUORj2OO4Q8CRohULZ1hm7JXdv1YUKM RRDflndmbdAVyvK6OacgY/2BcRNsXzpGG3lnd3xASSFJe1SbcnD4kX8R2zFrmQudqnfYJZ erzuCUuIhgMTwrWm3U+JpOGTmR1m3nElwCNHUWng5ESAfRTNMpj+fTcznvGtBg== 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 EA0F7454; Mon, 16 May 2022 22:36:00 +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 24GMa0pC089934; Mon, 16 May 2022 22:36:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24GMa08g089933; Mon, 16 May 2022 22:36:00 GMT (envelope-from git) Date: Mon, 16 May 2022 22:36:00 GMT Message-Id: <202205162236.24GMa08g089933@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: ecdc04d006de - main - makefs: fix calculation of file sizes List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: ecdc04d006de93eb343ce3b77208abd937d4f8ac Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652740561; 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=tpfHl6coIt01jFqKPL6B1jFgQbbQVZOsv2/GKJSoOWE=; b=pG1i37A4f/c15AxfKtWYnmnoCJTk8qeT7XRx68et/zT9oLwj9csUZvA7zRbdFVAPufEmMt dkKGyw+uPzhTEfbqtWuOHQAco2WEChxUsaR0EX2c/nqbHAb9GxGtVgh/lFZ6JVImgluAOp kVukiJz3rWyOLOzoriq9yaooYjwtZuqOLPHb1znlJhQGbP4nLXAFHpIb7QaKedrguOJsBN KkKY1MV4RgLkStQW58KA7CxaJKxpv35+w9cFZG2kwFXga4I3rqv6IvQyYGgleiD22Ictau 5/8s6chKsvrletPKPWAo8I8FIVy1eST97fiwg5L0Bl9wZNmLnp/aYkQ2wVpM0Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652740561; a=rsa-sha256; cv=none; b=KQa6pVg7RMjhscrZQOn1+kt8KXKZHbM2URZvdVL/Ol/FGHhpMVgjrgFilDQOYWdx7Uk+Qd lzbMcQe/Pkj54wjohSJW7+/Kd43aFAy7WE1flFdN0aUktV6bZN2I7oj1Z4PCJu8rOOj8Lk 0koATKLHWBkN01yPkKgLce5fmpmO67dQ2pa5flttlPWAaKLkphOyPVmL9MM4NfFNZNu6+s eQOUUFgm+bvLXohXt7+uU0YoGm7paDOnXGkIpKUt7FTKOZFV2MAn5GRvPA76Xp1W2aZHHd I/1o9lDVynEae12pN2YXujKFErsklOlO3F36uHAaLswQuYEQYGqFxLqWvpLdSw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=ecdc04d006de93eb343ce3b77208abd937d4f8ac commit ecdc04d006de93eb343ce3b77208abd937d4f8ac Author: Alan Somers AuthorDate: 2022-05-16 22:32:10 +0000 Commit: Alan Somers CommitDate: 2022-05-16 22:32:10 +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 MFC after: 2 weeks Sponsored by: Semihalf Submitted by: Kornel Dulęba Differential Revision: https://reviews.freebsd.org/D35131 Differential Revision: https://reviews.freebsd.org/D35132 --- 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 1e68b0931f16..81101b6aa6bf 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 100755 --- 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 \