* Cleanup, no functional change.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32683 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
03e8d9bdf3
commit
f8ebd1a328
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2008, Rene Gollent, rene@gollent.com. All rights reserved.
|
* Copyright 2008, Rene Gollent, rene@gollent.com. All rights reserved.
|
||||||
* Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
* Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -19,10 +19,11 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
static driver_settings_file *
|
static driver_settings_file*
|
||||||
find_driver_settings_file(const char *name)
|
find_driver_settings_file(const char* name)
|
||||||
{
|
{
|
||||||
for (driver_settings_file *file = gKernelArgs.driver_settings; file != NULL; file = file->next) {
|
for (driver_settings_file* file = gKernelArgs.driver_settings; file != NULL;
|
||||||
|
file = file->next) {
|
||||||
if (!strcmp(file->name, name))
|
if (!strcmp(file->name, name))
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
@ -32,7 +33,7 @@ find_driver_settings_file(const char *name)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
load_driver_settings_file(Directory *directory, const char *name)
|
load_driver_settings_file(Directory* directory, const char* name)
|
||||||
{
|
{
|
||||||
int fd = open_from(directory, name, O_RDONLY);
|
int fd = open_from(directory, name, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
@ -41,14 +42,15 @@ load_driver_settings_file(Directory *directory, const char *name)
|
|||||||
struct stat stat;
|
struct stat stat;
|
||||||
fstat(fd, &stat);
|
fstat(fd, &stat);
|
||||||
|
|
||||||
char *buffer = (char *)kernel_args_malloc(stat.st_size + 1);
|
char* buffer = (char*)kernel_args_malloc(stat.st_size + 1);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
if (read(fd, buffer, stat.st_size) != stat.st_size)
|
if (read(fd, buffer, stat.st_size) != stat.st_size)
|
||||||
return B_IO_ERROR;
|
return B_IO_ERROR;
|
||||||
|
|
||||||
driver_settings_file *file = (driver_settings_file *)kernel_args_malloc(sizeof(driver_settings_file));
|
driver_settings_file* file = (driver_settings_file*)kernel_args_malloc(
|
||||||
|
sizeof(driver_settings_file));
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
kernel_args_free(buffer);
|
kernel_args_free(buffer);
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@ -69,18 +71,21 @@ load_driver_settings_file(Directory *directory, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
load_driver_settings(stage2_args */*args*/, Directory *volume)
|
load_driver_settings(stage2_args* /*args*/, Directory* volume)
|
||||||
{
|
{
|
||||||
int fd = open_from(volume, "home/config/settings/kernel/drivers", O_RDONLY);
|
int fd = open_from(volume, "home/config/settings/kernel/drivers", O_RDONLY);
|
||||||
if (fd < B_OK)
|
if (fd < B_OK)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
Directory *settings = (Directory *)get_node_from(fd);
|
Directory* settings = (Directory*)get_node_from(fd);
|
||||||
if (settings == NULL)
|
if (settings == NULL)
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
void *cookie;
|
void* cookie;
|
||||||
if (settings->Open(&cookie, O_RDONLY) == B_OK) {
|
if (settings->Open(&cookie, O_RDONLY) == B_OK) {
|
||||||
char name[B_FILE_NAME_LENGTH];
|
char name[B_FILE_NAME_LENGTH];
|
||||||
while (settings->GetNextEntry(cookie, name, sizeof(name)) == B_OK) {
|
while (settings->GetNextEntry(cookie, name, sizeof(name)) == B_OK) {
|
||||||
@ -95,35 +100,32 @@ load_driver_settings(stage2_args */*args*/, Directory *volume)
|
|||||||
settings->Close(cookie);
|
settings->Close(cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if a kernel settings file exists
|
// Check if a kernel settings file exists
|
||||||
// if it does, prepend it to the safe mode settings. This allows the
|
// if it does, prepend it to the safe mode settings. This allows the
|
||||||
// settings from the kernel file to take effect while still allowing
|
// settings from the kernel file to take effect while still allowing
|
||||||
// overrides by safe mode since the settings are searched
|
// overrides by safe mode since the settings are searched
|
||||||
// in reverse order. This allows us to permanently set things like
|
// in reverse order. This allows us to permanently set things like
|
||||||
// disable_smp
|
// disable_smp
|
||||||
driver_settings_file *kernelFile = find_driver_settings_file("kernel");
|
driver_settings_file* kernelFile = find_driver_settings_file("kernel");
|
||||||
if (kernelFile != NULL) {
|
if (kernelFile != NULL) {
|
||||||
driver_settings_file *safemodeFile =
|
driver_settings_file* safemodeFile
|
||||||
find_driver_settings_file(B_SAFEMODE_DRIVER_SETTINGS);
|
= find_driver_settings_file(B_SAFEMODE_DRIVER_SETTINGS);
|
||||||
if (safemodeFile != NULL) {
|
if (safemodeFile != NULL) {
|
||||||
char *buffer = (char *)kernel_args_malloc(
|
char* buffer = (char*)kernel_args_malloc(
|
||||||
safemodeFile->size + kernelFile->size + 2);
|
safemodeFile->size + kernelFile->size + 2);
|
||||||
if (buffer != NULL) {
|
if (buffer != NULL) {
|
||||||
memcpy(buffer, kernelFile->buffer,
|
memcpy(buffer, kernelFile->buffer, kernelFile->size);
|
||||||
kernelFile->size);
|
|
||||||
|
|
||||||
// insert a newline just in case the kernel settings file
|
// insert a newline just in case the kernel settings file
|
||||||
// doesn't end with one
|
// doesn't end with one
|
||||||
buffer[kernelFile->size] = '\n';
|
buffer[kernelFile->size] = '\n';
|
||||||
|
|
||||||
memcpy(buffer + kernelFile->size + 1,
|
memcpy(buffer + kernelFile->size + 1, safemodeFile->buffer,
|
||||||
safemodeFile->buffer,
|
|
||||||
safemodeFile->size);
|
safemodeFile->size);
|
||||||
|
|
||||||
kernel_args_free(safemodeFile->buffer);
|
kernel_args_free(safemodeFile->buffer);
|
||||||
safemodeFile->buffer = buffer;
|
safemodeFile->buffer = buffer;
|
||||||
safemodeFile->size = safemodeFile->size +
|
safemodeFile->size = safemodeFile->size + kernelFile->size + 1;
|
||||||
kernelFile->size + 1;
|
|
||||||
buffer[safemodeFile->size] = '\0';
|
buffer[safemodeFile->size] = '\0';
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@ -135,30 +137,31 @@ load_driver_settings(stage2_args */*args*/, Directory *volume)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
add_stage2_driver_settings(stage2_args *args)
|
add_stage2_driver_settings(stage2_args* args)
|
||||||
{
|
{
|
||||||
const char **p = args->arguments;
|
// TODO: split more intelligently
|
||||||
//TODO: split more intelligently
|
for (const char** arg = args->arguments;
|
||||||
for (; p && *p; p++) {
|
arg != NULL && arg[0] != NULL; arg++) {
|
||||||
dprintf("adding args: '%s'\n", *p);
|
dprintf("adding args: '%s'\n", arg[0]);
|
||||||
add_safe_mode_settings((char *)*p);
|
add_safe_mode_settings((char*)arg[0]);
|
||||||
}
|
}
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
add_safe_mode_settings(char *settings)
|
add_safe_mode_settings(char* settings)
|
||||||
{
|
{
|
||||||
if (settings == NULL || settings[0] == '\0')
|
if (settings == NULL || settings[0] == '\0')
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
size_t length = strlen(settings);
|
size_t length = strlen(settings);
|
||||||
char *buffer = (char *)kernel_args_malloc(length + 1);
|
char* buffer = (char*)kernel_args_malloc(length + 1);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
driver_settings_file *file = (driver_settings_file *)kernel_args_malloc(sizeof(driver_settings_file));
|
driver_settings_file* file = (driver_settings_file*)kernel_args_malloc(
|
||||||
|
sizeof(driver_settings_file));
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
kernel_args_free(buffer);
|
kernel_args_free(buffer);
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@ -175,4 +178,3 @@ add_safe_mode_settings(char *settings)
|
|||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user