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


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

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


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

示例1: strerror

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


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