]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - VtoyTool/vtoytool.c
add support for UnionTechOS fuyu (#864)
[Ventoy.git] / VtoyTool / vtoytool.c
1 /******************************************************************************
2 * vtoytool.c ---- ventoy os tool
3 *
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 typedef int (*main_func)(int argc, char **argv);
27
28 typedef struct cmd_def
29 {
30 const char *cmd;
31 main_func func;
32 }cmd_def;
33
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
40 static char *g_vtoytool_name = NULL;
41 static cmd_def g_cmd_list[] =
42 {
43 { "vine_patch_loader", vtoyvine_main },
44 { "vtoydump", vtoydump_main },
45 { "vtoydm", vtoydm_main },
46 { "loader", vtoyloader_main },
47 { "--install", vtoytool_install },
48 };
49
50
51 int vtoytool_install(int argc, char **argv)
52 {
53 int i;
54 char toolpath[128];
55 char filepath[128];
56
57 for (i = 0; i < sizeof(g_cmd_list) / sizeof(g_cmd_list[0]); i++)
58 {
59 if (g_cmd_list[i].cmd[0] != '-')
60 {
61 snprintf(toolpath, sizeof(toolpath), "/ventoy/tool/%s", g_vtoytool_name);
62 snprintf(filepath, sizeof(filepath), "/ventoy/tool/%s", g_cmd_list[i].cmd);
63 link(toolpath, filepath);
64 }
65 }
66
67 return 0;
68 }
69
70 int main(int argc, char **argv)
71 {
72 int i;
73
74 if ((g_vtoytool_name = strstr(argv[0], "vtoytool")) != NULL)
75 {
76 argc--;
77 argv++;
78 }
79
80 if (argc == 0)
81 {
82 fprintf(stderr, "Invalid param number\n");
83 return 1;
84 }
85
86 for (i = 0; i < sizeof(g_cmd_list) / sizeof(g_cmd_list[0]); i++)
87 {
88 if (strstr(argv[0], g_cmd_list[i].cmd))
89 {
90 return g_cmd_list[i].func(argc, argv);
91 }
92 }
93
94 fprintf(stderr, "Invalid cmd %s\n", argv[0]);
95 return 1;
96 }
97