]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - vtoyfat/vtoyfat_linux.c
1 /******************************************************************************
2 * vtoyfat.c ---- Parse fat file system
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/>.
28 #include <fat_filelib.h>
30 static int g_disk_fd
= 0;
32 static int vtoy_disk_read(uint32 sector
, uint8
*buffer
, uint32 sector_count
)
34 lseek(g_disk_fd
, sector
* 512, SEEK_SET
);
35 read(g_disk_fd
, buffer
, sector_count
* 512);
40 static int check_secure_boot(void)
44 flfile
= fl_fopen("/EFI/BOOT/grubx64_real.efi", "rb");
54 static int get_ventoy_version(void)
63 flfile
= fl_fopen("/grub/grub.cfg", "rb");
66 fl_fseek(flfile
, 0, SEEK_END
);
67 size
= (int)fl_ftell(flfile
);
69 fl_fseek(flfile
, 0, SEEK_SET
);
71 buf
= malloc(size
+ 1);
74 fl_fread(buf
, 1, size
, flfile
);
77 pos
= strstr(buf
, "VENTOY_VERSION=");
80 pos
+= strlen("VENTOY_VERSION=");
87 while (*end
!= 0 && *end
!= '"' && *end
!= '\r' && *end
!= '\n')
106 int main(int argc
, char **argv
)
112 if (argc
!= 2 && argc
!= 3)
114 printf("Usage: vtoyfat /dev/sdbs \n");
115 printf("Usage: vtoyfat -s /dev/sdbs \n");
119 if (argv
[1][0] == '-' && argv
[1][1] == 'T')
125 if (argv
[1][0] == '-' && argv
[1][1] == 's')
131 g_disk_fd
= open(disk
, O_RDONLY
);
134 printf("Failed to open %s\n", disk
);
140 if (0 == fl_attach_media(vtoy_disk_read
, NULL
))
144 rc
= get_ventoy_version();
148 rc
= check_secure_boot();