示例#1
0
int64_t bled_uncompress_from_buffer_to_buffer(const char* src, const size_t src_len, char* dst, size_t dst_len, int type)
{
	int64_t ret;

	if (!bled_initialized) {
		bb_error_msg("The library has not been initialized");
		return -1;
	}

	if ((src == NULL) || (dst == NULL)) {
		bb_error_msg("Invalid parameter");
		return -1;
	}

	if (bb_virtual_buf != NULL) {
		bb_error_msg("Can not decompress more than one buffer at once");
		return -1;
	}

	bb_virtual_buf = (char*)src;
	bb_virtual_len = src_len;
	bb_virtual_pos = 0;
	bb_virtual_fd = 0;

	ret = bled_uncompress_to_buffer("", dst, dst_len, type);

	bb_virtual_buf = NULL;
	bb_virtual_len = 0;
	bb_virtual_fd = -1;

	return ret;
}
示例#2
0
文件: gpt.c 项目: endlessm/rufus
// compression_type: an element of bled_compression_type
uint64_t get_eos_archive_disk_image_size(const char *filepath, int compression_type, BOOL isInstallerImage)
{
    int64_t bytes_read = 0;
    int64_t result = 0;
    struct ptable pt;
    const int size = sizeof(pt); // should be 2048

    if (NULL == filepath) return 0;

    if (compression_type == BLED_COMPRESSION_NONE) {
        FILE *file = NULL;
        errno_t err = fopen_s(&file, filepath, "rb");
        if (err == 0) {
            // The 'size' and 'count' arguments are "backwards" because this
            // function returns the number of items read; by making the item
            // size 1 we get the number of bytes
            bytes_read = fread((void *)&pt, 1, size, file);
            fclose(file);
        } else {
            uprintf("Error opening %s: %d", filepath, err);
        }
    } else {
        bled_init(_uprintf, NULL, NULL);
        bytes_read = bled_uncompress_to_buffer(filepath, (char*)&pt, size, compression_type);
        bled_exit();
    }

    if (bytes_read < size) {
        // not enough bytes read
        return 0;
    }

    if (!is_eos_gpt_valid(&pt, isInstallerImage)) {
        return 0;
    }

    return get_disk_size(&pt);
}