Пример #1
0
Файл: libffs2.c Проект: gdhh/ffs
int ffs_check(const char *path, off_t offset)
{
	RAII(FILE*, file, fopen(path, "r"), fclose);
	if (file == NULL) {
		__error.errnum = -1;
		snprintf(__error.errstr, sizeof __error.errstr,
			 "%s: %s : %s(%d) : %s (errno=%d)\n",
			 program_invocation_short_name, "errno",
			 __FILE__, __LINE__, strerror(errno), errno);

		return -1;
	}

	int rc = __ffs_fcheck(file, offset);
	if (rc < 0) {
		err_t *err = err_get();
		assert(err != NULL);

		__error.errnum = err_code(err);
		snprintf(__error.errstr, sizeof __error.errstr,
			 "%s: %s : %s(%d) : (code=%d) %.*s\n",
			 program_invocation_short_name,
			 err_type_name(err), err_file(err), err_line(err),
			 err_code(err), err_size(err), (char *)err_data(err));

		// __ffs_check will return FFS_CHECK_* const's
	}

	return rc;
}
Пример #2
0
Файл: misc.c Проект: whs1787/ffs
int check_file(const char * path, FILE * file, off_t offset) {
	assert(file != NULL);

	switch (__ffs_fcheck(file, offset)) {
	case 0:
		return 0;
	case FFS_CHECK_HEADER_MAGIC:
		UNEXPECTED("'%s' no partition table found at offset '%llx'\n",
			   path, (long long)offset);
		return -1;
	case FFS_CHECK_HEADER_CHECKSUM:
		UNEXPECTED("'%s' partition table at offset '%llx', is "
			   "corrupted\n", path, (long long)offset);
		return -1;
	case FFS_CHECK_ENTRY_CHECKSUM:
		UNEXPECTED("'%s' partition table at offset '%llx', has "
			   "corrupted entries\n", path, (long long)offset);
		return -1;
	default:
		return -1;
	}
}