Skip to content

Commit

Permalink
create tmpdir in /dev
Browse files Browse the repository at this point in the history
  • Loading branch information
HuskyDG committed Jun 13, 2023
1 parent 7c100a3 commit 5108725
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
8 changes: 2 additions & 6 deletions magisk-module/post-fs-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ export MAGISKTMP="$(magisk --path)"
chmod 777 "$MODDIR/overlayfs_system"

OVERLAYDIR="/data/adb/overlay"
OVERLAYMNT="/mnt/overlay"
MODULEMNT="/mnt/loop"

if [ ! -e "/mnt/vendor/system" ]; then
OVERLAYMNT="/mnt/vendor/system"
fi
OVERLAYMNT="/dev/mount_overlayfs"
MODULEMNT="/dev/mount_loop"


mv -fT /cache/overlayfs.log /cache/overlayfs.log.bak
Expand Down
12 changes: 6 additions & 6 deletions native/jni/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace std;
rmdir(overlay_tmpdir.data());

int log_fd = -1;
std::string overlay_tmpdir;
std::string overlay_tmpdir = "";
std::vector<mount_info> mountinfo;

static void collect_mounts() {
Expand Down Expand Up @@ -184,11 +184,11 @@ int main(int argc, const char **argv) {
// list of directories should be mounted!
std::vector<string> mount_list;

overlay_tmpdir = std::string("/mnt/") + "overlayfs_" + random_strc(20);
if (mkdirs(overlay_tmpdir.data(), 750) != 0) {
LOGE("Cannot create temp folder, please make sure /mnt is clean and write-able!\n");
return -1;
}
do {
char *random_string = random_strc(20);
overlay_tmpdir = std::string("/dev/.") + "worker_" + random_string;
free(random_string);
} while (mkdirs(overlay_tmpdir.data(), 750) != 0);
mkdir(std::string(std::string(argv[1]) + "/upper").data(), 0750);
mkdir(std::string(std::string(argv[1]) + "/worker").data(), 0750);

Expand Down
24 changes: 12 additions & 12 deletions native/jni/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#include "logging.hpp"
#include "base.hpp"

std::string random_strc(int n){
std::string result = "";
FILE *urandom = fopen("/dev/urandom", "re");
if (urandom == nullptr) return result;
char *str = new char[n+1];
char *random_strc(int n){
int urandom_fd = open("/dev/urandom", O_RDONLY);
if (urandom_fd == -1) return nullptr;
char *str = (char*)malloc(sizeof(char)*(n+1));
if (str == nullptr) {
fclose(urandom);
return result;
close(urandom_fd);
return nullptr;
}
for (int i=0;i<n;i++){
str[i] = 'a' + (fgetc(urandom) % ('z'-'a'+1));
char x = 0;
read(urandom_fd, &x, 1);
str[i] = 'a' + (x % ('z'-'a'+1));
}
fclose(urandom);
result = str;
delete []str;
return result;
str[n] = '\0';
close(urandom_fd);
return str;
}


Expand Down
2 changes: 1 addition & 1 deletion native/jni/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "base.hpp"

std::string random_strc(int n);
char *random_strc(int n);
bool starts_with(const char *s, const char *ss);
bool is_dir(const char *path);
bool is_lnk(const char *path);
Expand Down

0 comments on commit 5108725

Please sign in to comment.