本文整理汇总了C++中UserStringParameter类的典型用法代码示例。如果您正苦于以下问题:C++ UserStringParameter类的具体用法?C++ UserStringParameter怎么用?C++ UserStringParameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserStringParameter类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _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;
}
示例2: _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;
}
示例3: _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());
}
示例4: _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);
}
示例5: _user_set_partition_parameters
status_t
_user_set_partition_parameters(partition_id partitionID, int32* _changeCounter,
partition_id childID, int32* _childChangeCounter, const char* _parameters)
{
// copy parameters in
UserStringParameter<true> parameters;
int32 changeCounter;
int32 childChangeCounter;
status_t error
= parameters.Init(_parameters, B_DISK_DEVICE_MAX_PARAMETER_SIZE);
if (error == B_OK)
error = copy_from_user_value(changeCounter, _changeCounter);
if (error == B_OK)
error = copy_from_user_value(childChangeCounter, _childChangeCounter);
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);
// register child
KPartition* child = manager->RegisterPartition(childID);
if (child == NULL)
return B_ENTRY_NOT_FOUND;
PartitionRegistrar registrar3(child, true);
// check change counters
if (changeCounter != partition->ChangeCounter()
|| childChangeCounter != child->ChangeCounter()) {
return B_BAD_VALUE;
}
// the partition must be initialized
KDiskSystem* diskSystem = partition->DiskSystem();
if (diskSystem == NULL)
return B_BAD_VALUE;
// child must indeed be a child of partition
if (child->Parent() != partition)
return B_BAD_VALUE;
// mark the partition busy and unlock
if (partition->IsBusy() || child->IsBusy())
return B_BUSY;
partition->SetBusy(true);
child->SetBusy(true);
locker.Unlock();
// set the child parameters
error = diskSystem->SetParameters(child, parameters.value, DUMMY_JOB_ID);
// re-lock and unmark busy
locker.Lock();
partition->SetBusy(false);
child->SetBusy(false);
if (error != B_OK)
return error;
// return change counters
error = copy_to_user_value(_changeCounter, partition->ChangeCounter());
if (error == B_OK)
error = copy_to_user_value(_childChangeCounter, child->ChangeCounter());
return error;
}
示例6: _user_create_child_partition
status_t
_user_create_child_partition(partition_id partitionID, int32* _changeCounter,
off_t offset, off_t size, const char* _type, const char* _name,
const char* _parameters, partition_id* childID, int32* childChangeCounter)
{
// copy parameters in
UserStringParameter<false> type;
UserStringParameter<true> name;
UserStringParameter<true> parameters;
int32 changeCounter;
status_t error = type.Init(_type, B_DISK_DEVICE_TYPE_LENGTH);
if (error == B_OK)
error = name.Init(_name, B_DISK_DEVICE_NAME_LENGTH);
if (error == B_OK)
error = parameters.Init(_parameters, B_DISK_DEVICE_MAX_PARAMETER_SIZE);
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();
// create the child
KPartition *child = NULL;
error = diskSystem->CreateChild(partition, offset, size, type.value,
name.value, parameters.value, DUMMY_JOB_ID, &child, -1);
// re-lock and unmark busy
locker.Lock();
partition->UnmarkBusy(false);
if (error != B_OK)
return error;
if (child == NULL)
return B_ERROR;
child->UnmarkBusy(true);
// return change counter and child ID
error = copy_to_user_value(_changeCounter, partition->ChangeCounter());
if (error == B_OK)
error = copy_to_user_value(childID, child->ID());
return error;
}
示例7: _user_initialize_partition
status_t
_user_initialize_partition(partition_id partitionID, int32* _changeCounter,
const char* _diskSystemName, const char* _name, const char* _parameters)
{
// copy parameters in
UserStringParameter<false> diskSystemName;
UserStringParameter<true> name;
UserStringParameter<true> parameters;
int32 changeCounter;
status_t error
= diskSystemName.Init(_diskSystemName, B_DISK_SYSTEM_NAME_LENGTH);
if (error == B_OK)
error = name.Init(_name, B_DISK_DEVICE_NAME_LENGTH);
if (error == B_OK)
error = parameters.Init(_parameters, B_DISK_DEVICE_MAX_PARAMETER_SIZE);
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 uninitialized
if (partition->DiskSystem() != NULL)
return B_BAD_VALUE;
// load the new disk system
KDiskSystem *diskSystem = manager->LoadDiskSystem(diskSystemName.value,
true);
if (diskSystem == NULL)
return B_ENTRY_NOT_FOUND;
DiskSystemLoader loader(diskSystem, true);
// mark the partition busy and unlock
if (!partition->CheckAndMarkBusy(true))
return B_BUSY;
locker.Unlock();
// let the disk system initialize the partition
error = diskSystem->Initialize(partition, name.value, parameters.value,
DUMMY_JOB_ID);
// re-lock and unmark busy
locker.Lock();
partition->UnmarkBusy(true);
if (error != B_OK)
return error;
// Set the disk system. Re-check whether a disk system is already set on the
// partition. Some disk systems just write the on-disk structures and let
// the DDM rescan the partition, in which case the disk system will already
// be set. In very unfortunate cases the on-disk structure of the previous
// disk system has not been destroyed and the previous disk system has a
// higher priority than the new one. The old disk system will thus prevail.
// Not setting the new disk system will at least prevent that the partition
// object gets into an inconsistent state.
if (partition->DiskSystem() == NULL)
partition->SetDiskSystem(diskSystem);
// return change counter
return copy_to_user_value(_changeCounter, partition->ChangeCounter());
}