]>
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 get_ventoy_version(void)
49 flfile
= fl_fopen("/grub/grub.cfg", "rb");
52 fl_fseek(flfile
, 0, SEEK_END
);
53 size
= (int)fl_ftell(flfile
);
55 fl_fseek(flfile
, 0, SEEK_SET
);
57 buf
= malloc(size
+ 1);
60 fl_fread(buf
, 1, size
, flfile
);
63 pos
= strstr(buf
, "VENTOY_VERSION=");
66 pos
+= strlen("VENTOY_VERSION=");
73 while (*end
!= 0 && *end
!= '"' && *end
!= '\r' && *end
!= '\n')
92 int main(int argc
, char **argv
)
98 printf("Usage: vtoyfat /dev/sdb \n");
102 if (argv
[1][0] == '-' && argv
[1][1] == 'T')
107 g_disk_fd
= open(argv
[1], O_RDONLY
);
110 printf("Failed to open %s\n", argv
[1]);
116 if (0 == fl_attach_media(vtoy_disk_read
, NULL
))
118 rc
= get_ventoy_version();