|
46 | 46 | #include "mtdutils/mtdutils.h" |
47 | 47 | #include "updater.h" |
48 | 48 | #include "install.h" |
| 49 | +#include "tune2fs.h" |
49 | 50 |
|
50 | 51 | #ifdef USE_EXT4 |
51 | 52 | #include "make_ext4fs.h" |
@@ -1539,6 +1540,37 @@ Value* EnableRebootFn(const char* name, State* state, int argc, Expr* argv[]) { |
1539 | 1540 | return StringValue(strdup("t")); |
1540 | 1541 | } |
1541 | 1542 |
|
| 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 | + |
1542 | 1574 | void RegisterInstallFunctions() { |
1543 | 1575 | RegisterFunction("mount", MountFn); |
1544 | 1576 | RegisterFunction("is_mounted", IsMountedFn); |
@@ -1589,4 +1621,5 @@ void RegisterInstallFunctions() { |
1589 | 1621 | RegisterFunction("set_stage", SetStageFn); |
1590 | 1622 |
|
1591 | 1623 | RegisterFunction("enable_reboot", EnableRebootFn); |
| 1624 | + RegisterFunction("tune2fs", Tune2FsFn); |
1592 | 1625 | } |
0 commit comments