aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-devtools/android-tools/android-tools/core/0015-libsparse-Split-off-most-of-sparse_file_read_normal-.patch
blob: 5009c73a05655e81d5b4f5eccb91ebfd41e30ccd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
From 7b74d23ed955206a789a96bdc3288593e702afac Mon Sep 17 00:00:00 2001
From: Sean Anderson <sean.anderson@seco.com>
Date: Thu, 30 Dec 2021 15:16:08 -0500
Subject: [PATCH] libsparse: Split off most of sparse_file_read_normal into a
 helper function

This carves out the core of sparse_file_read_normal and splits it off so
it can be reused in the next patch. No functional change intended.

Change-Id: Id00491fd7e5bb6fa28c517a0bb32b8b506539d4d
Upstream-Status: Backport [95657f3e5976d96073f7bbfe3a49192509999d1d]
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---
 libsparse/sparse_read.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/libsparse/sparse_read.c b/libsparse/sparse_read.c
index 8e188e9a4..ee4abd86a 100644
--- a/libsparse/sparse_read.c
+++ b/libsparse/sparse_read.c
@@ -353,13 +353,11 @@ static int sparse_file_read_sparse(struct sparse_file *s, int fd, bool crc)
 	return 0;
 }
 
-static int sparse_file_read_normal(struct sparse_file *s, int fd)
+static int do_sparse_file_read_normal(struct sparse_file *s, int fd, uint32_t* buf, int64_t offset,
+				      int64_t remain)
 {
 	int ret;
-	uint32_t *buf = malloc(s->block_size);
-	unsigned int block = 0;
-	int64_t remain = s->len;
-	int64_t offset = 0;
+	unsigned int block = offset / s->block_size;
 	unsigned int to_read;
 	unsigned int i;
 	bool sparse_block;
@@ -403,6 +401,19 @@ static int sparse_file_read_normal(struct sparse_file *s, int fd)
 	return 0;
 }
 
+static int sparse_file_read_normal(struct sparse_file* s, int fd)
+{
+	int ret;
+	uint32_t* buf = (uint32_t*)malloc(s->block_size);
+
+	if (!buf)
+		return -ENOMEM;
+
+	ret = do_sparse_file_read_normal(s, fd, buf, 0, s->len);
+	free(buf);
+	return ret;
+}
+
 int sparse_file_read(struct sparse_file *s, int fd, bool sparse, bool crc)
 {
 	if (crc && !sparse) {
-- 
2.35.1.1320.gc452695387.dirty