feat: add --no-umount flag

This commit is contained in:
7a72 2025-11-25 22:30:03 +00:00
commit f8884a593f
5 changed files with 56 additions and 2 deletions

View file

@ -20,6 +20,7 @@ void magic_mount_init(MagicMount *ctx)
memset(ctx, 0, sizeof(*ctx));
ctx->module_dir = DEFAULT_MODULE_DIR;
ctx->mount_source = DEFAULT_MOUNT_SOURCE;
ctx->enable_unmountable = true;
}
void magic_mount_cleanup(MagicMount *ctx)
@ -163,7 +164,9 @@ static int mm_apply_node_recursive(MagicMount *ctx,
strerror(errno));
return -1;
} else if (!strstr(target, ".magic_mount/workdir/")) {
ksu_send_unmountable(target);
if (ctx->enable_unmountable)
ksu_send_unmountable(path);
}
(void)mount(NULL, target, NULL,
@ -384,7 +387,9 @@ static int mm_apply_node_recursive(MagicMount *ctx,
LOGI("move mountpoint success: %s -> %s", wpath, path);
(void)mount(NULL, path, NULL, MS_REC | MS_PRIVATE, NULL);
ksu_send_unmountable(path);
if (ctx->enable_unmountable)
ksu_send_unmountable(path);
}
ctx->stats.nodes_mounted++;

View file

@ -2,6 +2,7 @@
#define MAGIC_MOUNT_H
#include <stddef.h>
#include <stdbool.h>
#define DISABLE_FILE_NAME "disable"
#define REMOVE_FILE_NAME "remove"
@ -35,6 +36,8 @@ typedef struct MagicMount {
char **extra_parts;
int extra_parts_count;
bool enable_unmountable;
} MagicMount;
/* Initialization ctx (module_dir/mount_source) */

View file

@ -25,6 +25,7 @@ typedef struct {
const char *log_file;
const char *partitions;
bool debug;
bool umount;
} Config;
/* --- Forward declarations --- */
@ -51,6 +52,7 @@ static void usage(const char *prog)
" -l, --log-file FILE Log file (default: stderr, '-' for stdout)\n"
" -c, --config FILE Config file (default: %s)\n"
" -v, --verbose Enable debug logging\n"
" --no_umount Disable umount\n"
" -h, --help Show this help message\n"
"\n",
VERSION, prog, DEFAULT_MODULE_DIR, DEFAULT_MOUNT_SOURCE,
@ -109,6 +111,9 @@ static int load_config_file(const char *path, Config *cfg, MagicMount *ctx)
} else if (!strcasecmp(key, "debug")) {
cfg->debug = str_is_true(val);
} else if (!strcasecmp(key, "umount")) {
cfg->umount = str_is_true(val);
} else if (!strcasecmp(key, "partitions")) {
cfg->partitions = strdup(val);
@ -213,6 +218,7 @@ int main(int argc, char **argv)
{
MagicMount ctx;
Config cfg = {0};
cfg.umount = true;
char auto_tmp[PATH_MAX] = {0};
const char *config_path = DEFAULT_CONFIG_PATH;
@ -254,6 +260,11 @@ int main(int argc, char **argv)
tmp_dir = cfg.temp_dir;
if (cfg.debug)
log_set_level(LOG_DEBUG);
if (cfg.umount)
ctx.enable_unmountable = true;
else
ctx.enable_unmountable = false;
for (int i = 1; i < argc; i++) {
const char *arg = argv[i];
@ -273,6 +284,9 @@ int main(int argc, char **argv)
} else if (!strcmp(arg, "-v") || !strcmp(arg, "--verbose")) {
log_set_level(LOG_DEBUG);
} else if (!strcmp(arg, "--no-umount")) {
ctx.enable_unmountable = false;
} else if ((!strcmp(arg, "-p") || !strcmp(arg, "--partitions")) && i + 1 < argc) {
cli_has_partitions = true;
if (parse_partitions(argv[++i], &ctx) < 0) {

View file

@ -10,6 +10,7 @@
mountsource: 'KSU',
logfile: '/data/adb/magic_mount/mm.log',
verbose: false,
umount: false,
partitions: []
};
@ -121,6 +122,9 @@
case 'debug':
result.verbose = isTrueValue(value);
break;
case 'umount':
result.umount = isTrueValue(value);
break;
case 'partitions':
result.partitions = value
.split(',')
@ -158,6 +162,8 @@
lines.push(`debug=${cfg.verbose ? 'true' : 'false'}`);
lines.push(`umount=${cfg.umount ? 'true' : 'false'}`);
if (cfg.partitions.length > 0) {
lines.push(`partitions=${cfg.partitions.join(',')}`);
}
@ -497,6 +503,26 @@
</div>
</div>
<div class="field">
<label for="umount-setting">{L.config.umountLabel}</label>
<div class="loglevel-switch" id="umount-setting" role="group">
<button
type="button"
class="lv-btn {!config.umount ? 'active' : ''}"
on:click|preventDefault={() => (config.umount = false)}
>
{L.config.umountOff}
</button>
<button
type="button"
class="lv-btn {config.umount ? 'active' : ''}"
on:click|preventDefault={() => (config.umount = true)}
>
{L.config.umountOn}
</button>
</div>
</div>
<div class="field">
<label for="moduledir-input">{L.config.moduleDir}</label>
<input

View file

@ -13,6 +13,9 @@
"verboseLabel": "Log Level",
"verboseOff": "Normal",
"verboseOn": "Verbose",
"umountLabel": "Try Unmount",
"umountOff": "Disabled",
"umountOn": "Enabled",
"moduleDir": "Module Directory",
"tempDir": "Temp Directory",
"mountSource": "Mount Source",
@ -61,6 +64,9 @@
"verboseLabel": "日志级别",
"verboseOff": "普通",
"verboseOn": "详细",
"umountLabel": "尝试卸载",
"umountOff": "禁用",
"umountOn": "启用",
"moduleDir": "模块目录",
"tempDir": "临时目录",
"mountSource": "挂载源",