diff --git a/src/kernel/boot/loader/partitions.cpp b/src/kernel/boot/loader/partitions.cpp index 7b8e217cfa..26cb54d58f 100644 --- a/src/kernel/boot/loader/partitions.cpp +++ b/src/kernel/boot/loader/partitions.cpp @@ -54,7 +54,7 @@ static file_system_module_info *sFileSystemModules[] = { }; static const int32 sNumFileSystemModules = sizeof(sFileSystemModules) / sizeof(file_system_module_info *); -extern list gPartitions; +extern NodeList gPartitions; namespace boot { @@ -90,12 +90,11 @@ Partition::Partition(int fd) fParent(NULL), fIsFileSystem(false) { - memset(this, 0, sizeof(partition_data)); + memset((partition_data *)this, 0, sizeof(partition_data)); id = (partition_id)this; // it's safe to close the file fFD = dup(fd); - list_init_etc(&fChildren, Partition::LinkOffset()); } @@ -166,7 +165,7 @@ Partition::AddChild() child->SetParent(this); child_count++; - list_add_item(&fChildren, (void *)child); + fChildren.Add(child); return child; } @@ -199,6 +198,8 @@ status_t Partition::Scan(bool mountFileSystems) { // scan for partitions first (recursively all eventual children as well) + + TRACE(("Partition::Scan()\n")); for (int32 i = 0; i < sNumPartitionModules; i++) { partition_module_info *module = sPartitionModules[i]; @@ -217,9 +218,10 @@ Partition::Scan(bool mountFileSystems) // now that we've found something, check our children // 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", child, child->offset, child->size, child->Parent())); @@ -227,19 +229,14 @@ Partition::Scan(bool mountFileSystems) if (!mountFileSystems || child->IsFileSystem()) { // move the partitions containing file systems to the partition list - list_remove_item(&fChildren, child); - list_add_item(&gPartitions, child); - - child = last; - // skip this item + fChildren.Remove(child); + gPartitions.Add(child); } - - last = child; } // 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; return B_OK; @@ -263,6 +260,8 @@ Partition::Scan(bool mountFileSystems) status_t 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); // set some magic/default values @@ -273,7 +272,7 @@ add_partitions_for(int fd, bool mountFileSystems) // or might contain a file system if ((partition->Scan(mountFileSystems) == B_OK && partition->IsFileSystem()) || (!partition->IsFileSystem() && !mountFileSystems)) { - list_add_item(&gPartitions, partition); + gPartitions.Add(partition); return B_OK; } @@ -285,6 +284,8 @@ add_partitions_for(int fd, bool mountFileSystems) status_t 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); if (fd < B_OK) return fd; diff --git a/src/kernel/boot/loader/vfs.cpp b/src/kernel/boot/loader/vfs.cpp index 60f79d49c2..3a189896dd 100644 --- a/src/kernel/boot/loader/vfs.cpp +++ b/src/kernel/boot/loader/vfs.cpp @@ -54,8 +54,8 @@ class Descriptor { #define MAX_VFS_DESCRIPTORS 64 -list gBootDevices; -list gPartitions; +NodeList gBootDevices; +NodeList gPartitions; Directory *gRoot; static Descriptor *sDescriptors[MAX_VFS_DESCRIPTORS]; static Node *sBootDevice; @@ -281,9 +281,6 @@ Descriptor::Release() status_t vfs_init(stage2_args *args) { - list_init(&gBootDevices); - list_init_etc(&gPartitions, Partition::LinkOffset()); - gRoot = new RootFileSystem(); if (gRoot == NULL) return B_NO_MEMORY; @@ -305,7 +302,7 @@ get_boot_file_system(stage2_args *args) return NULL; // 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) return NULL; @@ -318,8 +315,8 @@ get_boot_file_system(stage2_args *args) if (partition->Mount(&fileSystem) < B_OK) { // let's remove that partition, so that it is not scanned again // in mount_file_systems() - - list_remove_item(&gPartitions, partition); + + gPartitions.Remove(partition); delete partition; return NULL; } @@ -337,17 +334,14 @@ status_t mount_file_systems(stage2_args *args) { // mount other partitions on boot device (if any) + NodeIterator iterator = gPartitions.Iterator(); 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 if (partition->Scan(true) != B_OK && !partition->IsFileSystem()) { - Partition *last = (Partition *)list_get_prev_item(&gPartitions, partition); - - list_remove_item(&gPartitions, partition); + gPartitions.Remove(partition); delete partition; - - partition = last; } } @@ -357,8 +351,9 @@ mount_file_systems(stage2_args *args) if (status < B_OK) return status; + iterator = gBootDevices.Iterator(); 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 if (device == sBootDevice) continue; @@ -378,7 +373,7 @@ mount_file_systems(stage2_args *args) last = device; } - if (list_is_empty(&gPartitions)) + if (gPartitions.IsEmpty()) return B_ENTRY_NOT_FOUND; return B_OK; @@ -481,7 +476,7 @@ open_node(Node *node, int mode) if (fd == MAX_VFS_DESCRIPTORS) 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