]>
Commit | Line | Data |
---|---|---|
f0fa1795 MT |
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 | ||
25fcce25 | 26 | #define DESTINATION_MOUNT_PATH "/harddisk" |
fb76fc51 MT |
27 | #define SOURCE_MOUNT_PATH "/cdrom" |
28 | #define SOURCE_TEST_FILE SOURCE_MOUNT_PATH "/" DISTRO_SNAME "-" DISTRO_VERSION ".media" | |
f0fa1795 | 29 | |
d7dd283b MT |
30 | #define HW_MAX_DISKS 32 |
31 | #define STRING_SIZE 1024 | |
32 | #define DEV_SIZE 128 | |
33 | ||
25fcce25 MT |
34 | #define HW_PATH_BOOT "/boot" |
35 | #define HW_PATH_DATA "/var" | |
36 | ||
d7dd283b MT |
37 | #define HW_PART_TYPE_NORMAL 0 |
38 | #define HW_PART_TYPE_RAID1 1 | |
39 | ||
25fcce25 MT |
40 | #define HW_PART_TABLE_MSDOS 0 |
41 | #define HW_PART_TABLE_GPT 1 | |
42 | ||
43 | #define HW_FS_SWAP 0 | |
44 | #define HW_FS_REISERFS 1 | |
45 | #define HW_FS_EXT4 2 | |
46 | #define HW_FS_EXT4_WO_JOURNAL 3 | |
70a44b52 | 47 | #define HW_FS_XFS 4 |
25fcce25 MT |
48 | |
49 | #define HW_FS_DEFAULT HW_FS_EXT4 | |
50 | ||
7b4790d3 MT |
51 | #define RAID_METADATA "1.0" |
52 | ||
9dd16c6d MT |
53 | #define SERIAL_BAUDRATE 115200 |
54 | ||
25fcce25 MT |
55 | #define BYTES2MB(x) ((x) / 1024 / 1024) |
56 | #define MB2BYTES(x) ((unsigned long long)(x) * 1024 * 1024) | |
57 | ||
f0fa1795 MT |
58 | struct hw { |
59 | struct udev *udev; | |
5fb499f1 | 60 | int efi; |
f0fa1795 MT |
61 | }; |
62 | ||
d7dd283b MT |
63 | struct hw_disk { |
64 | char path[DEV_SIZE]; | |
65 | unsigned long long size; | |
66 | ||
67 | char description[STRING_SIZE]; | |
68 | char vendor[STRING_SIZE]; | |
69 | char model[STRING_SIZE]; | |
70 | ||
71 | // Reference counter | |
72 | int ref; | |
73 | }; | |
74 | ||
75 | struct hw_destination { | |
76 | char path[DEV_SIZE]; | |
d7dd283b MT |
77 | |
78 | int is_raid; | |
4a0d9bef | 79 | int raid_level; |
d7dd283b MT |
80 | const struct hw_disk* disk1; |
81 | const struct hw_disk* disk2; | |
82 | ||
25fcce25 | 83 | int part_table; |
48d6a112 | 84 | char part_bootldr[DEV_SIZE]; |
d7dd283b MT |
85 | char part_boot[DEV_SIZE]; |
86 | char part_swap[DEV_SIZE]; | |
87 | char part_root[DEV_SIZE]; | |
25fcce25 MT |
88 | int part_boot_idx; |
89 | ||
90 | int filesystem; | |
91 | ||
92 | unsigned long long size; | |
48d6a112 | 93 | unsigned long long size_bootldr; |
25fcce25 MT |
94 | unsigned long long size_boot; |
95 | unsigned long long size_swap; | |
96 | unsigned long long size_root; | |
d7dd283b MT |
97 | }; |
98 | ||
f0fa1795 MT |
99 | struct hw* hw_init(); |
100 | void hw_free(struct hw* hw); | |
101 | ||
25fcce25 | 102 | int hw_mount(const char* source, const char* target, const char* fs, int flags); |
f0fa1795 MT |
103 | int hw_umount(const char* target); |
104 | ||
105 | char* hw_find_source_medium(struct hw* hw); | |
106 | ||
ee00d203 | 107 | struct hw_disk** hw_find_disks(struct hw* hw, const char* sourcedrive); |
d7dd283b | 108 | void hw_free_disks(struct hw_disk** disks); |
335c5bd1 | 109 | unsigned int hw_count_disks(const struct hw_disk** disks); |
d7dd283b | 110 | struct hw_disk** hw_select_disks(struct hw_disk** disks, int* selection); |
a3e135c8 | 111 | struct hw_disk** hw_select_first_disk(const struct hw_disk** disks); |
d7dd283b | 112 | |
a8fca245 MT |
113 | struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks, |
114 | int disable_swap); | |
25fcce25 | 115 | |
c4e96674 MT |
116 | unsigned long long hw_memory(); |
117 | ||
46b56e20 MT |
118 | int hw_create_partitions(struct hw_destination* dest, const char* output); |
119 | int hw_create_filesystems(struct hw_destination* dest, const char* output); | |
25fcce25 MT |
120 | |
121 | int hw_mount_filesystems(struct hw_destination* dest, const char* prefix); | |
122 | int hw_umount_filesystems(struct hw_destination* dest, const char* prefix); | |
123 | ||
d78fffa0 | 124 | int hw_destroy_raid_superblocks(const struct hw_destination* dest, const char* output); |
46b56e20 MT |
125 | int hw_setup_raid(struct hw_destination* dest, const char* output); |
126 | int hw_stop_all_raid_arrays(const char* output); | |
4a0d9bef | 127 | |
46b56e20 | 128 | int hw_install_bootloader(struct hw_destination* dest, const char* output); |
7f69d8a4 | 129 | int hw_write_fstab(struct hw_destination* dest); |
f5007e9c | 130 | |
38c6822d MT |
131 | char* hw_find_backup_file(const char* output, const char* search_path); |
132 | int hw_restore_backup(const char* output, const char* backup_path, const char* destination); | |
133 | ||
335c5bd1 MT |
134 | int hw_start_networking(const char* output); |
135 | ||
282ec35e MT |
136 | void hw_sync(); |
137 | ||
f0fa1795 | 138 | #endif /* HEADER_HW_H */ |