2 * Copyright 2008, Rene Gollent, rene@gollent.com. All rights reserved.
3 * Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
4 * Distributed under the terms of the MIT License.
8 #include "load_driver_settings.h"
15 #include <drivers/driver_settings.h>
17 #include <safemode_defs.h>
19 #include <boot/driver_settings.h>
20 #include <boot/kernel_args.h>
21 #include <boot/stage2.h>
22 #include <boot/platform.h>
26 load_driver_settings_file(Directory
* directory
, const char* name
)
28 int fd
= open_from(directory
, name
, O_RDONLY
);
33 if (fstat(fd
, &stat
) < 0)
36 char* buffer
= (char*)kernel_args_malloc(stat
.st_size
+ 1);
40 if (read(fd
, buffer
, stat
.st_size
) != stat
.st_size
) {
41 kernel_args_free(buffer
);
45 driver_settings_file
* file
= (driver_settings_file
*)kernel_args_malloc(
46 sizeof(driver_settings_file
));
48 kernel_args_free(buffer
);
52 buffer
[stat
.st_size
] = '\0';
53 // null terminate the buffer
55 strlcpy(file
->name
, name
, sizeof(file
->name
));
56 file
->buffer
= buffer
;
57 file
->size
= stat
.st_size
;
60 file
->next
= gKernelArgs
.driver_settings
;
61 gKernelArgs
.driver_settings
= file
;
68 apply_boot_settings(void* kernelSettings
, void* safemodeSettings
)
70 #if B_HAIKU_PHYSICAL_BITS > 32
71 if ((kernelSettings
!= NULL
72 && get_driver_boolean_parameter(kernelSettings
,
73 B_SAFEMODE_4_GB_MEMORY_LIMIT
, false, false))
74 || (safemodeSettings
!= NULL
75 && get_driver_boolean_parameter(safemodeSettings
,
76 B_SAFEMODE_4_GB_MEMORY_LIMIT
, false, false))) {
77 ignore_physical_memory_ranges_beyond_4gb();
87 load_driver_settings(stage2_args
* /*args*/, Directory
* volume
)
89 int fd
= open_from(volume
, "home/config/settings/kernel/drivers", O_RDONLY
);
93 Directory
* settings
= (Directory
*)get_node_from(fd
);
95 return B_ENTRY_NOT_FOUND
;
98 if (settings
->Open(&cookie
, O_RDONLY
) == B_OK
) {
99 char name
[B_FILE_NAME_LENGTH
];
100 while (settings
->GetNextEntry(cookie
, name
, sizeof(name
)) == B_OK
) {
101 if (!strcmp(name
, ".") || !strcmp(name
, ".."))
104 status_t status
= load_driver_settings_file(settings
, name
);
106 dprintf("Could not load \"%s\" error %" B_PRIx32
"\n", name
, status
);
109 settings
->Close(cookie
);
117 add_stage2_driver_settings(stage2_args
* args
)
119 // TODO: split more intelligently
120 for (const char** arg
= args
->arguments
;
121 arg
!= NULL
&& args
->arguments_count
-- && arg
[0] != NULL
; arg
++) {
122 dprintf("adding args: '%s'\n", arg
[0]);
123 add_safe_mode_settings((char*)arg
[0]);
130 add_safe_mode_settings(const char* settings
)
132 if (settings
== NULL
|| settings
[0] == '\0')
135 size_t length
= strlen(settings
);
136 char* buffer
= (char*)kernel_args_malloc(length
+ 1);
140 driver_settings_file
* file
= (driver_settings_file
*)kernel_args_malloc(
141 sizeof(driver_settings_file
));
143 kernel_args_free(buffer
);
147 strlcpy(file
->name
, B_SAFEMODE_DRIVER_SETTINGS
, sizeof(file
->name
));
148 memcpy(buffer
, settings
, length
+ 1);
149 file
->buffer
= buffer
;
152 // add it to the list
153 file
->next
= gKernelArgs
.driver_settings
;
154 gKernelArgs
.driver_settings
= file
;
161 apply_boot_settings()
163 void* kernelSettings
= load_driver_settings("kernel");
164 void* safemodeSettings
= load_driver_settings(B_SAFEMODE_DRIVER_SETTINGS
);
166 apply_boot_settings(kernelSettings
, safemodeSettings
);
168 if (safemodeSettings
!= NULL
)
169 unload_driver_settings(safemodeSettings
);
171 unload_driver_settings(kernelSettings
);