// _SetTo status_t BPartition::_SetTo(BDiskDevice* device, BPartition* parent, user_partition_data* data) { _Unset(); if (!device || !data) return B_BAD_VALUE; fPartitionData = data; fDevice = device; fParent = parent; fPartitionData->user_data = this; // create and init children status_t error = B_OK; for (int32 i = 0; error == B_OK && i < fPartitionData->child_count; i++) { BPartition* child = new(nothrow) BPartition; if (child) { error = child->_SetTo(fDevice, this, fPartitionData->children[i]); if (error != B_OK) delete child; } else error = B_NO_MEMORY; } // cleanup on error if (error != B_OK) _Unset(); return error; }
// _Update status_t BPartition::_Update(user_partition_data* data, bool* updated) { user_partition_data* oldData = fPartitionData; fPartitionData = data; // check for changes if (data->offset != oldData->offset || data->size != oldData->size || data->block_size != oldData->block_size || data->status != oldData->status || data->flags != oldData->flags || data->volume != oldData->volume || data->disk_system != oldData->disk_system // not needed || compare_string(data->name, oldData->name) || compare_string(data->content_name, oldData->content_name) || compare_string(data->type, oldData->type) || compare_string(data->content_type, oldData->content_type) || compare_string(data->parameters, oldData->parameters) || compare_string(data->content_parameters, oldData->content_parameters)) { *updated = true; } // add new children and update existing ones status_t error = B_OK; for (int32 i = 0; i < data->child_count; i++) { user_partition_data* childData = data->children[i]; BPartition* child = (BPartition*)childData->user_data; if (child) { // old partition error = child->_Update(childData, updated); if (error != B_OK) return error; } else { // new partition *updated = true; child = new(nothrow) BPartition; if (!child) return B_NO_MEMORY; error = child->_SetTo(fDevice, this, childData); if (error != B_OK) { delete child; return error; } childData->user_data = child; } } return error; }