Switched to use the DoublyLinked::List implemenatition.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5017 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -54,7 +54,7 @@ static file_system_module_info *sFileSystemModules[] = {
|
|||||||
};
|
};
|
||||||
static const int32 sNumFileSystemModules = sizeof(sFileSystemModules) / sizeof(file_system_module_info *);
|
static const int32 sNumFileSystemModules = sizeof(sFileSystemModules) / sizeof(file_system_module_info *);
|
||||||
|
|
||||||
extern list gPartitions;
|
extern NodeList gPartitions;
|
||||||
|
|
||||||
|
|
||||||
namespace boot {
|
namespace boot {
|
||||||
@@ -90,12 +90,11 @@ Partition::Partition(int fd)
|
|||||||
fParent(NULL),
|
fParent(NULL),
|
||||||
fIsFileSystem(false)
|
fIsFileSystem(false)
|
||||||
{
|
{
|
||||||
memset(this, 0, sizeof(partition_data));
|
memset((partition_data *)this, 0, sizeof(partition_data));
|
||||||
id = (partition_id)this;
|
id = (partition_id)this;
|
||||||
|
|
||||||
// it's safe to close the file
|
// it's safe to close the file
|
||||||
fFD = dup(fd);
|
fFD = dup(fd);
|
||||||
list_init_etc(&fChildren, Partition::LinkOffset());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -166,7 +165,7 @@ Partition::AddChild()
|
|||||||
|
|
||||||
child->SetParent(this);
|
child->SetParent(this);
|
||||||
child_count++;
|
child_count++;
|
||||||
list_add_item(&fChildren, (void *)child);
|
fChildren.Add(child);
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
@@ -199,6 +198,8 @@ status_t
|
|||||||
Partition::Scan(bool mountFileSystems)
|
Partition::Scan(bool mountFileSystems)
|
||||||
{
|
{
|
||||||
// scan for partitions first (recursively all eventual children as well)
|
// scan for partitions first (recursively all eventual children as well)
|
||||||
|
|
||||||
|
TRACE(("Partition::Scan()\n"));
|
||||||
|
|
||||||
for (int32 i = 0; i < sNumPartitionModules; i++) {
|
for (int32 i = 0; i < sNumPartitionModules; i++) {
|
||||||
partition_module_info *module = sPartitionModules[i];
|
partition_module_info *module = sPartitionModules[i];
|
||||||
@@ -217,9 +218,10 @@ Partition::Scan(bool mountFileSystems)
|
|||||||
// now that we've found something, check our children
|
// now that we've found something, check our children
|
||||||
// out as well!
|
// out as well!
|
||||||
|
|
||||||
Partition *child = NULL, *last = NULL;
|
NodeIterator iterator = fChildren.Iterator();
|
||||||
|
Partition *child = NULL;
|
||||||
|
|
||||||
while ((child = (Partition *)list_get_next_item(&fChildren, child)) != NULL) {
|
while ((child = (Partition *)iterator.Next()) != NULL) {
|
||||||
TRACE(("*** scan child %p (start = %Ld, size = %Ld, parent = %p)!\n",
|
TRACE(("*** scan child %p (start = %Ld, size = %Ld, parent = %p)!\n",
|
||||||
child, child->offset, child->size, child->Parent()));
|
child, child->offset, child->size, child->Parent()));
|
||||||
|
|
||||||
@@ -227,19 +229,14 @@ Partition::Scan(bool 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
|
||||||
list_remove_item(&fChildren, child);
|
fChildren.Remove(child);
|
||||||
list_add_item(&gPartitions, child);
|
gPartitions.Add(child);
|
||||||
|
|
||||||
child = last;
|
|
||||||
// skip this item
|
|
||||||
}
|
}
|
||||||
|
|
||||||
last = child;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all unused children (we keep only file systems)
|
// remove all unused children (we keep only file systems)
|
||||||
|
|
||||||
while ((child = (Partition *)list_remove_head_item(&fChildren)) != NULL)
|
while ((child = (Partition *)fChildren.RemoveHead()) != NULL)
|
||||||
delete child;
|
delete child;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -263,6 +260,8 @@ Partition::Scan(bool mountFileSystems)
|
|||||||
status_t
|
status_t
|
||||||
add_partitions_for(int fd, bool mountFileSystems)
|
add_partitions_for(int fd, bool mountFileSystems)
|
||||||
{
|
{
|
||||||
|
TRACE(("add_partitions_for(fd = %ld, mountFS = %s)\n", fd, mountFileSystems ? "yes" : "no"));
|
||||||
|
|
||||||
Partition *partition = new Partition(fd);
|
Partition *partition = new Partition(fd);
|
||||||
|
|
||||||
// set some magic/default values
|
// set some magic/default values
|
||||||
@@ -273,7 +272,7 @@ add_partitions_for(int fd, bool mountFileSystems)
|
|||||||
// or might contain a file system
|
// or might contain a file system
|
||||||
if ((partition->Scan(mountFileSystems) == B_OK && partition->IsFileSystem())
|
if ((partition->Scan(mountFileSystems) == B_OK && partition->IsFileSystem())
|
||||||
|| (!partition->IsFileSystem() && !mountFileSystems)) {
|
|| (!partition->IsFileSystem() && !mountFileSystems)) {
|
||||||
list_add_item(&gPartitions, partition);
|
gPartitions.Add(partition);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,6 +284,8 @@ add_partitions_for(int fd, bool mountFileSystems)
|
|||||||
status_t
|
status_t
|
||||||
add_partitions_for(Node *device, bool mountFileSystems)
|
add_partitions_for(Node *device, bool mountFileSystems)
|
||||||
{
|
{
|
||||||
|
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)
|
||||||
return fd;
|
return fd;
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ class Descriptor {
|
|||||||
|
|
||||||
#define MAX_VFS_DESCRIPTORS 64
|
#define MAX_VFS_DESCRIPTORS 64
|
||||||
|
|
||||||
list gBootDevices;
|
NodeList gBootDevices;
|
||||||
list gPartitions;
|
NodeList gPartitions;
|
||||||
Directory *gRoot;
|
Directory *gRoot;
|
||||||
static Descriptor *sDescriptors[MAX_VFS_DESCRIPTORS];
|
static Descriptor *sDescriptors[MAX_VFS_DESCRIPTORS];
|
||||||
static Node *sBootDevice;
|
static Node *sBootDevice;
|
||||||
@@ -281,9 +281,6 @@ Descriptor::Release()
|
|||||||
status_t
|
status_t
|
||||||
vfs_init(stage2_args *args)
|
vfs_init(stage2_args *args)
|
||||||
{
|
{
|
||||||
list_init(&gBootDevices);
|
|
||||||
list_init_etc(&gPartitions, Partition::LinkOffset());
|
|
||||||
|
|
||||||
gRoot = new RootFileSystem();
|
gRoot = new RootFileSystem();
|
||||||
if (gRoot == NULL)
|
if (gRoot == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@@ -305,7 +302,7 @@ get_boot_file_system(stage2_args *args)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// add the boot device to the list of devices
|
// add the boot device to the list of devices
|
||||||
list_add_item(&gBootDevices, device);
|
gBootDevices.Add(device);
|
||||||
|
|
||||||
if (add_partitions_for(device, false) < B_OK)
|
if (add_partitions_for(device, false) < B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -318,8 +315,8 @@ get_boot_file_system(stage2_args *args)
|
|||||||
if (partition->Mount(&fileSystem) < B_OK) {
|
if (partition->Mount(&fileSystem) < B_OK) {
|
||||||
// let's remove that partition, so that it is not scanned again
|
// let's remove that partition, so that it is not scanned again
|
||||||
// in mount_file_systems()
|
// in mount_file_systems()
|
||||||
|
|
||||||
list_remove_item(&gPartitions, partition);
|
gPartitions.Remove(partition);
|
||||||
delete partition;
|
delete partition;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -337,17 +334,14 @@ status_t
|
|||||||
mount_file_systems(stage2_args *args)
|
mount_file_systems(stage2_args *args)
|
||||||
{
|
{
|
||||||
// mount other partitions on boot device (if any)
|
// mount other partitions on boot device (if any)
|
||||||
|
NodeIterator iterator = gPartitions.Iterator();
|
||||||
|
|
||||||
Partition *partition = NULL;
|
Partition *partition = NULL;
|
||||||
while ((partition = (Partition *)list_get_next_item(&gPartitions, partition)) != NULL) {
|
while ((partition = (Partition *)iterator.Next()) != NULL) {
|
||||||
// remove the partition if it doesn't contain a (known) file system
|
// remove the partition if it doesn't contain a (known) file system
|
||||||
if (partition->Scan(true) != B_OK && !partition->IsFileSystem()) {
|
if (partition->Scan(true) != B_OK && !partition->IsFileSystem()) {
|
||||||
Partition *last = (Partition *)list_get_prev_item(&gPartitions, partition);
|
gPartitions.Remove(partition);
|
||||||
|
|
||||||
list_remove_item(&gPartitions, partition);
|
|
||||||
delete partition;
|
delete partition;
|
||||||
|
|
||||||
partition = last;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,8 +351,9 @@ mount_file_systems(stage2_args *args)
|
|||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
iterator = gBootDevices.Iterator();
|
||||||
Node *device = NULL, *last = NULL;
|
Node *device = NULL, *last = NULL;
|
||||||
while ((device = (Node *)list_get_next_item(&gBootDevices, device)) != NULL) {
|
while ((device = iterator.Next()) != NULL) {
|
||||||
// don't scan former boot device again
|
// don't scan former boot device again
|
||||||
if (device == sBootDevice)
|
if (device == sBootDevice)
|
||||||
continue;
|
continue;
|
||||||
@@ -378,7 +373,7 @@ mount_file_systems(stage2_args *args)
|
|||||||
last = device;
|
last = device;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list_is_empty(&gPartitions))
|
if (gPartitions.IsEmpty())
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -481,7 +476,7 @@ open_node(Node *node, int mode)
|
|||||||
if (fd == MAX_VFS_DESCRIPTORS)
|
if (fd == MAX_VFS_DESCRIPTORS)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
TRACE(("got descriptor %d\n", fd));
|
TRACE(("got descriptor %d for node %p\n", fd, node));
|
||||||
|
|
||||||
// we got a free descriptor entry, now try to open the node
|
// we got a free descriptor entry, now try to open the node
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user