⛏️ index : haiku.git

author Augustin Cavalier <waddlesplash@gmail.com> 2025-11-26 23:03:51.0 -05:00:00
committer Augustin Cavalier <waddlesplash@gmail.com> 2025-11-26 23:03:51.0 -05:00:00
commit
9cbbc8208751660917c0bcc2ee41368189aa9645 [patch]
tree
d398f71d1b579d9d5c2b37acd5ad85723c0716e8
parent
5373300610693c1a0352b779c11d2651a14111ec
download
9cbbc8208751660917c0bcc2ee41368189aa9645.tar.gz

kernel/fs: Block mounting partitions that are already mounted.

Previously this actually succeeded, which could obviously cause
disk corruption and other such problems.

While at it, clean up some code style.

Fixes #16734. Related to #19303.

Diff

 src/system/kernel/fs/vfs.cpp | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp
index 112ea2f..479becc 100644
--- a/src/system/kernel/fs/vfs.cpp
+++ b/src/system/kernel/fs/vfs.cpp
@@ -7522,7 +7522,7 @@
			}
		}

		if (!partition) {
		if (partition == NULL) {
			TRACE(("fs_mount(): Partition `%s' not found.\n",
				normalizedDevice.Path()));
			return B_ENTRY_NOT_FOUND;
@@ -7538,28 +7538,31 @@
	// interfering.
	// TODO: Just mark the partition busy while mounting!
	KDiskDevice* diskDevice = NULL;
	if (partition) {
	if (partition != NULL) {
		diskDevice = ddm->WriteLockDevice(partition->Device()->ID());
		if (!diskDevice) {
		if (diskDevice == NULL) {
			TRACE(("fs_mount(): Failed to lock disk device!\n"));
			return B_ERROR;
		}
	}

	DeviceWriteLocker writeLocker(diskDevice, true);
		// this takes over the write lock acquired before

	if (partition != NULL) {
		// make sure, that the partition is not busy
		if (partition->IsBusy()) {
			TRACE(("fs_mount(): Partition is busy.\n"));
			return B_BUSY;
		}

		if (partition->IsMounted()) {
			TRACE(("fs_mount(): Partition is already mounted.\n"));
			return B_BUSY;
		}

		// if no FS name had been supplied, we get it from the partition
		if (fsName == NULL) {
			KDiskSystem* diskSystem = partition->DiskSystem();
			if (!diskSystem) {
			if (diskSystem == NULL) {
				TRACE(("fs_mount(): No FS name was given, and the DDM didn't "
					"recognize it.\n"));
				return B_BAD_VALUE;