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
741b6793
Commit
741b6793
authored
Jun 17, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup libbase
parent
90013e48
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
50 deletions
+15
-50
files.cpp
native/jni/base/files.cpp
+9
-30
files.hpp
native/jni/base/files.hpp
+5
-19
rootdir.cpp
native/jni/init/rootdir.cpp
+1
-1
No files found.
native/jni/base/files.cpp
View file @
741b6793
...
...
@@ -286,26 +286,7 @@ void fclone_attr(int src, int dest) {
fsetattr
(
dest
,
&
a
);
}
void
fd_full_read
(
int
fd
,
void
**
buf
,
size_t
*
size
)
{
*
size
=
lseek
(
fd
,
0
,
SEEK_END
);
lseek
(
fd
,
0
,
SEEK_SET
);
*
buf
=
xmalloc
(
*
size
+
1
);
xxread
(
fd
,
*
buf
,
*
size
);
((
char
*
)
*
buf
)[
*
size
]
=
'\0'
;
}
void
full_read
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
)
{
int
fd
=
xopen
(
filename
,
O_RDONLY
|
O_CLOEXEC
);
if
(
fd
<
0
)
{
*
buf
=
nullptr
;
*
size
=
0
;
return
;
}
fd_full_read
(
fd
,
buf
,
size
);
close
(
fd
);
}
void
fd_full_read
(
int
fd
,
string
&
str
)
{
void
full_read
(
int
fd
,
string
&
str
)
{
char
buf
[
4096
];
for
(
ssize_t
len
;
(
len
=
xread
(
fd
,
buf
,
sizeof
(
buf
)))
>
0
;)
str
.
insert
(
str
.
end
(),
buf
,
buf
+
len
);
...
...
@@ -313,14 +294,14 @@ void fd_full_read(int fd, string &str) {
void
full_read
(
const
char
*
filename
,
string
&
str
)
{
if
(
int
fd
=
xopen
(
filename
,
O_RDONLY
|
O_CLOEXEC
);
fd
>=
0
)
{
f
d_f
ull_read
(
fd
,
str
);
full_read
(
fd
,
str
);
close
(
fd
);
}
}
string
f
d_f
ull_read
(
int
fd
)
{
string
full_read
(
int
fd
)
{
string
str
;
f
d_f
ull_read
(
fd
,
str
);
full_read
(
fd
,
str
);
return
str
;
}
...
...
@@ -429,12 +410,10 @@ void backup_folder(const char *dir, vector<raw_file> &files) {
if
(
fgetattr
(
fd
,
&
file
.
attr
)
<
0
)
return
SKIP
;
if
(
entry
->
d_type
==
DT_REG
)
{
f
d_full_read
(
fd
,
file
.
buf
,
file
.
sz
);
f
ile
.
content
=
full_read
(
fd
);
}
else
if
(
entry
->
d_type
==
DT_LNK
)
{
xreadlinkat
(
dfd
,
entry
->
d_name
,
path
,
sizeof
(
path
));
file
.
sz
=
strlen
(
path
)
+
1
;
file
.
buf
=
(
uint8_t
*
)
xmalloc
(
file
.
sz
);
memcpy
(
file
.
buf
,
path
,
file
.
sz
);
file
.
content
=
path
;
}
files
.
emplace_back
(
std
::
move
(
file
));
return
CONTINUE
;
...
...
@@ -449,10 +428,10 @@ void restore_folder(const char *dir, vector<raw_file> &files) {
if
(
S_ISDIR
(
file
.
attr
.
st
.
st_mode
))
{
mkdirs
(
path
,
0
);
}
else
if
(
S_ISREG
(
file
.
attr
.
st
.
st_mode
))
{
auto
fp
=
xopen_file
(
path
.
data
(),
"we"
);
if
(
fp
)
fwrite
(
file
.
buf
,
1
,
file
.
sz
,
fp
.
get
());
if
(
auto
fp
=
xopen_file
(
path
.
data
(),
"we"
))
fwrite
(
file
.
content
.
data
(),
1
,
file
.
content
.
size
()
,
fp
.
get
());
}
else
if
(
S_ISLNK
(
file
.
attr
.
st
.
st_mode
))
{
symlink
(
(
char
*
)
file
.
buf
,
path
.
data
());
symlink
(
file
.
content
.
data
()
,
path
.
data
());
}
setattr
(
path
.
data
(),
&
file
.
attr
);
}
...
...
native/jni/base/files.hpp
View file @
741b6793
...
...
@@ -39,14 +39,14 @@ protected:
void
swap
(
byte_data
&
o
);
};
struct
raw_file
:
public
byte_data
{
struct
raw_file
{
std
::
string
path
;
file_attr
attr
;
std
::
string
content
;
raw_file
()
:
attr
{}
{}
raw_file
(
const
raw_file
&
)
=
delete
;
raw_file
(
raw_file
&&
o
)
:
path
(
std
::
move
(
o
.
path
)),
attr
(
o
.
attr
)
{
swap
(
o
);
}
~
raw_file
()
{
free
(
buf
);
}
raw_file
(
raw_file
&&
o
)
:
path
(
std
::
move
(
o
.
path
)),
attr
(
o
.
attr
),
content
(
std
::
move
(
o
.
content
))
{}
};
struct
mmap_data
:
public
byte_data
{
...
...
@@ -75,11 +75,9 @@ int setattrat(int dirfd, const char *name, file_attr *a);
int
fsetattr
(
int
fd
,
file_attr
*
a
);
void
fclone_attr
(
int
src
,
int
dest
);
void
clone_attr
(
const
char
*
src
,
const
char
*
dest
);
void
fd_full_read
(
int
fd
,
void
**
buf
,
size_t
*
size
);
void
full_read
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
void
fd_full_read
(
int
fd
,
std
::
string
&
str
);
void
full_read
(
int
fd
,
std
::
string
&
str
);
void
full_read
(
const
char
*
filename
,
std
::
string
&
str
);
std
::
string
f
d_f
ull_read
(
int
fd
);
std
::
string
full_read
(
int
fd
);
std
::
string
full_read
(
const
char
*
filename
);
void
write_zero
(
int
fd
,
size_t
size
);
void
file_readline
(
bool
trim
,
FILE
*
fp
,
const
std
::
function
<
bool
(
std
::
string_view
)
>
&
fn
);
...
...
@@ -103,18 +101,6 @@ void backup_folder(const char *dir, std::vector<raw_file> &files);
void
restore_folder
(
const
char
*
dir
,
std
::
vector
<
raw_file
>
&
files
);
std
::
string
find_apk_path
(
const
char
*
pkg
);
template
<
typename
T
>
void
full_read
(
const
char
*
filename
,
T
&
buf
,
size_t
&
size
)
{
static_assert
(
std
::
is_pointer
<
T
>::
value
);
full_read
(
filename
,
reinterpret_cast
<
void
**>
(
&
buf
),
&
size
);
}
template
<
typename
T
>
void
fd_full_read
(
int
fd
,
T
&
buf
,
size_t
&
size
)
{
static_assert
(
std
::
is_pointer
<
T
>::
value
);
fd_full_read
(
fd
,
reinterpret_cast
<
void
**>
(
&
buf
),
&
size
);
}
using
sFILE
=
std
::
unique_ptr
<
FILE
,
decltype
(
&
fclose
)
>
;
using
sDIR
=
std
::
unique_ptr
<
DIR
,
decltype
(
&
closedir
)
>
;
sDIR
make_dir
(
DIR
*
dp
);
...
...
native/jni/init/rootdir.cpp
View file @
741b6793
...
...
@@ -72,7 +72,7 @@ static void load_overlay_rc(const char *overlay) {
if
(
str_ends
(
entry
->
d_name
,
".rc"
))
{
LOGD
(
"Found rc script [%s]
\n
"
,
entry
->
d_name
);
int
rc
=
xopenat
(
dfd
,
entry
->
d_name
,
O_RDONLY
|
O_CLOEXEC
);
rc_list
.
push_back
(
f
d_f
ull_read
(
rc
));
rc_list
.
push_back
(
full_read
(
rc
));
close
(
rc
);
unlinkat
(
dfd
,
entry
->
d_name
,
0
);
}
...
...
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