#include "hw.h"
+// Array which contains the subvolumes which will be created when installing
+// IPFire on a BTRFS.
+const char* btrfs_subvolumes[7][2] = {
+ {"@root" ,"/"},
+ {"@snapshots", "/.snapshots"},
+ {"@home", "/home"},
+ {"@cache", "/var/cache"},
+ {"@lib", "/var/lib"},
+ {"@logs", "/var/log"},
+ {"@mails", "/var/mail"}
+};
+
+#define LEN(arr) ((int) (sizeof (arr) / sizeof (arr)[0]))
+
static int system_chroot(const char* output, const char* path, const char* cmd) {
char chroot_cmd[STRING_SIZE];
static int hw_format_filesystem(const char* path, int fs, const char* output) {
char cmd[STRING_SIZE] = "\0";
+ int r;
// Swap
if (fs == HW_FS_SWAP) {
// BTRFS
} else if (fs == HW_FS_BTRFS) {
- snprintf(cmd, sizeof(cmd), "/usr/bin/mkfs.btrfs -L rootfs -f %s", path);
+ r = hw_create_btrfs_layout(path, output);
+
+ return r;
// FAT32
} else if (fs == HW_FS_FAT32) {
assert(*cmd);
- int r = mysystem(output, cmd);
+ r = mysystem(output, cmd);
return r;
}
return 0;
}
+int hw_create_btrfs_layout(const char* path, const char* output) {
+ char cmd[STRING_SIZE];
+ char subvolume[STRING_SIZE];
+
+ // Create the main BTRFS.
+ snprintf(cmd, sizeof(cmd), "/usr/bin/mkfs.btrfs -L IPFire -f %s", path);
+ int r = mysystem(output, cmd);
+
+ if (r)
+ return r;
+
+ // We need to mount the FS in order to create any subvolumes.
+ r = hw_mount(path, DESTINATION_MOUNT_PATH, "btrfs", 0);
+
+ if (r)
+ return r;
+
+ // Loop through the array of subvolumes to create.
+ for ( int i = 0; i < LEN(btrfs_subvolumes); i++ ) {
+ snprintf(subvolume, sizeof(subvolume), "%s", btrfs_subvolumes[i][0]);
+
+ // Call function to create the subvolume
+ r = hw_create_btrfs_subvolume(output, subvolume);
+
+ if (r)
+ return r;
+ }
+
+ // Umount the main BTRFS after subvolume creation.
+ r = hw_umount(path, 0);
+
+ if (r)
+ return r;
+
+ return 0;
+}
+
int hw_mount_filesystems(struct hw_destination* dest, const char* prefix) {
char target[STRING_SIZE];
return 0;
}
+
+int hw_create_btrfs_subvolume(const char* output, const char* subvolume) {
+ char command [STRING_SIZE];
+ snprintf(command, sizeof(command), "/usr/bin/btrfs subvolume create %s/%s", DESTINATION_MOUNT_PATH, subvolume);
+
+ int r = mysystem(output, command);
+
+ if (r)
+ return -1;
+
+ return 0;
+}