int hw_mount_filesystems(struct hw_destination* dest, const char* prefix) {
char target[STRING_SIZE];
+ int r;
assert(*prefix == '/');
}
// root
- int r = hw_mount(dest->part_root, prefix, filesystem, 0);
- if (r)
- return r;
+ if (dest->filesystem == HW_FS_BTRFS) {
+ r = hw_mount_btrfs_subvolumes(dest->part_root);
+
+ if (r)
+ return r;
+ } else {
+ r = hw_mount(dest->part_root, prefix, filesystem, 0);
+
+ if (r)
+ return r;
+ }
// boot
snprintf(target, sizeof(target), "%s%s", prefix, HW_PATH_BOOT);
return 0;
}
+int hw_mount_btrfs_subvolumes(const char* source) {
+ int r;
+ char path[STRING_SIZE];
+ char options[STRING_SIZE];
+
+ // Mount the root subvolume
+ snprintf(options, sizeof(options), "subvol=%s,%s", btrfs_subvolumes[0][0], BTRFS_MOUNT_OPTIONS);
+ r = mount(source, DESTINATION_MOUNT_PATH, "btrfs", NULL, options);
+
+ if (r)
+ return r;
+
+ // Loop through the remain array of known subvolumes.
+ for ( int i = 1; i < LEN(btrfs_subvolumes); i++ ) {
+ snprintf(path, sizeof(path), "%s%s", DESTINATION_MOUNT_PATH, btrfs_subvolumes[i][1]);
+ snprintf(options, sizeof(options), "subvol=%s,", btrfs_subvolumes[i][0], BTRFS_MOUNT_OPTIONS);
+
+ // Create the directory.
+ r = hw_mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO);
+
+ if(r != 0 && errno != EEXIST)
+ return r;
+
+ // Try to mount the subvolume.
+ r = mount(source, path, "btrfs", NULL, options);
+
+ if (r)
+ return r;
+ }
+
+ return 0;
+}
+
int hw_umount_filesystems(struct hw_destination* dest, const char* prefix) {
int r;
char target[STRING_SIZE];