Fixed handling of partition and device flags and statuses.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3898 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
6cef630541
commit
55bf93d80d
@ -43,6 +43,8 @@ public:
|
|||||||
|
|
||||||
void SetDeviceFlags(uint32 flags); // comprises the ones below
|
void SetDeviceFlags(uint32 flags); // comprises the ones below
|
||||||
uint32 DeviceFlags() const;
|
uint32 DeviceFlags() const;
|
||||||
|
bool IsReadOnlyMedia() const;
|
||||||
|
bool IsWriteOnce() const;
|
||||||
bool IsRemovable() const;
|
bool IsRemovable() const;
|
||||||
bool HasMedia() const;
|
bool HasMedia() const;
|
||||||
|
|
||||||
|
@ -27,10 +27,19 @@ enum {
|
|||||||
B_PARTITION_DESCENDANT_BUSY = 0x40,
|
B_PARTITION_DESCENDANT_BUSY = 0x40,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// partition statuses
|
||||||
|
enum {
|
||||||
|
B_PARTITION_VALID,
|
||||||
|
B_PARTITION_CORRUPT,
|
||||||
|
B_PARTITION_UNRECOGNIZED,
|
||||||
|
};
|
||||||
|
|
||||||
// disk device flags
|
// disk device flags
|
||||||
enum {
|
enum {
|
||||||
B_DISK_DEVICE_REMOVABLE = 0x01,
|
B_DISK_DEVICE_REMOVABLE = 0x01,
|
||||||
B_DISK_DEVICE_HAS_MEDIA = 0x02,
|
B_DISK_DEVICE_HAS_MEDIA = 0x02,
|
||||||
|
B_DISK_DEVICE_READ_ONLY = 0x04,
|
||||||
|
B_DISK_DEVICE_WRITE_ONCE = 0x08,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -19,13 +19,6 @@ class BDiskSystem;
|
|||||||
class BVolume;
|
class BVolume;
|
||||||
struct user_partition_data;
|
struct user_partition_data;
|
||||||
|
|
||||||
// partition statuses
|
|
||||||
enum {
|
|
||||||
B_PARTITION_VALID,
|
|
||||||
B_PARTITION_CORRUPT,
|
|
||||||
B_PARTITION_UNRECOGNIZED,
|
|
||||||
};
|
|
||||||
|
|
||||||
class BPartition {
|
class BPartition {
|
||||||
public:
|
public:
|
||||||
// Partition Info
|
// Partition Info
|
||||||
|
@ -375,7 +375,7 @@ bfs_identify_partition(int fd, partition_data *partition, void **cookie)
|
|||||||
return 0.5;
|
return 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pm_scan_partition
|
// bfs_scan_partition
|
||||||
static
|
static
|
||||||
status_t
|
status_t
|
||||||
bfs_scan_partition(int fd, partition_data *partition, void *cookie)
|
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));
|
partition->block_size));
|
||||||
superBlock = (disk_super_block*)cookie;
|
superBlock = (disk_super_block*)cookie;
|
||||||
// fill in the partition_data structure
|
// fill in the partition_data structure
|
||||||
|
partition->status = B_PARTITION_VALID;
|
||||||
|
partition->flags |= B_PARTITION_MOUNTABLE;
|
||||||
partition->block_size = superBlock->block_size;
|
partition->block_size = superBlock->block_size;
|
||||||
partition->content_name = strdup(superBlock->name);
|
partition->content_name = strdup(superBlock->name);
|
||||||
partition->content_type = strdup(kPartitionTypeBFS);
|
partition->content_type = strdup(kPartitionTypeBFS);
|
||||||
@ -400,7 +402,7 @@ bfs_scan_partition(int fd, partition_data *partition, void *cookie)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pm_free_identify_partition_cookie
|
// bfs_free_identify_partition_cookie
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
bfs_free_identify_partition_cookie(partition_data *partition, void *cookie)
|
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);
|
free(cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pm_free_partition_content_cookie
|
// bfs_free_partition_content_cookie
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
bfs_free_partition_content_cookie(partition_data *partition)
|
bfs_free_partition_content_cookie(partition_data *partition)
|
||||||
|
@ -482,6 +482,9 @@ pm_scan_partition(int fd, partition_data *partition, void *cookie)
|
|||||||
partition->block_size));
|
partition->block_size));
|
||||||
PartitionMap *map = (PartitionMap*)cookie;
|
PartitionMap *map = (PartitionMap*)cookie;
|
||||||
// fill in the partition_data structure
|
// 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)
|
// (no content_name and content_parameters)
|
||||||
partition->content_type = strdup(kPartitionTypeIntel);
|
partition->content_type = strdup(kPartitionTypeIntel);
|
||||||
if (!partition->content_type)
|
if (!partition->content_type)
|
||||||
@ -621,6 +624,9 @@ ep_scan_partition(int fd, partition_data *partition, void *cookie)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
PrimaryPartition *primary = (PrimaryPartition*)partition->cookie;
|
PrimaryPartition *primary = (PrimaryPartition*)partition->cookie;
|
||||||
// fill in the partition_data structure
|
// 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)
|
// (no content_name and content_parameters)
|
||||||
partition->content_type = strdup(kPartitionTypeIntelExtended);
|
partition->content_type = strdup(kPartitionTypeIntelExtended);
|
||||||
if (!partition->content_type)
|
if (!partition->content_type)
|
||||||
|
@ -56,13 +56,32 @@ KDiskDevice::SetTo(const char *path)
|
|||||||
fFD = open(path, O_RDONLY);
|
fFD = open(path, O_RDONLY);
|
||||||
if (fFD < 0)
|
if (fFD < 0)
|
||||||
return errno;
|
return errno;
|
||||||
// get device geometry and media status
|
// get media status
|
||||||
error = GetMediaStatus(&fMediaStatus);
|
error = GetMediaStatus(&fMediaStatus);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
error = GetGeometry(&fDeviceData.geometry);
|
if (fMediaStatus == B_DEV_MEDIA_CHANGED)
|
||||||
if (error != B_OK)
|
fMediaStatus = B_OK;
|
||||||
return error;
|
// 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();
|
_InitPartitionData();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@ -88,7 +107,7 @@ KDiskDevice::Unset()
|
|||||||
fDeviceData.geometry.cylinder_count = 0;
|
fDeviceData.geometry.cylinder_count = 0;
|
||||||
fDeviceData.geometry.head_count = 0;
|
fDeviceData.geometry.head_count = 0;
|
||||||
fDeviceData.geometry.device_type = B_DISK;
|
fDeviceData.geometry.device_type = B_DISK;
|
||||||
fDeviceData.geometry.removable = false;
|
fDeviceData.geometry.removable = true;
|
||||||
fDeviceData.geometry.read_only = true;
|
fDeviceData.geometry.read_only = true;
|
||||||
fDeviceData.geometry.write_once = false;
|
fDeviceData.geometry.write_once = false;
|
||||||
}
|
}
|
||||||
@ -183,6 +202,20 @@ KDiskDevice::DeviceFlags() const
|
|||||||
return fDeviceData.flags;
|
return fDeviceData.flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsReadOnlyMedia
|
||||||
|
bool
|
||||||
|
KDiskDevice::IsReadOnlyMedia() const
|
||||||
|
{
|
||||||
|
return fDeviceData.geometry.read_only;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsWriteOnce
|
||||||
|
bool
|
||||||
|
KDiskDevice::IsWriteOnce() const
|
||||||
|
{
|
||||||
|
return fDeviceData.geometry.write_once;
|
||||||
|
}
|
||||||
|
|
||||||
// IsRemovable
|
// IsRemovable
|
||||||
bool
|
bool
|
||||||
KDiskDevice::IsRemovable() const
|
KDiskDevice::IsRemovable() const
|
||||||
|
@ -41,7 +41,7 @@ KPartition::KPartition(partition_id id)
|
|||||||
fPartitionData.block_size = 0;
|
fPartitionData.block_size = 0;
|
||||||
fPartitionData.child_count = 0;
|
fPartitionData.child_count = 0;
|
||||||
fPartitionData.index = -1;
|
fPartitionData.index = -1;
|
||||||
fPartitionData.status = /*B_PARTITION_UNRECOGNIZED*/ 0;
|
fPartitionData.status = B_PARTITION_UNRECOGNIZED;
|
||||||
fPartitionData.flags = 0;
|
fPartitionData.flags = 0;
|
||||||
fPartitionData.volume = -1;
|
fPartitionData.volume = -1;
|
||||||
fPartitionData.name = NULL;
|
fPartitionData.name = NULL;
|
||||||
@ -194,7 +194,7 @@ KPartition::SetBusy(bool busy)
|
|||||||
if (busy)
|
if (busy)
|
||||||
fPartitionData.flags |= B_PARTITION_BUSY;
|
fPartitionData.flags |= B_PARTITION_BUSY;
|
||||||
else
|
else
|
||||||
fPartitionData.flags &= ~B_PARTITION_BUSY;
|
fPartitionData.flags &= ~(uint32)B_PARTITION_BUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsBusy
|
// IsBusy
|
||||||
@ -211,7 +211,7 @@ KPartition::SetDescendantBusy(bool busy)
|
|||||||
if (busy)
|
if (busy)
|
||||||
fPartitionData.flags |= B_PARTITION_DESCENDANT_BUSY;
|
fPartitionData.flags |= B_PARTITION_DESCENDANT_BUSY;
|
||||||
else
|
else
|
||||||
fPartitionData.flags &= ~B_PARTITION_DESCENDANT_BUSY;
|
fPartitionData.flags &= ~(uint32)B_PARTITION_DESCENDANT_BUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsDescendantBusy
|
// IsDescendantBusy
|
||||||
@ -469,6 +469,10 @@ void
|
|||||||
KPartition::SetVolumeID(dev_t volumeID)
|
KPartition::SetVolumeID(dev_t volumeID)
|
||||||
{
|
{
|
||||||
fPartitionData.volume = volumeID;
|
fPartitionData.volume = volumeID;
|
||||||
|
if (VolumeID() >= 0)
|
||||||
|
SetFlags(Flags() | B_PARTITION_MOUNTED);
|
||||||
|
else
|
||||||
|
SetFlags(Flags() & ~(uint32)B_PARTITION_MOUNTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// VolumeID
|
// VolumeID
|
||||||
@ -527,6 +531,8 @@ void
|
|||||||
KPartition::SetDevice(KDiskDevice *device)
|
KPartition::SetDevice(KDiskDevice *device)
|
||||||
{
|
{
|
||||||
fDevice = device;
|
fDevice = device;
|
||||||
|
if (fDevice && fDevice->IsReadOnlyMedia())
|
||||||
|
SetFlags(Flags() | B_PARTITION_READ_ONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Device
|
// Device
|
||||||
@ -672,6 +678,13 @@ KPartition::SetDiskSystem(KDiskSystem *diskSystem)
|
|||||||
fDiskSystem = diskSystem;
|
fDiskSystem = diskSystem;
|
||||||
if (fDiskSystem)
|
if (fDiskSystem)
|
||||||
fDiskSystem->Load(); // can't fail, since it's already loaded
|
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
|
// DiskSystem
|
||||||
|
Loading…
Reference in New Issue
Block a user