From nobody Wed Nov 19 11:21:20 2025 X-Original-To: dev-commits-src-branches@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 4dBJvh59mLz6HYZ9 for ; Wed, 19 Nov 2025 11:21:20 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dBJvh4TpQz3X80 for ; Wed, 19 Nov 2025 11:21:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763551280; 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=qh1vAZVxGa4nnmLETrV7z0v81Cybx95JhEE7lTyd57k=; b=MGzrxd6v+g8+b7MfrP9Cze+rypm9T5oe0PfoPKQ9MdQjZDGti0/mg/WO5CYO5cGg+5on2y LMARZ5LFgEcSWFBMarSyD9Vl2VXtvOfc6pzfUfXB8uEfsaFzSXiG4bL6ig87z9j3Ax52wZ wT5nZ+mg3xQH1bdTq1nwOHxMhWqut+eft9NhGuJQEkFEbYs5T43WuDuK6VSP1y+FJqNm9T jL8FTtf8HoNNkbSu9k9/ouu6d/kO+bMpldm8VHt5T6LYRfTFVZt5cDfkIAx25h0gTi3GJh CINjCcFwarOaIcBsyL3OjoqtCd4JDGajl+TvFP70L3KFrzRBDKI6QB09JBcfQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763551280; 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=qh1vAZVxGa4nnmLETrV7z0v81Cybx95JhEE7lTyd57k=; b=N59H8342bGi7KMXYArFjicdem2PaolqgbDJOcPKDCIoH6GgEp2oJU2R4w3oUhbD/aFwvLy 99fV8MVUUDK7FXXxTNEpe/vAnpxM+Pa8YGmTwRvaa9HxMoMwJPtCDZAKIvZEO71IqT6tGg afb41ThdvgNunaKuBmitsFOVOaPG82u0Crfh1OSViMQHPLVyj4T1U7j/u3yhQQnUdneIHG +NmLJEYAbqBp7wYEJIN7B1LPmvJ0k9Z69HzXiz9gLQX6MQBGNHg7Dgi8NaPotGSGIt642B j9aGib7X4cFHr0wd4xD6KRR9Mqpm9pGYfv/f/RDQP9bWQc8zz0XzkMZhW9fxEw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763551280; a=rsa-sha256; cv=none; b=V4BI2g7HvY54VudylpR7Bqn1uGoTJoObkWCkpXW2Yfen8zUbGnGTZaIizjKH1tzGL85XNR OqrHwszcYfvwez0BprhWaWH4gfsRzhhPklCNll75BlB92BcMzZp0NEmCC/LUsWw9Lo0c1A SFtda/UZOjEMSLkgIQ9+W7HTzfcj7JjK0BsP6l35jsCQscoGpmLJoSWI8ubmdY2x8Bxzlt GJu5pPoHf9VosgWW3HMsN/X6rFKUudkTsyfEfaCAa9XfHIaDZAGRaRsYZlElG6Ni+U7oY2 bF+Rr4613WeM7WGuDrEMcXB1YvHOO/oCxCCLK9BtcFGlz4LcxbqEZZ7UrXaggw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dBJvh3zTDzfFK for ; Wed, 19 Nov 2025 11:21:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id b7c9 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 19 Nov 2025 11:21:20 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: 29343c4b8f94 - stable/13 - quot: Add tests List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 29343c4b8f94f3e7a6f0d26fec8fda625773a4c3 Auto-Submitted: auto-generated Date: Wed, 19 Nov 2025 11:21:20 +0000 Message-Id: <691da830.b7c9.95f0608@gitrepo.freebsd.org> The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=29343c4b8f94f3e7a6f0d26fec8fda625773a4c3 commit 29343c4b8f94f3e7a6f0d26fec8fda625773a4c3 Author: Dag-Erling Smørgrav AuthorDate: 2025-10-17 11:55:12 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-11-19 11:20:30 +0000 quot: Add tests To facilitate the task, we change the comparison function so that users with equal filesystem usage are sorted by UID, and add an undocumented option that prevents quot from replacing numerical UIDs with names. We also switch from getfsfile(3) to getmntpoint(3) so the first line is identical regardless of whether we pass quot a mountpoint or a device. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D53133 (cherry picked from commit aa870a1935bccb66e02c4c31630706768a3e7d74) (cherry picked from commit b5f3f1a661ab69986c3379fa4c9c2b38785933db) (cherry picked from commit b41551753a2baff6646e2958acb4a7fcd205b69c) --- etc/mtree/BSD.tests.dist | 2 + usr.sbin/quot/Makefile | 5 +- usr.sbin/quot/quot.c | 11 ++++- usr.sbin/quot/tests/Makefile | 4 ++ usr.sbin/quot/tests/quot_test.sh | 101 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 3 deletions(-) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index bbd0862c226b..5ae161ed5cd2 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -1177,6 +1177,8 @@ .. pw .. + quot + .. rpcbind .. sa diff --git a/usr.sbin/quot/Makefile b/usr.sbin/quot/Makefile index b18c37126448..1f87278f1bfa 100644 --- a/usr.sbin/quot/Makefile +++ b/usr.sbin/quot/Makefile @@ -1,7 +1,10 @@ +.include PROG= quot MAN= quot.8 -LIBADD= ufs +LIBADD= ufs util +HAS_TESTS= +SUBDIR.${MK_TESTS}= tests WARNS?= 2 diff --git a/usr.sbin/quot/quot.c b/usr.sbin/quot/quot.c index 7042acf07bc4..28a7173e7340 100644 --- a/usr.sbin/quot/quot.c +++ b/usr.sbin/quot/quot.c @@ -55,6 +55,7 @@ /* some flags of what to do: */ static char estimate; static char count; +static char noname; static char unused; static void (*func)(int, struct fs *, char *); static long blocksize; @@ -281,7 +282,7 @@ user(uid_t uid) usr--) { if (!usr->name) { usr->uid = uid; - if (!(pwd = getpwuid(uid))) { + if (noname || !(pwd = getpwuid(uid))) { asprintf(&usr->name, "#%u", uid); } else { usr->name = strdup(pwd->pw_name); @@ -308,7 +309,10 @@ cmpusers(const void *v1, const void *v2) u1 = (const struct user *)v1; u2 = (const struct user *)v2; - return u2->space - u1->space; + return (u2->space > u1->space ? 1 : + u2->space < u1->space ? -1 : + u1->uid > u2->uid ? 1 : + u1->uid < u2->uid ? -1 : 0); } #define sortusers(users) (qsort((users),nusers,sizeof(struct user), \ @@ -578,6 +582,9 @@ main(int argc, char *argv[]) while (--argc > 0 && **++argv == '-') { while (*++*argv) { switch (**argv) { + case 'N': + noname = 1; + break; case 'n': func = donames; break; diff --git a/usr.sbin/quot/tests/Makefile b/usr.sbin/quot/tests/Makefile new file mode 100644 index 000000000000..d4e64691f905 --- /dev/null +++ b/usr.sbin/quot/tests/Makefile @@ -0,0 +1,4 @@ +PACKAGE= tests +ATF_TESTS_SH= quot_test + +.include diff --git a/usr.sbin/quot/tests/quot_test.sh b/usr.sbin/quot/tests/quot_test.sh new file mode 100644 index 000000000000..7da9d23ca11f --- /dev/null +++ b/usr.sbin/quot/tests/quot_test.sh @@ -0,0 +1,101 @@ +# +# Copyright (c) 2025 Dag-Erling Smørgrav +# +# SPDX-License-Identifier: BSD-2-Clause +# + +# Create and mount a UFS filesystem on a small memory disk +quot_setup() +{ + atf_check -o save:dev mdconfig -t malloc -s 16M + local dev=$(cat dev) + atf_check -o ignore newfs "$@" /dev/$dev + atf_check mkdir mnt + local mnt=$(realpath mnt) + atf_check mount /dev/$dev "$mnt" + echo "/dev/$dev:" >expect + printf "%5d\t%5d\t%-8s\n" 8 2 "#0" >>expect +} + +# Create a directory owned by a given UID +quot_adduid() +{ + local uid=$1 + atf_check install -d -o $uid -g 0 mnt/$uid + printf "%5d\t%5d\t%-8s\n" 4 1 "#$uid" >>expect +} + +# Perform the tests +quot_test() +{ + local dev=$(cat dev) + # Create inodes owned by a large number of users to exercise + # hash collisions and rehashing. The code uses an open hash + # table that starts out with only 8 entries and doubles every + # time it fills up. + local uid + for uid in $(seq 1 32); do + quot_adduid $uid + done + # Also create inodes owned by users with long UIDs, up to the + # highest possible value (2^32 - 2, because chown(2) and + # friends interpret 2^32 - 1 as “leave unchanged”). + local shift + for shift in $(seq 6 32); do + quot_adduid $(((1 << shift) - 2)) + done + # Since quot operates directly on the underlying device, not + # on the mounted filesystem, we remount read-only to ensure + # that everything gets flushed to the memory disk. + atf_check mount -ur /dev/$dev + atf_check -o file:expect quot -fkN /dev/$dev +} + +# Unmount and release the memory disk +quot_cleanup() +{ + if [ -d mnt ]; then + umount mnt || true + fi + if [ -f dev ]; then + mdconfig -d -u $(cat dev) || true + fi +} + +atf_test_case ufs1 cleanup +ufs1_head() +{ + atf_set descr "Test quot on UFS1" + atf_set require.user root +} +ufs1_body() +{ + quot_setup -O1 + quot_test +} +ufs1_cleanup() +{ + quot_cleanup +} + +atf_test_case ufs2 cleanup +ufs2_head() +{ + atf_set descr "Test quot on UFS2" + atf_set require.user root +} +ufs2_body() +{ + quot_setup -O2 + quot_test +} +ufs2_cleanup() +{ + quot_cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case ufs1 + atf_add_test_case ufs2 +}