The beginning of the implementation of the DiskDevice API. Basic iteration functionality is implemented, though not tested yet.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2659 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+137
-14
@@ -3,7 +3,12 @@
|
|||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <new.h>
|
||||||
|
|
||||||
#include <DiskDevice.h>
|
#include <DiskDevice.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Partition.h>
|
||||||
|
#include <Session.h>
|
||||||
|
|
||||||
/*! \class BDiskDevice
|
/*! \class BDiskDevice
|
||||||
\brief A BDiskDevice object represents a storage device.
|
\brief A BDiskDevice object represents a storage device.
|
||||||
@@ -13,7 +18,18 @@
|
|||||||
/*! \brief Creates an uninitialized BDiskDevice object.
|
/*! \brief Creates an uninitialized BDiskDevice object.
|
||||||
*/
|
*/
|
||||||
BDiskDevice::BDiskDevice()
|
BDiskDevice::BDiskDevice()
|
||||||
|
: fSessions(10, true),
|
||||||
|
fUniqueID(-1),
|
||||||
|
fChangeCounter(0),
|
||||||
|
fMediaStatus(B_ERROR),
|
||||||
|
fSize(0),
|
||||||
|
fBlockSize(0),
|
||||||
|
fType(0),
|
||||||
|
fReadOnly(false),
|
||||||
|
fRemovable(false)//,
|
||||||
|
// fIsFloppy(false)
|
||||||
{
|
{
|
||||||
|
fPath[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
@@ -23,6 +39,23 @@ BDiskDevice::~BDiskDevice()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unset
|
||||||
|
void
|
||||||
|
BDiskDevice::Unset()
|
||||||
|
{
|
||||||
|
fSessions.MakeEmpty();
|
||||||
|
fUniqueID = -1;
|
||||||
|
fChangeCounter = 0;
|
||||||
|
fMediaStatus = B_ERROR;
|
||||||
|
fSize = 0;
|
||||||
|
fBlockSize = 0;
|
||||||
|
fType = 0;
|
||||||
|
fReadOnly = false;
|
||||||
|
fRemovable = false;
|
||||||
|
// fIsFloppy = false;
|
||||||
|
fPath[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
// Size
|
// Size
|
||||||
/*! \brief Returns the size of the device.
|
/*! \brief Returns the size of the device.
|
||||||
\return The size of the device in bytes.
|
\return The size of the device in bytes.
|
||||||
@@ -30,7 +63,7 @@ BDiskDevice::~BDiskDevice()
|
|||||||
off_t
|
off_t
|
||||||
BDiskDevice::Size() const
|
BDiskDevice::Size() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockSize
|
// BlockSize
|
||||||
@@ -40,7 +73,7 @@ BDiskDevice::Size() const
|
|||||||
int32
|
int32
|
||||||
BDiskDevice::BlockSize() const
|
BDiskDevice::BlockSize() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fBlockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountSessions
|
// CountSessions
|
||||||
@@ -50,7 +83,7 @@ BDiskDevice::BlockSize() const
|
|||||||
int32
|
int32
|
||||||
BDiskDevice::CountSessions() const
|
BDiskDevice::CountSessions() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fSessions.CountItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SessionAt
|
// SessionAt
|
||||||
@@ -62,7 +95,7 @@ BDiskDevice::CountSessions() const
|
|||||||
BSession *
|
BSession *
|
||||||
BDiskDevice::SessionAt(int32 index) const
|
BDiskDevice::SessionAt(int32 index) const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return fSessions.ItemAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountPartitions
|
// CountPartitions
|
||||||
@@ -72,17 +105,20 @@ BDiskDevice::SessionAt(int32 index) const
|
|||||||
int32
|
int32
|
||||||
BDiskDevice::CountPartitions() const
|
BDiskDevice::CountPartitions() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
int32 count = 0;
|
||||||
|
for (int32 i = 0; BSession *session = SessionAt(i); i++)
|
||||||
|
count += session->CountPartitions();
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DevicePath
|
// Path
|
||||||
/*! \brief Returns the path to the device.
|
/*! \brief Returns the path to the device.
|
||||||
\return The path to the device.
|
\return The path to the device.
|
||||||
*/
|
*/
|
||||||
const char *
|
const char *
|
||||||
BDiskDevice::DevicePath() const
|
BDiskDevice::Path() const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return (fPath[0] != '\0' ? fPath : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetName
|
// GetName
|
||||||
@@ -102,6 +138,7 @@ BDiskDevice::DevicePath() const
|
|||||||
void
|
void
|
||||||
BDiskDevice::GetName(BString *name, bool includeBusID, bool includeLUN) const
|
BDiskDevice::GetName(BString *name, bool includeBusID, bool includeLUN) const
|
||||||
{
|
{
|
||||||
|
// not implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetName
|
// GetName
|
||||||
@@ -121,6 +158,7 @@ BDiskDevice::GetName(BString *name, bool includeBusID, bool includeLUN) const
|
|||||||
void
|
void
|
||||||
BDiskDevice::GetName(char *name, bool includeBusID, bool includeLUN) const
|
BDiskDevice::GetName(char *name, bool includeBusID, bool includeLUN) const
|
||||||
{
|
{
|
||||||
|
// not implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsReadOnly
|
// IsReadOnly
|
||||||
@@ -130,7 +168,7 @@ BDiskDevice::GetName(char *name, bool includeBusID, bool includeLUN) const
|
|||||||
bool
|
bool
|
||||||
BDiskDevice::IsReadOnly() const
|
BDiskDevice::IsReadOnly() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return fReadOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsRemovable
|
// IsRemovable
|
||||||
@@ -140,7 +178,7 @@ BDiskDevice::IsReadOnly() const
|
|||||||
bool
|
bool
|
||||||
BDiskDevice::IsRemovable() const
|
BDiskDevice::IsRemovable() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return fRemovable;
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasMedia
|
// HasMedia
|
||||||
@@ -150,7 +188,7 @@ BDiskDevice::IsRemovable() const
|
|||||||
bool
|
bool
|
||||||
BDiskDevice::HasMedia() const
|
BDiskDevice::HasMedia() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return (fMediaStatus == B_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsFloppy
|
// IsFloppy
|
||||||
@@ -160,7 +198,7 @@ BDiskDevice::HasMedia() const
|
|||||||
bool
|
bool
|
||||||
BDiskDevice::IsFloppy() const
|
BDiskDevice::IsFloppy() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return !strcmp(fPath, "/dev/disk/floppy/raw");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type
|
// Type
|
||||||
@@ -183,7 +221,7 @@ BDiskDevice::IsFloppy() const
|
|||||||
uint8
|
uint8
|
||||||
BDiskDevice::Type() const
|
BDiskDevice::Type() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// UniqueID
|
// UniqueID
|
||||||
@@ -199,7 +237,7 @@ BDiskDevice::Type() const
|
|||||||
int32
|
int32
|
||||||
BDiskDevice::UniqueID() const
|
BDiskDevice::UniqueID() const
|
||||||
{
|
{
|
||||||
return -1; // not implemented
|
return fUniqueID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eject
|
// Eject
|
||||||
@@ -311,3 +349,88 @@ BDiskDevice::operator=(const BDiskDevice &)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// find_string
|
||||||
|
static
|
||||||
|
status_t
|
||||||
|
find_string(BMessage *message, const char *name, char *buffer)
|
||||||
|
{
|
||||||
|
const char *str;
|
||||||
|
status_t error = message->FindString(name, &str);
|
||||||
|
if (error != B_OK)
|
||||||
|
strcpy(buffer, str);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// _Unarchive
|
||||||
|
status_t
|
||||||
|
BDiskDevice::_Unarchive(BMessage *archive)
|
||||||
|
{
|
||||||
|
Unset();
|
||||||
|
status_t error = (archive ? B_OK : B_BAD_VALUE);
|
||||||
|
if (error == B_OK) {
|
||||||
|
// ID and change counter
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("id", &fUniqueID);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("change_counter", &fChangeCounter);
|
||||||
|
// geometry
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt64("size", &fSize);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("block_size", &fBlockSize);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt8("type", (int8*)&fType);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindBool("removable", &fRemovable);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindBool("read_only", fReadOnly);
|
||||||
|
// if (error == B_OK)
|
||||||
|
// error = archive->FindBool("write_once", fGeometry.write_once);
|
||||||
|
// other data
|
||||||
|
if (error == B_OK)
|
||||||
|
error = find_string(archive, "path", fPath);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("media_status", &fMediaStatus);
|
||||||
|
// sessions
|
||||||
|
type_code fieldType;
|
||||||
|
int32 count = 0;
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->GetInfo("sessions", &fieldType, &count);
|
||||||
|
for (int32 i = 0; error == B_OK && i < count; i++) {
|
||||||
|
// get the archived session
|
||||||
|
BMessage sessionArchive;
|
||||||
|
error = archive->FindMessage("sessions", i, &sessionArchive);
|
||||||
|
// allocate a session object
|
||||||
|
BSession *session = NULL;
|
||||||
|
if (error == B_OK) {
|
||||||
|
session = new(nothrow) BSession;
|
||||||
|
if (!session)
|
||||||
|
error = B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
// unarchive the session
|
||||||
|
if (error == B_OK)
|
||||||
|
error = session->_Unarchive(&sessionArchive);
|
||||||
|
// add the session
|
||||||
|
if (error == B_OK && !_AddSession(session))
|
||||||
|
error = B_NO_MEMORY;
|
||||||
|
// cleanup on error
|
||||||
|
if (error != B_OK && session)
|
||||||
|
delete session;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// cleanup on error
|
||||||
|
if (error != B_OK)
|
||||||
|
Unset();
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// _AddSession
|
||||||
|
bool
|
||||||
|
BDiskDevice::_AddSession(BSession *session)
|
||||||
|
{
|
||||||
|
bool result = fSessions.AddItem(session);
|
||||||
|
if (result)
|
||||||
|
session->_SetDevice(this);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,14 @@
|
|||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <new.h>
|
||||||
|
|
||||||
#include <DiskDeviceRoster.h>
|
#include <DiskDeviceRoster.h>
|
||||||
|
#include <DiskDevice.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Partition.h>
|
||||||
|
#include <RegistrarDefs.h>
|
||||||
|
#include <Session.h>
|
||||||
|
|
||||||
/*! \class BDiskDeviceRoster
|
/*! \class BDiskDeviceRoster
|
||||||
\brief An interface for iterating through the disk devices known to the
|
\brief An interface for iterating through the disk devices known to the
|
||||||
@@ -17,7 +24,15 @@
|
|||||||
The object is ready to be used after construction.
|
The object is ready to be used after construction.
|
||||||
*/
|
*/
|
||||||
BDiskDeviceRoster::BDiskDeviceRoster()
|
BDiskDeviceRoster::BDiskDeviceRoster()
|
||||||
|
: fManager(),
|
||||||
|
fCookie(0)
|
||||||
{
|
{
|
||||||
|
BMessage request(B_REG_GET_DISK_DEVICE_MESSENGER);
|
||||||
|
BMessage reply;
|
||||||
|
if (_send_to_roster_(&request, &reply, false) == B_OK
|
||||||
|
&& reply.what == B_REG_SUCCESS) {
|
||||||
|
reply.FindMessenger("messenger", &fManager);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
@@ -40,7 +55,33 @@ BDiskDeviceRoster::~BDiskDeviceRoster()
|
|||||||
status_t
|
status_t
|
||||||
BDiskDeviceRoster::GetNextDevice(BDiskDevice *device)
|
BDiskDeviceRoster::GetNextDevice(BDiskDevice *device)
|
||||||
{
|
{
|
||||||
return B_ERROR; // not implemented
|
status_t error = (device ? B_OK : B_BAD_VALUE);
|
||||||
|
// compose request message
|
||||||
|
BMessage request(B_REG_NEXT_DISK_DEVICE);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = request.AddInt32("cookie", fCookie);
|
||||||
|
// send request
|
||||||
|
BMessage reply;
|
||||||
|
if (error == B_OK)
|
||||||
|
error = fManager.SendMessage(&request, &reply);
|
||||||
|
// analyze reply
|
||||||
|
if (error == B_OK) {
|
||||||
|
// result
|
||||||
|
status_t result = B_OK;
|
||||||
|
error = reply.FindInt32("result", &result);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = result;
|
||||||
|
// cookie
|
||||||
|
if (error == B_OK)
|
||||||
|
error = reply.FindInt32("cookie", &fCookie);
|
||||||
|
// device
|
||||||
|
BMessage archive;
|
||||||
|
if (error == B_OK)
|
||||||
|
error = reply.FindMessage("device", &archive);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = device->_Unarchive(&archive);
|
||||||
|
}
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewind
|
// Rewind
|
||||||
@@ -50,7 +91,8 @@ BDiskDeviceRoster::GetNextDevice(BDiskDevice *device)
|
|||||||
status_t
|
status_t
|
||||||
BDiskDeviceRoster::Rewind()
|
BDiskDeviceRoster::Rewind()
|
||||||
{
|
{
|
||||||
return B_ERROR; // not implemented
|
fCookie = 0;
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitEachDevice
|
// VisitEachDevice
|
||||||
|
|||||||
+159
-28
@@ -4,6 +4,11 @@
|
|||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include <Partition.h>
|
#include <Partition.h>
|
||||||
|
#include <DiskDevice.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Mime.h>
|
||||||
|
#include <Session.h>
|
||||||
|
#include <Volume.h>
|
||||||
|
|
||||||
/*! \class BPartition
|
/*! \class BPartition
|
||||||
\brief A BPartition object represent a partition and provides a lot of
|
\brief A BPartition object represent a partition and provides a lot of
|
||||||
@@ -15,6 +20,13 @@
|
|||||||
(\see IsEmpty()).
|
(\see IsEmpty()).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
/*! \brief Frees all resources associated with this object.
|
||||||
|
*/
|
||||||
|
BPartition::~BPartition()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// Session
|
// Session
|
||||||
/*! \brief Returns the session this partition resides on.
|
/*! \brief Returns the session this partition resides on.
|
||||||
\return The session this partition resides on.
|
\return The session this partition resides on.
|
||||||
@@ -22,7 +34,7 @@
|
|||||||
BSession *
|
BSession *
|
||||||
BPartition::Session() const
|
BPartition::Session() const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return fSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Device
|
// Device
|
||||||
@@ -32,7 +44,7 @@ BPartition::Session() const
|
|||||||
BDiskDevice *
|
BDiskDevice *
|
||||||
BPartition::Device() const
|
BPartition::Device() const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return (fSession ? fSession->Device() : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Offset
|
// Offset
|
||||||
@@ -44,7 +56,7 @@ BPartition::Device() const
|
|||||||
off_t
|
off_t
|
||||||
BPartition::Offset() const
|
BPartition::Offset() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fInfo.info.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size
|
// Size
|
||||||
@@ -54,7 +66,7 @@ BPartition::Offset() const
|
|||||||
off_t
|
off_t
|
||||||
BPartition::Size() const
|
BPartition::Size() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fInfo.info.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockSize
|
// BlockSize
|
||||||
@@ -64,7 +76,7 @@ BPartition::Size() const
|
|||||||
int32
|
int32
|
||||||
BPartition::BlockSize() const
|
BPartition::BlockSize() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return (fSession ? fSession->BlockSize() : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Index
|
// Index
|
||||||
@@ -75,7 +87,7 @@ BPartition::BlockSize() const
|
|||||||
int32
|
int32
|
||||||
BPartition::Index() const
|
BPartition::Index() const
|
||||||
{
|
{
|
||||||
return -1; // not implemented
|
return fIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flags
|
// Flags
|
||||||
@@ -95,7 +107,7 @@ BPartition::Index() const
|
|||||||
uint32
|
uint32
|
||||||
BPartition::Flags() const
|
BPartition::Flags() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fInfo.flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsHidden
|
// IsHidden
|
||||||
@@ -107,7 +119,7 @@ BPartition::Flags() const
|
|||||||
bool
|
bool
|
||||||
BPartition::IsHidden() const
|
BPartition::IsHidden() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return (fInfo.flags & B_HIDDEN_PARTITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsVirtual
|
// IsVirtual
|
||||||
@@ -119,7 +131,7 @@ BPartition::IsHidden() const
|
|||||||
bool
|
bool
|
||||||
BPartition::IsVirtual() const
|
BPartition::IsVirtual() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return (fInfo.flags & B_VIRTUAL_PARTITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEmpty
|
// IsEmpty
|
||||||
@@ -130,7 +142,7 @@ BPartition::IsVirtual() const
|
|||||||
bool
|
bool
|
||||||
BPartition::IsEmpty() const
|
BPartition::IsEmpty() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return (fInfo.flags & B_EMPTY_PARTITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainsFileSystem
|
// ContainsFileSystem
|
||||||
@@ -142,7 +154,7 @@ BPartition::IsEmpty() const
|
|||||||
bool
|
bool
|
||||||
BPartition::ContainsFileSystem() const
|
BPartition::ContainsFileSystem() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return (fInfo.file_system_short_name[0] != '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
@@ -157,7 +169,7 @@ BPartition::ContainsFileSystem() const
|
|||||||
const char *
|
const char *
|
||||||
BPartition::Name() const
|
BPartition::Name() const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return (fInfo.partition_name[0] != '\0' ? fInfo.partition_name : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type
|
// Type
|
||||||
@@ -167,7 +179,7 @@ BPartition::Name() const
|
|||||||
const char *
|
const char *
|
||||||
BPartition::Type() const
|
BPartition::Type() const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return fInfo.partition_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileSystemShortName
|
// FileSystemShortName
|
||||||
@@ -183,7 +195,7 @@ BPartition::Type() const
|
|||||||
const char *
|
const char *
|
||||||
BPartition::FileSystemShortName() const
|
BPartition::FileSystemShortName() const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return (ContainsFileSystem() ? fInfo.file_system_short_name : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileSystemLongName
|
// FileSystemLongName
|
||||||
@@ -199,7 +211,7 @@ BPartition::FileSystemShortName() const
|
|||||||
const char *
|
const char *
|
||||||
BPartition::FileSystemLongName() const
|
BPartition::FileSystemLongName() const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return (ContainsFileSystem() ? fInfo.file_system_long_name : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// VolumeName
|
// VolumeName
|
||||||
@@ -214,7 +226,7 @@ BPartition::FileSystemLongName() const
|
|||||||
const char *
|
const char *
|
||||||
BPartition::VolumeName() const
|
BPartition::VolumeName() const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return (ContainsFileSystem() ? fInfo.volume_name : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileSystemFlags
|
// FileSystemFlags
|
||||||
@@ -236,7 +248,7 @@ BPartition::VolumeName() const
|
|||||||
uint32
|
uint32
|
||||||
BPartition::FileSystemFlags() const
|
BPartition::FileSystemFlags() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fInfo.file_system_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsMounted
|
// IsMounted
|
||||||
@@ -246,7 +258,7 @@ BPartition::FileSystemFlags() const
|
|||||||
bool
|
bool
|
||||||
BPartition::IsMounted() const
|
BPartition::IsMounted() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return (fVolumeID >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UniqueID
|
// UniqueID
|
||||||
@@ -262,7 +274,7 @@ BPartition::IsMounted() const
|
|||||||
int32
|
int32
|
||||||
BPartition::UniqueID() const
|
BPartition::UniqueID() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fUniqueID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVolume
|
// GetVolume
|
||||||
@@ -278,7 +290,10 @@ BPartition::UniqueID() const
|
|||||||
status_t
|
status_t
|
||||||
BPartition::GetVolume(BVolume *volume) const
|
BPartition::GetVolume(BVolume *volume) const
|
||||||
{
|
{
|
||||||
return B_ERROR; // not implemented
|
status_t error = (volume ? B_OK : B_BAD_VALUE);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = volume->SetTo(fVolumeID);
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetIcon
|
// GetIcon
|
||||||
@@ -297,7 +312,25 @@ BPartition::GetVolume(BVolume *volume) const
|
|||||||
status_t
|
status_t
|
||||||
BPartition::GetIcon(BBitmap *icon, icon_size which) const
|
BPartition::GetIcon(BBitmap *icon, icon_size which) const
|
||||||
{
|
{
|
||||||
return B_ERROR; // not implemented
|
status_t error = (icon ? B_OK : B_BAD_VALUE);
|
||||||
|
if (error == B_OK) {
|
||||||
|
if (IsMounted()) {
|
||||||
|
// mounted: get the icon from the volume
|
||||||
|
BVolume volume;
|
||||||
|
error = GetVolume(&volume);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = volume.GetIcon(icon, which);
|
||||||
|
} else {
|
||||||
|
// not mounted: retrieve the icon ourselves
|
||||||
|
if (BDiskDevice *device = Device()) {
|
||||||
|
// get the icon
|
||||||
|
if (error == B_OK)
|
||||||
|
error = get_device_icon(device->Path(), icon, which);
|
||||||
|
} else
|
||||||
|
error = B_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mount
|
// Mount
|
||||||
@@ -438,7 +471,21 @@ BPartition::GetFileSystemList(BObjectList<BString> *list)
|
|||||||
/*! \brief Creates an uninitialized BPartition object.
|
/*! \brief Creates an uninitialized BPartition object.
|
||||||
*/
|
*/
|
||||||
BPartition::BPartition()
|
BPartition::BPartition()
|
||||||
|
: fSession(NULL),
|
||||||
|
fUniqueID(-1),
|
||||||
|
fChangeCounter(0),
|
||||||
|
fIndex(-1),
|
||||||
|
fVolumeID(-1)
|
||||||
{
|
{
|
||||||
|
fInfo.info.offset = 0;
|
||||||
|
fInfo.info.size = 0;
|
||||||
|
fInfo.flags = 0;
|
||||||
|
fInfo.partition_name[0] = '\0';
|
||||||
|
fInfo.partition_type[0] = '\0';
|
||||||
|
fInfo.file_system_short_name[0] = '\0';
|
||||||
|
fInfo.file_system_long_name[0] = '\0';
|
||||||
|
fInfo.volume_name[0] = '\0';
|
||||||
|
fInfo.file_system_flags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
@@ -448,13 +495,6 @@ BPartition::BPartition(const BPartition &)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
/*! \brief Frees all resources associated with this object.
|
|
||||||
*/
|
|
||||||
BPartition::~BPartition()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// =
|
// =
|
||||||
/*! \brief Privatized assignment operator to avoid usage.
|
/*! \brief Privatized assignment operator to avoid usage.
|
||||||
*/
|
*/
|
||||||
@@ -464,3 +504,94 @@ BPartition::operator=(const BPartition &)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _Unset
|
||||||
|
void
|
||||||
|
BPartition::_Unset()
|
||||||
|
{
|
||||||
|
fSession = NULL;
|
||||||
|
fUniqueID = -1;
|
||||||
|
fChangeCounter = 0;
|
||||||
|
fIndex = -1;
|
||||||
|
fInfo.info.offset = 0;
|
||||||
|
fInfo.info.size = 0;
|
||||||
|
fInfo.flags = 0;
|
||||||
|
fInfo.partition_name[0] = '\0';
|
||||||
|
fInfo.partition_type[0] = '\0';
|
||||||
|
fInfo.file_system_short_name[0] = '\0';
|
||||||
|
fInfo.file_system_long_name[0] = '\0';
|
||||||
|
fInfo.volume_name[0] = '\0';
|
||||||
|
fInfo.file_system_flags = 0;
|
||||||
|
fVolumeID = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find_string
|
||||||
|
static
|
||||||
|
status_t
|
||||||
|
find_string(BMessage *message, const char *name, char *buffer)
|
||||||
|
{
|
||||||
|
const char *str;
|
||||||
|
status_t error = message->FindString(name, &str);
|
||||||
|
if (error != B_OK)
|
||||||
|
strcpy(buffer, str);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// _Unarchive
|
||||||
|
status_t
|
||||||
|
BPartition::_Unarchive(BMessage *archive)
|
||||||
|
{
|
||||||
|
_Unset();
|
||||||
|
status_t error = (archive ? B_OK : B_BAD_VALUE);
|
||||||
|
if (error == B_OK) {
|
||||||
|
// ID, change counter and index
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("id", &fUniqueID);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("change_counter", &fChangeCounter);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("index", &fIndex);
|
||||||
|
// fInfo.info.*
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt64("offset", &fInfo.info.offset);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt64("size", &fInfo.info.size);
|
||||||
|
// fInfo.*
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("flags", (int32*)&fInfo.flags);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = find_string(archive, "name", fInfo.partition_name);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = find_string(archive, "type", fInfo.partition_type);
|
||||||
|
if (error == B_OK) {
|
||||||
|
error = find_string(archive, "fs_short_name",
|
||||||
|
fInfo.file_system_short_name);
|
||||||
|
}
|
||||||
|
if (error == B_OK) {
|
||||||
|
error = find_string(archive, "fs_long_name",
|
||||||
|
fInfo.file_system_long_name);
|
||||||
|
}
|
||||||
|
if (error == B_OK)
|
||||||
|
error = find_string(archive, "volume_name", fInfo.volume_name);
|
||||||
|
if (error == B_OK) {
|
||||||
|
error = archive->FindInt32("fs_flags",
|
||||||
|
(int32*)&fInfo.file_system_flags);
|
||||||
|
}
|
||||||
|
// dev_t, if mounted
|
||||||
|
if (error == B_OK) {
|
||||||
|
if (archive->FindInt32("volume_id", &fVolumeID) != B_OK)
|
||||||
|
fVolumeID = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// cleanup on error
|
||||||
|
if (error != B_OK)
|
||||||
|
_Unset();
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// _SetSession
|
||||||
|
void
|
||||||
|
BPartition::_SetSession(BSession *session)
|
||||||
|
{
|
||||||
|
fSession = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+134
-20
@@ -3,7 +3,12 @@
|
|||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <new.h>
|
||||||
|
|
||||||
#include <Session.h>
|
#include <Session.h>
|
||||||
|
#include <DiskDevice.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Partition.h>
|
||||||
|
|
||||||
/*! \class BSession
|
/*! \class BSession
|
||||||
\brief A BSession object represent a session and provides a lot of
|
\brief A BSession object represent a session and provides a lot of
|
||||||
@@ -19,6 +24,13 @@
|
|||||||
*/
|
*/
|
||||||
const char *B_INTEL_PARTITIONING = "intel";
|
const char *B_INTEL_PARTITIONING = "intel";
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
/*! \brief Frees all resources associated with this object.
|
||||||
|
*/
|
||||||
|
BSession::~BSession()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// Device
|
// Device
|
||||||
/*! \brief Returns the device this session resides on.
|
/*! \brief Returns the device this session resides on.
|
||||||
\return The device this session resides on.
|
\return The device this session resides on.
|
||||||
@@ -26,7 +38,7 @@ const char *B_INTEL_PARTITIONING = "intel";
|
|||||||
BDiskDevice *
|
BDiskDevice *
|
||||||
BSession::Device() const
|
BSession::Device() const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return fDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Offset
|
// Offset
|
||||||
@@ -38,7 +50,7 @@ BSession::Device() const
|
|||||||
off_t
|
off_t
|
||||||
BSession::Offset() const
|
BSession::Offset() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fInfo.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size
|
// Size
|
||||||
@@ -48,7 +60,17 @@ BSession::Offset() const
|
|||||||
off_t
|
off_t
|
||||||
BSession::Size() const
|
BSession::Size() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fInfo.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
// BlockSize
|
||||||
|
/*! \brief Returns the block size of the device.
|
||||||
|
\return The block size of the device in bytes.
|
||||||
|
*/
|
||||||
|
int32
|
||||||
|
BSession::BlockSize() const
|
||||||
|
{
|
||||||
|
return (fDevice ? fDevice->BlockSize() : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountPartitions
|
// CountPartitions
|
||||||
@@ -58,7 +80,7 @@ BSession::Size() const
|
|||||||
int32
|
int32
|
||||||
BSession::CountPartitions() const
|
BSession::CountPartitions() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fPartitions.CountItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
// PartitionAt
|
// PartitionAt
|
||||||
@@ -70,7 +92,7 @@ BSession::CountPartitions() const
|
|||||||
BPartition *
|
BPartition *
|
||||||
BSession::PartitionAt(int32 index) const
|
BSession::PartitionAt(int32 index) const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return fPartitions.ItemAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Index
|
// Index
|
||||||
@@ -80,7 +102,7 @@ BSession::PartitionAt(int32 index) const
|
|||||||
int32
|
int32
|
||||||
BSession::Index() const
|
BSession::Index() const
|
||||||
{
|
{
|
||||||
return -1; // not implemented
|
return fIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flags
|
// Flags
|
||||||
@@ -97,7 +119,7 @@ BSession::Index() const
|
|||||||
uint32
|
uint32
|
||||||
BSession::Flags() const
|
BSession::Flags() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fInfo.flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsAudio
|
// IsAudio
|
||||||
@@ -107,7 +129,7 @@ BSession::Flags() const
|
|||||||
bool
|
bool
|
||||||
BSession::IsAudio() const
|
BSession::IsAudio() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return !IsData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsData
|
// IsData
|
||||||
@@ -117,7 +139,7 @@ BSession::IsAudio() const
|
|||||||
bool
|
bool
|
||||||
BSession::IsData() const
|
BSession::IsData() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return (fInfo.flags & B_DATA_SESSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsVirtual
|
// IsVirtual
|
||||||
@@ -129,7 +151,7 @@ BSession::IsData() const
|
|||||||
bool
|
bool
|
||||||
BSession::IsVirtual() const
|
BSession::IsVirtual() const
|
||||||
{
|
{
|
||||||
return false; // not implemented
|
return (fInfo.flags & B_VIRTUAL_SESSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PartitioningSystem
|
// PartitioningSystem
|
||||||
@@ -144,7 +166,8 @@ BSession::IsVirtual() const
|
|||||||
const char *
|
const char *
|
||||||
BSession::PartitioningSystem() const
|
BSession::PartitioningSystem() const
|
||||||
{
|
{
|
||||||
return NULL; // not implemented
|
return (fPartitioningSystem.Length() > 0
|
||||||
|
? fPartitioningSystem.String() : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UniqueID
|
// UniqueID
|
||||||
@@ -160,7 +183,7 @@ BSession::PartitioningSystem() const
|
|||||||
int32
|
int32
|
||||||
BSession::UniqueID() const
|
BSession::UniqueID() const
|
||||||
{
|
{
|
||||||
return 0; // not implemented
|
return fUniqueID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitEachPartition
|
// VisitEachPartition
|
||||||
@@ -286,14 +309,16 @@ BSession::GetPartitioningSystemList(BObjectList<BString> *list)
|
|||||||
/*! \brief Creates an uninitialized BSession object.
|
/*! \brief Creates an uninitialized BSession object.
|
||||||
*/
|
*/
|
||||||
BSession::BSession()
|
BSession::BSession()
|
||||||
|
: fDevice(NULL),
|
||||||
|
fPartitions(10, true),
|
||||||
|
fUniqueID(-1),
|
||||||
|
fChangeCounter(0),
|
||||||
|
fIndex(-1),
|
||||||
|
fPartitioningSystem()
|
||||||
{
|
{
|
||||||
}
|
fInfo.offset = 0;
|
||||||
|
fInfo.size = 0;
|
||||||
// destructor
|
fInfo.flags = 0;
|
||||||
/*! \brief Frees all resources associated with this object.
|
|
||||||
*/
|
|
||||||
BSession::~BSession()
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy constructor
|
// copy constructor
|
||||||
@@ -309,6 +334,95 @@ BSession::BSession(const BSession &)
|
|||||||
BSession &
|
BSession &
|
||||||
BSession::operator=(const BSession &)
|
BSession::operator=(const BSession &)
|
||||||
{
|
{
|
||||||
return *this; // not implemented
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// _Unset
|
||||||
|
void
|
||||||
|
BSession::_Unset()
|
||||||
|
{
|
||||||
|
fDevice = NULL;
|
||||||
|
fPartitions.MakeEmpty();
|
||||||
|
fUniqueID = -1;
|
||||||
|
fChangeCounter = 0;
|
||||||
|
fIndex = -1;
|
||||||
|
fInfo.offset = 0;
|
||||||
|
fInfo.size = 0;
|
||||||
|
fInfo.flags = 0;
|
||||||
|
fPartitioningSystem.SetTo("");
|
||||||
|
}
|
||||||
|
|
||||||
|
// _Unarchive
|
||||||
|
status_t
|
||||||
|
BSession::_Unarchive(BMessage *archive)
|
||||||
|
{
|
||||||
|
_Unset();
|
||||||
|
status_t error = (archive ? B_OK : B_BAD_VALUE);
|
||||||
|
if (error == B_OK) {
|
||||||
|
// ID, change counter and index
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("id", &fUniqueID);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("change_counter", &fChangeCounter);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("index", &fIndex);
|
||||||
|
// fInfo.*
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt64("offset", &fInfo.offset);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt64("size", &fInfo.size);
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindInt32("flags", (int32*)&fInfo.flags);
|
||||||
|
// other data
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->FindString("partitioning", &fPartitioningSystem);
|
||||||
|
// partitions
|
||||||
|
type_code fieldType;
|
||||||
|
int32 count = 0;
|
||||||
|
if (error == B_OK)
|
||||||
|
error = archive->GetInfo("partitions", &fieldType, &count);
|
||||||
|
for (int32 i = 0; error == B_OK && i < count; i++) {
|
||||||
|
// get the archived partitions
|
||||||
|
BMessage partitionArchive;
|
||||||
|
error = archive->FindMessage("partitions", i, &partitionArchive);
|
||||||
|
// allocate a partition object
|
||||||
|
BPartition *partition = NULL;
|
||||||
|
if (error == B_OK) {
|
||||||
|
partition = new(nothrow) BPartition;
|
||||||
|
if (!partition)
|
||||||
|
error = B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
// unarchive the partition
|
||||||
|
if (error == B_OK)
|
||||||
|
error = partition->_Unarchive(&partitionArchive);
|
||||||
|
// add the partition
|
||||||
|
if (error == B_OK && !_AddPartition(partition))
|
||||||
|
error = B_NO_MEMORY;
|
||||||
|
// cleanup on error
|
||||||
|
if (error != B_OK && partition)
|
||||||
|
delete partition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// cleanup on error
|
||||||
|
if (error != B_OK)
|
||||||
|
_Unset();
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// _SetDevice
|
||||||
|
void
|
||||||
|
BSession::_SetDevice(BDiskDevice *device)
|
||||||
|
{
|
||||||
|
fDevice = device;
|
||||||
|
}
|
||||||
|
|
||||||
|
// _AddPartition
|
||||||
|
bool
|
||||||
|
BSession::_AddPartition(BPartition *partition)
|
||||||
|
{
|
||||||
|
bool result = fPartitions.AddItem(partition);
|
||||||
|
if (result)
|
||||||
|
partition->_SetSession(this);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user