VM Preflet: Add an automatic swap option swap_auto
* Add swap_auto to the virtual memory settings file * Disable controls based on the context of what is enabled * hamishm gave permission to adjust his copyrights to Haiku, Inc.
This commit is contained in:
parent
749ab62820
commit
a9816d4372
@ -1,7 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2011, Hamish Morrison, hamish@lavabit.com
|
||||
* Copyright 2005, Axel Dörfler, axeld@pinc-software.de
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Hamish Morrison, hamish@lavabit.com
|
||||
* Alexander von Gluck, kallisti5@unixzen.com
|
||||
*/
|
||||
|
||||
|
||||
@ -27,6 +33,7 @@ static const off_t kMegaByte = 1024 * 1024;
|
||||
Settings::Settings()
|
||||
{
|
||||
fDefaultSettings.enabled = true;
|
||||
fDefaultSettings.automatic = true;
|
||||
|
||||
system_info sysInfo;
|
||||
get_system_info(&sysInfo);
|
||||
@ -44,6 +51,15 @@ Settings::SetSwapEnabled(bool enabled, bool revertable)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::SetSwapAutomatic(bool automatic, bool revertable)
|
||||
{
|
||||
fCurrentSettings.automatic = automatic;
|
||||
if (!revertable)
|
||||
fInitialSettings.automatic = automatic;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::SetSwapSize(off_t size, bool revertable)
|
||||
{
|
||||
@ -116,6 +132,8 @@ Settings::ReadSwapSettings()
|
||||
return kErrorSettingsNotFound;
|
||||
|
||||
const char* enabled = get_driver_parameter(settings, "vm", NULL, NULL);
|
||||
const char* automatic = get_driver_parameter(settings, "swap_auto",
|
||||
NULL, NULL);
|
||||
const char* size = get_driver_parameter(settings, "swap_size", NULL, NULL);
|
||||
const char* volume = get_driver_parameter(settings, "swap_volume_name",
|
||||
NULL, NULL);
|
||||
@ -126,14 +144,16 @@ Settings::ReadSwapSettings()
|
||||
const char* capacity = get_driver_parameter(settings,
|
||||
"swap_volume_capacity", NULL, NULL);
|
||||
|
||||
if (enabled == NULL || size == NULL || device == NULL || volume == NULL
|
||||
|| capacity == NULL || filesystem == NULL)
|
||||
if (enabled == NULL || automatic == NULL || size == NULL || device == NULL
|
||||
|| volume == NULL || capacity == NULL || filesystem == NULL)
|
||||
return kErrorSettingsInvalid;
|
||||
|
||||
off_t volCapacity = atoll(capacity);
|
||||
|
||||
SetSwapEnabled(get_driver_boolean_parameter(settings,
|
||||
"vm", false, false));
|
||||
"vm", true, false));
|
||||
SetSwapAutomatic(get_driver_boolean_parameter(settings,
|
||||
"swap_auto", true, false));
|
||||
SetSwapSize(atoll(size));
|
||||
unload_driver_settings(settings);
|
||||
|
||||
@ -193,11 +213,12 @@ Settings::WriteSwapSettings()
|
||||
fs_stat_dev(SwapVolume(), &info);
|
||||
|
||||
char buffer[1024];
|
||||
snprintf(buffer, sizeof(buffer), "vm %s\nswap_size %lld\n"
|
||||
snprintf(buffer, sizeof(buffer), "vm %s\nswap_auto %s\nswap_size %lld\n"
|
||||
"swap_volume_name %s\nswap_volume_device %s\n"
|
||||
"swap_volume_filesystem %s\nswap_volume_capacity %lld\n",
|
||||
SwapEnabled() ? "on" : "off", SwapSize(), info.volume_name,
|
||||
info.device_name, info.fsh_name, info.total_blocks * info.block_size);
|
||||
SwapEnabled() ? "on" : "off", SwapAutomatic() ? "yes" : "no",
|
||||
SwapSize(), info.volume_name, info.device_name, info.fsh_name,
|
||||
info.total_blocks * info.block_size);
|
||||
|
||||
file.Write(buffer, strlen(buffer));
|
||||
return B_OK;
|
||||
@ -208,6 +229,7 @@ bool
|
||||
Settings::IsRevertable()
|
||||
{
|
||||
return SwapEnabled() != fInitialSettings.enabled
|
||||
|| SwapAutomatic() != fInitialSettings.automatic
|
||||
|| SwapSize() != fInitialSettings.size
|
||||
|| SwapVolume() != fInitialSettings.volume;
|
||||
}
|
||||
@ -217,6 +239,7 @@ void
|
||||
Settings::RevertSwapSettings()
|
||||
{
|
||||
SetSwapEnabled(fInitialSettings.enabled);
|
||||
SetSwapAutomatic(fInitialSettings.automatic);
|
||||
SetSwapSize(fInitialSettings.size);
|
||||
SetSwapVolume(fInitialSettings.volume);
|
||||
}
|
||||
@ -226,6 +249,7 @@ bool
|
||||
Settings::IsDefaultable()
|
||||
{
|
||||
return SwapEnabled() != fDefaultSettings.enabled
|
||||
|| SwapAutomatic() != fDefaultSettings.automatic
|
||||
|| SwapSize() != fDefaultSettings.size
|
||||
|| SwapVolume() != fDefaultSettings.volume;
|
||||
}
|
||||
@ -235,6 +259,7 @@ void
|
||||
Settings::DefaultSwapSettings(bool revertable)
|
||||
{
|
||||
SetSwapEnabled(fDefaultSettings.enabled);
|
||||
SetSwapAutomatic(fDefaultSettings.automatic);
|
||||
SetSwapSize(fDefaultSettings.size);
|
||||
SetSwapVolume(fDefaultSettings.volume);
|
||||
if (!revertable)
|
||||
|
@ -1,7 +1,13 @@
|
||||
/*
|
||||
* Copyright 2011, Hamish Morrison, hamish@lavabit.com
|
||||
* Copyright 2005, Axel Dörfler, axeld@pinc-software.de
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Hamish Morrison, hamish@lavabit.com
|
||||
* Alexander von Gluck, kallisti5@unixzen.com
|
||||
*/
|
||||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
@ -18,19 +24,23 @@ static const int32 kErrorSettingsInvalid = B_ERRORS_END + 2;
|
||||
static const int32 kErrorVolumeNotFound = B_ERRORS_END + 3;
|
||||
|
||||
|
||||
|
||||
class Settings {
|
||||
public:
|
||||
Settings();
|
||||
|
||||
bool SwapEnabled() const
|
||||
{ return fCurrentSettings.enabled; }
|
||||
bool SwapAutomatic() const
|
||||
{ return fCurrentSettings.automatic; }
|
||||
off_t SwapSize() const { return fCurrentSettings.size; }
|
||||
dev_t SwapVolume() { return fCurrentSettings.volume; }
|
||||
BPoint WindowPosition() const { return fWindowPosition; }
|
||||
|
||||
|
||||
void SetSwapEnabled(bool enabled,
|
||||
bool revertable = true);
|
||||
void SetSwapAutomatic(bool automatic,
|
||||
bool revertable = true);
|
||||
void SetSwapSize(off_t size, bool revertable = true);
|
||||
void SetSwapVolume(dev_t volume,
|
||||
bool revertable = true);
|
||||
@ -49,6 +59,7 @@ public:
|
||||
private:
|
||||
struct SwapSettings {
|
||||
bool enabled;
|
||||
bool automatic;
|
||||
off_t size;
|
||||
dev_t volume;
|
||||
};
|
||||
|
@ -1,7 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2011, Hamish Morrison, hamish@lavabit.com
|
||||
* Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Hamish Morrison, hamish@lavabit.com
|
||||
* Alexander von Gluck, kallisti5@unixzen.com
|
||||
*/
|
||||
|
||||
|
||||
@ -41,6 +47,7 @@ static const uint32 kMsgDefaults = 'dflt';
|
||||
static const uint32 kMsgRevert = 'rvrt';
|
||||
static const uint32 kMsgSliderUpdate = 'slup';
|
||||
static const uint32 kMsgSwapEnabledUpdate = 'swen';
|
||||
static const uint32 kMsgSwapAutomaticUpdate = 'swat';
|
||||
static const uint32 kMsgVolumeSelected = 'vlsl';
|
||||
static const off_t kMegaByte = 1024 * 1024;
|
||||
static dev_t gBootDev = -1;
|
||||
@ -154,6 +161,11 @@ SettingsWindow::SettingsWindow()
|
||||
new BMessage(kMsgSwapEnabledUpdate));
|
||||
fSwapEnabledCheckBox->SetExplicitAlignment(align);
|
||||
|
||||
fSwapAutomaticCheckBox = new BCheckBox("auto swap",
|
||||
B_TRANSLATE("Choose swap size automatically"),
|
||||
new BMessage(kMsgSwapAutomaticUpdate));
|
||||
fSwapEnabledCheckBox->SetExplicitAlignment(align);
|
||||
|
||||
char sizeStr[16];
|
||||
system_info info;
|
||||
get_system_info(&info);
|
||||
@ -204,6 +216,7 @@ SettingsWindow::SettingsWindow()
|
||||
box->AddChild(BLayoutBuilder::Group<>(B_VERTICAL, B_USE_DEFAULT_SPACING)
|
||||
.Add(memoryView)
|
||||
.Add(swapFileView)
|
||||
.Add(fSwapAutomaticCheckBox)
|
||||
.Add(fVolumeMenuField)
|
||||
.Add(fSizeSlider)
|
||||
.Add(fWarningStringView)
|
||||
@ -331,6 +344,12 @@ SettingsWindow::MessageReceived(BMessage* message)
|
||||
_Update();
|
||||
break;
|
||||
}
|
||||
case kMsgSwapAutomaticUpdate:
|
||||
{
|
||||
fSettings.SetSwapAutomatic(fSwapAutomaticCheckBox->Value());
|
||||
_Update();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
@ -404,6 +423,7 @@ void
|
||||
SettingsWindow::_Update()
|
||||
{
|
||||
fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
|
||||
fSwapAutomaticCheckBox->SetValue(fSettings.SwapAutomatic());
|
||||
|
||||
VolumeMenuItem* item = _FindVolumeMenuItem(fSettings.SwapVolume());
|
||||
if (item != NULL) {
|
||||
@ -445,4 +465,14 @@ SettingsWindow::_Update()
|
||||
fWarningStringView->Hide();
|
||||
fRevertButton->SetEnabled(revertable);
|
||||
fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
|
||||
|
||||
// Automatic Swap depends on swap being enabled
|
||||
fSwapAutomaticCheckBox->SetEnabled(fSettings.SwapEnabled());
|
||||
|
||||
// Manual swap settings depend on enabled swap
|
||||
// and automatic swap being disabled
|
||||
fSizeSlider->SetEnabled(fSettings.SwapEnabled()
|
||||
&& !fSwapAutomaticCheckBox->Value());
|
||||
fVolumeMenuField->SetEnabled(fSettings.SwapEnabled()
|
||||
&& !fSwapAutomaticCheckBox->Value());
|
||||
}
|
||||
|
@ -1,7 +1,13 @@
|
||||
/*
|
||||
* Copyright 2011, Hamish Morrison, hamish@lavabit.com
|
||||
* Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Copyright 2010-2012 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Hamish Morrison, hamish@lavabit.com
|
||||
* Alexander von Gluck, kallisti5@unixzen.com
|
||||
*/
|
||||
#ifndef SETTINGS_WINDOW_H
|
||||
#define SETTINGS_WINDOW_H
|
||||
@ -66,6 +72,7 @@ private:
|
||||
void _Update();
|
||||
|
||||
BCheckBox* fSwapEnabledCheckBox;
|
||||
BCheckBox* fSwapAutomaticCheckBox;
|
||||
BSlider* fSizeSlider;
|
||||
BButton* fDefaultsButton;
|
||||
BButton* fRevertButton;
|
||||
|
Loading…
x
Reference in New Issue
Block a user