Module Name: src Committed By: perseant Date: Wed Jul 3 18:41:08 UTC 2024
Modified Files: src/sys/fs/exfatfs [perseant-exfatfs]: exfatfs_balloc.c Log Message: Correct logic to search the beginning of the bitmap too, if we started in the middle. Correct a sign error that triggered a spurious assertion failure. To generate a diff of this commit: cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/fs/exfatfs/exfatfs_balloc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/fs/exfatfs/exfatfs_balloc.c diff -u src/sys/fs/exfatfs/exfatfs_balloc.c:1.1.2.1 src/sys/fs/exfatfs/exfatfs_balloc.c:1.1.2.2 --- src/sys/fs/exfatfs/exfatfs_balloc.c:1.1.2.1 Tue Jul 2 20:36:50 2024 +++ src/sys/fs/exfatfs/exfatfs_balloc.c Wed Jul 3 18:41:08 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: exfatfs_balloc.c,v 1.1.2.1 2024/07/02 20:36:50 perseant Exp $ */ +/* $NetBSD: exfatfs_balloc.c,v 1.1.2.2 2024/07/03 18:41:08 perseant Exp $ */ /*- * Copyright (c) 2022, 2024 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: exfatfs_balloc.c,v 1.1.2.1 2024/07/02 20:36:50 perseant Exp $"); +__KERNEL_RCSID(0, "$NetBSD: exfatfs_balloc.c,v 1.1.2.2 2024/07/03 18:41:08 perseant Exp $"); #include <sys/types.h> #include <sys/buf.h> @@ -145,7 +145,7 @@ exfatfs_bitmap_alloc(struct exfatfs *fs, ++off; } if (r != INVALID) { - assert(r >= 2 && r < fs->xf_ClusterCount - 2); + assert(r >= 2 && r < fs->xf_ClusterCount + 2); DPRINTF(("basic allocate cluster %u/%u" " at lbn %u bit %d\n", (unsigned)r, (unsigned)end, @@ -162,15 +162,19 @@ exfatfs_bitmap_alloc(struct exfatfs *fs, off = 0; assert(++c <= 2 * fs->xf_ClusterCount); } - if (start == ostart && start > 2) { - end = start; - start = 2; - DPRINTF((" not found, now start=%u end=%u\n", - (unsigned)start, (unsigned)end)); - continue; - } - } while (0); + + /* If we've searched everywhere, we are done */ + if (start != ostart || ostart <= 2) + break; + + /* We've only searched the end. Now search the begninning. */ + end = start; + start = 2; + DPRINTF((" not found, now start=%u end=%u\n", + (unsigned)start, (unsigned)end)); + } while (1); + DPRINTF(("no clusters to allocate, returning ENOSPC\n")); return ENOSPC; }