git: 49a83b94395a - main - stress2: Do not make assumptions about the value of UFS_LINK_MAX

From: Peter Holm <pho_at_FreeBSD.org>
Date: Sat, 25 Nov 2023 09:37:22 UTC
The branch main has been updated by pho:

URL: https://cgit.FreeBSD.org/src/commit/?id=49a83b94395a6eaae4642aa72c9f6a40143f0f45

commit 49a83b94395a6eaae4642aa72c9f6a40143f0f45
Author:     Peter Holm <pho@FreeBSD.org>
AuthorDate: 2023-11-25 09:36:00 +0000
Commit:     Peter Holm <pho@FreeBSD.org>
CommitDate: 2023-11-25 09:36:00 +0000

    stress2: Do not make assumptions about the value of UFS_LINK_MAX
---
 tools/test/stress2/misc/nlink3.sh | 2 +-
 tools/test/stress2/misc/nlink4.sh | 2 +-
 tools/test/stress2/misc/nlink5.sh | 7 +++++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/test/stress2/misc/nlink3.sh b/tools/test/stress2/misc/nlink3.sh
index 0c1b9fc0c32d..55557124c9c2 100755
--- a/tools/test/stress2/misc/nlink3.sh
+++ b/tools/test/stress2/misc/nlink3.sh
@@ -52,7 +52,7 @@ main (void) {
 		err(1, "creat(%s)", file);
 	close(fd);
 
-	mx = UFS_LINK_MAX - 1; /* UFS_LINK_MAX = 32767 */
+	mx = UFS_LINK_MAX - 1;
 	for (i = 0; i < mx; i++) {
 		snprintf(file, sizeof(file), "%d", i);
 		if (link("f", file) == -1)
diff --git a/tools/test/stress2/misc/nlink4.sh b/tools/test/stress2/misc/nlink4.sh
index 5f31df2c24d0..cce8bb06985a 100755
--- a/tools/test/stress2/misc/nlink4.sh
+++ b/tools/test/stress2/misc/nlink4.sh
@@ -51,7 +51,7 @@ main (void) {
 		err(1, "creat(%s)", file);
 	close(fd);
 
-	mx = UFS_LINK_MAX - 1; /* UFS_LINK_MAX = 32767 */
+	mx = UFS_LINK_MAX - 1;
 	for (i = 0; i < mx; i++) {
 		snprintf(file, sizeof(file), "%d", i);
 		if (link("f", file) == -1)
diff --git a/tools/test/stress2/misc/nlink5.sh b/tools/test/stress2/misc/nlink5.sh
index af19d052f9f3..4e7f2d9c827d 100755
--- a/tools/test/stress2/misc/nlink5.sh
+++ b/tools/test/stress2/misc/nlink5.sh
@@ -33,6 +33,9 @@
 
 . ../default.cfg
 
+UFS_LINK_MAX=`grep UFS_LINK_MAX /usr/include/ufs/ufs/dinode.h 2>/dev/null`
+[ -z "$UFS_LINK_MAX" ] && exit 0
+UFS_LINK_MAX=`echo $UFS_LINK_MAX | awk '{print $NF}'`
 cat > /tmp/nlink5.c <<EOF
 #include <sys/stat.h>
 #include <ufs/ufs/dinode.h>
@@ -46,7 +49,7 @@ main (void) {
 	int i, mx;
 	char dir[100];
 
-	mx = UFS_LINK_MAX - 2; /* UFS_LINK_MAX = 32767 */
+	mx = UFS_LINK_MAX - 2;
 	for (i = 0; i < mx; i++) {
 		snprintf(dir, sizeof(dir), "%d", i);
 		if (mkdir(dir, 0700) == -1)
@@ -111,7 +114,7 @@ set +e
 cd $mntpoint
 /tmp/nlink5; s=$?
 n=`find . -type d -maxdepth 1 | wc -l`
-[ $n -ne 32766 ] && s=2
+[ $n -ne $((UFS_LINK_MAX - 1)) ] && s=2
 cd $here
 
 umount $mntpoint