NTFS: Added simple disk_system add-on for ntfs

This commit is contained in:
threedeyes 2012-11-03 13:00:22 +00:00
parent 04db9fefe3
commit e1f99aae59
8 changed files with 404 additions and 1 deletions

View File

@ -694,7 +694,7 @@ AddFilesToHaikuImage system add-ons Screen\ Savers
: $(SYSTEM_ADD_ONS_SCREENSAVERS) ;
AddFilesToHaikuImage system add-ons disk_systems
: <disk_system>intel <disk_system>bfs ;
: <disk_system>intel <disk_system>bfs <disk_system>ntfs ;
# decorators
AddDirectoryToHaikuImage home config add-ons decorators ;

View File

@ -2,3 +2,4 @@ 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 intel ;
SubInclude HAIKU_TOP src add-ons disk_systems ntfs ;

View File

@ -0,0 +1,97 @@
/*
* Copyright 2009-2010, Stephan Aßmus <superstippi@gmx.de>
* Copyright 2009, Bryce Groff, brycegroff@gmail.com.
* Distributed under the terms of the MIT License.
*/
#include <stdio.h>
#include "InitializeParameterEditor.h"
#include <Button.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <ControlLook.h>
#include <GridLayoutBuilder.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <PartitionParameterEditor.h>
#include <PopUpMenu.h>
#include <SpaceLayoutItem.h>
#include <TextControl.h>
#include <View.h>
#include <Window.h>
static uint32 MSG_NAME_CHANGED = 'nmch';
InitializeNTFSEditor::InitializeNTFSEditor()
:
BPartitionParameterEditor(),
fView(NULL),
fNameTC(NULL),
fParameters(NULL)
{
_CreateViewControls();
}
InitializeNTFSEditor::~InitializeNTFSEditor()
{
}
BView*
InitializeNTFSEditor::View()
{
return fView;
}
bool
InitializeNTFSEditor::FinishedEditing()
{
fParameters = "";
fParameters << "name \"" << fNameTC->Text() << "\";\n";
return true;
}
status_t
InitializeNTFSEditor::GetParameters(BString* parameters)
{
if (parameters == NULL)
return B_BAD_VALUE;
*parameters = fParameters;
return B_OK;
}
status_t
InitializeNTFSEditor::PartitionNameChanged(const char* name)
{
fNameTC->SetText(name);
return B_OK;
}
void
InitializeNTFSEditor::_CreateViewControls()
{
fNameTC = new BTextControl("Name:", "Haiku", NULL);
fNameTC->SetModificationMessage(new BMessage(MSG_NAME_CHANGED));
// TODO find out what is the max length for this specific FS partition name
fNameTC->TextView()->SetMaxBytes(31);
float spacing = be_control_look->DefaultItemSpacing();
fView = BGridLayoutBuilder(spacing, spacing)
// row 1
.Add(fNameTC->CreateLabelLayoutItem(), 0, 0)
.Add(fNameTC->CreateTextViewLayoutItem(), 1, 0).View()
;
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2009-2010, Stephan Aßmus <superstippi@gmx.de>
* Copyright 2009, Bryce Groff, brycegroff@gmail.com.
* 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 InitializeNTFSEditor : public BPartitionParameterEditor {
public:
InitializeNTFSEditor();
virtual ~InitializeNTFSEditor();
virtual bool FinishedEditing();
virtual BView* View();
virtual status_t GetParameters(BString* parameters);
virtual status_t PartitionNameChanged(const char* name);
private:
void _CreateViewControls();
BView* fView;
BTextControl* fNameTC;
BString fParameters;
};
#endif //_INITIALIZE_PARAMETER_EDITOR

View File

@ -0,0 +1,15 @@
SubDir HAIKU_TOP src add-ons disk_systems ntfs ;
UsePrivateKernelHeaders ;
UsePrivateHeaders shared storage ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems ntfs ] ;
AddResources <disk_system>ntfs : NTFSAddOn.rdef ;
Addon <disk_system>ntfs :
NTFSAddOn.cpp
InitializeParameterEditor.cpp
: be $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSUPC++) libshared.a
;

View File

@ -0,0 +1,182 @@
/*
* Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2008-2012, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2012, Gerasim Troeglazov (3dEyes**), 3dEyes@gmail.com
*
* Distributed under the terms of the MIT License.
*/
#include "NTFSAddOn.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 <debug.h>
#include <stdio.h>
#ifdef ASSERT
# undef ASSERT
#endif
using std::nothrow;
#define kPartitionTypeNTFS "NTFS File System"
static const uint32 kDiskSystemFlags =
0
| B_DISK_SYSTEM_SUPPORTS_INITIALIZING
| B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME
;
#define TRACE printf
NTFSAddOn::NTFSAddOn()
: BDiskSystemAddOn(kPartitionTypeNTFS, kDiskSystemFlags)
{
}
NTFSAddOn::~NTFSAddOn()
{
}
status_t
NTFSAddOn::CreatePartitionHandle(BMutablePartition* partition,
BPartitionHandle** _handle)
{
NTFSPartitionHandle* handle = new(nothrow) NTFSPartitionHandle(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
NTFSAddOn::CanInitialize(const BMutablePartition* partition)
{
return true;
}
status_t
NTFSAddOn::ValidateInitialize(const BMutablePartition* partition, BString* name,
const char* parameterString)
{
if (!CanInitialize(partition) || !name)
return B_BAD_VALUE;
if (name->Length() >= MAX_PATH)
name->Truncate(MAX_PATH - 1);
name->ReplaceAll('/', '-');
return B_OK;
}
status_t
NTFSAddOn::Initialize(BMutablePartition* partition, const char* name,
const char* parameterString, BPartitionHandle** _handle)
{
if (!CanInitialize(partition) || name == NULL)
return B_BAD_VALUE;
NTFSPartitionHandle* handle = new(nothrow) NTFSPartitionHandle(partition);
if (!handle)
return B_NO_MEMORY;
ObjectDeleter<NTFSPartitionHandle> handleDeleter(handle);
status_t error = partition->SetContentType(Name());
if (error != B_OK)
return error;
partition->SetContentName(name);
partition->SetContentParameters(parameterString);
uint32 blockSize = 4096;
partition->SetBlockSize(blockSize);
partition->SetContentSize(partition->Size() / blockSize * blockSize);
partition->Changed(B_PARTITION_CHANGED_INITIALIZATION);
*_handle = handleDeleter.Detach();
return B_OK;
}
status_t
NTFSAddOn::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type,
BPartitionParameterEditor** editor)
{
*editor = NULL;
if (type == B_INITIALIZE_PARAMETER_EDITOR) {
try {
*editor = new InitializeNTFSEditor();
} catch (std::bad_alloc) {
return B_NO_MEMORY;
}
return B_OK;
}
return B_NOT_SUPPORTED;
}
NTFSPartitionHandle::NTFSPartitionHandle(BMutablePartition* partition)
: BPartitionHandle(partition)
{
}
NTFSPartitionHandle::~NTFSPartitionHandle()
{
}
status_t
NTFSPartitionHandle::Init()
{
return B_OK;
}
uint32
NTFSPartitionHandle::SupportedOperations(uint32 mask)
{
return kDiskSystemFlags & mask;
}
status_t
get_disk_system_add_ons(BList* addOns)
{
NTFSAddOn* addOn = new(nothrow) NTFSAddOn;
if (!addOn)
return B_NO_MEMORY;
if (!addOns->AddItem(addOn)) {
delete addOn;
return B_NO_MEMORY;
}
return B_OK;
}

View File

@ -0,0 +1,53 @@
/*
* Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2008-2012, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2012, Gerasim Troeglazov (3dEyes**), 3dEyes@gmail.com
*
* Distributed under the terms of the MIT License.
*/
#ifndef _NTFS_ADD_ON_H
#define _NTFS_ADD_ON_H
#include <DiskSystemAddOn.h>
#ifndef MAX_PATH
#define MAX_PATH 1024
#endif
class NTFSAddOn : public BDiskSystemAddOn {
public:
NTFSAddOn();
virtual ~NTFSAddOn();
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 NTFSPartitionHandle : public BPartitionHandle {
public:
NTFSPartitionHandle(
BMutablePartition* partition);
~NTFSPartitionHandle();
status_t Init();
virtual uint32 SupportedOperations(uint32 mask);
};
#endif // _NTFS_ADD_ON_H

View File

@ -0,0 +1,15 @@
/*
* NTFSAddOn.rdef
*/
resource app_signature "application/x-vnd.Haiku-NTFSAddOn";
resource app_version {
major = 0,
middle = 0,
minor = 1,
variety = 0,
internal = 0,
short_info = "0.0.1",
long_info = "Haiku NTFS disk add-on."
};