-
Notifications
You must be signed in to change notification settings - Fork 11
/
fdisk_hal_unix.c
68 lines (51 loc) · 1.12 KB
/
fdisk_hal_unix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <strings.h>
#include "fdisk_hal.h"
FILE* sdcard = NULL;
unsigned char hal_border_flicker = 0;
void sdcard_visual_feedback(const uint8_t do_flicker)
{
}
void mega65_fast(void)
{
}
void sdcard_map_sector_buffer(void)
{
}
uint32_t sdcard_getsize(void)
{
struct stat s;
int r = fstat(fileno(sdcard), &s);
if (r) {
perror("stat");
exit(-1);
}
return s.st_size / 512;
}
void sdcard_open(void)
{
sdcard = fopen("sdcard.img", "r+b");
if (!sdcard) {
fprintf(stderr, "Could not open sdcard.img.\n");
perror("fopen");
exit(-1);
}
}
uint32_t write_count = 0;
void sdcard_writesector(const uint32_t sector_number)
{
const uint8_t* buffer = sector_buffer;
fseek(sdcard, sector_number * 512LL, SEEK_SET);
fwrite(buffer, 512, 1, sdcard);
write_count++;
}
void sdcard_erase(const uint32_t first_sector, const uint32_t last_sector)
{
uint32_t n;
bzero(sector_buffer, sizeof(512));
fprintf(stderr, "Erasing sectors %d..%d\n", first_sector, last_sector);
for (n = first_sector; n <= last_sector; n++)
sdcard_writesector(n);
}