当前位置: 首页>>代码示例>>C++>>正文


C++ KDiskDeviceManager类代码示例

本文整理汇总了C++中KDiskDeviceManager的典型用法代码示例。如果您正苦于以下问题:C++ KDiskDeviceManager类的具体用法?C++ KDiskDeviceManager怎么用?C++ KDiskDeviceManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了KDiskDeviceManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _user_find_file_disk_device

partition_id
_user_find_file_disk_device(const char *_filename, size_t *neededSize)
{
	UserStringParameter<false> filename;
	status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
	if (error != B_OK)
		return error;

	KPath path(filename, KPath::NORMALIZE);

	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	// find the device
	KFileDiskDevice* device = manager->RegisterFileDevice(path.Path());
	if (device == NULL)
		return B_ENTRY_NOT_FOUND;
	PartitionRegistrar _(device, true);
	partition_id id = device->ID();
	if (neededSize != NULL) {
		if (DeviceReadLocker locker = device) {
			// get the needed size
			UserDataWriter writer;
			device->WriteUserData(writer);
			error = copy_to_user_value(neededSize, writer.AllocatedSize());
			if (error != B_OK)
				return error;
		} else
			return B_ERROR;
	}
	return id;
}
开发者ID:looncraz,项目名称:haiku,代码行数:30,代码来源:ddm_userland_interface.cpp

示例2: _user_get_file_disk_device_path

status_t
_user_get_file_disk_device_path(partition_id id, char* buffer,
	size_t bufferSize)
{
	if (id < 0 || buffer == NULL || bufferSize == 0)
		return B_BAD_VALUE;
	if (!IS_USER_ADDRESS(buffer))
		return B_BAD_ADDRESS;

	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	KDiskDevice *device = manager->RegisterDevice(id, true);
	if (device != NULL) {
		PartitionRegistrar _(device, true);
		if (DeviceReadLocker locker = device) {
			KFileDiskDevice* fileDevice
				= dynamic_cast<KFileDiskDevice*>(device);
			if (fileDevice == NULL)
				return B_BAD_VALUE;

			ssize_t copied = user_strlcpy(buffer, fileDevice->FilePath(),
				bufferSize);
			if (copied < 0)
				return copied;
			return (size_t)copied < bufferSize ? B_OK : B_BUFFER_OVERFLOW;
		}
	}

	return B_ERROR;
}
开发者ID:looncraz,项目名称:haiku,代码行数:29,代码来源:ddm_userland_interface.cpp

示例3: _user_get_next_disk_device_id

partition_id
_user_get_next_disk_device_id(int32 *_cookie, size_t *neededSize)
{
	int32 cookie;
	status_t error = copy_from_user_value(cookie, _cookie);
	if (error != B_OK)
		return error;

	partition_id id = B_ENTRY_NOT_FOUND;
	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	// get the next device
	if (KDiskDevice *device = manager->RegisterNextDevice(&cookie)) {
		PartitionRegistrar _(device, true);
		id = device->ID();
		if (neededSize != NULL) {
			if (DeviceReadLocker locker = device) {
				// get the needed size
				UserDataWriter writer;
				device->WriteUserData(writer);
				status_t status = copy_to_user_value(neededSize,
					writer.AllocatedSize());
				if (status != B_OK)
					return status;
			} else
				id = B_ERROR;
		}
	}

	error = copy_to_user_value(_cookie, cookie);
	if (error != B_OK)
		return error;
	return id;
}
开发者ID:looncraz,项目名称:haiku,代码行数:33,代码来源:ddm_userland_interface.cpp

示例4: _user_get_next_disk_system_info

status_t
_user_get_next_disk_system_info(int32 *_cookie, user_disk_system_info *_info)
{
	if (_info == NULL)
		return B_BAD_VALUE;
	if (!IS_USER_ADDRESS(_info))
		return B_BAD_ADDRESS;
	int32 cookie;
	status_t result = copy_from_user_value(cookie, _cookie);
	if (result != B_OK)
		return result;
	result = B_ENTRY_NOT_FOUND;
	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	if (ManagerLocker locker = manager) {
		KDiskSystem *diskSystem = manager->NextDiskSystem(&cookie);
		if (diskSystem != NULL) {
			user_disk_system_info info;
			diskSystem->GetInfo(&info);
			result = copy_to_user_value(_info, info);
		}
	}
	status_t error = copy_to_user_value(_cookie, cookie);
	if (error != B_OK)
		result = error;
	return result;
}
开发者ID:looncraz,项目名称:haiku,代码行数:26,代码来源:ddm_userland_interface.cpp

示例5: _user_find_partition

partition_id
_user_find_partition(const char *_filename, size_t *neededSize)
{
	UserStringParameter<false> filename;
	status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
	if (error != B_OK)
		return error;

	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	// find the partition
	KPartition *partition = manager->RegisterPartition(filename);
	if (partition == NULL)
		return B_ENTRY_NOT_FOUND;
	PartitionRegistrar _(partition, true);
	partition_id id = partition->ID();
	if (neededSize != NULL) {
		// get and lock the partition's device
		KDiskDevice *device = manager->RegisterDevice(partition->ID(), false);
		if (device == NULL)
			return B_ENTRY_NOT_FOUND;
		PartitionRegistrar _2(device, true);
		if (DeviceReadLocker locker = device) {
			// get the needed size
			UserDataWriter writer;
			device->WriteUserData(writer);
			error = copy_to_user_value(neededSize, writer.AllocatedSize());
			if (error != B_OK)
				return error;
		} else
			return B_ERROR;
	}
	return id;
}
开发者ID:looncraz,项目名称:haiku,代码行数:33,代码来源:ddm_userland_interface.cpp

示例6: _user_set_partition_content_parameters

status_t
_user_set_partition_content_parameters(partition_id partitionID,
	int32* _changeCounter, const char* _parameters)
{
	// copy parameters in
	UserStringParameter<true> parameters;
	int32 changeCounter;

	status_t error
		= parameters.Init(_parameters, B_DISK_DEVICE_MAX_PARAMETER_SIZE);
	if (error != B_OK || (error = copy_from_user_value(changeCounter,
			_changeCounter)) != B_OK) {
		return error;
	}

	// get the partition
	KDiskDeviceManager* manager = KDiskDeviceManager::Default();
	KPartition* partition = manager->WriteLockPartition(partitionID);
	if (!partition)
		return B_ENTRY_NOT_FOUND;

	PartitionRegistrar registrar1(partition, true);
	PartitionRegistrar registrar2(partition->Device(), true);
	DeviceWriteLocker locker(partition->Device(), true);

	// check change counter
	if (changeCounter != partition->ChangeCounter())
		return B_BAD_VALUE;

	// the partition must be initialized
	KDiskSystem* diskSystem = partition->DiskSystem();
	if (!diskSystem)
		return B_BAD_VALUE;

	// mark the partition busy and unlock
	if (!partition->CheckAndMarkBusy(true))
		return B_BUSY;
	locker.Unlock();

	// set content parameters
	error = diskSystem->SetContentParameters(partition, parameters.value,
		DUMMY_JOB_ID);

	// re-lock and unmark busy
	locker.Lock();
	partition->UnmarkBusy(true);

	if (error != B_OK)
		return error;

	// return change counter
	if ((error = copy_to_user_value(_changeCounter, partition->ChangeCounter()))
			!= B_OK) {
		return error;
	}

	return B_OK;
}
开发者ID:,项目名称:,代码行数:58,代码来源:

示例7: _user_repair_partition

status_t
_user_repair_partition(partition_id partitionID, int32* _changeCounter,
	bool checkOnly)
{
	// copy parameters in
	int32 changeCounter;

	status_t error;
	if ((error = copy_from_user_value(changeCounter, _changeCounter)) != B_OK)
		return error;

	// get the partition
	KDiskDeviceManager* manager = KDiskDeviceManager::Default();
	KPartition* partition = manager->WriteLockPartition(partitionID);
	if (!partition)
		return B_ENTRY_NOT_FOUND;

	PartitionRegistrar registrar1(partition, true);
	PartitionRegistrar registrar2(partition->Device(), true);
	DeviceWriteLocker locker(partition->Device(), true);

	// check change counter
	if (changeCounter != partition->ChangeCounter())
		return B_BAD_VALUE;

	// the partition must be initialized
	KDiskSystem* diskSystem = partition->DiskSystem();
	if (!diskSystem)
		return B_BAD_VALUE;

	// mark the partition busy and unlock
	if (!partition->CheckAndMarkBusy(false))
		return B_BUSY;
	locker.Unlock();

	// repair/check
	error = diskSystem->Repair(partition, checkOnly, DUMMY_JOB_ID);

	// re-lock and unmark busy
	locker.Lock();
	partition->UnmarkBusy(false);

	if (error != B_OK)
		return error;

	// return change counter
	if ((error = copy_to_user_value(_changeCounter, partition->ChangeCounter()))
			!= B_OK) {
		return error;
	}

	return B_OK;
}
开发者ID:,项目名称:,代码行数:53,代码来源:

示例8: device

/*!	\brief Writes data describing the disk device identified by ID and all
		   its partitions into the supplied buffer.

	The function passes the buffer size required to hold the data back
	through the \a _neededSize parameter, if the device could be found at
	least and no serious error occured. If fails with \c B_BUFFER_OVERFLOW,
	if the supplied buffer is too small or a \c NULL buffer is supplied
	(and \c bufferSize is 0).

	The device is identified by \a id. If \a deviceOnly is \c true, then
	it must be the ID of a disk device, otherwise the disk device is
	chosen, on which the partition \a id refers to resides.

	\param id The ID of an arbitrary partition on the disk device (including
		   the disk device itself), whose data shall be returned
		   (if \a deviceOnly is \c false), or the ID of the disk device
		   itself (if \a deviceOnly is true).
	\param deviceOnly Specifies whether only IDs of disk devices (\c true),
		   or also IDs of partitions (\c false) are accepted for \a id.
	\param buffer The buffer into which the disk device data shall be written.
		   May be \c NULL.
	\param bufferSize The size of \a buffer.
	\param _neededSize Pointer to a variable into which the actually needed
		   buffer size is written. May be \c NULL.
	\return
	- \c B_OK: Everything went fine. The device was found and, if not \c NULL,
	  in \a _neededSize the actually needed buffer size is returned. And
	  \a buffer will contain the disk device data.
	- \c B_BAD_VALUE: \c NULL \a buffer, but not 0 \a bufferSize.
	- \c B_BUFFER_OVERFLOW: The supplied buffer was too small. \a _neededSize,
	  if not \c NULL, will contain the required buffer size.
	- \c B_NO_MEMORY: Insufficient memory to complete the operation.
	- \c B_ENTRY_NOT_FOUND: \a id is no valid disk device ID (if \a deviceOnly
	  is \c true) or not even a valid partition ID (if \a deviceOnly is
	  \c false).
	- \c B_ERROR: An unexpected error occured.
	- another error code...
*/
status_t
_user_get_disk_device_data(partition_id id, bool deviceOnly,
	user_disk_device_data *buffer, size_t bufferSize, size_t *_neededSize)
{
	if (buffer == NULL && bufferSize > 0)
		return B_BAD_VALUE;
	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	// get the device
	KDiskDevice *device = manager->RegisterDevice(id, deviceOnly);
	if (device == NULL)
		return B_ENTRY_NOT_FOUND;

	PartitionRegistrar _(device, true);
	if (DeviceReadLocker locker = device) {
		// do a dry run first to get the needed size
		UserDataWriter writer;
		device->WriteUserData(writer);
		size_t neededSize = writer.AllocatedSize();
		if (_neededSize != NULL) {
			status_t error = copy_ref_var_to_user(neededSize, _neededSize);
			if (error != B_OK)
				return error;
		}
		// if no buffer has been supplied or the buffer is too small,
		// then we're done
		if (buffer == NULL || bufferSize < neededSize)
			return B_BUFFER_OVERFLOW;
		if (!IS_USER_ADDRESS(buffer))
			return B_BAD_ADDRESS;
		// otherwise allocate a kernel buffer
		user_disk_device_data *kernelBuffer
			= static_cast<user_disk_device_data*>(malloc(neededSize));
		if (kernelBuffer == NULL)
			return B_NO_MEMORY;
		MemoryDeleter deleter(kernelBuffer);
		// write the device data into the buffer
		writer.SetTo(kernelBuffer, bufferSize);
		device->WriteUserData(writer);
		// sanity check
		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;
		}
		// relocate
		status_t error = writer.Relocate(buffer);
		if (error != B_OK)
			return error;
		// copy out
		return user_memcpy(buffer, kernelBuffer, neededSize);
	} else
		return B_ERROR;
}
开发者ID:looncraz,项目名称:haiku,代码行数:91,代码来源:ddm_userland_interface.cpp

示例9: _user_set_partition_content_name

status_t
_user_set_partition_content_name(partition_id partitionID,
	int32* _changeCounter, const char* _name)
{
	// copy parameters in
	UserStringParameter<true> name;
	int32 changeCounter;

	status_t error = name.Init(_name, B_DISK_DEVICE_NAME_LENGTH);
	if (error == B_OK)
		error = copy_from_user_value(changeCounter, _changeCounter);
	if (error != B_OK)
		return error;

	// get the partition
	KDiskDeviceManager* manager = KDiskDeviceManager::Default();
	KPartition* partition = manager->WriteLockPartition(partitionID);
	if (partition == NULL)
		return B_ENTRY_NOT_FOUND;

	PartitionRegistrar registrar1(partition, true);
	PartitionRegistrar registrar2(partition->Device(), true);
	DeviceWriteLocker locker(partition->Device(), true);

	// check change counter
	if (changeCounter != partition->ChangeCounter())
		return B_BAD_VALUE;

	// the partition must be initialized
	KDiskSystem* diskSystem = partition->DiskSystem();
	if (diskSystem == NULL)
		return B_BAD_VALUE;

	// mark the partition busy and unlock
	if (!partition->CheckAndMarkBusy(false))
		return B_BUSY;
	locker.Unlock();

	// set content parameters
	error = diskSystem->SetContentName(partition, name.value, DUMMY_JOB_ID);

	// re-lock and unmark busy
	locker.Lock();
	partition->UnmarkBusy(false);

	if (error != B_OK)
		return error;

	// return change counter
	return copy_to_user_value(_changeCounter, partition->ChangeCounter());
}
开发者ID:looncraz,项目名称:haiku,代码行数:51,代码来源:ddm_userland_interface.cpp

示例10: _user_unregister_file_device

status_t
_user_unregister_file_device(partition_id deviceID, const char *_filename)
{
	if (deviceID < 0 && _filename == NULL)
		return B_BAD_VALUE;
	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	if (deviceID >= 0)
		return manager->DeleteFileDevice(deviceID);

	UserStringParameter<false> filename;
	status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
	if (error != B_OK)
		return error;

	return manager->DeleteFileDevice(filename);
}
开发者ID:looncraz,项目名称:haiku,代码行数:16,代码来源:ddm_userland_interface.cpp

示例11: _user_get_disk_system_info

status_t
_user_get_disk_system_info(disk_system_id id, user_disk_system_info *_info)
{
	if (_info == NULL)
		return B_BAD_VALUE;
	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	if (ManagerLocker locker = manager) {
		KDiskSystem *diskSystem = manager->FindDiskSystem(id);
		if (diskSystem != NULL) {
			user_disk_system_info info;
			diskSystem->GetInfo(&info);
			return copy_to_user_value(_info, info);
		}
	}
	return B_ENTRY_NOT_FOUND;
}
开发者ID:looncraz,项目名称:haiku,代码行数:16,代码来源:ddm_userland_interface.cpp

示例12: _user_get_disk_system_info

status_t
_user_get_disk_system_info(disk_system_id id, user_disk_system_info *_info)
{
	if (!_info)
		return B_BAD_VALUE;
	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	if (ManagerLocker locker = manager) {
		if (KDiskSystem *diskSystem = manager->FindDiskSystem(id)) {
			user_disk_system_info info;
			diskSystem->GetInfo(&info);
			user_memcpy(_info, &info, sizeof(info));
			return B_OK;
		}
	}
	return B_ENTRY_NOT_FOUND;
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例13: _user_register_file_device

partition_id
_user_register_file_device(const char *_filename)
{
	UserStringParameter<false> filename;
	status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
	if (error != B_OK)
		return error;

	KPath path(filename, true);

	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	if (ManagerLocker locker = manager) {
		if (KFileDiskDevice *device = manager->FindFileDevice(path.Path()))
			return device->ID();
		return manager->CreateFileDevice(path.Path());
	}
	return B_ERROR;
}
开发者ID:,项目名称:,代码行数:18,代码来源:

示例14: _user_get_next_disk_system_info

status_t
_user_get_next_disk_system_info(int32 *_cookie, user_disk_system_info *_info)
{
	if (!_cookie || !_info)
		return B_BAD_VALUE;
	int32 cookie;
	user_memcpy(&cookie, _cookie, sizeof(cookie));
	status_t result = B_ENTRY_NOT_FOUND;
	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	if (ManagerLocker locker = manager) {
		if (KDiskSystem *diskSystem = manager->NextDiskSystem(&cookie)) {
			user_disk_system_info info;
			diskSystem->GetInfo(&info);
			user_memcpy(_info, &info, sizeof(info));
			result = B_OK;
		}
	}
	user_memcpy(_cookie, &cookie, sizeof(cookie));
	return result;
}
开发者ID:,项目名称:,代码行数:20,代码来源:

示例15: _user_find_disk_system

status_t
_user_find_disk_system(const char *_name, user_disk_system_info *_info)
{
	if (!_name || !_info)
		return B_BAD_VALUE;
	char name[B_DISK_SYSTEM_NAME_LENGTH];
	status_t error = ddm_strlcpy(name, _name, B_DISK_SYSTEM_NAME_LENGTH);
	if (error)
		return error;
	KDiskDeviceManager *manager = KDiskDeviceManager::Default();
	if (ManagerLocker locker = manager) {
		if (KDiskSystem *diskSystem = manager->FindDiskSystem(name)) {
			user_disk_system_info info;
			diskSystem->GetInfo(&info);
			user_memcpy(_info, &info, sizeof(info));
			return B_OK;
		}
	}
	return B_ENTRY_NOT_FOUND;
}
开发者ID:,项目名称:,代码行数:20,代码来源:


注:本文中的KDiskDeviceManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。