blob: b3893f0c80f4ded304b9cd5dd84d7933120f6a71 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001From 7b74d23ed955206a789a96bdc3288593e702afac Mon Sep 17 00:00:00 2001
2From: Sean Anderson <sean.anderson@seco.com>
3Date: Thu, 30 Dec 2021 15:16:08 -0500
4Subject: [PATCH] libsparse: Split off most of sparse_file_read_normal into a
5 helper function
6
7This carves out the core of sparse_file_read_normal and splits it off so
8it can be reused in the next patch. No functional change intended.
9
10Change-Id: Id00491fd7e5bb6fa28c517a0bb32b8b506539d4d
11Upstream-status: Backport [95657f3e5976d96073f7bbfe3a49192509999d1d]
12Signed-off-by: Sean Anderson <sean.anderson@seco.com>
13---
14 libsparse/sparse_read.c | 21 ++++++++++++++++-----
15 1 file changed, 16 insertions(+), 5 deletions(-)
16
17diff --git a/libsparse/sparse_read.c b/libsparse/sparse_read.c
18index 8e188e9a4..ee4abd86a 100644
19--- a/libsparse/sparse_read.c
20+++ b/libsparse/sparse_read.c
21@@ -353,13 +353,11 @@ static int sparse_file_read_sparse(struct sparse_file *s, int fd, bool crc)
22 return 0;
23 }
24
25-static int sparse_file_read_normal(struct sparse_file *s, int fd)
26+static int do_sparse_file_read_normal(struct sparse_file *s, int fd, uint32_t* buf, int64_t offset,
27+ int64_t remain)
28 {
29 int ret;
30- uint32_t *buf = malloc(s->block_size);
31- unsigned int block = 0;
32- int64_t remain = s->len;
33- int64_t offset = 0;
34+ unsigned int block = offset / s->block_size;
35 unsigned int to_read;
36 unsigned int i;
37 bool sparse_block;
38@@ -403,6 +401,19 @@ static int sparse_file_read_normal(struct sparse_file *s, int fd)
39 return 0;
40 }
41
42+static int sparse_file_read_normal(struct sparse_file* s, int fd)
43+{
44+ int ret;
45+ uint32_t* buf = (uint32_t*)malloc(s->block_size);
46+
47+ if (!buf)
48+ return -ENOMEM;
49+
50+ ret = do_sparse_file_read_normal(s, fd, buf, 0, s->len);
51+ free(buf);
52+ return ret;
53+}
54+
55 int sparse_file_read(struct sparse_file *s, int fd, bool sparse, bool crc)
56 {
57 if (crc && !sparse) {
58--
592.35.1.1320.gc452695387.dirty
60