]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - vtoycli/vtoycli.c
1 /******************************************************************************
4 * Copyright (c) 2021, 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/>.
30 #include <sys/types.h>
32 #include <sys/ioctl.h>
34 #include <sys/types.h>
39 void ventoy_gen_preudo_uuid(void *uuid
)
44 fd
= open("/dev/urandom", O_RDONLY
);
48 for (i
= 0; i
< 8; i
++)
50 *((uint16_t *)uuid
+ i
) = (uint16_t)(rand() & 0xFFFF);
60 UINT64
get_disk_size_in_byte(const char *disk
)
64 const char *pos
= disk
;
65 unsigned long long size
= 0;
66 char diskpath
[256] = {0};
67 char sizebuf
[64] = {0};
69 if (strncmp(disk
, "/dev/", 5) == 0)
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)
78 fd
= open(diskpath
, O_RDONLY
);
81 read(fd
, sizebuf
, sizeof(sizebuf
));
82 size
= strtoull(sizebuf
, NULL
, 10);
89 printf("%s not exist \n", diskpath
);
92 printf("disk %s size %llu bytes\n", disk
, (unsigned long long)size
);
97 int main(int argc
, char **argv
)
103 else if (strcmp(argv
[1], "fat") == 0)
105 return vtoyfat_main(argc
- 1, argv
+ 1);
107 else if (strcmp(argv
[1], "gpt") == 0)
109 return vtoygpt_main(argc
- 1, argv
+ 1);
111 else if (strcmp(argv
[1], "partresize") == 0)
113 return partresize_main(argc
- 1, argv
+ 1);