]> git.ipfire.org Git - ipfire-2.x.git/blob - src/installer/hw.h
kernel: reset asix88179 twice like in older kernels
[ipfire-2.x.git] / src / installer / hw.h
1 /*#############################################################################
2 # #
3 # IPFire - An Open Source Firewall Distribution #
4 # Copyright (C) 2014 IPFire development team #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 #############################################################################*/
20
21 #ifndef HEADER_HW_H
22 #define HEADER_HW_H
23
24 #include <libudev.h>
25
26 #define DESTINATION_MOUNT_PATH "/harddisk"
27 #define SOURCE_MOUNT_PATH "/cdrom"
28 #define SOURCE_TEST_FILE SOURCE_MOUNT_PATH "/" DISTRO_SNAME "-" DISTRO_VERSION ".media"
29
30 #define HW_MAX_DISKS 32
31 #define STRING_SIZE 1024
32 #define DEV_SIZE 128
33
34 #define HW_PATH_BOOT "/boot"
35 #define HW_PATH_BOOT_EFI "/boot/efi"
36 #define HW_PATH_DATA "/var"
37
38 #define HW_PART_TYPE_NORMAL 0
39 #define HW_PART_TYPE_RAID1 1
40
41 #define HW_PART_TABLE_MSDOS 0
42 #define HW_PART_TABLE_GPT 1
43
44 #define HW_FS_SWAP 0
45 #define HW_FS_EXT4 1
46 #define HW_FS_EXT4_WO_JOURNAL 2
47 #define HW_FS_XFS 3
48 #define HW_FS_FAT32 4
49 #define HW_FS_BTRFS 5
50
51 #define HW_FS_DEFAULT HW_FS_EXT4
52
53 #define RAID_METADATA "1.0"
54
55 #define SERIAL_BAUDRATE 115200
56
57 #define BTRFS_MOUNT_OPTIONS "compress=zstd:1"
58
59 #define BYTES2MB(x) ((x) / 1024 / 1024)
60 #define MB2BYTES(x) ((unsigned long long)(x) * 1024 * 1024)
61
62 struct hw {
63 struct udev *udev;
64 char arch[STRING_SIZE];
65
66 // Enabled if we should install in EFI mode
67 int efi;
68 };
69
70 struct hw_disk {
71 char path[DEV_SIZE];
72 unsigned long long size;
73
74 char description[STRING_SIZE];
75 char vendor[STRING_SIZE];
76 char model[STRING_SIZE];
77
78 // Reference counter
79 int ref;
80 };
81
82 struct hw_destination {
83 char path[DEV_SIZE];
84
85 int is_raid;
86 int raid_level;
87 const struct hw_disk* disk1;
88 const struct hw_disk* disk2;
89
90 int part_table;
91 char part_bootldr[DEV_SIZE];
92 char part_boot[DEV_SIZE];
93 char part_boot_efi[DEV_SIZE];
94 char part_swap[DEV_SIZE];
95 char part_root[DEV_SIZE];
96 int part_boot_idx;
97 int part_boot_efi_idx;
98
99 int filesystem;
100
101 unsigned long long size;
102 unsigned long long size_bootldr;
103 unsigned long long size_boot;
104 unsigned long long size_boot_efi;
105 unsigned long long size_swap;
106 unsigned long long size_root;
107 };
108
109 // Struct to define the BTRFS subvolumes layout
110 static const struct btrfs_subvolumes {
111 const char* name;
112 const char* mount_path;
113 } btrfs_subvolumes[] = {
114 { "@", "/" },
115 { "@snapshots", "/.snapshots" },
116 { "@home", "/home" },
117 { "@root", "/root" },
118 { "@cache", "/var/cache" },
119 { "@backups", "/var/ipfire/backup" },
120 { "@lib", "/var/lib" },
121 { "@logs", "/var/log" },
122 { "@mails", "/var/mail" },
123 { "@tmp", "/var/tmp" },
124
125 // Sentinel
126 { NULL },
127 };
128
129 struct hw* hw_init();
130 void hw_free(struct hw* hw);
131
132 int hw_mount(const char* source, const char* target, const char* fs, int flags);
133 int hw_umount(const char* source, const char* prefix);
134
135 char* hw_find_source_medium(struct hw* hw);
136
137 struct hw_disk** hw_find_disks(struct hw* hw, const char* sourcedrive);
138 void hw_free_disks(struct hw_disk** disks);
139 unsigned int hw_count_disks(struct hw_disk** disks);
140 struct hw_disk** hw_select_disks(struct hw_disk** disks, int* selection);
141 struct hw_disk** hw_select_first_disk(struct hw_disk** disks);
142
143 struct hw_destination* hw_make_destination(struct hw* hw, int part_type, struct hw_disk** disks,
144 int disable_swap, int filesystem);
145
146 unsigned long long hw_memory();
147
148 int hw_create_partitions(struct hw_destination* dest, const char* output);
149 int hw_create_filesystems(struct hw_destination* dest, const char* output);
150
151 int hw_mount_filesystems(struct hw_destination* dest, const char* prefix);
152 int hw_umount_filesystems(struct hw_destination* dest, const char* prefix);
153
154 int hw_destroy_raid_superblocks(const struct hw_destination* dest, const char* output);
155 int hw_setup_raid(struct hw_destination* dest, const char* output);
156 int hw_stop_all_raid_arrays(const char* output);
157
158 int hw_install_bootloader(struct hw* hw, struct hw_destination* dest, const char* output);
159 int hw_write_fstab(struct hw_destination* dest);
160
161 char* hw_find_backup_file(const char* output, const char* search_path);
162 int hw_restore_backup(const char* output, const char* backup_path, const char* destination);
163
164 int hw_start_networking(const char* output);
165
166 void hw_sync();
167
168 #endif /* HEADER_HW_H */