Added a new variant of add_partitions_for() which takes a device instead

of a file descriptor as first argument.
add_partitions_for() is now able to only mount file systems if requested;
partitions with unknown contents will not be removed from the list if it
doesn't try to mount them.
Moved the file system mounting code to the new Partition::Mount() method.
Partition::Scan() now only mounts file systems if requested.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4882 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2003-10-01 01:10:56 +00:00
parent 8df661e6f8
commit 221807be72
+50 -19
View File
@@ -173,7 +173,30 @@ Partition::AddChild()
status_t
Partition::Scan()
Partition::Mount(Directory **_fileSystem)
{
for (int32 i = 0; i < sNumFileSystemModules; i++) {
file_system_module_info *module = sFileSystemModules[i];
TRACE(("check for file_system: %s\n", module->pretty_name));
Directory *fileSystem;
if (module->get_file_system(this, &fileSystem) == B_OK) {
gRoot->AddNode(fileSystem);
if (_fileSystem)
*_fileSystem = fileSystem;
fIsFileSystem = true;
return B_OK;
}
}
return B_ENTRY_NOT_FOUND;
}
status_t
Partition::Scan(bool mountFileSystems)
{
// scan for partitions first (recursively all eventual children as well)
@@ -200,10 +223,10 @@ Partition::Scan()
TRACE(("*** scan child %p (start = %Ld, size = %Ld, parent = %p)!\n",
child, child->offset, child->size, child->Parent()));
child->Scan();
child->Scan(mountFileSystems);
if (child->IsFileSystem()) {
// move the file systems to the partition list
if (!mountFileSystems || child->IsFileSystem()) {
// move the partitions containing file systems to the partition list
list_remove_item(&fChildren, child);
list_add_item(&gPartitions, child);
@@ -225,19 +248,8 @@ Partition::Scan()
// scan for file systems
for (int32 i = 0; i < sNumFileSystemModules; i++) {
file_system_module_info *module = sFileSystemModules[i];
TRACE(("check for file_system: %s\n", module->pretty_name));
Directory *fileSystem;
if (module->get_file_system(this, &fileSystem) == B_OK) {
gRoot->AddNode(fileSystem);
fIsFileSystem = true;
return B_OK;
}
}
if (mountFileSystems)
return Mount();
return B_ENTRY_NOT_FOUND;
}
@@ -249,7 +261,7 @@ Partition::Scan()
status_t
add_partitions_for(int fd)
add_partitions_for(int fd, bool mountFileSystems)
{
Partition *partition = new Partition(fd);
@@ -257,7 +269,10 @@ add_partitions_for(int fd)
partition->block_size = 512;
partition->size = partition->Size();
if (partition->Scan() == B_OK && partition->IsFileSystem()) {
// add this partition to the list of partitions, if it contains
// or might contain a file system
if ((partition->Scan(mountFileSystems) == B_OK && partition->IsFileSystem())
|| (!partition->IsFileSystem() && !mountFileSystems)) {
list_add_item(&gPartitions, partition);
return B_OK;
}
@@ -267,6 +282,22 @@ add_partitions_for(int fd)
}
status_t
add_partitions_for(Node *device, bool mountFileSystems)
{
int fd = open_node(device, O_RDONLY);
if (fd < B_OK)
return fd;
status_t status = add_partitions_for(fd, mountFileSystems);
if (status < B_OK)
printf("add_partitions_for(%d) failed: %ld\n", fd, status);
close(fd);
return B_OK;
}
partition_data *
create_child_partition(partition_id id, int32 index, partition_id childID)
{