- Updated partition name and partition content name length limits
to B_FILE_NAME_LENGTH.
- Added partition [content] name copy-out code to
_kern_validate_{set_partition_name,set_partition_content_name,
intialize_partition}.
- Added parameter security to _kern_supports_moving_partition().
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5177 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -505,46 +505,65 @@ _kern_supports_resizing_partition(partition_id partitionID,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: Add parameter security
|
|
||||||
// _kern_supports_moving_partition
|
// _kern_supports_moving_partition
|
||||||
bool
|
bool
|
||||||
_kern_supports_moving_partition(partition_id partitionID, int32 changeCounter,
|
_kern_supports_moving_partition(partition_id partitionID, int32 changeCounter,
|
||||||
partition_id *unmovable,
|
partition_id *_unmovable,
|
||||||
partition_id *needUnmounting,
|
partition_id *_needUnmounting,
|
||||||
size_t bufferSize)
|
size_t bufferSize)
|
||||||
{
|
{
|
||||||
if ((!unmovable || needUnmounting) && bufferSize > 0)
|
if ((!_unmovable || !_needUnmounting) && bufferSize > 0)
|
||||||
return false;
|
return false;
|
||||||
|
partition_id *unmovable = NULL;
|
||||||
|
partition_id *needUnmounting = NULL;
|
||||||
|
if (bufferSize > 0) {
|
||||||
|
unmovable = static_cast<partition_id*>(malloc(bufferSize));
|
||||||
|
needUnmounting = static_cast<partition_id*>(malloc(bufferSize));
|
||||||
|
if (unmovable && needUnmounting) {
|
||||||
|
user_memcpy(unmovable, _unmovable, bufferSize);
|
||||||
|
user_memcpy(needUnmounting, _needUnmounting, bufferSize);
|
||||||
|
} else {
|
||||||
|
free(unmovable);
|
||||||
|
free(needUnmounting);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
||||||
// get the partition
|
// get the partition
|
||||||
KPartition *partition = manager->ReadLockPartition(partitionID);
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
||||||
if (!partition)
|
bool result = partition;
|
||||||
return false;
|
if (result) {
|
||||||
PartitionRegistrar registrar1(partition, true);
|
PartitionRegistrar registrar1(partition, true);
|
||||||
PartitionRegistrar registrar2(partition->Device(), true);
|
PartitionRegistrar registrar2(partition->Device(), true);
|
||||||
DeviceReadLocker locker(partition->Device(), true);
|
DeviceReadLocker locker(partition->Device(), true);
|
||||||
if (!check_shadow_partition(partition, changeCounter)
|
result = check_shadow_partition(partition, changeCounter)
|
||||||
|| !partition->Parent()) {
|
&& partition->Parent();
|
||||||
return false;
|
if (result) {
|
||||||
}
|
result = !partition->Parent()->IsBusy()
|
||||||
if (partition->Parent()->IsBusy()
|
&& !partition->Parent()->IsDescendantBusy();
|
||||||
|| partition->Parent()->IsDescendantBusy()) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
if (result) {
|
||||||
// get the parent disk system
|
// get the parent disk system
|
||||||
KDiskSystem *parentDiskSystem = partition->Parent()->DiskSystem();
|
KDiskSystem *parentDiskSystem = partition->Parent()->DiskSystem();
|
||||||
if (!parentDiskSystem)
|
result = parentDiskSystem;
|
||||||
return false;
|
if (result)
|
||||||
bool result = parentDiskSystem->SupportsMovingChild(partition);
|
result = parentDiskSystem->SupportsMovingChild(partition);
|
||||||
if (!result)
|
if (result) {
|
||||||
return false;
|
|
||||||
// check the movability of the descendants' contents
|
// check the movability of the descendants' contents
|
||||||
size_t unmovableSize = bufferSize;
|
size_t unmovableSize = bufferSize;
|
||||||
size_t needUnmountingSize = bufferSize;
|
size_t needUnmountingSize = bufferSize;
|
||||||
if (!get_unmovable_descendants(partition, unmovable, unmovableSize,
|
result = get_unmovable_descendants(partition, unmovable,
|
||||||
needUnmounting, needUnmountingSize)) {
|
unmovableSize, needUnmounting,
|
||||||
return false;
|
needUnmountingSize);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result && bufferSize > 0) {
|
||||||
|
user_memcpy(_unmovable, unmovable, bufferSize);
|
||||||
|
user_memcpy(_needUnmounting, needUnmounting, bufferSize);
|
||||||
|
}
|
||||||
|
free(unmovable);
|
||||||
|
free(needUnmounting);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -849,8 +868,8 @@ _kern_validate_set_partition_name(partition_id partitionID,
|
|||||||
{
|
{
|
||||||
if (!_name)
|
if (!_name)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
char name[B_OS_NAME_LENGTH];
|
char name[B_FILE_NAME_LENGTH];
|
||||||
status_t error = ddm_strlcpy(name, _name, B_OS_NAME_LENGTH, true);
|
status_t error = ddm_strlcpy(name, _name, B_FILE_NAME_LENGTH, true);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
||||||
@@ -861,7 +880,10 @@ _kern_validate_set_partition_name(partition_id partitionID,
|
|||||||
PartitionRegistrar registrar1(partition, true);
|
PartitionRegistrar registrar1(partition, true);
|
||||||
PartitionRegistrar registrar2(partition->Device(), true);
|
PartitionRegistrar registrar2(partition->Device(), true);
|
||||||
DeviceReadLocker locker(partition->Device(), true);
|
DeviceReadLocker locker(partition->Device(), true);
|
||||||
return validate_set_partition_name(partition, changeCounter, name);
|
error = validate_set_partition_name(partition, changeCounter, name);
|
||||||
|
if (!error)
|
||||||
|
error = ddm_strlcpy(_name, name, B_FILE_NAME_LENGTH);
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _kern_validate_set_partition_content_name
|
// _kern_validate_set_partition_content_name
|
||||||
@@ -871,8 +893,8 @@ _kern_validate_set_partition_content_name(partition_id partitionID,
|
|||||||
{
|
{
|
||||||
if (!_name)
|
if (!_name)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
char name[B_OS_NAME_LENGTH];
|
char name[B_FILE_NAME_LENGTH];
|
||||||
status_t error = ddm_strlcpy(name, _name, B_OS_NAME_LENGTH, true);
|
status_t error = ddm_strlcpy(name, _name, B_FILE_NAME_LENGTH, true);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
||||||
@@ -883,7 +905,10 @@ _kern_validate_set_partition_content_name(partition_id partitionID,
|
|||||||
PartitionRegistrar registrar1(partition, true);
|
PartitionRegistrar registrar1(partition, true);
|
||||||
PartitionRegistrar registrar2(partition->Device(), true);
|
PartitionRegistrar registrar2(partition->Device(), true);
|
||||||
DeviceReadLocker locker(partition->Device(), true);
|
DeviceReadLocker locker(partition->Device(), true);
|
||||||
return validate_set_partition_content_name(partition, changeCounter, name);
|
error = validate_set_partition_content_name(partition, changeCounter, name);
|
||||||
|
if (!error)
|
||||||
|
error = ddm_strlcpy(_name, name, B_FILE_NAME_LENGTH);
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _kern_validate_set_partition_type
|
// _kern_validate_set_partition_type
|
||||||
@@ -919,11 +944,11 @@ _kern_validate_initialize_partition(partition_id partitionID,
|
|||||||
if (!_diskSystemName || !_name)
|
if (!_diskSystemName || !_name)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
char diskSystemName[B_OS_NAME_LENGTH];
|
char diskSystemName[B_OS_NAME_LENGTH];
|
||||||
char name[B_OS_NAME_LENGTH];
|
char name[B_FILE_NAME_LENGTH];
|
||||||
char *parameters = NULL;
|
char *parameters = NULL;
|
||||||
status_t error = ddm_strlcpy(diskSystemName, _diskSystemName, B_OS_NAME_LENGTH);
|
status_t error = ddm_strlcpy(diskSystemName, _diskSystemName, B_OS_NAME_LENGTH);
|
||||||
if (!error)
|
if (!error)
|
||||||
error = ddm_strlcpy(name, _name, B_OS_NAME_LENGTH, true);
|
error = ddm_strlcpy(name, _name, B_FILE_NAME_LENGTH, true);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
if (_parameters) {
|
if (_parameters) {
|
||||||
@@ -944,6 +969,8 @@ _kern_validate_initialize_partition(partition_id partitionID,
|
|||||||
error = validate_initialize_partition(partition, changeCounter,
|
error = validate_initialize_partition(partition, changeCounter,
|
||||||
diskSystemName, name, parameters);
|
diskSystemName, name, parameters);
|
||||||
}
|
}
|
||||||
|
if (!error)
|
||||||
|
error = ddm_strlcpy(_name, name, B_FILE_NAME_LENGTH);
|
||||||
free(parameters);
|
free(parameters);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -1274,7 +1301,7 @@ _kern_set_partition_name(partition_id partitionID, int32 changeCounter,
|
|||||||
if (!_name)
|
if (!_name)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
char name[B_OS_NAME_LENGTH];
|
char name[B_OS_NAME_LENGTH];
|
||||||
status_t error = ddm_strlcpy(name, _name, B_OS_NAME_LENGTH);
|
status_t error = ddm_strlcpy(name, _name, B_FILE_NAME_LENGTH);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
||||||
@@ -1312,7 +1339,7 @@ _kern_set_partition_content_name(partition_id partitionID, int32 changeCounter,
|
|||||||
if (!_name)
|
if (!_name)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
char name[B_OS_NAME_LENGTH];
|
char name[B_OS_NAME_LENGTH];
|
||||||
status_t error = ddm_strlcpy(name, _name, B_OS_NAME_LENGTH);
|
status_t error = ddm_strlcpy(name, _name, B_FILE_NAME_LENGTH);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
||||||
@@ -1473,7 +1500,7 @@ _kern_initialize_partition(partition_id partitionID, int32 changeCounter,
|
|||||||
char *parameters = NULL;
|
char *parameters = NULL;
|
||||||
status_t error = ddm_strlcpy(diskSystemName, _diskSystemName, B_OS_NAME_LENGTH);
|
status_t error = ddm_strlcpy(diskSystemName, _diskSystemName, B_OS_NAME_LENGTH);
|
||||||
if (!error)
|
if (!error)
|
||||||
error = ddm_strlcpy(name, _name, B_OS_NAME_LENGTH);
|
error = ddm_strlcpy(name, _name, B_FILE_NAME_LENGTH);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
if (_parameters) {
|
if (_parameters) {
|
||||||
|
|||||||
Reference in New Issue
Block a user