forked from comex/formatter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fat.c
43 lines (30 loc) · 790 Bytes
/
fat.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
/*
BootMii - a Free Software replacement for the Nintendo/BroadOn bootloader.
Requires mini.
Copyright (C) 2009 Andre Heider "dhewg" <[email protected]>
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
#include "fat.h"
static FATFS fatfs;
u32 fat_mount(void) {
DSTATUS stat;
f_mount(0, NULL);
stat = disk_initialize(0);
if (stat & STA_NODISK)
return -1;
if (stat & STA_NOINIT)
return -2;
return f_mount(0, &fatfs);
}
u32 fat_umount(void) {
f_mount(0, NULL);
return 0;
}
s32 fat_getfree(void) {
FATFS *fatfs_p = &fatfs;
DWORD free_clusters = 0;
FRESULT res = f_getfree("/", &free_clusters, &fatfs_p);
if (res != FR_OK) return -res;
return free_clusters;
}