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


C++ BPartition::IsReadOnly方法代码示例

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


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

示例1: if

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;
	}
}
开发者ID:mmanley,项目名称:Antares,代码行数:88,代码来源:isvolume.cpp

示例2: BMessage

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 {
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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