* Copyright 2003-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <KernelExport.h>
#include <util/kernel_cpp.h>
#include "ddm_userland_interface.h"
#include "KDiskDeviceManager.h"
#include "KDiskDeviceUtils.h"
#include "KDiskSystem.h"
#ifdef TRACE_KDISK_SYSTEM
# define TRACE(x...) dprintf(x)
#else
# define TRACE(x...) do { } while (false)
#endif
KDiskSystem::KDiskSystem(const char *name)
: fID(_NextID()),
fName(NULL),
fShortName(NULL),
fPrettyName(NULL),
fLoadCounter(0)
{
set_string(fName, name);
}
KDiskSystem::~KDiskSystem()
{
free(fName);
free(fShortName);
free(fPrettyName);
}
status_t
KDiskSystem::Init()
{
return fName ? B_OK : B_NO_MEMORY;
}
KDiskSystem::SetID(disk_system_id id)
{
fID = id;
}*/
disk_system_id
KDiskSystem::ID() const
{
return fID;
}
const char *
KDiskSystem::Name() const
{
return fName;
}
const char *
KDiskSystem::ShortName() const
{
return fShortName;
}
const char *
KDiskSystem::PrettyName() const
{
return fPrettyName;
}
uint32
KDiskSystem::Flags() const
{
return fFlags;
}
bool
KDiskSystem::IsFileSystem() const
{
return (fFlags & B_DISK_SYSTEM_IS_FILE_SYSTEM);
}
bool
KDiskSystem::IsPartitioningSystem() const
{
return !(fFlags & B_DISK_SYSTEM_IS_FILE_SYSTEM);
}
void
KDiskSystem::GetInfo(user_disk_system_info *info)
{
if (!info)
return;
info->id = ID();
strlcpy(info->name, Name(), sizeof(info->name));
strlcpy(info->short_name, ShortName(), sizeof(info->short_name));
strlcpy(info->pretty_name, PrettyName(), sizeof(info->pretty_name));
info->flags = Flags();
}
status_t
KDiskSystem::Load()
{
ManagerLocker locker(KDiskDeviceManager::Default());
TRACE("KDiskSystem::Load(): %s -> %ld\n", Name(), fLoadCounter + 1);
status_t error = B_OK;
if (fLoadCounter == 0)
error = LoadModule();
if (error == B_OK)
fLoadCounter++;
return error;
}
void
KDiskSystem::Unload()
{
ManagerLocker locker(KDiskDeviceManager::Default());
TRACE("KDiskSystem::Unload(): %s -> %ld\n", Name(), fLoadCounter - 1);
if (fLoadCounter > 0 && --fLoadCounter == 0)
UnloadModule();
}
bool
KDiskSystem::IsLoaded() const
{
ManagerLocker locker(KDiskDeviceManager::Default());
return (fLoadCounter > 0);
}
float
KDiskSystem::Identify(KPartition *partition, void **cookie)
{
return -1;
}
status_t
KDiskSystem::Scan(KPartition *partition, void *cookie)
{
return B_ERROR;
}
void
KDiskSystem::FreeIdentifyCookie(KPartition *partition, void *cookie)
{
}
void
KDiskSystem::FreeCookie(KPartition *partition)
{
}
void
KDiskSystem::FreeContentCookie(KPartition *partition)
{
}
status_t
KDiskSystem::Defragment(KPartition* partition, disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::Repair(KPartition* partition, bool checkOnly, disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::Resize(KPartition* partition, off_t size, disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::ResizeChild(KPartition* child, off_t size, disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::Move(KPartition* partition, off_t offset, disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::MoveChild(KPartition* child, off_t offset, disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::SetName(KPartition* partition, const char* name, disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::SetContentName(KPartition* partition, const char* name,
disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::SetType(KPartition* partition, const char *type, disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::SetParameters(KPartition* partition, const char* parameters,
disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::SetContentParameters(KPartition* partition,
const char* parameters, disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::Initialize(KPartition* partition, const char* name,
const char* parameters, disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::Uninitialize(KPartition* partition, disk_job_id job)
{
return B_NOT_SUPPORTED;
}
status_t
KDiskSystem::CreateChild(KPartition* partition, off_t offset, off_t size,
const char* type, const char* name, const char* parameters, disk_job_id job,
KPartition **child, partition_id childID)
{
return B_ERROR;
}
status_t
KDiskSystem::DeleteChild(KPartition* child, disk_job_id job)
{
return B_ERROR;
}
status_t
KDiskSystem::LoadModule()
{
return B_ERROR;
}
void
KDiskSystem::UnloadModule()
{
}
status_t
KDiskSystem::SetShortName(const char *name)
{
return set_string(fShortName, name);
}
status_t
KDiskSystem::SetPrettyName(const char *name)
{
return set_string(fPrettyName, name);
}
void
KDiskSystem::SetFlags(uint32 flags)
{
fFlags = flags;
}
int32
KDiskSystem::_NextID()
{
return atomic_add(&fNextID, 1);
}
int32 KDiskSystem::fNextID = 0;