rem: if (neededSize) *neededSize = writer.AllocatedSize(); if (writer.AllocatedSize() > bufferSize) result = B_BUFFER_OVERFLOW; } } else { result = B_ENTRY_NOT_FOUND;
add: if (writer.AllocatedSize() != neededSize) { ERROR(("Size of written disk device user data changed from " "%lu to %lu while device was locked!\n")); return B_ERROR; }  status_t error = writer.Relocate(buffer); if (error != B_OK) return error;  if (buffer) return user_memcpy(buffer, kernelBuffer, neededSize); } else return B_ERROR;
context: _kern_get_disk_device_data(partition_id id, bool deviceOnly, bool shadow,						   user_disk_device_data *_buffer, size_t bufferSize,						   size_t *neededSize){	if (!_buffer && bufferSize > 0)		return B_BAD_VALUE;	// copy in	user_disk_device_data *buffer = bufferSize > 0	                                ? reinterpret_cast<user_disk_device_data*>(malloc(bufferSize))	                                : NULL;	if (buffer)		user_memcpy(buffer, _buffer, bufferSize);			status_t result = B_OK;		KDiskDeviceManager *manager = KDiskDeviceManager::Default();	// get the device	if (KDiskDevice *device = manager->RegisterDevice(id, deviceOnly)) {		PartitionRegistrar _(device, true);		if (DeviceReadLocker locker = device) {			// write the device data into the buffer			UserDataWriter writer(buffer, bufferSize);			device->WriteUserData(writer, shadow);			if (neededSize)				*neededSize = writer.AllocatedSize();			if (writer.AllocatedSize() > bufferSize)				result = B_BUFFER_OVERFLOW;		}	} else {		result = B_ENTRY_NOT_FOUND;	}	// copy out	if (result == B_OK && buffer)		user_memcpy(_buffer, buffer, bufferSize);	free(buffer);		return result;}