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
7e652964
Commit
7e652964
authored
Sep 07, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small improvement to cpio
parent
cd5f5d70
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
50 deletions
+34
-50
bootstages.c
jni/daemon/bootstages.c
+2
-2
vector.h
jni/include/vector.h
+2
-0
cpio.c
jni/magiskboot/cpio.c
+17
-35
cpio.h
jni/magiskboot/cpio.h
+13
-0
magiskboot.h
jni/magiskboot/magiskboot.h
+0
-13
No files found.
jni/daemon/bootstages.c
View file @
7e652964
...
@@ -101,7 +101,7 @@ static struct node_entry *insert_child(struct node_entry *p, struct node_entry *
...
@@ -101,7 +101,7 @@ static struct node_entry *insert_child(struct node_entry *p, struct node_entry *
if
(
c
->
status
>
e
->
status
)
{
if
(
c
->
status
>
e
->
status
)
{
// Precedence is higher, replace with new node
// Precedence is higher, replace with new node
destroy_subtree
(
e
);
destroy_subtree
(
e
);
vec_
entry
(
p
->
children
)[
_
]
=
c
;
vec_
cur
(
p
->
children
)
=
c
;
return
c
;
return
c
;
}
else
{
}
else
{
// Free the new entry, return old
// Free the new entry, return old
...
@@ -654,7 +654,7 @@ void post_fs_data(int client) {
...
@@ -654,7 +654,7 @@ void post_fs_data(int client) {
child
->
name
=
strdup
(
"vendor"
);
child
->
name
=
strdup
(
"vendor"
);
child
->
status
=
0
;
child
->
status
=
0
;
// Swap!
// Swap!
vec_
entry
(
sys_root
->
children
)[
_
]
=
child
;
vec_
cur
(
sys_root
->
children
)
=
child
;
ven_root
->
parent
=
NULL
;
ven_root
->
parent
=
NULL
;
break
;
break
;
}
}
...
...
jni/include/vector.h
View file @
7e652964
...
@@ -32,4 +32,6 @@ struct vector *vec_dup(struct vector *v);
...
@@ -32,4 +32,6 @@ struct vector *vec_dup(struct vector *v);
e = v ? (v)->data[(v)->size - 1] : NULL; \
e = v ? (v)->data[(v)->size - 1] : NULL; \
for (size_t _ = (v)->size; v && _ > 0; --_, e = (v)->data[_ - 1])
for (size_t _ = (v)->size; v && _ > 0; --_, e = (v)->data[_ - 1])
#define vec_cur(v) vec_entry(v)[_]
#endif
#endif
jni/magiskboot/cpio.c
View file @
7e652964
...
@@ -28,31 +28,15 @@ static void cpio_free(cpio_file *f) {
...
@@ -28,31 +28,15 @@ static void cpio_free(cpio_file *f) {
}
}
static
void
cpio_vec_insert
(
struct
vector
*
v
,
cpio_file
*
n
)
{
static
void
cpio_vec_insert
(
struct
vector
*
v
,
cpio_file
*
n
)
{
cpio_file
*
f
,
*
t
;
cpio_file
*
f
;
int
shift
=
0
;
// Insert in alphabet order
vec_for_each
(
v
,
f
)
{
vec_for_each
(
v
,
f
)
{
if
(
shift
)
{
vec_entry
(
v
)[
_
]
=
t
;
t
=
f
;
continue
;
}
t
=
f
;
if
(
strcmp
(
f
->
filename
,
n
->
filename
)
==
0
)
{
if
(
strcmp
(
f
->
filename
,
n
->
filename
)
==
0
)
{
// Replace, then all is done
// Replace, then all is done
cpio_free
(
f
);
cpio_free
(
f
);
vec_
entry
(
v
)[
_
]
=
n
;
vec_
cur
(
v
)
=
n
;
return
;
return
;
}
else
if
(
strcmp
(
f
->
filename
,
n
->
filename
)
>
0
)
{
// Insert, then start shifting
vec_entry
(
v
)[
_
]
=
n
;
t
=
f
;
shift
=
1
;
}
}
}
}
if
(
shift
)
vec_push_back
(
v
,
t
);
else
vec_push_back
(
v
,
n
);
vec_push_back
(
v
,
n
);
}
}
...
@@ -66,7 +50,7 @@ static void parse_cpio(const char *filename, struct vector *v) {
...
@@ -66,7 +50,7 @@ static void parse_cpio(const char *filename, struct vector *v) {
int
fd
=
xopen
(
filename
,
O_RDONLY
);
int
fd
=
xopen
(
filename
,
O_RDONLY
);
cpio_newc_header
header
;
cpio_newc_header
header
;
cpio_file
*
f
;
cpio_file
*
f
;
while
(
read
(
fd
,
&
header
,
110
)
==
110
)
{
while
(
xxread
(
fd
,
&
header
,
110
)
!=
-
1
)
{
f
=
xcalloc
(
sizeof
(
*
f
),
1
);
f
=
xcalloc
(
sizeof
(
*
f
),
1
);
// f->ino = x8u(header.ino);
// f->ino = x8u(header.ino);
f
->
mode
=
x8u
(
header
.
mode
);
f
->
mode
=
x8u
(
header
.
mode
);
...
@@ -81,7 +65,7 @@ static void parse_cpio(const char *filename, struct vector *v) {
...
@@ -81,7 +65,7 @@ static void parse_cpio(const char *filename, struct vector *v) {
// f->rdevminor = x8u(header.rdevminor);
// f->rdevminor = x8u(header.rdevminor);
f
->
namesize
=
x8u
(
header
.
namesize
);
f
->
namesize
=
x8u
(
header
.
namesize
);
// f->check = x8u(header.check);
// f->check = x8u(header.check);
f
->
filename
=
malloc
(
f
->
namesize
);
f
->
filename
=
x
malloc
(
f
->
namesize
);
xxread
(
fd
,
f
->
filename
,
f
->
namesize
);
xxread
(
fd
,
f
->
filename
,
f
->
namesize
);
file_align
(
fd
,
4
,
0
);
file_align
(
fd
,
4
,
0
);
if
(
strcmp
(
f
->
filename
,
"."
)
==
0
||
strcmp
(
f
->
filename
,
".."
)
==
0
)
{
if
(
strcmp
(
f
->
filename
,
"."
)
==
0
||
strcmp
(
f
->
filename
,
".."
)
==
0
)
{
...
@@ -100,8 +84,6 @@ static void parse_cpio(const char *filename, struct vector *v) {
...
@@ -100,8 +84,6 @@ static void parse_cpio(const char *filename, struct vector *v) {
vec_push_back
(
v
,
f
);
vec_push_back
(
v
,
f
);
}
}
close
(
fd
);
close
(
fd
);
// Sort by name
vec_sort
(
v
,
cpio_compare
);
}
}
static
void
dump_cpio
(
const
char
*
filename
,
struct
vector
*
v
)
{
static
void
dump_cpio
(
const
char
*
filename
,
struct
vector
*
v
)
{
...
@@ -109,6 +91,8 @@ static void dump_cpio(const char *filename, struct vector *v) {
...
@@ -109,6 +91,8 @@ static void dump_cpio(const char *filename, struct vector *v) {
int
fd
=
open_new
(
filename
);
int
fd
=
open_new
(
filename
);
unsigned
inode
=
300000
;
unsigned
inode
=
300000
;
char
header
[
111
];
char
header
[
111
];
// Sort by name
vec_sort
(
v
,
cpio_compare
);
cpio_file
*
f
;
cpio_file
*
f
;
vec_for_each
(
v
,
f
)
{
vec_for_each
(
v
,
f
)
{
if
(
f
->
remove
)
continue
;
if
(
f
->
remove
)
continue
;
...
@@ -170,8 +154,7 @@ static void cpio_mkdir(mode_t mode, const char *entry, struct vector *v) {
...
@@ -170,8 +154,7 @@ static void cpio_mkdir(mode_t mode, const char *entry, struct vector *v) {
cpio_file
*
f
=
xcalloc
(
sizeof
(
*
f
),
1
);
cpio_file
*
f
=
xcalloc
(
sizeof
(
*
f
),
1
);
f
->
mode
=
S_IFDIR
|
mode
;
f
->
mode
=
S_IFDIR
|
mode
;
f
->
namesize
=
strlen
(
entry
)
+
1
;
f
->
namesize
=
strlen
(
entry
)
+
1
;
f
->
filename
=
xmalloc
(
f
->
namesize
);
f
->
filename
=
strdup
(
entry
);
memcpy
(
f
->
filename
,
entry
,
f
->
namesize
);
cpio_vec_insert
(
v
,
f
);
cpio_vec_insert
(
v
,
f
);
fprintf
(
stderr
,
"Create directory [%s] (%04o)
\n
"
,
entry
,
mode
);
fprintf
(
stderr
,
"Create directory [%s] (%04o)
\n
"
,
entry
,
mode
);
}
}
...
@@ -181,11 +164,10 @@ static void cpio_add(mode_t mode, const char *entry, const char *filename, struc
...
@@ -181,11 +164,10 @@ static void cpio_add(mode_t mode, const char *entry, const char *filename, struc
cpio_file
*
f
=
xcalloc
(
sizeof
(
*
f
),
1
);
cpio_file
*
f
=
xcalloc
(
sizeof
(
*
f
),
1
);
f
->
mode
=
S_IFREG
|
mode
;
f
->
mode
=
S_IFREG
|
mode
;
f
->
namesize
=
strlen
(
entry
)
+
1
;
f
->
namesize
=
strlen
(
entry
)
+
1
;
f
->
filename
=
xmalloc
(
f
->
namesize
);
f
->
filename
=
strdup
(
entry
);
memcpy
(
f
->
filename
,
entry
,
f
->
namesize
);
f
->
filesize
=
lseek
(
fd
,
0
,
SEEK_END
);
f
->
filesize
=
lseek
(
fd
,
0
,
SEEK_END
);
lseek
(
fd
,
0
,
SEEK_SET
);
lseek
(
fd
,
0
,
SEEK_SET
);
f
->
data
=
malloc
(
f
->
filesize
);
f
->
data
=
x
malloc
(
f
->
filesize
);
xxread
(
fd
,
f
->
data
,
f
->
filesize
);
xxread
(
fd
,
f
->
data
,
f
->
filesize
);
close
(
fd
);
close
(
fd
);
cpio_vec_insert
(
v
,
f
);
cpio_vec_insert
(
v
,
f
);
...
@@ -362,6 +344,10 @@ static void cpio_backup(const char *orig, struct vector *v) {
...
@@ -362,6 +344,10 @@ static void cpio_backup(const char *orig, struct vector *v) {
cpio_rm
(
1
,
".backup"
,
o
);
cpio_rm
(
1
,
".backup"
,
o
);
cpio_rm
(
1
,
".backup"
,
v
);
cpio_rm
(
1
,
".backup"
,
v
);
// Sort both vectors before comparing
vec_sort
(
v
,
cpio_compare
);
vec_sort
(
o
,
cpio_compare
);
// Init the directory and rmlist
// Init the directory and rmlist
dir
->
filename
=
strdup
(
".backup"
);
dir
->
filename
=
strdup
(
".backup"
);
dir
->
namesize
=
strlen
(
dir
->
filename
)
+
1
;
dir
->
namesize
=
strlen
(
dir
->
filename
)
+
1
;
...
@@ -431,9 +417,6 @@ static void cpio_backup(const char *orig, struct vector *v) {
...
@@ -431,9 +417,6 @@ static void cpio_backup(const char *orig, struct vector *v) {
dir
->
remove
=
1
;
dir
->
remove
=
1
;
}
}
// Sort
vec_sort
(
v
,
cpio_compare
);
// Cleanup
// Cleanup
cpio_vec_destroy
(
o
);
cpio_vec_destroy
(
o
);
}
}
...
@@ -454,10 +437,9 @@ static int cpio_restore(struct vector *v) {
...
@@ -454,10 +437,9 @@ static int cpio_restore(struct vector *v) {
n
=
xcalloc
(
sizeof
(
*
n
),
1
);
n
=
xcalloc
(
sizeof
(
*
n
),
1
);
memcpy
(
n
,
f
,
sizeof
(
*
f
));
memcpy
(
n
,
f
,
sizeof
(
*
f
));
n
->
namesize
-=
8
;
n
->
namesize
-=
8
;
n
->
filename
=
xmalloc
(
n
->
namesize
);
n
->
filename
=
strdup
(
f
->
filename
+
8
);
memcpy
(
n
->
filename
,
f
->
filename
+
8
,
n
->
namesize
);
n
->
data
=
f
->
data
;
n
->
data
=
xmalloc
(
n
->
filesize
);
f
->
data
=
NULL
;
memcpy
(
n
->
data
,
f
->
data
,
n
->
filesize
);
n
->
remove
=
0
;
n
->
remove
=
0
;
fprintf
(
stderr
,
"Restoring [%s] -> [%s]
\n
"
,
f
->
filename
,
n
->
filename
);
fprintf
(
stderr
,
"Restoring [%s] -> [%s]
\n
"
,
f
->
filename
,
n
->
filename
);
cpio_vec_insert
(
v
,
n
);
cpio_vec_insert
(
v
,
n
);
...
...
jni/magiskboot/cpio.h
View file @
7e652964
...
@@ -47,4 +47,17 @@ typedef struct cpio_newc_header {
...
@@ -47,4 +47,17 @@ typedef struct cpio_newc_header {
char
check
[
8
];
char
check
[
8
];
}
cpio_newc_header
;
}
cpio_newc_header
;
typedef
enum
{
NONE
,
RM
,
MKDIR
,
ADD
,
EXTRACT
,
TEST
,
PATCH
,
BACKUP
,
RESTORE
,
STOCKSHA1
}
command_t
;
#endif
#endif
jni/magiskboot/magiskboot.h
View file @
7e652964
...
@@ -46,19 +46,6 @@ typedef enum {
...
@@ -46,19 +46,6 @@ typedef enum {
MTK
MTK
}
file_t
;
}
file_t
;
typedef
enum
{
NONE
,
RM
,
MKDIR
,
ADD
,
EXTRACT
,
TEST
,
PATCH
,
BACKUP
,
RESTORE
,
STOCKSHA1
}
command_t
;
extern
char
*
SUP_LIST
[];
extern
char
*
SUP_LIST
[];
extern
char
*
SUP_EXT_LIST
[];
extern
char
*
SUP_EXT_LIST
[];
extern
file_t
SUP_TYPE_LIST
[];
extern
file_t
SUP_TYPE_LIST
[];
...
...
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