Merge changes from topic "libsparse-callback"
* changes: fastboot: Track the libsparse API change. libsparse: Use 'size_t' for the 'len' parameter in callbacks.
This commit is contained in:
commit
49b7f296b9
5 changed files with 30 additions and 26 deletions
|
|
@ -278,19 +278,14 @@ int64_t fb_upload_data(Transport* transport, const char* outfile) {
|
||||||
return _command_end(transport);
|
return _command_end(transport);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TRANSPORT_BUF_SIZE 1024
|
static constexpr size_t TRANSPORT_BUF_SIZE = 1024;
|
||||||
static char transport_buf[TRANSPORT_BUF_SIZE];
|
static char transport_buf[TRANSPORT_BUF_SIZE];
|
||||||
static int transport_buf_len;
|
static size_t transport_buf_len;
|
||||||
|
|
||||||
static int fb_download_data_sparse_write(void *priv, const void *data, int len)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
Transport* transport = reinterpret_cast<Transport*>(priv);
|
|
||||||
int to_write;
|
|
||||||
const char* ptr = reinterpret_cast<const char*>(data);
|
|
||||||
|
|
||||||
|
static int fb_download_data_sparse_write(void* priv, const void* data, size_t len) {
|
||||||
|
const char* ptr = static_cast<const char*>(data);
|
||||||
if (transport_buf_len) {
|
if (transport_buf_len) {
|
||||||
to_write = std::min(TRANSPORT_BUF_SIZE - transport_buf_len, len);
|
size_t to_write = std::min(TRANSPORT_BUF_SIZE - transport_buf_len, len);
|
||||||
|
|
||||||
memcpy(transport_buf + transport_buf_len, ptr, to_write);
|
memcpy(transport_buf + transport_buf_len, ptr, to_write);
|
||||||
transport_buf_len += to_write;
|
transport_buf_len += to_write;
|
||||||
|
|
@ -298,9 +293,10 @@ static int fb_download_data_sparse_write(void *priv, const void *data, int len)
|
||||||
len -= to_write;
|
len -= to_write;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Transport* transport = static_cast<Transport*>(priv);
|
||||||
if (transport_buf_len == TRANSPORT_BUF_SIZE) {
|
if (transport_buf_len == TRANSPORT_BUF_SIZE) {
|
||||||
r = _command_write_data(transport, transport_buf, TRANSPORT_BUF_SIZE);
|
int64_t r = _command_write_data(transport, transport_buf, TRANSPORT_BUF_SIZE);
|
||||||
if (r != TRANSPORT_BUF_SIZE) {
|
if (r != static_cast<int64_t>(TRANSPORT_BUF_SIZE)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
transport_buf_len = 0;
|
transport_buf_len = 0;
|
||||||
|
|
@ -311,9 +307,9 @@ static int fb_download_data_sparse_write(void *priv, const void *data, int len)
|
||||||
g_error = "internal error: transport_buf not empty";
|
g_error = "internal error: transport_buf not empty";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
to_write = round_down(len, TRANSPORT_BUF_SIZE);
|
size_t to_write = round_down(len, TRANSPORT_BUF_SIZE);
|
||||||
r = _command_write_data(transport, ptr, to_write);
|
int64_t r = _command_write_data(transport, ptr, to_write);
|
||||||
if (r != to_write) {
|
if (r != static_cast<int64_t>(to_write)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ptr += to_write;
|
ptr += to_write;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
#define _LIBSPARSE_SPARSE_H_
|
#define _LIBSPARSE_SPARSE_H_
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
@ -26,6 +27,11 @@ extern "C" {
|
||||||
|
|
||||||
struct sparse_file;
|
struct sparse_file;
|
||||||
|
|
||||||
|
// The callbacks in sparse_file_callback() and sparse_file_foreach_chunk() take
|
||||||
|
// size_t as the length type (was `int` in past). This allows clients to keep
|
||||||
|
// their codes compatibile with both versions as needed.
|
||||||
|
#define SPARSE_CALLBACK_USES_SIZE_T
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sparse_file_new - create a new sparse file cookie
|
* sparse_file_new - create a new sparse file cookie
|
||||||
*
|
*
|
||||||
|
|
@ -201,7 +207,7 @@ unsigned int sparse_file_block_size(struct sparse_file *s);
|
||||||
* Returns 0 on success, negative errno on error.
|
* Returns 0 on success, negative errno on error.
|
||||||
*/
|
*/
|
||||||
int sparse_file_callback(struct sparse_file *s, bool sparse, bool crc,
|
int sparse_file_callback(struct sparse_file *s, bool sparse, bool crc,
|
||||||
int (*write)(void *priv, const void *data, int len), void *priv);
|
int (*write)(void *priv, const void *data, size_t len), void *priv);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sparse_file_foreach_chunk - call a callback for data blocks in sparse file
|
* sparse_file_foreach_chunk - call a callback for data blocks in sparse file
|
||||||
|
|
@ -218,7 +224,7 @@ int sparse_file_callback(struct sparse_file *s, bool sparse, bool crc,
|
||||||
* Returns 0 on success, negative errno on error.
|
* Returns 0 on success, negative errno on error.
|
||||||
*/
|
*/
|
||||||
int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc,
|
int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc,
|
||||||
int (*write)(void *priv, const void *data, int len, unsigned int block,
|
int (*write)(void *priv, const void *data, size_t len, unsigned int block,
|
||||||
unsigned int nr_blocks),
|
unsigned int nr_blocks),
|
||||||
void *priv);
|
void *priv);
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ struct output_file_normal {
|
||||||
struct output_file_callback {
|
struct output_file_callback {
|
||||||
struct output_file out;
|
struct output_file out;
|
||||||
void *priv;
|
void *priv;
|
||||||
int (*write)(void *priv, const void *buf, int len);
|
int (*write)(void *priv, const void *buf, size_t len);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define to_output_file_callback(_o) \
|
#define to_output_file_callback(_o) \
|
||||||
|
|
@ -634,7 +634,8 @@ static struct output_file *output_file_new_normal(void)
|
||||||
return &outn->out;
|
return &outn->out;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct output_file *output_file_open_callback(int (*write)(void *, const void *, int),
|
struct output_file *output_file_open_callback(
|
||||||
|
int (*write)(void *, const void *, size_t),
|
||||||
void *priv, unsigned int block_size, int64_t len,
|
void *priv, unsigned int block_size, int64_t len,
|
||||||
int gz __unused, int sparse, int chunks, int crc)
|
int gz __unused, int sparse, int chunks, int crc)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@ struct output_file;
|
||||||
|
|
||||||
struct output_file *output_file_open_fd(int fd, unsigned int block_size, int64_t len,
|
struct output_file *output_file_open_fd(int fd, unsigned int block_size, int64_t len,
|
||||||
int gz, int sparse, int chunks, int crc);
|
int gz, int sparse, int chunks, int crc);
|
||||||
struct output_file *output_file_open_callback(int (*write)(void *, const void *, int),
|
struct output_file *output_file_open_callback(
|
||||||
|
int (*write)(void *, const void *, size_t),
|
||||||
void *priv, unsigned int block_size, int64_t len, int gz, int sparse,
|
void *priv, unsigned int block_size, int64_t len, int gz, int sparse,
|
||||||
int chunks, int crc);
|
int chunks, int crc);
|
||||||
int write_data_chunk(struct output_file *out, unsigned int len, void *data);
|
int write_data_chunk(struct output_file *out, unsigned int len, void *data);
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ int sparse_file_write(struct sparse_file *s, int fd, bool gz, bool sparse,
|
||||||
}
|
}
|
||||||
|
|
||||||
int sparse_file_callback(struct sparse_file *s, bool sparse, bool crc,
|
int sparse_file_callback(struct sparse_file *s, bool sparse, bool crc,
|
||||||
int (*write)(void *priv, const void *data, int len), void *priv)
|
int (*write)(void *priv, const void *data, size_t len), void *priv)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int chunks;
|
int chunks;
|
||||||
|
|
@ -203,11 +203,11 @@ struct chunk_data {
|
||||||
void *priv;
|
void *priv;
|
||||||
unsigned int block;
|
unsigned int block;
|
||||||
unsigned int nr_blocks;
|
unsigned int nr_blocks;
|
||||||
int (*write)(void *priv, const void *data, int len, unsigned int block,
|
int (*write)(void *priv, const void *data, size_t len,
|
||||||
unsigned int nr_blocks);
|
unsigned int block, unsigned int nr_blocks);
|
||||||
};
|
};
|
||||||
|
|
||||||
static int foreach_chunk_write(void *priv, const void *data, int len)
|
static int foreach_chunk_write(void *priv, const void *data, size_t len)
|
||||||
{
|
{
|
||||||
struct chunk_data *chk = priv;
|
struct chunk_data *chk = priv;
|
||||||
|
|
||||||
|
|
@ -215,7 +215,7 @@ static int foreach_chunk_write(void *priv, const void *data, int len)
|
||||||
}
|
}
|
||||||
|
|
||||||
int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc,
|
int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc,
|
||||||
int (*write)(void *priv, const void *data, int len, unsigned int block,
|
int (*write)(void *priv, const void *data, size_t len, unsigned int block,
|
||||||
unsigned int nr_blocks),
|
unsigned int nr_blocks),
|
||||||
void *priv)
|
void *priv)
|
||||||
{
|
{
|
||||||
|
|
@ -250,7 +250,7 @@ int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int out_counter_write(void *priv, const void *data __unused, int len)
|
static int out_counter_write(void *priv, const void *data __unused, size_t len)
|
||||||
{
|
{
|
||||||
int64_t *count = priv;
|
int64_t *count = priv;
|
||||||
*count += len;
|
*count += len;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue