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
1e77e086
Commit
1e77e086
authored
Jan 02, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate fstab finding to its own function
parent
8c696cb8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
34 deletions
+40
-34
init.hpp
native/jni/init/init.hpp
+1
-0
twostage.cpp
native/jni/init/twostage.cpp
+39
-34
No files found.
native/jni/init/init.hpp
View file @
1e77e086
...
@@ -92,6 +92,7 @@ public:
...
@@ -92,6 +92,7 @@ public:
class
FirstStageInit
:
public
BaseInit
{
class
FirstStageInit
:
public
BaseInit
{
private
:
private
:
void
prepare
();
void
prepare
();
void
get_default_fstab
(
char
*
buf
,
size_t
len
);
public
:
public
:
FirstStageInit
(
char
*
argv
[],
BootConfig
*
cmd
)
:
BaseInit
(
argv
,
cmd
)
{
FirstStageInit
(
char
*
argv
[],
BootConfig
*
cmd
)
:
BaseInit
(
argv
,
cmd
)
{
LOGD
(
"%s
\n
"
,
__FUNCTION__
);
LOGD
(
"%s
\n
"
,
__FUNCTION__
);
...
...
native/jni/init/twostage.cpp
View file @
1e77e086
...
@@ -109,6 +109,41 @@ static void append_oplus(vector<fstab_entry> &fstab) {
...
@@ -109,6 +109,41 @@ static void append_oplus(vector<fstab_entry> &fstab) {
unlink
(
"oplus.fstab"
);
unlink
(
"oplus.fstab"
);
}
}
void
FirstStageInit
::
get_default_fstab
(
char
*
buf
,
size_t
len
)
{
buf
[
0
]
=
'\0'
;
// Find existing fstab file
for
(
const
char
*
suffix
:
{
config
->
fstab_suffix
,
config
->
hardware
,
config
->
hardware_plat
})
{
if
(
suffix
[
0
]
==
'\0'
)
continue
;
for
(
const
char
*
prefix
:
{
"odm/etc/fstab"
,
"vendor/etc/fstab"
,
"system/etc/fstab"
,
"fstab"
})
{
snprintf
(
buf
,
len
,
"%s.%s"
,
prefix
,
suffix
);
if
(
access
(
buf
,
F_OK
)
==
0
)
{
LOGD
(
"Found fstab file: %s
\n
"
,
buf
);
return
;
}
}
}
buf
[
0
]
=
'\0'
;
// No existing fstab file is found, create a valid path
const
char
*
suffix
=
[
&
]()
->
const
char
*
{
if
(
config
->
fstab_suffix
[
0
])
return
config
->
fstab_suffix
;
if
(
config
->
hardware
[
0
])
return
config
->
hardware
;
if
(
config
->
hardware_plat
[
0
])
return
config
->
hardware_plat
;
return
nullptr
;
}();
if
(
suffix
==
nullptr
)
{
LOGE
(
"Cannot determine fstab suffix!
\n
"
);
return
;
}
snprintf
(
buf
,
len
,
"fstab.%s"
,
suffix
);
}
void
FirstStageInit
::
prepare
()
{
void
FirstStageInit
::
prepare
()
{
if
(
is_dsu
())
{
if
(
is_dsu
())
{
rename
(
backup_init
(),
"/init"
);
rename
(
backup_init
(),
"/init"
);
...
@@ -135,23 +170,11 @@ void FirstStageInit::prepare() {
...
@@ -135,23 +170,11 @@ void FirstStageInit::prepare() {
}
}
char
fstab_file
[
128
];
char
fstab_file
[
128
];
fstab_file
[
0
]
=
'\0'
;
get_default_fstab
(
fstab_file
,
sizeof
(
fstab_file
))
;
// Find existing fstab file
// Empty fstab file path is an error
for
(
const
char
*
suffix
:
{
config
->
fstab_suffix
,
config
->
hardware
,
config
->
hardware_plat
})
{
if
(
fstab_file
[
0
]
==
'\0'
)
if
(
suffix
[
0
]
==
'\0'
)
return
;
continue
;
for
(
const
char
*
prefix
:
{
"odm/etc/fstab"
,
"vendor/etc/fstab"
,
"system/etc/fstab"
,
"fstab"
})
{
snprintf
(
fstab_file
,
sizeof
(
fstab_file
),
"%s.%s"
,
prefix
,
suffix
);
if
(
access
(
fstab_file
,
F_OK
)
!=
0
)
{
fstab_file
[
0
]
=
'\0'
;
}
else
{
LOGD
(
"Found fstab file: %s
\n
"
,
fstab_file
);
goto
exit_loop
;
}
}
}
exit_loop
:
// Try to load dt fstab
// Try to load dt fstab
vector
<
fstab_entry
>
fstab
;
vector
<
fstab_entry
>
fstab
;
...
@@ -177,24 +200,6 @@ exit_loop:
...
@@ -177,24 +200,6 @@ exit_loop:
}
// TODO: else if expected_field checks and fs_mgr_flags checks
}
// TODO: else if expected_field checks and fs_mgr_flags checks
}
}
if
(
fstab_file
[
0
]
==
'\0'
)
{
const
char
*
suffix
=
[
&
]()
->
const
char
*
{
if
(
config
->
fstab_suffix
[
0
])
return
config
->
fstab_suffix
;
if
(
config
->
hardware
[
0
])
return
config
->
hardware
;
if
(
config
->
hardware_plat
[
0
])
return
config
->
hardware_plat
;
return
nullptr
;
}();
if
(
suffix
==
nullptr
)
{
LOGE
(
"Cannot determine fstab suffix!
\n
"
);
return
;
}
snprintf
(
fstab_file
,
sizeof
(
fstab_file
),
"fstab.%s"
,
suffix
);
}
if
(
skip
)
{
if
(
skip
)
{
// When dt fstab fails, fall back to default fstab
// When dt fstab fails, fall back to default fstab
LOGI
(
"dt fstab contains error, fall back to default fstab
\n
"
);
LOGI
(
"dt fstab contains error, fall back to default fstab
\n
"
);
...
...
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