Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
5cc14405
Commit
5cc14405
authored
Aug 10, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Combine image related functions
parent
f0cfd60e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
75 deletions
+76
-75
bootstages.c
jni/daemon/bootstages.c
+0
-75
utils.h
jni/include/utils.h
+7
-0
img.c
jni/utils/img.c
+69
-0
No files found.
jni/daemon/bootstages.c
View file @
5cc14405
...
@@ -54,81 +54,6 @@ struct node_entry {
...
@@ -54,81 +54,6 @@ struct node_entry {
#define IS_LNK(n) (n->type == DT_LNK)
#define IS_LNK(n) (n->type == DT_LNK)
#define IS_REG(n) (n->type == DT_REG)
#define IS_REG(n) (n->type == DT_REG)
/******************
* Image handling *
******************/
#define round_size(a) ((((a) / 32) + 2) * 32)
#define SOURCE_TMP "/dev/source"
#define TARGET_TMP "/dev/target"
static
int
merge_img
(
const
char
*
source
,
const
char
*
target
)
{
if
(
access
(
source
,
F_OK
)
==
-
1
)
return
0
;
if
(
access
(
target
,
F_OK
)
==
-
1
)
{
rename
(
source
,
target
);
return
0
;
}
// resize target to worst case
int
s_used
,
s_total
,
t_used
,
t_total
,
n_total
;
get_img_size
(
source
,
&
s_used
,
&
s_total
);
get_img_size
(
target
,
&
t_used
,
&
t_total
);
n_total
=
round_size
(
s_used
+
t_used
);
if
(
n_total
!=
t_total
)
resize_img
(
target
,
n_total
);
xmkdir
(
SOURCE_TMP
,
0755
);
xmkdir
(
TARGET_TMP
,
0755
);
char
*
s_loop
,
*
t_loop
;
s_loop
=
mount_image
(
source
,
SOURCE_TMP
);
if
(
s_loop
==
NULL
)
return
1
;
t_loop
=
mount_image
(
target
,
TARGET_TMP
);
if
(
t_loop
==
NULL
)
return
1
;
DIR
*
dir
;
struct
dirent
*
entry
;
if
(
!
(
dir
=
opendir
(
SOURCE_TMP
)))
return
1
;
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
entry
->
d_type
==
DT_DIR
)
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
||
strcmp
(
entry
->
d_name
,
".core"
)
==
0
||
strcmp
(
entry
->
d_name
,
"lost+found"
)
==
0
)
continue
;
// Cleanup old module if exists
snprintf
(
buf
,
PATH_MAX
,
"%s/%s"
,
TARGET_TMP
,
entry
->
d_name
);
if
(
access
(
buf
,
F_OK
)
==
0
)
{
LOGI
(
"Upgrade module: %s
\n
"
,
entry
->
d_name
);
rm_rf
(
buf
);
}
else
{
LOGI
(
"New module: %s
\n
"
,
entry
->
d_name
);
}
}
}
closedir
(
dir
);
clone_dir
(
SOURCE_TMP
,
TARGET_TMP
);
// Unmount all loop devices
umount_image
(
SOURCE_TMP
,
s_loop
);
umount_image
(
TARGET_TMP
,
t_loop
);
rmdir
(
SOURCE_TMP
);
rmdir
(
TARGET_TMP
);
free
(
s_loop
);
free
(
t_loop
);
unlink
(
source
);
return
0
;
}
static
void
trim_img
(
const
char
*
img
)
{
int
used
,
total
,
new_size
;
get_img_size
(
img
,
&
used
,
&
total
);
new_size
=
round_size
(
used
);
if
(
new_size
!=
total
)
resize_img
(
img
,
new_size
);
}
/***********
/***********
* Scripts *
* Scripts *
***********/
***********/
...
...
jni/include/utils.h
View file @
5cc14405
...
@@ -96,10 +96,17 @@ int switch_mnt_ns(int pid);
...
@@ -96,10 +96,17 @@ int switch_mnt_ns(int pid);
void
link_busybox
();
void
link_busybox
();
// img.c
// img.c
#define round_size(a) ((((a) / 32) + 2) * 32)
#define SOURCE_TMP "/dev/source"
#define TARGET_TMP "/dev/target"
int
create_img
(
const
char
*
img
,
int
size
);
int
create_img
(
const
char
*
img
,
int
size
);
int
get_img_size
(
const
char
*
img
,
int
*
used
,
int
*
total
);
int
get_img_size
(
const
char
*
img
,
int
*
used
,
int
*
total
);
int
resize_img
(
const
char
*
img
,
int
size
);
int
resize_img
(
const
char
*
img
,
int
size
);
char
*
mount_image
(
const
char
*
img
,
const
char
*
target
);
char
*
mount_image
(
const
char
*
img
,
const
char
*
target
);
void
umount_image
(
const
char
*
target
,
const
char
*
device
);
void
umount_image
(
const
char
*
target
,
const
char
*
device
);
int
merge_img
(
const
char
*
source
,
const
char
*
target
);
void
trim_img
(
const
char
*
img
);
#endif
#endif
jni/utils/img.c
View file @
5cc14405
...
@@ -146,3 +146,72 @@ void umount_image(const char *target, const char *device) {
...
@@ -146,3 +146,72 @@ void umount_image(const char *target, const char *device) {
ioctl
(
fd
,
LOOP_CLR_FD
);
ioctl
(
fd
,
LOOP_CLR_FD
);
close
(
fd
);
close
(
fd
);
}
}
int
merge_img
(
const
char
*
source
,
const
char
*
target
)
{
if
(
access
(
source
,
F_OK
)
==
-
1
)
return
0
;
if
(
access
(
target
,
F_OK
)
==
-
1
)
{
rename
(
source
,
target
);
return
0
;
}
char
buffer
[
PATH_MAX
];
// resize target to worst case
int
s_used
,
s_total
,
t_used
,
t_total
,
n_total
;
get_img_size
(
source
,
&
s_used
,
&
s_total
);
get_img_size
(
target
,
&
t_used
,
&
t_total
);
n_total
=
round_size
(
s_used
+
t_used
);
if
(
n_total
!=
t_total
)
resize_img
(
target
,
n_total
);
xmkdir
(
SOURCE_TMP
,
0755
);
xmkdir
(
TARGET_TMP
,
0755
);
char
*
s_loop
,
*
t_loop
;
s_loop
=
mount_image
(
source
,
SOURCE_TMP
);
if
(
s_loop
==
NULL
)
return
1
;
t_loop
=
mount_image
(
target
,
TARGET_TMP
);
if
(
t_loop
==
NULL
)
return
1
;
DIR
*
dir
;
struct
dirent
*
entry
;
if
(
!
(
dir
=
opendir
(
SOURCE_TMP
)))
return
1
;
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
entry
->
d_type
==
DT_DIR
)
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
||
strcmp
(
entry
->
d_name
,
".core"
)
==
0
||
strcmp
(
entry
->
d_name
,
"lost+found"
)
==
0
)
continue
;
// Cleanup old module if exists
snprintf
(
buffer
,
sizeof
(
buffer
),
"%s/%s"
,
TARGET_TMP
,
entry
->
d_name
);
if
(
access
(
buffer
,
F_OK
)
==
0
)
{
LOGI
(
"Upgrade module: %s
\n
"
,
entry
->
d_name
);
rm_rf
(
buffer
);
}
else
{
LOGI
(
"New module: %s
\n
"
,
entry
->
d_name
);
}
}
}
closedir
(
dir
);
clone_dir
(
SOURCE_TMP
,
TARGET_TMP
);
// Unmount all loop devices
umount_image
(
SOURCE_TMP
,
s_loop
);
umount_image
(
TARGET_TMP
,
t_loop
);
rmdir
(
SOURCE_TMP
);
rmdir
(
TARGET_TMP
);
free
(
s_loop
);
free
(
t_loop
);
unlink
(
source
);
return
0
;
}
void
trim_img
(
const
char
*
img
)
{
int
used
,
total
,
new_size
;
get_img_size
(
img
,
&
used
,
&
total
);
new_size
=
round_size
(
used
);
if
(
new_size
!=
total
)
resize_img
(
img
,
new_size
);
}
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