From 03b8a419e4b6e33f6a6f2765d4dda879b31ad5c1 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Fri, 28 Oct 2016 11:26:44 +0000 Subject: [PATCH] If the fatchain() call in chainalloc() returned an error, revert marking the cluster run as in-use. Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks --- sys/fs/msdosfs/msdosfs_fat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/fs/msdosfs/msdosfs_fat.c b/sys/fs/msdosfs/msdosfs_fat.c index 96c9f187fdcb..7a3ade3a3d2d 100644 --- a/sys/fs/msdosfs/msdosfs_fat.c +++ b/sys/fs/msdosfs/msdosfs_fat.c @@ -691,8 +691,11 @@ chainalloc(struct msdosfsmount *pmp, u_long start, u_long count, pmp->pm_nxtfree = CLUST_FIRST; pmp->pm_flags |= MSDOSFS_FSIMOD; error = fatchain(pmp, start, count, fillwith); - if (error != 0) + if (error != 0) { + for (cl = start, n = count; n-- > 0;) + usemap_free(pmp, cl++); return (error); + } #ifdef MSDOSFS_DEBUG printf("clusteralloc(): allocated cluster chain at %lu (%lu clusters)\n", start, count);