Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
bootable_recovery
Commits
0d28ba45
Commit
0d28ba45
authored
9 years ago
by
Yabin Cui
Browse files
Options
Download
Plain Diff
resolve merge conflicts of
e5d3d15c
to nyc-dev
Change-Id: Ie8b30e6b114b648e8c03866456c64cf8b740d1e3
parents
e1305768
e5d3d15c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
15 deletions
+52
-15
minzip/SysUtil.c
minzip/SysUtil.c
+52
-15
No files found.
minzip/SysUtil.c
View file @
0d28ba45
...
@@ -39,6 +39,11 @@ static bool sysMapFD(int fd, MemMapping* pMap) {
...
@@ -39,6 +39,11 @@ static bool sysMapFD(int fd, MemMapping* pMap) {
pMap
->
length
=
sb
.
st_size
;
pMap
->
length
=
sb
.
st_size
;
pMap
->
range_count
=
1
;
pMap
->
range_count
=
1
;
pMap
->
ranges
=
malloc
(
sizeof
(
MappedRange
));
pMap
->
ranges
=
malloc
(
sizeof
(
MappedRange
));
if
(
pMap
->
ranges
==
NULL
)
{
LOGE
(
"malloc failed: %s
\n
"
,
strerror
(
errno
));
munmap
(
memPtr
,
sb
.
st_size
);
return
false
;
}
pMap
->
ranges
[
0
].
addr
=
memPtr
;
pMap
->
ranges
[
0
].
addr
=
memPtr
;
pMap
->
ranges
[
0
].
length
=
sb
.
st_size
;
pMap
->
ranges
[
0
].
length
=
sb
.
st_size
;
...
@@ -50,7 +55,7 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap)
...
@@ -50,7 +55,7 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap)
char
block_dev
[
PATH_MAX
+
1
];
char
block_dev
[
PATH_MAX
+
1
];
size_t
size
;
size_t
size
;
unsigned
int
blksize
;
unsigned
int
blksize
;
unsigned
in
t
blocks
;
size_
t
blocks
;
unsigned
int
range_count
;
unsigned
int
range_count
;
unsigned
int
i
;
unsigned
int
i
;
...
@@ -69,49 +74,80 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap)
...
@@ -69,49 +74,80 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap)
LOGE
(
"failed to parse block map header
\n
"
);
LOGE
(
"failed to parse block map header
\n
"
);
return
-
1
;
return
-
1
;
}
}
if
(
blksize
!=
0
)
{
blocks
=
((
size
-
1
)
/
blksize
)
+
1
;
blocks
=
((
size
-
1
)
/
blksize
)
+
1
;
}
if
(
size
==
0
||
blksize
==
0
||
blocks
>
SIZE_MAX
/
blksize
||
range_count
==
0
)
{
LOGE
(
"invalid data in block map file: size %zu, blksize %u, range_count %u
\n
"
,
size
,
blksize
,
range_count
);
return
-
1
;
}
pMap
->
range_count
=
range_count
;
pMap
->
range_count
=
range_count
;
pMap
->
ranges
=
malloc
(
range_count
*
sizeof
(
MappedRange
));
pMap
->
ranges
=
calloc
(
range_count
,
sizeof
(
MappedRange
));
memset
(
pMap
->
ranges
,
0
,
range_count
*
sizeof
(
MappedRange
));
if
(
pMap
->
ranges
==
NULL
)
{
LOGE
(
"calloc(%u, %zu) failed: %s
\n
"
,
range_count
,
sizeof
(
MappedRange
),
strerror
(
errno
));
return
-
1
;
}
// Reserve enough contiguous address space for the whole file.
// Reserve enough contiguous address space for the whole file.
unsigned
char
*
reserve
;
unsigned
char
*
reserve
;
reserve
=
mmap64
(
NULL
,
blocks
*
blksize
,
PROT_NONE
,
MAP_PRIVATE
|
MAP_ANON
,
-
1
,
0
);
reserve
=
mmap64
(
NULL
,
blocks
*
blksize
,
PROT_NONE
,
MAP_PRIVATE
|
MAP_ANON
,
-
1
,
0
);
if
(
reserve
==
MAP_FAILED
)
{
if
(
reserve
==
MAP_FAILED
)
{
LOGE
(
"failed to reserve address space: %s
\n
"
,
strerror
(
errno
));
LOGE
(
"failed to reserve address space: %s
\n
"
,
strerror
(
errno
));
free
(
pMap
->
ranges
);
return
-
1
;
return
-
1
;
}
}
pMap
->
ranges
[
range_count
-
1
].
addr
=
reserve
;
pMap
->
ranges
[
range_count
-
1
].
length
=
blocks
*
blksize
;
int
fd
=
open
(
block_dev
,
O_RDONLY
);
int
fd
=
open
(
block_dev
,
O_RDONLY
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
LOGE
(
"failed to open block device %s: %s
\n
"
,
block_dev
,
strerror
(
errno
));
LOGE
(
"failed to open block device %s: %s
\n
"
,
block_dev
,
strerror
(
errno
));
munmap
(
reserve
,
blocks
*
blksize
);
free
(
pMap
->
ranges
);
return
-
1
;
return
-
1
;
}
}
unsigned
char
*
next
=
reserve
;
unsigned
char
*
next
=
reserve
;
size_t
remaining_size
=
blocks
*
blksize
;
bool
success
=
true
;
for
(
i
=
0
;
i
<
range_count
;
++
i
)
{
for
(
i
=
0
;
i
<
range_count
;
++
i
)
{
in
t
start
,
end
;
size_
t
start
,
end
;
if
(
fscanf
(
mapf
,
"%
d %d
\n
"
,
&
start
,
&
end
)
!=
2
)
{
if
(
fscanf
(
mapf
,
"%
zu %zu
\n
"
,
&
start
,
&
end
)
!=
2
)
{
LOGE
(
"failed to parse range %d in block map
\n
"
,
i
);
LOGE
(
"failed to parse range %d in block map
\n
"
,
i
);
return
-
1
;
success
=
false
;
break
;
}
size_t
length
=
(
end
-
start
)
*
blksize
;
if
(
end
<=
start
||
(
end
-
start
)
>
SIZE_MAX
/
blksize
||
length
>
remaining_size
)
{
LOGE
(
"unexpected range in block map: %zu %zu
\n
"
,
start
,
end
);
success
=
false
;
break
;
}
}
void
*
addr
=
mmap64
(
next
,
(
en
d
-
start
)
*
blksize
,
PROT_READ
,
MAP_PRIVATE
|
MAP_FIXED
,
fd
,
((
off64_t
)
start
)
*
blksize
);
void
*
addr
=
mmap64
(
next
,
l
en
gth
,
PROT_READ
,
MAP_PRIVATE
|
MAP_FIXED
,
fd
,
((
off64_t
)
start
)
*
blksize
);
if
(
addr
==
MAP_FAILED
)
{
if
(
addr
==
MAP_FAILED
)
{
LOGE
(
"failed to map block %d: %s
\n
"
,
i
,
strerror
(
errno
));
LOGE
(
"failed to map block %d: %s
\n
"
,
i
,
strerror
(
errno
));
return
-
1
;
success
=
false
;
break
;
}
}
pMap
->
ranges
[
i
].
addr
=
addr
;
pMap
->
ranges
[
i
].
addr
=
addr
;
pMap
->
ranges
[
i
].
length
=
(
en
d
-
start
)
*
blksize
;
pMap
->
ranges
[
i
].
length
=
l
en
gth
;
next
+=
pMap
->
ranges
[
i
].
length
;
next
+=
length
;
remaining_size
-=
length
;
}
if
(
success
&&
remaining_size
!=
0
)
{
LOGE
(
"ranges in block map are invalid: remaining_size = %zu
\n
"
,
remaining_size
);
success
=
false
;
}
if
(
!
success
)
{
close
(
fd
);
munmap
(
reserve
,
blocks
*
blksize
);
free
(
pMap
->
ranges
);
return
-
1
;
}
}
close
(
fd
);
pMap
->
addr
=
reserve
;
pMap
->
addr
=
reserve
;
pMap
->
length
=
size
;
pMap
->
length
=
size
;
...
@@ -134,6 +170,7 @@ int sysMapFile(const char* fn, MemMapping* pMap)
...
@@ -134,6 +170,7 @@ int sysMapFile(const char* fn, MemMapping* pMap)
if
(
sysMapBlockFile
(
mapf
,
pMap
)
!=
0
)
{
if
(
sysMapBlockFile
(
mapf
,
pMap
)
!=
0
)
{
LOGE
(
"Map of '%s' failed
\n
"
,
fn
);
LOGE
(
"Map of '%s' failed
\n
"
,
fn
);
fclose
(
mapf
);
return
-
1
;
return
-
1
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment