diff options
author | Tao Bao | 2018-04-30 16:48:46 -0500 |
---|---|---|
committer | Gerrit Code Review | 2018-04-30 16:48:46 -0500 |
commit | 49b7f296b9e513b69fa60088e03a70cb354a3120 (patch) | |
tree | 22f172fe17a4f8bf0652b80e24488a907cfd5948 | |
parent | 4e6f3d9603bf8a8511e2751c5ed3e31896cccdd8 (diff) | |
parent | 7d27ffdd4584990ad3bc2415e188718110b44e31 (diff) | |
download | platform-system-core-49b7f296b9e513b69fa60088e03a70cb354a3120.tar.gz platform-system-core-49b7f296b9e513b69fa60088e03a70cb354a3120.tar.xz platform-system-core-49b7f296b9e513b69fa60088e03a70cb354a3120.zip |
Merge changes from topic "libsparse-callback"
* changes:
fastboot: Track the libsparse API change.
libsparse: Use 'size_t' for the 'len' parameter in callbacks.
-rw-r--r-- | fastboot/protocol.cpp | 26 | ||||
-rw-r--r-- | libsparse/include/sparse/sparse.h | 10 | ||||
-rw-r--r-- | libsparse/output_file.c | 5 | ||||
-rw-r--r-- | libsparse/output_file.h | 3 | ||||
-rw-r--r-- | libsparse/sparse.c | 12 |
5 files changed, 30 insertions, 26 deletions
diff --git a/fastboot/protocol.cpp b/fastboot/protocol.cpp index 7a333ee06..fda6f5dcb 100644 --- a/fastboot/protocol.cpp +++ b/fastboot/protocol.cpp | |||
@@ -278,19 +278,14 @@ int64_t fb_upload_data(Transport* transport, const char* outfile) { | |||
278 | return _command_end(transport); | 278 | return _command_end(transport); |
279 | } | 279 | } |
280 | 280 | ||
281 | #define TRANSPORT_BUF_SIZE 1024 | 281 | static constexpr size_t TRANSPORT_BUF_SIZE = 1024; |
282 | static char transport_buf[TRANSPORT_BUF_SIZE]; | 282 | static char transport_buf[TRANSPORT_BUF_SIZE]; |
283 | static int transport_buf_len; | 283 | static size_t transport_buf_len; |
284 | |||
285 | static int fb_download_data_sparse_write(void *priv, const void *data, int len) | ||
286 | { | ||
287 | int r; | ||
288 | Transport* transport = reinterpret_cast<Transport*>(priv); | ||
289 | int to_write; | ||
290 | const char* ptr = reinterpret_cast<const char*>(data); | ||
291 | 284 | ||
285 | static int fb_download_data_sparse_write(void* priv, const void* data, size_t len) { | ||
286 | const char* ptr = static_cast<const char*>(data); | ||
292 | if (transport_buf_len) { | 287 | if (transport_buf_len) { |
293 | to_write = std::min(TRANSPORT_BUF_SIZE - transport_buf_len, len); | 288 | size_t to_write = std::min(TRANSPORT_BUF_SIZE - transport_buf_len, len); |
294 | 289 | ||
295 | memcpy(transport_buf + transport_buf_len, ptr, to_write); | 290 | memcpy(transport_buf + transport_buf_len, ptr, to_write); |
296 | transport_buf_len += to_write; | 291 | transport_buf_len += to_write; |
@@ -298,9 +293,10 @@ static int fb_download_data_sparse_write(void *priv, const void *data, int len) | |||
298 | len -= to_write; | 293 | len -= to_write; |
299 | } | 294 | } |
300 | 295 | ||
296 | Transport* transport = static_cast<Transport*>(priv); | ||
301 | if (transport_buf_len == TRANSPORT_BUF_SIZE) { | 297 | if (transport_buf_len == TRANSPORT_BUF_SIZE) { |
302 | r = _command_write_data(transport, transport_buf, TRANSPORT_BUF_SIZE); | 298 | int64_t r = _command_write_data(transport, transport_buf, TRANSPORT_BUF_SIZE); |
303 | if (r != TRANSPORT_BUF_SIZE) { | 299 | if (r != static_cast<int64_t>(TRANSPORT_BUF_SIZE)) { |
304 | return -1; | 300 | return -1; |
305 | } | 301 | } |
306 | transport_buf_len = 0; | 302 | transport_buf_len = 0; |
@@ -311,9 +307,9 @@ static int fb_download_data_sparse_write(void *priv, const void *data, int len) | |||
311 | g_error = "internal error: transport_buf not empty"; | 307 | g_error = "internal error: transport_buf not empty"; |
312 | return -1; | 308 | return -1; |
313 | } | 309 | } |
314 | to_write = round_down(len, TRANSPORT_BUF_SIZE); | 310 | size_t to_write = round_down(len, TRANSPORT_BUF_SIZE); |
315 | r = _command_write_data(transport, ptr, to_write); | 311 | int64_t r = _command_write_data(transport, ptr, to_write); |
316 | if (r != to_write) { | 312 | if (r != static_cast<int64_t>(to_write)) { |
317 | return -1; | 313 | return -1; |
318 | } | 314 | } |
319 | ptr += to_write; | 315 | ptr += to_write; |
diff --git a/libsparse/include/sparse/sparse.h b/libsparse/include/sparse/sparse.h index 356f65fd0..1b91ead5c 100644 --- a/libsparse/include/sparse/sparse.h +++ b/libsparse/include/sparse/sparse.h | |||
@@ -18,6 +18,7 @@ | |||
18 | #define _LIBSPARSE_SPARSE_H_ | 18 | #define _LIBSPARSE_SPARSE_H_ |
19 | 19 | ||
20 | #include <stdbool.h> | 20 | #include <stdbool.h> |
21 | #include <stddef.h> | ||
21 | #include <stdint.h> | 22 | #include <stdint.h> |
22 | 23 | ||
23 | #ifdef __cplusplus | 24 | #ifdef __cplusplus |
@@ -26,6 +27,11 @@ extern "C" { | |||
26 | 27 | ||
27 | struct sparse_file; | 28 | struct sparse_file; |
28 | 29 | ||
30 | // The callbacks in sparse_file_callback() and sparse_file_foreach_chunk() take | ||
31 | // size_t as the length type (was `int` in past). This allows clients to keep | ||
32 | // their codes compatibile with both versions as needed. | ||
33 | #define SPARSE_CALLBACK_USES_SIZE_T | ||
34 | |||
29 | /** | 35 | /** |
30 | * sparse_file_new - create a new sparse file cookie | 36 | * sparse_file_new - create a new sparse file cookie |
31 | * | 37 | * |
@@ -201,7 +207,7 @@ unsigned int sparse_file_block_size(struct sparse_file *s); | |||
201 | * Returns 0 on success, negative errno on error. | 207 | * Returns 0 on success, negative errno on error. |
202 | */ | 208 | */ |
203 | int sparse_file_callback(struct sparse_file *s, bool sparse, bool crc, | 209 | int sparse_file_callback(struct sparse_file *s, bool sparse, bool crc, |
204 | int (*write)(void *priv, const void *data, int len), void *priv); | 210 | int (*write)(void *priv, const void *data, size_t len), void *priv); |
205 | 211 | ||
206 | /** | 212 | /** |
207 | * sparse_file_foreach_chunk - call a callback for data blocks in sparse file | 213 | * 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, | |||
218 | * Returns 0 on success, negative errno on error. | 224 | * Returns 0 on success, negative errno on error. |
219 | */ | 225 | */ |
220 | int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc, | 226 | int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc, |
221 | int (*write)(void *priv, const void *data, int len, unsigned int block, | 227 | int (*write)(void *priv, const void *data, size_t len, unsigned int block, |
222 | unsigned int nr_blocks), | 228 | unsigned int nr_blocks), |
223 | void *priv); | 229 | void *priv); |
224 | /** | 230 | /** |
diff --git a/libsparse/output_file.c b/libsparse/output_file.c index 51e60ef79..002ad2746 100644 --- a/libsparse/output_file.c +++ b/libsparse/output_file.c | |||
@@ -109,7 +109,7 @@ struct output_file_normal { | |||
109 | struct output_file_callback { | 109 | struct output_file_callback { |
110 | struct output_file out; | 110 | struct output_file out; |
111 | void *priv; | 111 | void *priv; |
112 | int (*write)(void *priv, const void *buf, int len); | 112 | int (*write)(void *priv, const void *buf, size_t len); |
113 | }; | 113 | }; |
114 | 114 | ||
115 | #define to_output_file_callback(_o) \ | 115 | #define to_output_file_callback(_o) \ |
@@ -634,7 +634,8 @@ static struct output_file *output_file_new_normal(void) | |||
634 | return &outn->out; | 634 | return &outn->out; |
635 | } | 635 | } |
636 | 636 | ||
637 | struct output_file *output_file_open_callback(int (*write)(void *, const void *, int), | 637 | struct output_file *output_file_open_callback( |
638 | int (*write)(void *, const void *, size_t), | ||
638 | void *priv, unsigned int block_size, int64_t len, | 639 | void *priv, unsigned int block_size, int64_t len, |
639 | int gz __unused, int sparse, int chunks, int crc) | 640 | int gz __unused, int sparse, int chunks, int crc) |
640 | { | 641 | { |
diff --git a/libsparse/output_file.h b/libsparse/output_file.h index b67e94ecb..690f61057 100644 --- a/libsparse/output_file.h +++ b/libsparse/output_file.h | |||
@@ -27,7 +27,8 @@ struct output_file; | |||
27 | 27 | ||
28 | struct output_file *output_file_open_fd(int fd, unsigned int block_size, int64_t len, | 28 | struct output_file *output_file_open_fd(int fd, unsigned int block_size, int64_t len, |
29 | int gz, int sparse, int chunks, int crc); | 29 | int gz, int sparse, int chunks, int crc); |
30 | struct output_file *output_file_open_callback(int (*write)(void *, const void *, int), | 30 | struct output_file *output_file_open_callback( |
31 | int (*write)(void *, const void *, size_t), | ||
31 | void *priv, unsigned int block_size, int64_t len, int gz, int sparse, | 32 | void *priv, unsigned int block_size, int64_t len, int gz, int sparse, |
32 | int chunks, int crc); | 33 | int chunks, int crc); |
33 | int write_data_chunk(struct output_file *out, unsigned int len, void *data); | 34 | int write_data_chunk(struct output_file *out, unsigned int len, void *data); |
diff --git a/libsparse/sparse.c b/libsparse/sparse.c index b17586066..466435f7b 100644 --- a/libsparse/sparse.c +++ b/libsparse/sparse.c | |||
@@ -179,7 +179,7 @@ int sparse_file_write(struct sparse_file *s, int fd, bool gz, bool sparse, | |||
179 | } | 179 | } |
180 | 180 | ||
181 | int sparse_file_callback(struct sparse_file *s, bool sparse, bool crc, | 181 | int sparse_file_callback(struct sparse_file *s, bool sparse, bool crc, |
182 | int (*write)(void *priv, const void *data, int len), void *priv) | 182 | int (*write)(void *priv, const void *data, size_t len), void *priv) |
183 | { | 183 | { |
184 | int ret; | 184 | int ret; |
185 | int chunks; | 185 | int chunks; |
@@ -203,11 +203,11 @@ struct chunk_data { | |||
203 | void *priv; | 203 | void *priv; |
204 | unsigned int block; | 204 | unsigned int block; |
205 | unsigned int nr_blocks; | 205 | unsigned int nr_blocks; |
206 | int (*write)(void *priv, const void *data, int len, unsigned int block, | 206 | int (*write)(void *priv, const void *data, size_t len, |
207 | unsigned int nr_blocks); | 207 | unsigned int block, unsigned int nr_blocks); |
208 | }; | 208 | }; |
209 | 209 | ||
210 | static int foreach_chunk_write(void *priv, const void *data, int len) | 210 | static int foreach_chunk_write(void *priv, const void *data, size_t len) |
211 | { | 211 | { |
212 | struct chunk_data *chk = priv; | 212 | struct chunk_data *chk = priv; |
213 | 213 | ||
@@ -215,7 +215,7 @@ static int foreach_chunk_write(void *priv, const void *data, int len) | |||
215 | } | 215 | } |
216 | 216 | ||
217 | int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc, | 217 | int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc, |
218 | int (*write)(void *priv, const void *data, int len, unsigned int block, | 218 | int (*write)(void *priv, const void *data, size_t len, unsigned int block, |
219 | unsigned int nr_blocks), | 219 | unsigned int nr_blocks), |
220 | void *priv) | 220 | void *priv) |
221 | { | 221 | { |
@@ -250,7 +250,7 @@ int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc, | |||
250 | return ret; | 250 | return ret; |
251 | } | 251 | } |
252 | 252 | ||
253 | static int out_counter_write(void *priv, const void *data __unused, int len) | 253 | static int out_counter_write(void *priv, const void *data __unused, size_t len) |
254 | { | 254 | { |
255 | int64_t *count = priv; | 255 | int64_t *count = priv; |
256 | *count += len; | 256 | *count += len; |