btrfs: add initial disk system add-on
Change-Id: I8f26a78770e679527a99b49a04557c1aa4334b53 Reviewed-on: https://review.haiku-os.org/c/1396 Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
committed by
Jérôme Duval
parent
25de7c1b12
commit
1712a3c957
@@ -102,7 +102,7 @@ if $(HAIKU_GCC_VERSION_$(architecture)[1]) = 2 {
|
||||
AddFilesToPackage servers : $(SYSTEM_SERVERS) ;
|
||||
|
||||
# apps
|
||||
AddFilesToPackage : runtime_loader Deskbar Tracker ;
|
||||
AddFilesToPackage : runtime_loader Deskbar Tracker ;
|
||||
AddFilesToPackage bin : $(SYSTEM_BIN) consoled ;
|
||||
AddFilesToPackage apps : $(SYSTEM_APPS) ;
|
||||
AddFilesToPackage preferences : $(SYSTEM_PREFERENCES) ;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
SubDir HAIKU_TOP src add-ons disk_systems ;
|
||||
|
||||
SubInclude HAIKU_TOP src add-ons disk_systems bfs ;
|
||||
SubInclude HAIKU_TOP src add-ons disk_systems btrfs ;
|
||||
SubInclude HAIKU_TOP src add-ons disk_systems fat ;
|
||||
SubInclude HAIKU_TOP src add-ons disk_systems gpt ;
|
||||
SubInclude HAIKU_TOP src add-ons disk_systems intel ;
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold, [email protected].
|
||||
* Copyright 2008-2012, Axel Dörfler, [email protected].
|
||||
* Copyright 2012, Gerasim Troeglazov (3dEyes**), [email protected]
|
||||
* Copyright 2019, Les De Ridder, [email protected]
|
||||
*
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "BTRFSAddOn.h"
|
||||
#include "InitializeParameterEditor.h"
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <Directory.h>
|
||||
#include <List.h>
|
||||
#include <Path.h>
|
||||
#include <Volume.h>
|
||||
|
||||
#include <DiskDeviceTypes.h>
|
||||
#include <MutablePartition.h>
|
||||
|
||||
#include <AutoDeleter.h>
|
||||
#include <StringForSize.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <debug.h>
|
||||
|
||||
#include "btrfs.h"
|
||||
#include "btrfs_disk_system.h"
|
||||
|
||||
#ifdef ASSERT
|
||||
# undef ASSERT
|
||||
#endif
|
||||
|
||||
|
||||
using std::nothrow;
|
||||
|
||||
static const uint32 kDiskSystemFlags =
|
||||
0
|
||||
| B_DISK_SYSTEM_SUPPORTS_INITIALIZING
|
||||
| B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME
|
||||
// | B_DISK_SYSTEM_SUPPORTS_CHECKING
|
||||
// | B_DISK_SYSTEM_SUPPORTS_REPAIRING
|
||||
// | B_DISK_SYSTEM_SUPPORTS_CHECKING_WHILE_MOUNTED
|
||||
// | B_DISK_SYSTEM_SUPPORTS_REPAIRING_WHILE_MOUNTED
|
||||
// | B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING
|
||||
// | B_DISK_SYSTEM_SUPPORTS_DEFRAGMENTING_WHILE_MOUNTED
|
||||
;
|
||||
|
||||
//#define TRACE_BTRFS_ADD_ON
|
||||
#undef TRACE
|
||||
#ifdef TRACE_BTRFS_ADD_ON
|
||||
# define TRACE(x...) printf(x)
|
||||
#else
|
||||
# define TRACE(x...) do {} while (false)
|
||||
#endif
|
||||
|
||||
BTRFSAddOn::BTRFSAddOn()
|
||||
: BDiskSystemAddOn(kPartitionTypeBTRFS, kDiskSystemFlags)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BTRFSAddOn::~BTRFSAddOn()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BTRFSAddOn::CreatePartitionHandle(BMutablePartition* partition,
|
||||
BPartitionHandle** _handle)
|
||||
{
|
||||
BTRFSPartitionHandle* handle = new(nothrow) BTRFSPartitionHandle(partition);
|
||||
if (!handle)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
status_t error = handle->Init();
|
||||
if (error != B_OK) {
|
||||
delete handle;
|
||||
return error;
|
||||
}
|
||||
|
||||
*_handle = handle;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BTRFSAddOn::CanInitialize(const BMutablePartition* partition)
|
||||
{
|
||||
// We can initialize if the partition is large enough.
|
||||
|
||||
//TODO(lesderid): Check min size
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BTRFSAddOn::ValidateInitialize(const BMutablePartition* partition,
|
||||
BString* name, const char* parameterString)
|
||||
{
|
||||
if (!CanInitialize(partition) || !name)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// truncate, if it is too long
|
||||
if (name->Length() >= BTRFS_LABEL_SIZE)
|
||||
name->Truncate(BTRFS_LABEL_SIZE - 1);
|
||||
|
||||
// replace '/' and '\\' by '-'
|
||||
name->ReplaceAll('/', '-');
|
||||
name->ReplaceAll('\\', '-');
|
||||
|
||||
// check parameters
|
||||
initialize_parameters parameters;
|
||||
status_t error = parse_initialize_parameters(parameterString, parameters);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BTRFSAddOn::Initialize(BMutablePartition* partition, const char* name,
|
||||
const char* parameterString, BPartitionHandle** _handle)
|
||||
{
|
||||
if (!CanInitialize(partition) || check_volume_name(name) != B_OK)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
initialize_parameters parameters;
|
||||
status_t error = parse_initialize_parameters(parameterString, parameters);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
BTRFSPartitionHandle* handle = new(nothrow) BTRFSPartitionHandle(partition);
|
||||
if (!handle)
|
||||
return B_NO_MEMORY;
|
||||
ObjectDeleter<BTRFSPartitionHandle> handleDeleter(handle);
|
||||
|
||||
error = partition->SetContentType(Name());
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
partition->SetContentName(name);
|
||||
partition->SetContentParameters(parameterString);
|
||||
uint32 blockSize = parameters.blockSize;
|
||||
partition->SetBlockSize(blockSize);
|
||||
partition->SetContentSize(partition->Size() / blockSize * blockSize);
|
||||
partition->Changed(B_PARTITION_CHANGED_INITIALIZATION);
|
||||
|
||||
*_handle = handleDeleter.Detach();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BTRFSAddOn::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type,
|
||||
BPartitionParameterEditor** editor)
|
||||
{
|
||||
*editor = NULL;
|
||||
if (type == B_INITIALIZE_PARAMETER_EDITOR) {
|
||||
try {
|
||||
*editor = new InitializeBTRFSEditor();
|
||||
} catch (std::bad_alloc&) {
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
BTRFSPartitionHandle::BTRFSPartitionHandle(BMutablePartition* partition)
|
||||
: BPartitionHandle(partition)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BTRFSPartitionHandle::~BTRFSPartitionHandle()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BTRFSPartitionHandle::Init()
|
||||
{
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
BTRFSPartitionHandle::SupportedOperations(uint32 mask)
|
||||
{
|
||||
return kDiskSystemFlags & mask;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BTRFSPartitionHandle::Repair(bool checkOnly)
|
||||
{
|
||||
TRACE("BTRFSPartitionHandle::Repair(checkOnly=%d)\n", checkOnly);
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
get_disk_system_add_ons(BList* addOns)
|
||||
{
|
||||
BTRFSAddOn* addOn = new(nothrow) BTRFSAddOn;
|
||||
if (!addOn) {
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
if (!addOns->AddItem(addOn)) {
|
||||
delete addOn;
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold, [email protected].
|
||||
* Copyright 2019, Les De Ridder, [email protected]
|
||||
*
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef _BTRFS_ADD_ON_H
|
||||
#define _BTRFS_ADD_ON_H
|
||||
|
||||
#include <DiskSystemAddOn.h>
|
||||
|
||||
class BTRFSAddOn : public BDiskSystemAddOn {
|
||||
public:
|
||||
BTRFSAddOn();
|
||||
virtual ~BTRFSAddOn();
|
||||
|
||||
virtual status_t CreatePartitionHandle(
|
||||
BMutablePartition* partition,
|
||||
BPartitionHandle** handle);
|
||||
virtual status_t GetParameterEditor(
|
||||
B_PARAMETER_EDITOR_TYPE type,
|
||||
BPartitionParameterEditor** editor);
|
||||
|
||||
virtual bool CanInitialize(
|
||||
const BMutablePartition* partition);
|
||||
virtual status_t ValidateInitialize(
|
||||
const BMutablePartition* partition,
|
||||
BString* name, const char* parameters);
|
||||
virtual status_t Initialize(BMutablePartition* partition,
|
||||
const char* name, const char* parameters,
|
||||
BPartitionHandle** handle);
|
||||
};
|
||||
|
||||
|
||||
class BTRFSPartitionHandle : public BPartitionHandle {
|
||||
public:
|
||||
BTRFSPartitionHandle(
|
||||
BMutablePartition* partition);
|
||||
~BTRFSPartitionHandle();
|
||||
|
||||
status_t Init();
|
||||
|
||||
virtual uint32 SupportedOperations(uint32 mask);
|
||||
|
||||
virtual status_t Repair(bool checkOnly);
|
||||
};
|
||||
|
||||
|
||||
#endif // _BTRFS_ADD_ON_H
|
||||
@@ -0,0 +1,11 @@
|
||||
resource app_signature "application/x-vnd.Haiku-BTRFSDiskAddOn";
|
||||
|
||||
resource app_version {
|
||||
major = 1,
|
||||
middle = 0,
|
||||
minor = 0,
|
||||
variety = 0,
|
||||
internal = 0,
|
||||
short_info = "1.0.0",
|
||||
long_info = "btrfs disk add-on."
|
||||
};
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2013, Axel Dörfler, [email protected].
|
||||
* Copyright 2009-2010, Stephan Aßmus <[email protected]>
|
||||
* Copyright 2009, Bryce Groff, [email protected].
|
||||
* Copyright 2019, Les De Ridder, [email protected]
|
||||
*
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "InitializeParameterEditor.h"
|
||||
|
||||
#include <Button.h>
|
||||
#include <Catalog.h>
|
||||
#include <ControlLook.h>
|
||||
#include <GridLayoutBuilder.h>
|
||||
#include <Partition.h>
|
||||
#include <SpaceLayoutItem.h>
|
||||
#include <TextControl.h>
|
||||
#include <Variant.h>
|
||||
#include <View.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "btrfs.h"
|
||||
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
#define B_TRANSLATION_CONTEXT "BTRFS_Initialize_Parameter"
|
||||
|
||||
|
||||
static uint32 MSG_NAME_CHANGED = 'nmch';
|
||||
|
||||
|
||||
InitializeBTRFSEditor::InitializeBTRFSEditor()
|
||||
:
|
||||
BPartitionParameterEditor(),
|
||||
fView(NULL),
|
||||
fNameControl(NULL),
|
||||
fParameters(NULL)
|
||||
{
|
||||
_CreateViewControls();
|
||||
}
|
||||
|
||||
|
||||
InitializeBTRFSEditor::~InitializeBTRFSEditor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InitializeBTRFSEditor::SetTo(BPartition* partition)
|
||||
{
|
||||
BString name = partition->Name();
|
||||
if (name.IsEmpty())
|
||||
name = partition->ContentName();
|
||||
if (!name.IsEmpty())
|
||||
fNameControl->SetText(name.String());
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
InitializeBTRFSEditor::View()
|
||||
{
|
||||
return fView;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
InitializeBTRFSEditor::ValidateParameters() const
|
||||
{
|
||||
// The name must be set
|
||||
return fNameControl->TextView()->TextLength() > 0;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
InitializeBTRFSEditor::ParameterChanged(const char* name,
|
||||
const BVariant& variant)
|
||||
{
|
||||
if (!strcmp(name, "name"))
|
||||
fNameControl->SetText(variant.ToString());
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
InitializeBTRFSEditor::GetParameters(BString& parameters)
|
||||
{
|
||||
parameters = "name \"";
|
||||
parameters << fNameControl->Text() << "\";\n";
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InitializeBTRFSEditor::_CreateViewControls()
|
||||
{
|
||||
fNameControl = new BTextControl(B_TRANSLATE("Name:"), "New Btrfs Volume",
|
||||
NULL);
|
||||
fNameControl->SetModificationMessage(new BMessage(MSG_NAME_CHANGED));
|
||||
fNameControl->TextView()->SetMaxBytes(BTRFS_LABEL_SIZE);
|
||||
|
||||
// TODO(lesderid): Controls for block size, sector size, uuid, etc.
|
||||
|
||||
float spacing = be_control_look->DefaultItemSpacing();
|
||||
|
||||
fView = BGridLayoutBuilder(spacing, spacing)
|
||||
.Add(fNameControl->CreateLabelLayoutItem(), 0, 0)
|
||||
.Add(fNameControl->CreateTextViewLayoutItem(), 1, 0).View()
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2013, Axel Dörfler, [email protected].
|
||||
* Copyright 2009-2010, Stephan Aßmus <[email protected]>
|
||||
* Copyright 2009, Bryce Groff, [email protected].
|
||||
* Copyright 2019, Les De Ridder, [email protected]
|
||||
*
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _INITIALIZE_PARAMETER_EDITOR
|
||||
#define _INITIALIZE_PARAMETER_EDITOR
|
||||
|
||||
|
||||
#include <PartitionParameterEditor.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class BCheckBox;
|
||||
class BMenuField;
|
||||
class BTextControl;
|
||||
class BView;
|
||||
|
||||
|
||||
class InitializeBTRFSEditor : public BPartitionParameterEditor {
|
||||
public:
|
||||
InitializeBTRFSEditor();
|
||||
virtual ~InitializeBTRFSEditor();
|
||||
|
||||
virtual void SetTo(BPartition* partition);
|
||||
|
||||
virtual bool ValidateParameters() const;
|
||||
virtual status_t ParameterChanged(const char* name,
|
||||
const BVariant& variant);
|
||||
|
||||
virtual BView* View();
|
||||
|
||||
virtual status_t GetParameters(BString& parameters);
|
||||
|
||||
private:
|
||||
void _CreateViewControls();
|
||||
|
||||
private:
|
||||
BView* fView;
|
||||
BTextControl* fNameControl;
|
||||
|
||||
BString fParameters;
|
||||
};
|
||||
|
||||
|
||||
#endif //_INITIALIZE_PARAMETER_EDITOR
|
||||
@@ -0,0 +1,29 @@
|
||||
SubDir HAIKU_TOP src add-ons disk_systems btrfs ;
|
||||
|
||||
UsePrivateKernelHeaders ;
|
||||
UsePrivateHeaders shared storage ;
|
||||
UseBuildFeatureHeaders zlib ;
|
||||
|
||||
Includes [ FGristFiles BTRFSAddOn.cpp ]
|
||||
: [ BuildFeatureAttribute zlib : headers ] ;
|
||||
|
||||
UseHeaders [ FDirName $(HAIKU_TOP) src libs uuid ] : true ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems btrfs ] ;
|
||||
|
||||
AddResources <disk_system>btrfs : BTRFSAddOn.rdef ;
|
||||
|
||||
Addon <disk_system>btrfs :
|
||||
BTRFSAddOn.cpp
|
||||
InitializeParameterEditor.cpp
|
||||
|
||||
btrfs_disk_system.cpp
|
||||
|
||||
: be localestub [ TargetLibsupc++ ] shared
|
||||
;
|
||||
|
||||
DoCatalogs <disk_system>btrfs :
|
||||
x-vnd.Haiku-BTRFSDiskAddOn
|
||||
:
|
||||
InitializeParameterEditor.cpp
|
||||
;
|
||||
Reference in New Issue
Block a user