Skip to content

Instantly share code, notes, and snippets.

@Tasssadar
Last active December 24, 2015 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tasssadar/6730280 to your computer and use it in GitHub Desktop.
Save Tasssadar/6730280 to your computer and use it in GitHub Desktop.
/*
* This file contains device specific hooks.
* Always enclose hooks to #if MR_DEVICE_HOOKS >= ver
* with corresponding hook version!
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#if MR_DEVICE_HOOKS >= 1
int mrom_hook_after_android_mounts(const char *busybox_path, const char *base_path, int type)
{
// On M7, this fstab file is used to remount system to RO,
// but with MultiROM, it remounts everything as RO, even /data and /cache
if(access("/remount.qcom", F_OK) >= 0)
return remove("/remount.qcom");
// Sense ROMs still use init.rc to mount partitions
if(access("/init.target.rc", F_OK) >= 0)
{
char line[1024];
int add_dummy = 0;
FILE *f_in = fopen("/init.target.rc", "r");
if(!f_in)
return -1;
FILE *f_out = fopen("/init.target.rc.new", "w");
if(!f_out)
{
fclose(f_in);
return -1;
}
while((fgets(line, sizeof(line), f_in)))
{
if (strstr(line, "on "))
add_dummy = 1;
else if (strstr(line, "mount ") && !strstr(line, "tmpfs") &&
(strstr(line, "/data") || strstr(line, "/system") || strstr(line, "/cache")))
{
if(add_dummy == 1)
{
add_dummy = 0;
fputs(" export DUMMY_LINE_INGORE_IT 1\n", f_out);
}
fputc((int)'#', f_out);
}
fputs(line, f_out);
}
fclose(f_in);
fclose(f_out);
rename("/init.target.rc.new", "/init.target.rc");
chmod("/init.target.rc", 0755);
}
return 0;
}
#endif /* MR_DEVICE_HOOKS >= 1 */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment