本文整理汇总了C++中BPartition类的典型用法代码示例。如果您正苦于以下问题:C++ BPartition类的具体用法?C++ BPartition怎么用?C++ BPartition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BPartition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _Unset
// _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;
}
示例2: _DisplayPartitionError
void
MainWindow::_Mount(BDiskDevice* disk, partition_id selectedPartition)
{
if (!disk || selectedPartition < 0) {
_DisplayPartitionError(B_TRANSLATE("You need to select a partition "
"entry from the list."));
return;
}
BPartition* partition = disk->FindDescendant(selectedPartition);
if (!partition) {
_DisplayPartitionError(B_TRANSLATE("Unable to find the selected "
"partition by ID."));
return;
}
if (!partition->IsMounted()) {
status_t ret = partition->Mount();
if (ret < B_OK) {
_DisplayPartitionError(
B_TRANSLATE("Could not mount partition %s."), partition, ret);
} else {
// successful mount, adapt to the changes
_ScanDrives();
}
} else {
_DisplayPartitionError(
B_TRANSLATE("The partition %s is already mounted."), partition);
}
}
示例3: new
// _CreateDelegates
status_t
BPartition::_CreateDelegates()
{
if (fDelegate || !fPartitionData)
return B_NO_INIT;
// create and init delegate
fDelegate = new(nothrow) Delegate(this);
if (!fDelegate)
return B_NO_MEMORY;
status_t error = fDelegate->InitHierarchy(fPartitionData,
fParent ? fParent->fDelegate : NULL);
if (error != B_OK)
return error;
// create child delegates
int32 count = _CountChildren();
for (int32 i = 0; i < count; i++) {
BPartition* child = _ChildAt(i);
error = child->_CreateDelegates();
if (error != B_OK)
return error;
}
return B_OK;
}
示例4: sizeof
void
AutoMounter::_MountVolume(const BMessage* message)
{
int32 id;
if (message->FindInt32("id", &id) != B_OK)
return;
BDiskDeviceRoster roster;
BPartition *partition;
BDiskDevice device;
if (roster.GetPartitionWithID(id, &device, &partition) != B_OK)
return;
uint32 mountFlags;
if (!_SuggestMountFlags(partition, &mountFlags))
return;
status_t status = partition->Mount(NULL, mountFlags);
if (status < B_OK) {
char text[512];
snprintf(text, sizeof(text),
B_TRANSLATE("Error mounting volume:\n\n%s"), strerror(status));
BAlert* alert = new BAlert(B_TRANSLATE("Mount error"), text,
B_TRANSLATE("OK"));
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go(NULL);
}
}
示例5: Parent
// CanMove
bool
BPartition::CanMove(BObjectList<BPartition>* unmovableDescendants,
BObjectList<BPartition>* movableOnlyIfUnmounted) const
{
BPartition* parent = Parent();
if (!parent || !fDelegate)
return false;
if (!parent->_SupportsChildOperation(this,
B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD)) {
return false;
}
bool whileMounted;
bool movable = _SupportsOperation(B_DISK_SYSTEM_SUPPORTS_MOVING,
B_DISK_SYSTEM_SUPPORTS_MOVING_WHILE_MOUNTED, &whileMounted);
if (!movable)
return false;
if (!whileMounted)
movableOnlyIfUnmounted->AddItem(const_cast<BPartition*>(this));
// collect descendent partitions
// TODO: ...
// TODO: Currently there's no interface for asking descendents. They'll still
// have the same offset (relative to their parent) after moving. The only thing
// we really have to ask is whether they need to be unmounted.
return true;
}
示例6: ChildAt
// DeleteChild
status_t
BPartition::DeleteChild(int32 index)
{
if (!fDelegate)
return B_NO_INIT;
BPartition* child = ChildAt(index);
if (!child || child->Parent() != this)
return B_BAD_VALUE;
return fDelegate->DeleteChild(child->fDelegate);
}
示例7: BPartition
BPartition* BImage::getFullPartition()
{
BPartition* ret = new BPartition(this);
for (int x=0; x<myWidth; x++)
{
for (int y=0; y<myHeight; y++)
{
// setPixelOwner(x,y,ret,1);
ret->addPixelFromSrc(x,y);
}
}
return ret;
}
示例8: compare_string
// _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;
}
示例9: volume
void
AutoMounter::_UnmountAndEjectVolume(BMessage* message)
{
int32 id;
if (message->FindInt32("id", &id) == B_OK) {
BDiskDeviceRoster roster;
BPartition *partition;
BDiskDevice device;
if (roster.GetPartitionWithID(id, &device, &partition) != B_OK)
return;
BPath path;
if (partition->GetMountPoint(&path) == B_OK)
_UnmountAndEjectVolume(partition, path, partition->ContentName());
} else {
// see if we got a dev_t
dev_t device;
if (message->FindInt32("device_id", &device) != B_OK)
return;
BVolume volume(device);
status_t status = volume.InitCheck();
char name[B_FILE_NAME_LENGTH];
if (status == B_OK)
status = volume.GetName(name);
if (status < B_OK)
snprintf(name, sizeof(name), "device:%" B_PRIdDEV, device);
BPath path;
if (status == B_OK) {
BDirectory mountPoint;
status = volume.GetRootDirectory(&mountPoint);
if (status == B_OK)
status = path.SetTo(&mountPoint, ".");
}
if (status == B_OK)
_UnmountAndEjectVolume(NULL, path, name);
}
}
示例10: dir
void
InstallerWindow::_PublishPackages()
{
fPackagesView->Clean();
PartitionMenuItem *item = (PartitionMenuItem *)fSrcMenu->FindMarked();
if (!item)
return;
BPath directory;
BDiskDeviceRoster roster;
BDiskDevice device;
BPartition *partition;
if (roster.GetPartitionWithID(item->ID(), &device, &partition) == B_OK) {
if (partition->GetMountPoint(&directory) != B_OK)
return;
} else if (roster.GetDeviceWithID(item->ID(), &device) == B_OK) {
if (device.GetMountPoint(&directory) != B_OK)
return;
} else
return; // shouldn't happen
directory.Append(PACKAGES_DIRECTORY);
BDirectory dir(directory.Path());
if (dir.InitCheck() != B_OK)
return;
BEntry packageEntry;
BList packages;
while (dir.GetNextEntry(&packageEntry) == B_OK) {
Package* package = Package::PackageFromEntry(packageEntry);
if (package != NULL)
packages.AddItem(package);
}
packages.SortItems(_ComparePackages);
fPackagesView->AddPackages(packages, new BMessage(PACKAGE_CHECKBOX));
PostMessage(PACKAGE_CHECKBOX);
}
示例11: CountChildren
// _RemoveObsoleteDescendants
status_t
BPartition::_RemoveObsoleteDescendants(user_partition_data* data, bool* updated)
{
// remove all children not longer persistent
// Not exactly efficient: O(n^2), considering BList::RemoveItem()
// O(1). We could do better (O(n*log(n))), when sorting the arrays before,
// but then the list access is more random and we had to find the
// BPartition to remove, which makes the list operation definitely O(n).
int32 count = CountChildren();
for (int32 i = count - 1; i >= 0; i--) {
BPartition* child = ChildAt(i);
bool found = false;
for (int32 k = data->child_count - 1; k >= 0; k--) {
if (data->children[k]->id == child->ID()) {
// found partition: ask it to remove its obsolete descendants
found = true;
status_t error = child->_RemoveObsoleteDescendants(
data->children[k], updated);
if (error != B_OK)
return error;
// set the user data to the BPartition object to find it
// quicker later
data->children[k]->user_data = child;
break;
}
}
// if partition is obsolete, remove it
if (!found) {
*updated = true;
_RemoveChild(i);
}
}
return B_OK;
}
示例12: main
int
main(int argc, char** argv)
{
dev_t volumeDevice = dev_for_path(".");
uint32 isVolumeFlags = 0;
fs_info volumeInfo;
bool doPartitionReadOnlyCheck = false;
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--help")) {
usage();
return 0;
}
if (argv[i][0] == '-') {
if (strcmp(argv[i], "-readonly") == 0)
isVolumeFlags |= B_FS_IS_READONLY;
else if (strcmp(argv[i], "-query") == 0)
isVolumeFlags |= B_FS_HAS_QUERY;
else if (strcmp(argv[i], "-attribute") == 0)
isVolumeFlags |= B_FS_HAS_ATTR;
else if (strcmp(argv[i], "-mime") == 0)
isVolumeFlags |= B_FS_HAS_MIME;
else if (strcmp(argv[i], "-shared") == 0)
isVolumeFlags |= B_FS_IS_SHARED;
else if (strcmp(argv[i], "-persistent") == 0)
isVolumeFlags |= B_FS_IS_PERSISTENT;
else if (strcmp(argv[i], "-removable") == 0)
isVolumeFlags |= B_FS_IS_REMOVABLE;
else if (strcmp(argv[i], "-readonly-partion"))
doPartitionReadOnlyCheck = true;
else {
fprintf(stderr,
"%s: option %s is not understood (use --help for help)\n",
argv[0], argv[i]);
return 1;
}
} else {
volumeDevice = dev_for_path(argv[i]);
if (volumeDevice < 0) {
fprintf(stderr, "%s: can't get information about volume: %s\n",
argv[0], argv[i]);
return 1;
}
}
}
if (doPartitionReadOnlyCheck) {
// This requires an extra code-path, because volumes may now appear
// writable, but only because of the "write" file-system overlay.
BVolume volume(volumeDevice);
status_t ret = volume.InitCheck();
if (ret != B_OK) {
fprintf(stderr, "%s: failed to get BVolume for device %ld: %s\n",
argv[0], volumeDevice, strerror(ret));
return 1;
}
BDiskDeviceRoster roster;
BDiskDevice diskDevice;
BPartition* partition;
ret = roster.FindPartitionByVolume(volume, &diskDevice, &partition);
if (ret != B_OK) {
fprintf(stderr, "%s: failed to get partition for device %ld: %s\n",
argv[0], volumeDevice, strerror(ret));
return 1;
}
// check this option directly and not via fs_stat_dev()
if (partition->IsReadOnly()) {
printf("yes\n");
return 0;
}
}
if (fs_stat_dev(volumeDevice, &volumeInfo) == B_OK) {
if (volumeInfo.flags & isVolumeFlags)
printf("yes\n");
else
printf("no\n");
return 0;
} else {
fprintf(stderr, "%s: can't get information about dev_t: %ld\n",
argv[0], volumeDevice);
return 1;
}
}
示例13: main
int
main(int argc, char** argv)
{
const struct option kLongOptions[] = {
{ "help", 0, NULL, 'h' },
{ "check-only", 0, NULL, 'c' },
{ NULL, 0, NULL, 0 }
};
const char* kShortOptions = "hc";
// parse argument list
bool checkOnly = false;
while (true) {
int nextOption = getopt_long(argc, argv, kShortOptions, kLongOptions,
NULL);
if (nextOption == -1)
break;
switch (nextOption) {
case 'h': // --help
usage(stdout);
return 0;
case 'c': // --check-only
checkOnly = true;
break;
default: // everything else
usage(stderr);
return 1;
}
}
// the device name should be the only non-option element
if (optind != argc - 1) {
usage(stderr);
return 1;
}
const char* path = argv[optind];
//UnregisterFileDevice unregisterFileDevice;
BDiskDeviceRoster roster;
BPartition* partition;
BDiskDevice device;
status_t status = roster.GetPartitionForPath(path, &device,
&partition);
if (status != B_OK) {
if (strncmp(path, "/dev", 4)) {
// try mounted volume
status = roster.FindPartitionByMountPoint(path, &device, &partition)
? B_OK : B_BAD_VALUE;
}
// TODO: try to register file device
if (status != B_OK) {
fprintf(stderr, "%s: Failed to get disk device for path \"%s\": "
"%s\n", kProgramName, path, strerror(status));
return 1;
}
}
// Prepare the device for modifications
status = device.PrepareModifications();
if (status != B_OK) {
fprintf(stderr, "%s: Could not prepare the device for modifications: "
"%s\n", kProgramName, strerror(status));
return 1;
}
// Check if the partition supports repairing
bool canRepairWhileMounted;
bool canRepair = partition->CanRepair(checkOnly, &canRepairWhileMounted);
if (!canRepair && !canRepairWhileMounted) {
fprintf(stderr, "%s: The disk system does not support repairing.\n",
kProgramName);
return 1;
}
if (partition->IsMounted() && !canRepairWhileMounted) {
fprintf(stderr, "%s: The disk system does not support repairing a "
"mounted volume.\n", kProgramName);
return 1;
}
if (!partition->IsMounted() && !canRepair) {
fprintf(stderr, "%s: The disk system does not support repairing a "
"volume that is not mounted.\n", kProgramName);
return 1;
}
BDiskSystem diskSystem;
status = partition->GetDiskSystem(&diskSystem);
if (status != B_OK) {
fprintf(stderr, "%s: Failed to get disk system for partition: %s\n",
kProgramName, strerror(status));
return 1;
}
//.........这里部分代码省略.........
示例14: while
void
MainWindow::_UpdateMenus(BDiskDevice* disk,
partition_id selectedPartition, partition_id parentID)
{
while (BMenuItem* item = fFormatMenu->RemoveItem(0L))
delete item;
while (BMenuItem* item = fDiskInitMenu->RemoveItem(0L))
delete item;
fCreateMI->SetEnabled(false);
fUnmountMI->SetEnabled(false);
fDiskInitMenu->SetEnabled(false);
fFormatMenu->SetEnabled(false);
if (!disk) {
fWipeMI->SetEnabled(false);
fEjectMI->SetEnabled(false);
fSurfaceTestMI->SetEnabled(false);
} else {
// fWipeMI->SetEnabled(true);
fWipeMI->SetEnabled(false);
fEjectMI->SetEnabled(disk->IsRemovableMedia());
// fSurfaceTestMI->SetEnabled(true);
fSurfaceTestMI->SetEnabled(false);
// Create menu and items
BPartition* parentPartition = NULL;
if (selectedPartition <= -2) {
// a partitionable space item is selected
parentPartition = disk->FindDescendant(parentID);
}
if (parentPartition && parentPartition->ContainsPartitioningSystem())
fCreateMI->SetEnabled(true);
bool prepared = disk->PrepareModifications() == B_OK;
fFormatMenu->SetEnabled(prepared);
fDeleteMI->SetEnabled(prepared);
BPartition* partition = disk->FindDescendant(selectedPartition);
BDiskSystem diskSystem;
fDDRoster.RewindDiskSystems();
while (fDDRoster.GetNextDiskSystem(&diskSystem) == B_OK) {
if (!diskSystem.SupportsInitializing())
continue;
BMessage* message = new BMessage(MSG_INITIALIZE);
message->AddInt32("parent id", parentID);
message->AddString("disk system", diskSystem.PrettyName());
BString label = diskSystem.PrettyName();
label << B_UTF8_ELLIPSIS;
BMenuItem* item = new BMenuItem(label.String(), message);
// TODO: Very unintuitive that we have to use PrettyName (vs Name)
item->SetEnabled(partition != NULL
&& partition->CanInitialize(diskSystem.PrettyName()));
if (disk->ID() == selectedPartition
&& !diskSystem.IsFileSystem()) {
// Disk is selected, and DiskSystem is a partition map
fDiskInitMenu->AddItem(item);
} else if (diskSystem.IsFileSystem()) {
// Otherwise a filesystem
fFormatMenu->AddItem(item);
}
}
// Mount items
if (partition) {
fFormatMenu->SetEnabled(!partition->IsMounted()
&& !partition->IsReadOnly()
&& partition->Device()->HasMedia()
&& fFormatMenu->CountItems() > 0);
fDiskInitMenu->SetEnabled(!partition->IsMounted()
&& !partition->IsReadOnly()
&& partition->Device()->HasMedia()
&& partition->IsDevice()
&& fDiskInitMenu->CountItems() > 0);
fDeleteMI->SetEnabled(!partition->IsMounted()
&& !partition->IsDevice());
fMountMI->SetEnabled(!partition->IsMounted());
bool unMountable = false;
if (partition->IsMounted()) {
// see if this partition is the boot volume
BVolume volume;
BVolume bootVolume;
if (BVolumeRoster().GetBootVolume(&bootVolume) == B_OK
&& partition->GetVolume(&volume) == B_OK) {
unMountable = volume != bootVolume;
} else
unMountable = true;
}
fUnmountMI->SetEnabled(unMountable);
} else {
//.........这里部分代码省略.........
示例15: if
void
MountVolume::ArgvReceived(int32 argc, char** argv)
{
MountVisitor mountVisitor;
PrintPartitionsVisitor printPartitionsVisitor;
bool listAllDevices = false;
if (argc < 2)
printPartitionsVisitor.listMountablePartitions = true;
// parse arguments
for (int argi = 1; argi < argc; argi++) {
const char* arg = argv[argi];
if (arg[0] != '\0' && arg[0] != '-') {
mountVisitor.toMount.insert(arg);
} else if (strcmp(arg, "-s") == 0) {
mountVisitor.silent = true;
} else if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
print_usage_and_exit(false);
} else if (strcmp(arg, "-all") == 0) {
mountVisitor.mountAll = true;
} else if (strcmp(arg, "-allbfs") == 0) {
mountVisitor.mountBFS = true;
} else if (strcmp(arg, "-allhfs") == 0) {
mountVisitor.mountHFS = true;
} else if (strcmp(arg, "-alldos") == 0) {
mountVisitor.mountDOS = true;
} else if (strcmp(arg, "-ro") == 0 || strcmp(arg, "-readonly") == 0) {
mountVisitor.readOnly = true;
} else if (strcmp(arg, "-u") == 0 || strcmp(arg, "-unmount") == 0) {
argi++;
if (argi >= argc)
print_usage_and_exit(true);
mountVisitor.toUnmount.insert(argv[argi]);
} else if (strcmp(arg, "-p") == 0 || strcmp(arg, "-l") == 0) {
printPartitionsVisitor.listMountablePartitions = true;
} else if (strcmp(arg, "-lh") == 0) {
printPartitionsVisitor.listAllPartitions = true;
} else if (strcmp(arg, "-dd") == 0) {
listAllDevices = true;
} else if (strcmp(arg, "-r") == 0 || strcmp(arg, "-publishall") == 0
|| strcmp(arg, "-publishbfs") == 0
|| strcmp(arg, "-publishhfs") == 0
|| strcmp(arg, "-publishdos") == 0) {
// obsolete: ignore
} else
print_usage_and_exit(true);
}
// get a disk device list
BDiskDeviceList deviceList;
status_t error = deviceList.Fetch();
if (error != B_OK) {
fprintf(stderr, "Failed to get the list of disk devices: %s",
strerror(error));
exit(1);
}
// mount/unmount volumes
deviceList.VisitEachMountablePartition(&mountVisitor);
BDiskDeviceRoster roster;
// try mount file images
for (StringSet::iterator iterator = mountVisitor.toMount.begin();
iterator != mountVisitor.toMount.end();) {
const char* name = (*iterator).c_str();
iterator++;
BEntry entry(name, true);
if (!entry.Exists())
continue;
// TODO: improve error messages
BPath path;
if (entry.GetPath(&path) != B_OK)
continue;
partition_id id = -1;
BDiskDevice device;
BPartition* partition;
if (!strncmp(path.Path(), "/dev/", 5)) {
// seems to be a device path
if (roster.GetPartitionForPath(path.Path(), &device, &partition)
!= B_OK)
continue;
} else {
// a file with this name exists, so try to mount it
id = roster.RegisterFileDevice(path.Path());
if (id < 0)
continue;
if (roster.GetPartitionWithID(id, &device, &partition) != B_OK) {
roster.UnregisterFileDevice(id);
continue;
}
}
//.........这里部分代码省略.........