* Moved code to remove the parent to the Partition destructor - this should fix
the problem that the parent partition was still referenced in some cases. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23172 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -44,7 +44,8 @@ static const partition_module_info *sPartitionModules[] = {
|
|||||||
&gApplePartitionModule,
|
&gApplePartitionModule,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
static const int32 sNumPartitionModules = sizeof(sPartitionModules) / sizeof(partition_module_info *);
|
static const int32 sNumPartitionModules = sizeof(sPartitionModules)
|
||||||
|
/ sizeof(partition_module_info *);
|
||||||
|
|
||||||
/* supported file system modules */
|
/* supported file system modules */
|
||||||
|
|
||||||
@@ -65,17 +66,17 @@ static file_system_module_info *sFileSystemModules[] = {
|
|||||||
&gTarFileSystemModule,
|
&gTarFileSystemModule,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
static const int32 sNumFileSystemModules = sizeof(sFileSystemModules) / sizeof(file_system_module_info *);
|
static const int32 sNumFileSystemModules = sizeof(sFileSystemModules)
|
||||||
|
/ sizeof(file_system_module_info *);
|
||||||
|
|
||||||
extern NodeList gPartitions;
|
extern NodeList gPartitions;
|
||||||
|
|
||||||
|
|
||||||
namespace boot {
|
namespace boot {
|
||||||
|
|
||||||
/** A convenience class to automatically close a
|
/*! A convenience class to automatically close a
|
||||||
* file descriptor upon deconstruction.
|
file descriptor upon deconstruction.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class NodeOpener {
|
class NodeOpener {
|
||||||
public:
|
public:
|
||||||
NodeOpener(Node *node, int mode)
|
NodeOpener(Node *node, int mode)
|
||||||
@@ -117,6 +118,17 @@ Partition::Partition(int fd)
|
|||||||
Partition::~Partition()
|
Partition::~Partition()
|
||||||
{
|
{
|
||||||
TRACE(("%p Partition::~Partition\n", this));
|
TRACE(("%p Partition::~Partition\n", this));
|
||||||
|
|
||||||
|
// Tell the children that their parent is gone
|
||||||
|
|
||||||
|
NodeIterator iterator = gPartitions.GetIterator();
|
||||||
|
Partition *child;
|
||||||
|
|
||||||
|
while ((child = (Partition *)iterator.Next()) != NULL) {
|
||||||
|
if (child->Parent() == this)
|
||||||
|
child->SetParent(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
close(fFD);
|
close(fFD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +144,7 @@ Partition::SetParent(Partition *parent)
|
|||||||
Partition *
|
Partition *
|
||||||
Partition::Parent() const
|
Partition::Parent() const
|
||||||
{
|
{
|
||||||
TRACE(("%p Partition::Parent is %p\n", this, fParent));
|
//TRACE(("%p Partition::Parent is %p\n", this, fParent));
|
||||||
return fParent;
|
return fParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +165,8 @@ Partition::ReadAt(void *cookie, off_t position, void *buffer, size_t bufferSize)
|
|||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
Partition::WriteAt(void *cookie, off_t position, const void *buffer, size_t bufferSize)
|
Partition::WriteAt(void *cookie, off_t position, const void *buffer,
|
||||||
|
size_t bufferSize)
|
||||||
{
|
{
|
||||||
if (position > this->size)
|
if (position > this->size)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -250,7 +263,7 @@ status_t
|
|||||||
Partition::Scan(bool mountFileSystems, bool isBootDevice)
|
Partition::Scan(bool mountFileSystems, bool isBootDevice)
|
||||||
{
|
{
|
||||||
// scan for partitions first (recursively all eventual children as well)
|
// scan for partitions first (recursively all eventual children as well)
|
||||||
|
|
||||||
TRACE(("%p Partition::Scan()\n", this));
|
TRACE(("%p Partition::Scan()\n", this));
|
||||||
|
|
||||||
// if we were not booted from the real boot device, we won't scan
|
// if we were not booted from the real boot device, we won't scan
|
||||||
@@ -277,6 +290,7 @@ Partition::Scan(bool mountFileSystems, bool isBootDevice)
|
|||||||
if (priority < 0.0)
|
if (priority < 0.0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
TRACE((" priority: %ld\n", (int32)(priority * 1000)));
|
||||||
if (priority <= bestPriority) {
|
if (priority <= bestPriority) {
|
||||||
// the disk system recognized the partition worse than the currently
|
// the disk system recognized the partition worse than the currently
|
||||||
// best one
|
// best one
|
||||||
@@ -292,7 +306,6 @@ Partition::Scan(bool mountFileSystems, bool isBootDevice)
|
|||||||
bestPriority = priority;
|
bestPriority = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// find the best FS module
|
// find the best FS module
|
||||||
const file_system_module_info *bestFSModule = NULL;
|
const file_system_module_info *bestFSModule = NULL;
|
||||||
float bestFSPriority = -1;
|
float bestFSPriority = -1;
|
||||||
@@ -335,13 +348,15 @@ Partition::Scan(bool mountFileSystems, bool isBootDevice)
|
|||||||
Partition *child = NULL;
|
Partition *child = NULL;
|
||||||
|
|
||||||
while ((child = (Partition *)iterator.Next()) != NULL) {
|
while ((child = (Partition *)iterator.Next()) != NULL) {
|
||||||
TRACE(("%p Partition::Scan: *** scan child %p (start = %Ld, size = %Ld, parent = %p)!\n",
|
TRACE(("%p Partition::Scan: *** scan child %p (start = %Ld, size "
|
||||||
this, child, child->offset, child->size, child->Parent()));
|
"= %Ld, parent = %p)!\n", this, child, child->offset,
|
||||||
|
child->size, child->Parent()));
|
||||||
|
|
||||||
child->Scan(mountFileSystems);
|
child->Scan(mountFileSystems);
|
||||||
|
|
||||||
if (!mountFileSystems || child->IsFileSystem()) {
|
if (!mountFileSystems || child->IsFileSystem()) {
|
||||||
// move the partitions containing file systems to the partition list
|
// move the partitions containing file systems to the partition
|
||||||
|
// list
|
||||||
fChildren.Remove(child);
|
fChildren.Remove(child);
|
||||||
gPartitions.Add(child);
|
gPartitions.Add(child);
|
||||||
}
|
}
|
||||||
@@ -377,15 +392,15 @@ Partition::Scan(bool mountFileSystems, bool isBootDevice)
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
/** Scans the device passed in for partitioning systems. If none are found,
|
/*! Scans the device passed in for partitioning systems. If none are found,
|
||||||
* a partition containing the whole device is created.
|
a partition containing the whole device is created.
|
||||||
* All created partitions are added to the gPartitions list.
|
All created partitions are added to the gPartitions list.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice)
|
add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice)
|
||||||
{
|
{
|
||||||
TRACE(("add_partitions_for(fd = %d, mountFS = %s)\n", fd, mountFileSystems ? "yes" : "no"));
|
TRACE(("add_partitions_for(fd = %d, mountFS = %s)\n", fd,
|
||||||
|
mountFileSystems ? "yes" : "no"));
|
||||||
|
|
||||||
Partition *partition = new Partition(fd);
|
Partition *partition = new Partition(fd);
|
||||||
|
|
||||||
@@ -395,22 +410,14 @@ add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice)
|
|||||||
|
|
||||||
// add this partition to the list of partitions, if it contains
|
// add this partition to the list of partitions, if it contains
|
||||||
// or might contain a file system
|
// or might contain a file system
|
||||||
if ((partition->Scan(mountFileSystems, isBootDevice) == B_OK && partition->IsFileSystem())
|
if ((partition->Scan(mountFileSystems, isBootDevice) == B_OK
|
||||||
|
&& partition->IsFileSystem())
|
||||||
|| (!partition->IsPartitioningSystem() && !mountFileSystems)) {
|
|| (!partition->IsPartitioningSystem() && !mountFileSystems)) {
|
||||||
gPartitions.Add(partition);
|
gPartitions.Add(partition);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if not, we'll need to tell the children that their parent is gone
|
// if not, we no longer need the partition
|
||||||
|
|
||||||
NodeIterator iterator = gPartitions.GetIterator();
|
|
||||||
Partition *child = NULL;
|
|
||||||
|
|
||||||
while ((child = (Partition *)iterator.Next()) != NULL) {
|
|
||||||
if (child->Parent() == partition)
|
|
||||||
child->SetParent(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete partition;
|
delete partition;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -419,7 +426,8 @@ add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice)
|
|||||||
status_t
|
status_t
|
||||||
add_partitions_for(Node *device, bool mountFileSystems, bool isBootDevice)
|
add_partitions_for(Node *device, bool mountFileSystems, bool isBootDevice)
|
||||||
{
|
{
|
||||||
TRACE(("add_partitions_for(%p, mountFS = %s)\n", device, mountFileSystems ? "yes" : "no"));
|
TRACE(("add_partitions_for(%p, mountFS = %s)\n", device,
|
||||||
|
mountFileSystems ? "yes" : "no"));
|
||||||
|
|
||||||
int fd = open_node(device, O_RDONLY);
|
int fd = open_node(device, O_RDONLY);
|
||||||
if (fd < B_OK)
|
if (fd < B_OK)
|
||||||
|
|||||||
Reference in New Issue
Block a user