]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - vtoycli/vtoycli.c
Fix French language (#2850)
[Ventoy.git] / vtoycli / vtoycli.c
1 /******************************************************************************
2 * vtoycli.c
3 *
4 * Copyright (c) 2021, 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 <stdio.h>
23 #include <stdlib.h>
24 #include <stdint.h>
25 #include <string.h>
26 #include <errno.h>
27 #include <time.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30 #include <sys/types.h>
31 #include <sys/mman.h>
32 #include <sys/ioctl.h>
33 #include <sys/stat.h>
34 #include <sys/types.h>
35 #include <dirent.h>
36
37 #include "vtoycli.h"
38
39 void ventoy_gen_preudo_uuid(void *uuid)
40 {
41 int i;
42 int fd;
43
44 fd = open("/dev/urandom", O_RDONLY);
45 if (fd < 0)
46 {
47 srand(time(NULL));
48 for (i = 0; i < 8; i++)
49 {
50 *((uint16_t *)uuid + i) = (uint16_t)(rand() & 0xFFFF);
51 }
52 }
53 else
54 {
55 read(fd, uuid, 16);
56 close(fd);
57 }
58 }
59
60 UINT64 get_disk_size_in_byte(const char *disk)
61 {
62 int fd;
63 int rc;
64 const char *pos = disk;
65 unsigned long long size = 0;
66 char diskpath[256] = {0};
67 char sizebuf[64] = {0};
68
69 if (strncmp(disk, "/dev/", 5) == 0)
70 {
71 pos = disk + 5;
72 }
73
74 // Try 1: get size from sysfs
75 snprintf(diskpath, sizeof(diskpath) - 1, "/sys/block/%s/size", pos);
76 if (access(diskpath, F_OK) >= 0)
77 {
78 fd = open(diskpath, O_RDONLY);
79 if (fd >= 0)
80 {
81 read(fd, sizebuf, sizeof(sizebuf));
82 size = strtoull(sizebuf, NULL, 10);
83 close(fd);
84 return (size * 512);
85 }
86 }
87 else
88 {
89 printf("%s not exist \n", diskpath);
90 }
91
92 printf("disk %s size %llu bytes\n", disk, (unsigned long long)size);
93 return size;
94 }
95
96
97 int main(int argc, char **argv)
98 {
99 if (argc < 2)
100 {
101 return 1;
102 }
103 else if (strcmp(argv[1], "fat") == 0)
104 {
105 return vtoyfat_main(argc - 1, argv + 1);
106 }
107 else if (strcmp(argv[1], "gpt") == 0)
108 {
109 return vtoygpt_main(argc - 1, argv + 1);
110 }
111 else if (strcmp(argv[1], "partresize") == 0)
112 {
113 return partresize_main(argc - 1, argv + 1);
114 }
115 else
116 {
117 return 1;
118 }
119 }
120