* Style cleanup.
* Moved method documentation from headers to source files. * Removed test code. * Added TODOs where I spotted problems. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21717 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
|
||||
// constructor
|
||||
PartitionLocker::PartitionLocker(partition_id partitionID)
|
||||
: device_(NULL),
|
||||
partitionID_(partitionID)
|
||||
: fDevice(NULL),
|
||||
fPartitionID(partitionID)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -26,14 +26,14 @@ PartitionLocker::~PartitionLocker()
|
||||
bool
|
||||
PartitionLocker::IsLocked() const
|
||||
{
|
||||
return device_;
|
||||
return fDevice;
|
||||
}
|
||||
|
||||
// PartitionId
|
||||
partition_id
|
||||
PartitionLocker::PartitionId() const
|
||||
{
|
||||
return partitionID_;
|
||||
return fPartitionID;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ PartitionLocker::PartitionId() const
|
||||
PartitionReadLocker::PartitionReadLocker(partition_id partitionID)
|
||||
: PartitionLocker(partitionID)
|
||||
{
|
||||
device_ = read_lock_disk_device(partitionID);
|
||||
fDevice = read_lock_disk_device(partitionID);
|
||||
}
|
||||
|
||||
// destructor
|
||||
@@ -62,7 +62,7 @@ PartitionReadLocker::~PartitionReadLocker()
|
||||
PartitionWriteLocker::PartitionWriteLocker(partition_id partitionID)
|
||||
: PartitionLocker(partitionID)
|
||||
{
|
||||
device_ = write_lock_disk_device(partitionID);
|
||||
fDevice = write_lock_disk_device(partitionID);
|
||||
}
|
||||
|
||||
// destructor
|
||||
|
||||
@@ -17,42 +17,47 @@
|
||||
|
||||
#include <disk_device_manager.h>
|
||||
|
||||
|
||||
class PartitionLocker {
|
||||
public:
|
||||
PartitionLocker(partition_id partitionID);
|
||||
virtual ~PartitionLocker();
|
||||
~PartitionLocker();
|
||||
|
||||
bool IsLocked() const;
|
||||
partition_id PartitionId() const;
|
||||
|
||||
protected:
|
||||
const disk_device_data *device_;
|
||||
const disk_device_data *fDevice;
|
||||
|
||||
private:
|
||||
partition_id partitionID_;
|
||||
partition_id fPartitionID;
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
\brief Structure which locks given partition for reading.
|
||||
|
||||
When this structure is going to be destroyed, it automatically unlocks
|
||||
that partition.
|
||||
*/
|
||||
|
||||
class PartitionReadLocker : public PartitionLocker {
|
||||
public:
|
||||
PartitionReadLocker(partition_id partitionID);
|
||||
virtual ~PartitionReadLocker();
|
||||
~PartitionReadLocker();
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
\brief Structure which locks given partition for writing.
|
||||
|
||||
When this structure is going to be destroyed, it automatically unlocks
|
||||
that partition.
|
||||
*/
|
||||
|
||||
class PartitionWriteLocker : public PartitionLocker {
|
||||
public:
|
||||
PartitionWriteLocker(partition_id partitionID);
|
||||
virtual ~PartitionWriteLocker();
|
||||
~PartitionWriteLocker();
|
||||
};
|
||||
|
||||
#endif // _PARTITION_LOCKER_H
|
||||
|
||||
#endif // _PARTITION_LOCKER_H
|
||||
|
||||
@@ -183,62 +183,105 @@ is_inside_partitions(off_t location, const Partition **partitions, int32 count)
|
||||
|
||||
// constructor
|
||||
PartitionType::PartitionType()
|
||||
: type_(0),
|
||||
valid_(false)
|
||||
: fType(0),
|
||||
fValid(false)
|
||||
{
|
||||
}
|
||||
|
||||
// SetType
|
||||
/*!
|
||||
\brief Sets the \a type via its ID.
|
||||
\param type ID of the partition type, it is in the range [0..255].
|
||||
*/
|
||||
void
|
||||
PartitionType::SetType(uint8 type)
|
||||
{
|
||||
type_ = type;
|
||||
valid_ = partition_type_string(type);
|
||||
fType = type;
|
||||
fValid = partition_type_string(type);
|
||||
}
|
||||
|
||||
// SetType
|
||||
/*!
|
||||
\brief Sets the type via its string name.
|
||||
\param typeName Name of the partition type.
|
||||
*/
|
||||
void
|
||||
PartitionType::SetType(const char *type_name)
|
||||
PartitionType::SetType(const char *typeName)
|
||||
{
|
||||
for (int32 i = 0; kPartitionTypes[i].name ; i++) {
|
||||
if (!strcmp(type_name, kPartitionTypes[i].name)) {
|
||||
type_ = kPartitionTypes[i].type;
|
||||
valid_ = true;
|
||||
if (!strcmp(typeName, kPartitionTypes[i].name)) {
|
||||
fType = kPartitionTypes[i].type;
|
||||
fValid = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
valid_ = false;
|
||||
fValid = false;
|
||||
}
|
||||
|
||||
// SetContentType
|
||||
/*!
|
||||
\brief Converts content type to the partition type that fits best.
|
||||
\param content_type Name of the content type, it is standardized by system.
|
||||
*/
|
||||
void
|
||||
PartitionType::SetContentType(const char *content_type)
|
||||
PartitionType::SetContentType(const char *contentType)
|
||||
{
|
||||
for (int32 i = 0; kPartitionContentTypes[i].name ; i++) {
|
||||
if (!strcmp(content_type, kPartitionContentTypes[i].name)) {
|
||||
type_ = kPartitionContentTypes[i].type;
|
||||
valid_ = true;
|
||||
if (!strcmp(contentType, kPartitionContentTypes[i].name)) {
|
||||
fType = kPartitionContentTypes[i].type;
|
||||
fValid = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
valid_ = false;
|
||||
fValid = false;
|
||||
}
|
||||
|
||||
// FindNext
|
||||
/*!
|
||||
\brief Finds next supported partition.
|
||||
*/
|
||||
void
|
||||
PartitionType::FindNext()
|
||||
{
|
||||
for (int32 i = 0; kPartitionTypes[i].name; i++) {
|
||||
if (type_ < kPartitionTypes[i].type) {
|
||||
type_ = kPartitionTypes[i].type;
|
||||
valid_ = true;
|
||||
if (fType < kPartitionTypes[i].type) {
|
||||
fType = kPartitionTypes[i].type;
|
||||
fValid = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
valid_ = false;
|
||||
fValid = false;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool PartitionType::IsValid() const
|
||||
\brief Check whether the current type is valid.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool PartitionType::IsEmpty() const
|
||||
\brief Check whether the current type describes empty type.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool PartitionType::IsExtended() const
|
||||
\brief Check whether the current type describes extended partition type.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn uint8 PartitionType::Type() const
|
||||
\brief Returns ID of the current type.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void PartitionType::GetTypeString(char *buffer) const
|
||||
\brief Returns string name of the current type.
|
||||
\param buffer Buffer where the name is stored, has to be allocated with
|
||||
sufficient length.
|
||||
*/
|
||||
|
||||
|
||||
// #pragma mark - Partition
|
||||
|
||||
|
||||
|
||||
@@ -31,24 +31,21 @@
|
||||
|
||||
|
||||
// is_empty_type
|
||||
static inline
|
||||
bool
|
||||
static inline bool
|
||||
is_empty_type(uint8 type)
|
||||
{
|
||||
return (type == 0x00);
|
||||
}
|
||||
|
||||
// is_extended_type
|
||||
static inline
|
||||
bool
|
||||
static inline bool
|
||||
is_extended_type(uint8 type)
|
||||
{
|
||||
return (type == 0x05 || type == 0x0f || type == 0x85);
|
||||
}
|
||||
|
||||
// fill_buffer
|
||||
static inline
|
||||
void
|
||||
static inline void
|
||||
fill_buffer(char *buffer, uint32 length, char ch)
|
||||
{
|
||||
for (uint32 i = 0; i < length; i++)
|
||||
@@ -104,53 +101,21 @@ class PartitionType {
|
||||
public:
|
||||
PartitionType();
|
||||
|
||||
/*!
|
||||
\brief Sets the \a type via its ID.
|
||||
\param type ID of the partition type, it is in the range [0..255].
|
||||
*/
|
||||
void SetType(uint8 type);
|
||||
/*!
|
||||
\brief Sets the type via its string name.
|
||||
\param type_name Name of the partition type.
|
||||
*/
|
||||
void SetType(const char *type_name);
|
||||
/*!
|
||||
\brief Converts content type to the partition type that fits best.
|
||||
\param content_type Name of the content type, it is standardized by system.
|
||||
*/
|
||||
void SetContentType(const char *content_type);
|
||||
void SetType(const char *typeName);
|
||||
void SetContentType(const char *contentType);
|
||||
|
||||
/*!
|
||||
\brief Check whether the current type is valid.
|
||||
*/
|
||||
bool IsValid() const { return valid_; }
|
||||
/*!
|
||||
\brief Check whether the current type describes empty type.
|
||||
*/
|
||||
bool IsEmpty() const { return is_empty_type(type_); }
|
||||
/*!
|
||||
\brief Check whether the current type describes extended partition type.
|
||||
*/
|
||||
bool IsExtended() const { return is_extended_type(type_); }
|
||||
bool IsValid() const { return fValid; }
|
||||
bool IsEmpty() const { return is_empty_type(fType); }
|
||||
bool IsExtended() const { return is_extended_type(fType); }
|
||||
|
||||
/*!
|
||||
\brief Returns ID of the current type.
|
||||
*/
|
||||
uint8 Type() const { return type_; }
|
||||
/*!
|
||||
\brief Finds next supported partition.
|
||||
*/
|
||||
uint8 Type() const { return fType; }
|
||||
void FindNext();
|
||||
/*!
|
||||
\brief Returns string name of the current type.
|
||||
\param buffer Buffer where the name is stored, has to be allocated with
|
||||
sufficient length.
|
||||
*/
|
||||
void GetTypeString(char *buffer) const
|
||||
{ get_partition_type_string(type_, buffer); }
|
||||
{ get_partition_type_string(fType, buffer); }
|
||||
private:
|
||||
uint8 type_;
|
||||
bool valid_;
|
||||
uint8 fType;
|
||||
bool fValid;
|
||||
};
|
||||
|
||||
// Partition
|
||||
@@ -158,10 +123,10 @@ class Partition {
|
||||
public:
|
||||
Partition();
|
||||
Partition(const partition_descriptor *descriptor, off_t ptsOffset,
|
||||
off_t baseOffset, int32 blockSize);
|
||||
off_t baseOffset, int32 blockSize);
|
||||
|
||||
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
|
||||
off_t baseOffset, int32 blockSize);
|
||||
off_t baseOffset, int32 blockSize);
|
||||
void Unset();
|
||||
|
||||
bool IsEmpty() const { return is_empty_type(fType); }
|
||||
@@ -201,10 +166,10 @@ class PrimaryPartition : public Partition {
|
||||
public:
|
||||
PrimaryPartition();
|
||||
PrimaryPartition(const partition_descriptor *descriptor, off_t ptsOffset,
|
||||
int32 blockSize);
|
||||
int32 blockSize);
|
||||
|
||||
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
|
||||
int32 blockSize);
|
||||
int32 blockSize);
|
||||
void Unset();
|
||||
|
||||
// only if extended
|
||||
@@ -224,10 +189,10 @@ class LogicalPartition : public Partition {
|
||||
public:
|
||||
LogicalPartition();
|
||||
LogicalPartition(const partition_descriptor *descriptor, off_t ptsOffset,
|
||||
int32 blockSize, PrimaryPartition *primary);
|
||||
int32 blockSize, PrimaryPartition *primary);
|
||||
|
||||
void SetTo(const partition_descriptor *descriptor, off_t ptsOffset,
|
||||
int32 blockSize, PrimaryPartition *primary);
|
||||
int32 blockSize, PrimaryPartition *primary);
|
||||
void Unset();
|
||||
|
||||
void SetPrimaryPartition(PrimaryPartition *primary) { fPrimary = primary; }
|
||||
|
||||
@@ -33,8 +33,16 @@
|
||||
using std::nothrow;
|
||||
|
||||
// constructor
|
||||
/*!
|
||||
\brief Creates the writer.
|
||||
|
||||
\param deviceFD File descriptor.
|
||||
\param sessionOffset Disk offset of the partition with partitioning system.
|
||||
\param sessionSize Size of the partition with partitioning system.
|
||||
\param blockSize Size of the sector on given disk.
|
||||
*/
|
||||
PartitionMapWriter::PartitionMapWriter(int deviceFD, off_t sessionOffset,
|
||||
off_t sessionSize, int32 blockSize)
|
||||
off_t sessionSize, int32 blockSize)
|
||||
: fDeviceFD(deviceFD),
|
||||
fSessionOffset(sessionOffset),
|
||||
fSessionSize(sessionSize),
|
||||
@@ -50,6 +58,15 @@ PartitionMapWriter::~PartitionMapWriter()
|
||||
}
|
||||
|
||||
// WriteMBR
|
||||
/*!
|
||||
\brief Writes Master Boot Record to the first sector of the disk.
|
||||
|
||||
If a \a block is not specified, the sector is firstly read from the disk
|
||||
and after changing relevant items it is written back to the disk.
|
||||
This allows to keep code area in MBR intact.
|
||||
\param block Pointer to \c partition_table_sector.
|
||||
\param map Pointer to the PartitionMap structure describing disk partitions.
|
||||
*/
|
||||
status_t
|
||||
PartitionMapWriter::WriteMBR(uint8 *block, const PartitionMap *map)
|
||||
{
|
||||
@@ -78,8 +95,21 @@ PartitionMapWriter::WriteMBR(uint8 *block, const PartitionMap *map)
|
||||
}
|
||||
|
||||
// WriteLogical
|
||||
/*!
|
||||
\brief Writes Partition Table Sector of the logical \a partition to the
|
||||
disk.
|
||||
|
||||
This function ensures that the connection of the following linked list
|
||||
of logical partitions will be correct. It do nothing with the connection of
|
||||
previous logical partitions (call this function on previous logical
|
||||
partition to ensure it).
|
||||
|
||||
\param block Pointer to \c partition_table_sector.
|
||||
\param partition Pointer to the logical partition.
|
||||
*/
|
||||
status_t
|
||||
PartitionMapWriter::WriteLogical(uint8 *block, const LogicalPartition *partition)
|
||||
PartitionMapWriter::WriteLogical(uint8 *block,
|
||||
const LogicalPartition *partition)
|
||||
{
|
||||
status_t error = (partition ? B_OK : B_BAD_VALUE);
|
||||
if (error == B_OK) {
|
||||
@@ -103,9 +133,21 @@ PartitionMapWriter::WriteLogical(uint8 *block, const LogicalPartition *partition
|
||||
}
|
||||
|
||||
// WriteExtendedHead
|
||||
/*!
|
||||
\brief Writes Extended Boot Record to the first sector of Extended
|
||||
Partition.
|
||||
|
||||
Writes the head of linked list describing logical partitions.
|
||||
|
||||
If the \a first_partition is not specified, it only initializes EBR and the
|
||||
linked list contains no logical partitions.
|
||||
|
||||
\param block Pointer to \c partition_table_sector.
|
||||
\param first_partition Pointer to the first logical partition.
|
||||
*/
|
||||
status_t
|
||||
PartitionMapWriter::WriteExtendedHead(uint8 *block,
|
||||
const LogicalPartition *first_partition)
|
||||
const LogicalPartition *first_partition)
|
||||
{
|
||||
LogicalPartition partition;
|
||||
if (first_partition)
|
||||
@@ -160,8 +202,7 @@ PartitionMapWriter::_WritePrimary(partition_table_sector *pts)
|
||||
// _WriteExtended
|
||||
status_t
|
||||
PartitionMapWriter::_WriteExtended(partition_table_sector *pts,
|
||||
const LogicalPartition *partition,
|
||||
const LogicalPartition *next)
|
||||
const LogicalPartition *partition, const LogicalPartition *next)
|
||||
{
|
||||
if (!pts || !partition)
|
||||
return B_BAD_VALUE;
|
||||
@@ -172,7 +213,8 @@ PartitionMapWriter::_WriteExtended(partition_table_sector *pts,
|
||||
// check the partition's location
|
||||
if (!partition->CheckLocation(fSessionSize, fBlockSize)) {
|
||||
TRACE(("intel: _WriteExtended(): Invalid partition "
|
||||
"location: pts: %lld, offset: %lld, size: %lld, fSessionSize: %lld\n",
|
||||
"location: pts: %lld, offset: %lld, size: %lld, "
|
||||
"fSessionSize: %lld\n",
|
||||
partition->PTSOffset(), partition->Offset(),
|
||||
partition->Size(), fSessionSize));
|
||||
return B_BAD_DATA;
|
||||
@@ -180,7 +222,8 @@ PartitionMapWriter::_WriteExtended(partition_table_sector *pts,
|
||||
|
||||
// write the table
|
||||
partition_descriptor *descriptor = &(pts->table[0]);
|
||||
partition->GetPartitionDescriptor(descriptor, partition->PTSOffset(), fBlockSize);
|
||||
partition->GetPartitionDescriptor(descriptor, partition->PTSOffset(),
|
||||
fBlockSize);
|
||||
|
||||
// setting offset and size of the next partition in the linked list
|
||||
descriptor = &(pts->table[1]);
|
||||
@@ -205,9 +248,10 @@ PartitionMapWriter::_WriteExtended(partition_table_sector *pts,
|
||||
}
|
||||
|
||||
// _ReadPTS
|
||||
/*! \brief Reads the sector from the disk.
|
||||
*/
|
||||
status_t
|
||||
PartitionMapWriter::_ReadPTS(off_t offset, partition_table_sector *pts)
|
||||
// reads the sector from the disk
|
||||
{
|
||||
status_t error = B_OK;
|
||||
if (!pts)
|
||||
@@ -233,9 +277,10 @@ PartitionMapWriter::_ReadPTS(off_t offset, partition_table_sector *pts)
|
||||
}
|
||||
|
||||
// _WritePTS
|
||||
/*! \brief Writes the sector to the disk.
|
||||
*/
|
||||
status_t
|
||||
PartitionMapWriter::_WritePTS(off_t offset, const partition_table_sector *pts)
|
||||
// writes the sector to the disk
|
||||
{
|
||||
status_t error = B_OK;
|
||||
if (!pts)
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
\ingroup intel_module
|
||||
\brief Implementation of disk writer for "intel" style partitions.
|
||||
|
||||
Writer can write \b Master \b Boot \b Record or \b Extended \b Boot \b Records
|
||||
to the disk according to partitions defined in \c PartitionMap structure.
|
||||
Writer can write \b Master \b Boot \b Record or \b Extended \b Boot
|
||||
\b Records to the disk according to partitions defined in \c PartitionMap
|
||||
structure.
|
||||
*/
|
||||
|
||||
|
||||
@@ -33,66 +34,30 @@ struct partition_table_sector;
|
||||
This class serves for writing \a primary and \a logical \a partitions to disk.
|
||||
*/
|
||||
class PartitionMapWriter {
|
||||
public:
|
||||
/*!
|
||||
\brief Creates the writer.
|
||||
public:
|
||||
PartitionMapWriter(int deviceFD, off_t sessionOffset, off_t sessionSize,
|
||||
int32 blockSize);
|
||||
~PartitionMapWriter();
|
||||
|
||||
\param deviceFD File descriptor.
|
||||
\param sessionOffset Disk offset of the partition with partitioning system.
|
||||
\param sessionSize Size of the partition with partitioning system.
|
||||
\param blockSize Size of the sector on given disk.
|
||||
*/
|
||||
PartitionMapWriter(int deviceFD, off_t sessionOffset, off_t sessionSize,
|
||||
int32 blockSize);
|
||||
~PartitionMapWriter();
|
||||
status_t WriteMBR(uint8 *block, const PartitionMap *map);
|
||||
status_t WriteLogical(uint8 *block, const LogicalPartition *partition);
|
||||
status_t WriteExtendedHead(uint8 *block,
|
||||
const LogicalPartition *first_partition);
|
||||
|
||||
/*!
|
||||
\brief Writes Master Boot Record to the first sector of the disk.
|
||||
private:
|
||||
status_t _WritePrimary(partition_table_sector *pts);
|
||||
status_t _WriteExtended(partition_table_sector *pts,
|
||||
const LogicalPartition *partition, const LogicalPartition *next);
|
||||
status_t _ReadPTS(off_t offset, partition_table_sector *pts = NULL);
|
||||
status_t _WritePTS(off_t offset, const partition_table_sector *pts = NULL);
|
||||
|
||||
If a \a block is not specified, the sector is firstly read from the disk
|
||||
and after changing relevant items it is written back to the disk.
|
||||
This allows to keep code area in MBR intact.
|
||||
\param block Pointer to \c partition_table_sector.
|
||||
\param map Pointer to the PartitionMap structure describing disk partitions.
|
||||
*/
|
||||
status_t WriteMBR(uint8 *block, const PartitionMap *map);
|
||||
/*!
|
||||
\brief Writes Partition Table Sector of the logical \a partition to the disk.
|
||||
|
||||
This function ensures that the connection of the following linked list of logical
|
||||
partitions will be correct. It do nothing with the connection of previous logical
|
||||
partitions (call this function on previous logical partition to ensure it).
|
||||
\param block Pointer to \c partition_table_sector.
|
||||
\param partition Pointer to the logical partition.
|
||||
*/
|
||||
status_t WriteLogical(uint8 *block, const LogicalPartition *partition);
|
||||
/*!
|
||||
\brief Writes Extended Boot Record to the first sector of Extended Partition.
|
||||
|
||||
Writes the head of linked list describing logical partitions.
|
||||
|
||||
If the \a first_partition is not specified, it only initializes EBR and the linked
|
||||
list contains no logical partitions.
|
||||
\param block Pointer to \c partition_table_sector.
|
||||
\param first_partition Pointer to the first logical partition.
|
||||
*/
|
||||
status_t WriteExtendedHead(uint8 *block, const LogicalPartition *first_partition);
|
||||
|
||||
private:
|
||||
status_t _WritePrimary(partition_table_sector *pts);
|
||||
status_t _WriteExtended(partition_table_sector *pts,
|
||||
const LogicalPartition *partition,
|
||||
const LogicalPartition *next);
|
||||
status_t _ReadPTS(off_t offset, partition_table_sector *pts = NULL);
|
||||
status_t _WritePTS(off_t offset, const partition_table_sector *pts = NULL);
|
||||
|
||||
private:
|
||||
int fDeviceFD;
|
||||
off_t fSessionOffset;
|
||||
off_t fSessionSize;
|
||||
int32 fBlockSize;
|
||||
partition_table_sector *fPTS; // while writing
|
||||
const PartitionMap *fMap;
|
||||
private:
|
||||
int fDeviceFD;
|
||||
off_t fSessionOffset;
|
||||
off_t fSessionSize;
|
||||
int32 fBlockSize;
|
||||
partition_table_sector *fPTS; // while writing
|
||||
const PartitionMap *fMap;
|
||||
};
|
||||
|
||||
#endif // PARTITION_MAP_WRITER_H
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user