Skip to content

Commit 69138a5

Browse files
committed
EFS TAR & Image backup
1 parent 8e7ff50 commit 69138a5

File tree

3 files changed

+78
-16
lines changed

3 files changed

+78
-16
lines changed

extendedcommands.c

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -940,21 +940,25 @@ static void
940940

941941
#define BRTYPE_B_SYS 0
942942
#define BRTYPE_B_DATA 1
943-
#define BRTYPE_HL1 2
944-
#define BRTYPE_RESTORE 3
945-
#define BRTYPE_REST_FORMAT 4
943+
#define BRTYPE_B_EFS 2
944+
#define BRTYPE_HL1 3
945+
#define BRTYPE_RESTORE 4
946+
#define BRTYPE_REST_FORMAT 5
946947

947948
char st[255];
948-
static char* backup_parts[] = { "/system", "/data"};
949-
static char* backup_file[] = { "Sys", "Data"};
949+
static char* backup_parts[] = { "/system", "/data", "/efs"};
950+
static char* backup_file[] = { "Sys", "Data", "Efs"};
950951

951952
static char* items[] = { "TAR backup system",
952953
"TAR backup data",
954+
"TAR backup efs",
953955
" -------",
954956
"TAR restore",
955957
"TAR restore (+ format)",
956958
NULL };
957959

960+
if (ensure_root_path_mounted("SDCARD:")) { ui_print("\nError mount sdcard\n"); return; }
961+
958962

959963
for (;;) {
960964

@@ -982,6 +986,28 @@ static void
982986
ui_print("/data");
983987
if (!format_root_device("DATA:")) ui_print("ok");
984988
}
989+
}
990+
if (strstr(st, "_Efs.")) {
991+
if (!ensure_root_path_unmounted("EFS:")) {
992+
ui_print("/efs");
993+
//We won't format EFS without an image backup
994+
int ret;
995+
struct statfs s;
996+
if (0 != (ret = statfs("/sdcard", &s)))
997+
return print_and_error("Unable to stat /sdcard\n");
998+
uint64_t bavail = s.f_bavail;
999+
uint64_t bsize = s.f_bsize;
1000+
uint64_t sdcard_free = bavail * bsize;
1001+
uint64_t sdcard_free_mb = sdcard_free / (uint64_t)(1024 * 1024);
1002+
if (sdcard_free_mb < 20 ) return print_and_error("You should have at least 20MB free on your SD card\n");
1003+
if (chdir("/sdcard/samdroid/image")) {
1004+
__system("mkdir -p /sdcard/samdroid/image");
1005+
}
1006+
unlink("/sdcard/samdroid/image/before_tar_restore.img");
1007+
if (!__system("dd if=/dev/stl10 of=/sdcard/samdroid/image/efs_before_tar_restore.img")) {
1008+
if (format_root_device("EFS:")) return print_and_error("Can't format EFS\n");
1009+
}
1010+
}
9851011
}
9861012
case BRTYPE_RESTORE:
9871013
strcpy(sfpath, "/sdcard/samdroid/");
@@ -996,6 +1022,10 @@ static void
9961022
ui_print("/data");
9971023
if (ensure_root_path_mounted("DATA:")) { ui_print("\nError mount /data\n"); return; }
9981024
}
1025+
if (strstr(st, "_Efs.")) {
1026+
ui_print("/efs");
1027+
if (ensure_root_path_mounted("EFS:")) { ui_print("\nError mount /efs\n"); return; }
1028+
}
9991029

10001030
ui_print("\nRestoring..");
10011031

@@ -1004,7 +1034,7 @@ static void
10041034
chdir("/");
10051035
char *args[] = {"/xbin/tar", "-x","-f", sfpath, NULL};
10061036
execv("/xbin/tar", args);
1007-
fprintf(stderr, "E:Can't backup\n(%s)\n", strerror(errno));
1037+
fprintf(stderr, "E:Can't restore\n(%s)\n", strerror(errno));
10081038
_exit(-1);
10091039
}
10101040

@@ -1021,6 +1051,8 @@ static void
10211051
} else {
10221052
ui_print("\nRestore complete.\n");
10231053
}
1054+
case BRTYPE_B_EFS:
1055+
ensure_root_path_unmounted("EFS:");
10241056
break;
10251057
}
10261058
continue;
@@ -1043,12 +1075,26 @@ static void
10431075
case BRTYPE_B_DATA:
10441076
if (ensure_root_path_mounted("DATA:")) { ui_print("\nError mount /data\n"); return; }
10451077
break;
1078+
case BRTYPE_B_EFS:
1079+
if (ensure_root_path_mounted("EFS:")) { ui_print("\nError mount /efs\n"); return; }
1080+
break;
10461081
}
1082+
int ret;
1083+
struct statfs s;
1084+
if (0 != (ret = statfs("/sdcard", &s)))
1085+
return print_and_error("Unable to stat /sdcard\n");
1086+
uint64_t bavail = s.f_bavail;
1087+
uint64_t bsize = s.f_bsize;
1088+
uint64_t sdcard_free = bavail * bsize;
1089+
uint64_t sdcard_free_mb = sdcard_free / (uint64_t)(1024 * 1024);
1090+
10471091
switch (chosen_item) {
10481092
case BRTYPE_B_SYS:
10491093
case BRTYPE_B_DATA:
1050-
if (ensure_root_path_mounted("SDCARD:")) { ui_print("\nError mount sdcard\n"); return; }
1051-
ui_print("\nBackuping: ");
1094+
if (sdcard_free_mb < 220 ) return print_and_error("You should have at least 220MB free on your SD card\n");
1095+
case BRTYPE_B_EFS:
1096+
if (sdcard_free_mb < 20 ) return print_and_error("You should have at least 20MB free on your SD card\n");
1097+
ui_print("\nBacking up: ");
10521098
ui_print(backup_parts[chosen_item]);
10531099
ui_print("\n");
10541100

@@ -1080,16 +1126,18 @@ static void
10801126
}
10811127
ui_print("\n");
10821128

1083-
if (!WIFEXITED(status) || (WEXITSTATUS(status) == 2)) {
1129+
if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
10841130
LOGE("Can't create tar file %s\n", st);
10851131
} else {
10861132
ui_print("Backup complete.\n");
10871133
}
1134+
if ( chosen_item == BRTYPE_B_EFS )
1135+
ensure_root_path_unmounted("EFS:");
10881136
break;
10891137
}
10901138

10911139
} else {
1092-
ui_print("\nData backup aborted.\n");
1140+
ui_print("\nBackup aborted.\n");
10931141
}
10941142
if (!ui_text_visible()) break;
10951143
}
@@ -1541,6 +1589,7 @@ void image_backup() {
15411589
static char* list[] = { "DATA:",
15421590
"SYSTEM:",
15431591
"SDEXT:",
1592+
"EFS:",
15441593
NULL
15451594
};
15461595

@@ -1598,7 +1647,7 @@ void image_backup() {
15981647
sprintf(st,"%s%s%s",st,part,".img");
15991648
char cmd[PATH_MAX];
16001649
sprintf(cmd,"/xbin/dd if=\"%s\" of=\"%s\"",info->device,st);
1601-
ui_print("Backuping..");
1650+
ui_print("Backing up..");
16021651
if (ensure_root_path_mounted("SDCARD:") != 0) //Just to be sure
16031652
return print_and_error("Can't mount sdcard\n");
16041653
pid_t pid=fork();
@@ -1615,7 +1664,7 @@ void image_backup() {
16151664
ui_print(".");
16161665
sleep(1);
16171666
}
1618-
if ( WEXITSTATUS(status) == 2 ) return print_and_error("\nBackuping failed!\n");
1667+
if ( WEXITSTATUS(status) == 2 ) return print_and_error("\nBacking up failed!\n");
16191668
else {
16201669
ui_print("\nBackup Finished!\n");
16211670
return;
@@ -1806,7 +1855,7 @@ void show_fs_select(RootInfo* info)
18061855
}
18071856
char cmd[PATH_MAX];
18081857
if ( strcmp(info->name,"CACHE:") ) {
1809-
ui_print("\nBackuping");
1858+
ui_print("\nBacking up");
18101859
sprintf(cmd,"/xbin/tar -c --exclude=*RFS_LOG.LO* -f %s %s",backup,info->mount_point);
18111860
pid_t pid=fork();
18121861
if (pid==0) {
@@ -1818,8 +1867,8 @@ void show_fs_select(RootInfo* info)
18181867
ui_print(".");
18191868
sleep(1);
18201869
}
1821-
if ( WEXITSTATUS(status) == 2 ) err=1;
1822-
if ( err ) return print_and_error("\nBackuping failed!\n");
1870+
if ( WEXITSTATUS(status) != 0 ) err=1;
1871+
if ( err ) return print_and_error("\nBacking up failed!\n");
18231872

18241873
}
18251874
if (ensure_root_path_unmounted(info->name)) {
@@ -1859,7 +1908,7 @@ void show_fs_select(RootInfo* info)
18591908
ui_print(".");
18601909
sleep(1);
18611910
}
1862-
if ( WEXITSTATUS(status) == 2 ) err=1;
1911+
if ( WEXITSTATUS(status) != 0 ) err=1;
18631912
if ( err ) return print_and_error("Restoring failed!\n");
18641913
}
18651914
if (!err) ui_print("\nConversion was successful!\n");

roots.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static RootInfo g_roots[] = {
5858
{ "SDEXT:", SDEXT_DEVICE, NULL, NULL, "/sd-ext", SDEXT_FILESYSTEM, NULL },
5959
{ "MBM:", g_mtd_device, NULL, "mbm", NULL, g_raw, NULL },
6060
{ "TMP:", NULL, NULL, NULL, "/tmp", NULL, NULL },
61+
{ "EFS:", EFS_DEVICE, NULL, "efs", "/efs", EFS_FILESYSTEM, EFS_FILESYSTEM_OPTIONS },
6162
};
6263
#define NUM_ROOTS (sizeof(g_roots) / sizeof(g_roots[0]))
6364

roots.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@
6969
#define SYSTEM_FILESYSTEM "auto"
7070
#endif
7171

72+
#ifndef EFS_DEVICE
73+
#define EFS_DEVICE "/dev/stl10"
74+
#endif
75+
76+
#ifndef EFS_FILESYSTEM
77+
#define EFS_FILESYSTEM "rfs"
78+
#endif
79+
7280
#ifndef DATA_FILESYSTEM_OPTIONS
7381
#define DATA_FILESYSTEM_OPTIONS NULL
7482
#endif
@@ -85,6 +93,10 @@
8593
#define SYSTEM_FILESYSTEM_OPTIONS NULL
8694
#endif
8795

96+
#ifndef EFS_FILESYSTEM_OPTIONS
97+
#define EFS_FILESYSTEM_OPTIONS "nodev,nosuid,codepage=utf8,xattr,check=no"
98+
#endif
99+
88100

89101
/* Any of the "root_path" arguments can be paths with relative
90102
* components, like "SYSTEM:a/b/c".

0 commit comments

Comments
 (0)