]>
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/>.
29 #include <fat_filelib.h>
31 static int g_disk_fd
= 0;
33 static int vtoy_disk_read(uint32 sector
, uint8
*buffer
, uint32 sector_count
)
35 lseek(g_disk_fd
, sector
* 512, SEEK_SET
);
36 read(g_disk_fd
, buffer
, sector_count
* 512);
41 static int check_secure_boot(void)
45 flfile
= fl_fopen("/EFI/BOOT/grubx64_real.efi", "rb");
55 static int get_ventoy_version(void)
64 flfile
= fl_fopen("/grub/grub.cfg", "rb");
67 fl_fseek(flfile
, 0, SEEK_END
);
68 size
= (int)fl_ftell(flfile
);
70 fl_fseek(flfile
, 0, SEEK_SET
);
72 buf
= malloc(size
+ 1);
75 fl_fread(buf
, 1, size
, flfile
);
78 pos
= strstr(buf
, "VENTOY_VERSION=");
81 pos
+= strlen("VENTOY_VERSION=");
88 while (*end
!= 0 && *end
!= '"' && *end
!= '\r' && *end
!= '\n')
107 int main(int argc
, char **argv
)
113 if (argc
!= 2 && argc
!= 3)
115 printf("Usage: vtoyfat /dev/sdbs \n");
116 printf("Usage: vtoyfat -s /dev/sdbs \n");
120 if (argv
[1][0] == '-' && argv
[1][1] == 'T')
126 if (argv
[1][0] == '-' && argv
[1][1] == 's')
132 g_disk_fd
= open(disk
, O_RDONLY
);
135 printf("Failed to open %s\n", disk
);
141 if (0 == fl_attach_media(vtoy_disk_read
, NULL
))
145 rc
= get_ventoy_version();
149 rc
= check_secure_boot();