Skip to content

Commit b278c25

Browse files
author
Michael Runge
committed
Add support for tune2fs file operations
This allows tune2fs to be executed from within OTA scripts, allowing for file system modifications without formatting the partition Bug: 18430740 Change-Id: I0c2e05b5ef4a81ecea043e9b7b99b545d18fe5e6
1 parent e5879c3 commit b278c25

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

updater/Android.mk

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ LOCAL_STATIC_LIBRARIES += libapplypatch libedify libmtdutils libminzip libz
3434
LOCAL_STATIC_LIBRARIES += libmincrypt libbz
3535
LOCAL_STATIC_LIBRARIES += libcutils liblog libstdc++ libc
3636
LOCAL_STATIC_LIBRARIES += libselinux
37+
tune2fs_static_libraries := \
38+
libext2_com_err \
39+
libext2_blkid \
40+
libext2_quota \
41+
libext2_uuid_static \
42+
libext2_e2p \
43+
libext2fs
44+
LOCAL_STATIC_LIBRARIES += libtune2fs $(tune2fs_static_libraries)
45+
46+
LOCAL_C_INCLUDES += external/e2fsprogs/misc
3747
LOCAL_C_INCLUDES += $(LOCAL_PATH)/..
3848

3949
# Each library in TARGET_RECOVERY_UPDATER_LIBS should have a function

updater/install.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "mtdutils/mtdutils.h"
4747
#include "updater.h"
4848
#include "install.h"
49+
#include "tune2fs.h"
4950

5051
#ifdef USE_EXT4
5152
#include "make_ext4fs.h"
@@ -1539,6 +1540,37 @@ Value* EnableRebootFn(const char* name, State* state, int argc, Expr* argv[]) {
15391540
return StringValue(strdup("t"));
15401541
}
15411542

1543+
Value* Tune2FsFn(const char* name, State* state, int argc, Expr* argv[]) {
1544+
if (argc == 0) {
1545+
return ErrorAbort(state, "%s() expects args, got %d", name, argc);
1546+
}
1547+
1548+
char** args = ReadVarArgs(state, argc, argv);
1549+
if (args == NULL) {
1550+
return ErrorAbort(state, "%s() could not read args", name);
1551+
}
1552+
1553+
int i;
1554+
char** args2 = malloc(sizeof(char*) * (argc+1));
1555+
// Tune2fs expects the program name as its args[0]
1556+
args2[0] = strdup(name);
1557+
for (i = 0; i < argc; ++i) {
1558+
args2[i + 1] = args[i];
1559+
}
1560+
int result = tune2fs_main(argc + 1, args2);
1561+
for (i = 0; i < argc; ++i) {
1562+
free(args[i]);
1563+
}
1564+
free(args);
1565+
1566+
free(args2[0]);
1567+
free(args2);
1568+
if (result != 0) {
1569+
return ErrorAbort(state, "%s() returned error code %d", name, result);
1570+
}
1571+
return StringValue(strdup("t"));
1572+
}
1573+
15421574
void RegisterInstallFunctions() {
15431575
RegisterFunction("mount", MountFn);
15441576
RegisterFunction("is_mounted", IsMountedFn);
@@ -1589,4 +1621,5 @@ void RegisterInstallFunctions() {
15891621
RegisterFunction("set_stage", SetStageFn);
15901622

15911623
RegisterFunction("enable_reboot", EnableRebootFn);
1624+
RegisterFunction("tune2fs", Tune2FsFn);
15921625
}

0 commit comments

Comments
 (0)