]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - VtoyTool/vtoytool.c
1 /******************************************************************************
2 * vtoytool.c ---- ventoy os tool
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 typedef int (*main_func
)(int argc
, char **argv
);
28 typedef struct cmd_def
34 int vtoydump_main(int argc
, char **argv
);
35 int vtoydm_main(int argc
, char **argv
);
36 int vtoytool_install(int argc
, char **argv
);
37 int vtoyloader_main(int argc
, char **argv
);
38 int vtoyvine_main(int argc
, char **argv
);
39 int vtoyksym_main(int argc
, char **argv
);
40 int vtoykmod_main(int argc
, char **argv
);
42 static char *g_vtoytool_name
= NULL
;
43 static cmd_def g_cmd_list
[] =
45 { "vine_patch_loader", vtoyvine_main
},
46 { "vtoydump", vtoydump_main
},
47 { "vtoydm", vtoydm_main
},
48 { "loader", vtoyloader_main
},
49 { "vtoyksym", vtoyksym_main
},
50 { "vtoykmod", vtoykmod_main
},
51 { "--install", vtoytool_install
},
55 int vtoytool_install(int argc
, char **argv
)
61 for (i
= 0; i
< sizeof(g_cmd_list
) / sizeof(g_cmd_list
[0]); i
++)
63 if (g_cmd_list
[i
].cmd
[0] != '-')
65 snprintf(toolpath
, sizeof(toolpath
), "/ventoy/tool/%s", g_vtoytool_name
);
66 snprintf(filepath
, sizeof(filepath
), "/ventoy/tool/%s", g_cmd_list
[i
].cmd
);
67 link(toolpath
, filepath
);
74 int main(int argc
, char **argv
)
78 if ((g_vtoytool_name
= strstr(argv
[0], "vtoytool")) != NULL
)
86 fprintf(stderr
, "Invalid param number\n");
90 for (i
= 0; i
< sizeof(g_cmd_list
) / sizeof(g_cmd_list
[0]); i
++)
92 if (strstr(argv
[0], g_cmd_list
[i
].cmd
))
94 return g_cmd_list
[i
].func(argc
, argv
);
98 fprintf(stderr
, "Invalid cmd %s\n", argv
[0]);