forked from openSUSE/linuxrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rootimage.c
135 lines (106 loc) · 2.76 KB
/
rootimage.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
*
* rootimage.c Loading of rootimage
*
* Copyright (c) 1996-2002 Hubert Mantel, SuSE Linux AG (mantel@suse.de)
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
#include <ctype.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <endian.h>
#include <errno.h>
#include "global.h"
#include "util.h"
#include "dialog.h"
#include "window.h"
#include "display.h"
#include "rootimage.h"
#include "module.h"
#include "linuxrc.h"
#include "install.h"
#include "linux_fs.h"
static int root_check_root (char *root_string_tv);
/*
* Check if we still have enough free memory for 'size'. If not, ask user
* for more swap.
*
* size: in kbytes!
*
* return: 0 ok, -1 error
*/
int ask_for_swap(int64_t size, char *msg)
{
int i, j, did_init = 0;
char *partition = NULL;
char *argv[] = { NULL, NULL };
if(size >= 0 && config.memoryXXX.current >= config.memoryXXX.min_free + size) return 0;
if(!config.win) {
util_disp_init();
did_init = 1;
}
do {
j = inst_choose_partition(&partition, 1, "To continue, activate some swap space.", "Enter the swap partition (e.g., /dev/sda2)");
if(j == 0 && partition) {
argv[1] = long_dev(partition);
fprintf(stderr, "swapon %s\n", argv[1]);
i = util_swapon_main(2, argv);
if(i) {
dia_message("Error activating swap space.", MSGTYPE_ERROR);
j = 1;
}
}
util_free_mem();
}
while(j > 0);
str_copy(&partition, NULL);
if(did_init) util_disp_done();
return j;
}
int root_check_root(char *root_string_tv)
{
char buf[256];
int rc;
if(strstr(root_string_tv, "/dev/") == root_string_tv) {
root_string_tv += sizeof "/dev/" - 1;
}
sprintf(buf, "/dev/%s", root_string_tv);
if(util_mount_ro(buf, config.mountpoint.instdata, NULL)) return -1;
sprintf(buf, "%s/etc/passwd", config.mountpoint.instdata);
rc = util_check_exist(buf);
umount(config.mountpoint.instdata);
return rc == 'r' ? 0 : -1;
}
int root_boot_system()
{
int rc;
char *module, *type;
char buf[256], root[256];
do {
rc = inst_choose_partition(&config.device, 0, "Choose the root partition.", "Enter your root partition (e.g., /dev/sda3)");
if(rc || !config.device) return -1;
sprintf(root, "/dev/%s", config.device);
if((type = util_fstype(root, &module))) {
if(module && config.module.dir) {
sprintf(buf, "%s/%s" MODULE_SUFFIX, config.module.dir, module);
mod_modprobe(module, NULL);
}
}
if((rc = root_check_root(root))) {
dia_message("Invalid root device.", MSGTYPE_ERROR);
}
}
while(rc);
str_copy(&config.new_root, root);
return 0;
}