diff --git a/headers/private/kernel/disk_device_manager/KDiskDevice.h b/headers/private/kernel/disk_device_manager/KDiskDevice.h index c2ff45c12a..f30e941bf6 100644 --- a/headers/private/kernel/disk_device_manager/KDiskDevice.h +++ b/headers/private/kernel/disk_device_manager/KDiskDevice.h @@ -43,6 +43,8 @@ public: void SetDeviceFlags(uint32 flags); // comprises the ones below uint32 DeviceFlags() const; + bool IsReadOnlyMedia() const; + bool IsWriteOnce() const; bool IsRemovable() const; bool HasMedia() const; diff --git a/headers/private/storage/DiskDeviceDefs.h b/headers/private/storage/DiskDeviceDefs.h index 89cc8e6d1b..5803364eba 100644 --- a/headers/private/storage/DiskDeviceDefs.h +++ b/headers/private/storage/DiskDeviceDefs.h @@ -27,10 +27,19 @@ enum { B_PARTITION_DESCENDANT_BUSY = 0x40, }; +// partition statuses +enum { + B_PARTITION_VALID, + B_PARTITION_CORRUPT, + B_PARTITION_UNRECOGNIZED, +}; + // disk device flags enum { B_DISK_DEVICE_REMOVABLE = 0x01, B_DISK_DEVICE_HAS_MEDIA = 0x02, + B_DISK_DEVICE_READ_ONLY = 0x04, + B_DISK_DEVICE_WRITE_ONCE = 0x08, }; #ifdef __cplusplus diff --git a/headers/private/storage/Partition.h b/headers/private/storage/Partition.h index eff239cbff..3017112094 100644 --- a/headers/private/storage/Partition.h +++ b/headers/private/storage/Partition.h @@ -19,13 +19,6 @@ class BDiskSystem; class BVolume; struct user_partition_data; -// partition statuses -enum { - B_PARTITION_VALID, - B_PARTITION_CORRUPT, - B_PARTITION_UNRECOGNIZED, -}; - class BPartition { public: // Partition Info diff --git a/src/add-ons/kernel/disk_scanner/fs/bfs.c b/src/add-ons/kernel/disk_scanner/fs/bfs.c index 0698720a30..d3cff5f16e 100644 --- a/src/add-ons/kernel/disk_scanner/fs/bfs.c +++ b/src/add-ons/kernel/disk_scanner/fs/bfs.c @@ -375,7 +375,7 @@ bfs_identify_partition(int fd, partition_data *partition, void **cookie) return 0.5; } -// pm_scan_partition +// bfs_scan_partition static status_t bfs_scan_partition(int fd, partition_data *partition, void *cookie) @@ -389,6 +389,8 @@ bfs_scan_partition(int fd, partition_data *partition, void *cookie) partition->block_size)); superBlock = (disk_super_block*)cookie; // fill in the partition_data structure + partition->status = B_PARTITION_VALID; + partition->flags |= B_PARTITION_MOUNTABLE; partition->block_size = superBlock->block_size; partition->content_name = strdup(superBlock->name); partition->content_type = strdup(kPartitionTypeBFS); @@ -400,7 +402,7 @@ bfs_scan_partition(int fd, partition_data *partition, void *cookie) return B_OK; } -// pm_free_identify_partition_cookie +// bfs_free_identify_partition_cookie static void bfs_free_identify_partition_cookie(partition_data *partition, void *cookie) @@ -409,7 +411,7 @@ bfs_free_identify_partition_cookie(partition_data *partition, void *cookie) free(cookie); } -// pm_free_partition_content_cookie +// bfs_free_partition_content_cookie static void bfs_free_partition_content_cookie(partition_data *partition) diff --git a/src/add-ons/kernel/partitioning_systems/intel/intel.cpp b/src/add-ons/kernel/partitioning_systems/intel/intel.cpp index 5acb97b291..172c4d23a6 100644 --- a/src/add-ons/kernel/partitioning_systems/intel/intel.cpp +++ b/src/add-ons/kernel/partitioning_systems/intel/intel.cpp @@ -482,6 +482,9 @@ pm_scan_partition(int fd, partition_data *partition, void *cookie) partition->block_size)); PartitionMap *map = (PartitionMap*)cookie; // fill in the partition_data structure + partition->status = B_PARTITION_VALID; + partition->flags |= B_PARTITION_PARTITIONABLE | B_PARTITION_READ_ONLY; + // TODO: Update when write functionality is implemented. // (no content_name and content_parameters) partition->content_type = strdup(kPartitionTypeIntel); if (!partition->content_type) @@ -621,6 +624,9 @@ ep_scan_partition(int fd, partition_data *partition, void *cookie) return B_ERROR; PrimaryPartition *primary = (PrimaryPartition*)partition->cookie; // fill in the partition_data structure + partition->status = B_PARTITION_VALID; + partition->flags |= B_PARTITION_PARTITIONABLE | B_PARTITION_READ_ONLY; + // TODO: Update when write functionality is implemented. // (no content_name and content_parameters) partition->content_type = strdup(kPartitionTypeIntelExtended); if (!partition->content_type) diff --git a/src/kernel/core/disk_device_manager/KDiskDevice.cpp b/src/kernel/core/disk_device_manager/KDiskDevice.cpp index a131cd67da..458d267ed7 100644 --- a/src/kernel/core/disk_device_manager/KDiskDevice.cpp +++ b/src/kernel/core/disk_device_manager/KDiskDevice.cpp @@ -56,13 +56,32 @@ KDiskDevice::SetTo(const char *path) fFD = open(path, O_RDONLY); if (fFD < 0) return errno; - // get device geometry and media status + // get media status error = GetMediaStatus(&fMediaStatus); if (error != B_OK) return error; - error = GetGeometry(&fDeviceData.geometry); - if (error != B_OK) - return error; + if (fMediaStatus == B_DEV_MEDIA_CHANGED) + fMediaStatus = B_OK; + // get device geometry + if (fMediaStatus == B_OK) { + error = GetGeometry(&fDeviceData.geometry); + if (error != B_OK) + return error; + } else { + // no media: try to get the device geometry, but don't fail, if + // we can't get it + GetGeometry(&fDeviceData.geometry); + } + // set device flags + if (fDeviceData.geometry.removable) + SetDeviceFlags(DeviceFlags() | B_DISK_DEVICE_REMOVABLE); + if (fMediaStatus == B_OK) + SetDeviceFlags(DeviceFlags() | B_DISK_DEVICE_HAS_MEDIA); + if (fDeviceData.geometry.read_only) + SetDeviceFlags(DeviceFlags() | B_DISK_DEVICE_READ_ONLY); + if (fDeviceData.geometry.write_once) + SetDeviceFlags(DeviceFlags() | B_DISK_DEVICE_WRITE_ONCE); + // update partition data _InitPartitionData(); return B_OK; } @@ -88,7 +107,7 @@ KDiskDevice::Unset() fDeviceData.geometry.cylinder_count = 0; fDeviceData.geometry.head_count = 0; fDeviceData.geometry.device_type = B_DISK; - fDeviceData.geometry.removable = false; + fDeviceData.geometry.removable = true; fDeviceData.geometry.read_only = true; fDeviceData.geometry.write_once = false; } @@ -183,6 +202,20 @@ KDiskDevice::DeviceFlags() const return fDeviceData.flags; } +// IsReadOnlyMedia +bool +KDiskDevice::IsReadOnlyMedia() const +{ + return fDeviceData.geometry.read_only; +} + +// IsWriteOnce +bool +KDiskDevice::IsWriteOnce() const +{ + return fDeviceData.geometry.write_once; +} + // IsRemovable bool KDiskDevice::IsRemovable() const diff --git a/src/kernel/core/disk_device_manager/KPartition.cpp b/src/kernel/core/disk_device_manager/KPartition.cpp index d821f82e2a..50d4cc8341 100644 --- a/src/kernel/core/disk_device_manager/KPartition.cpp +++ b/src/kernel/core/disk_device_manager/KPartition.cpp @@ -41,7 +41,7 @@ KPartition::KPartition(partition_id id) fPartitionData.block_size = 0; fPartitionData.child_count = 0; fPartitionData.index = -1; - fPartitionData.status = /*B_PARTITION_UNRECOGNIZED*/ 0; + fPartitionData.status = B_PARTITION_UNRECOGNIZED; fPartitionData.flags = 0; fPartitionData.volume = -1; fPartitionData.name = NULL; @@ -194,7 +194,7 @@ KPartition::SetBusy(bool busy) if (busy) fPartitionData.flags |= B_PARTITION_BUSY; else - fPartitionData.flags &= ~B_PARTITION_BUSY; + fPartitionData.flags &= ~(uint32)B_PARTITION_BUSY; } // IsBusy @@ -211,7 +211,7 @@ KPartition::SetDescendantBusy(bool busy) if (busy) fPartitionData.flags |= B_PARTITION_DESCENDANT_BUSY; else - fPartitionData.flags &= ~B_PARTITION_DESCENDANT_BUSY; + fPartitionData.flags &= ~(uint32)B_PARTITION_DESCENDANT_BUSY; } // IsDescendantBusy @@ -469,6 +469,10 @@ void KPartition::SetVolumeID(dev_t volumeID) { fPartitionData.volume = volumeID; + if (VolumeID() >= 0) + SetFlags(Flags() | B_PARTITION_MOUNTED); + else + SetFlags(Flags() & ~(uint32)B_PARTITION_MOUNTED); } // VolumeID @@ -527,6 +531,8 @@ void KPartition::SetDevice(KDiskDevice *device) { fDevice = device; + if (fDevice && fDevice->IsReadOnlyMedia()) + SetFlags(Flags() | B_PARTITION_READ_ONLY); } // Device @@ -672,6 +678,13 @@ KPartition::SetDiskSystem(KDiskSystem *diskSystem) fDiskSystem = diskSystem; if (fDiskSystem) fDiskSystem->Load(); // can't fail, since it's already loaded + // update concerned partition flags + if (fDiskSystem) { + if (fDiskSystem->IsFileSystem()) + SetFlags(Flags() | B_PARTITION_MOUNTABLE); + else + SetFlags(Flags() | B_PARTITION_PARTITIONABLE); + } } // DiskSystem