[11/17] installer: Add code to proper unmount the BTRFS layout

Message ID 20240315191442.3951-12-stefan.schantl@ipfire.org
State Superseded
Headers
Series BTRFS support on IPFire 2.x (experimental) |

Commit Message

Stefan Schantl March 15, 2024, 7:14 p.m. UTC
  Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 src/installer/hw.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
  

Patch

diff --git a/src/installer/hw.c b/src/installer/hw.c
index 1c4adc24b..b5b853e92 100644
--- a/src/installer/hw.c
+++ b/src/installer/hw.c
@@ -1106,13 +1106,36 @@  int hw_umount_filesystems(struct hw_destination* dest, const char* prefix) {
 		return -1;
 
 	// root
-	r = hw_umount(prefix, NULL);
+	if(dest->filesystem == HW_FS_BTRFS) {
+		r = hw_umount_btrfs_layout();
+	} else {
+		r = hw_umount(prefix, NULL);
+	}
+
 	if (r)
 		return -1;
 
 	return 0;
 }
 
+int hw_umount_btrfs_layout() {
+	char path[STRING_SIZE];
+	int r;
+
+	// Reverse loop through the array of known subvolumes.
+	for ( int i = LEN(btrfs_subvolumes); i >= 0; i-- ) {
+		snprintf(path, sizeof(path), "%s%s", DESTINATION_MOUNT_PATH, btrfs_subvolumes[i][1]);
+
+		// umount the subvolume.
+		r = hw_umount(path, NULL);
+
+		if (r)
+			return r;
+	}
+
+	return 0;
+}
+
 int hw_destroy_raid_superblocks(const struct hw_destination* dest, const char* output) {
 	char cmd[STRING_SIZE];