diff --git a/arm9/source/driveMenu.cpp b/arm9/source/driveMenu.cpp index f2f5043..c2b9683 100644 --- a/arm9/source/driveMenu.cpp +++ b/arm9/source/driveMenu.cpp @@ -200,7 +200,9 @@ void dm_drawBottomScreen(void) { } printf ("\n(SD FAT, "); printDriveBytes(sdSize); - printf(")"); + printf(")\n"); + printDriveBytes(getBytesFree("sd:/")); + printf(" space free"); } else if (dmAssignedOp[dmCursorPosition] == 1) { printf ("[fat:] FLASHCART"); if (fatLabel[0] != '\0') { @@ -208,7 +210,9 @@ void dm_drawBottomScreen(void) { } printf ("\n(Slot-1 SD FAT, "); printDriveBytes(fatSize); - printf(")"); + printf(")\n"); + printDriveBytes(getBytesFree("fat:/")); + printf(" space free"); } else if (dmAssignedOp[dmCursorPosition] == 2) { printf ("GBA GAMECART\n"); printf ("(GBA Game)"); @@ -228,7 +232,9 @@ void dm_drawBottomScreen(void) { printf ("[nand:] SYSNAND"); printf ("\n(SysNAND FAT, "); printDriveBytes(nandSize); - printf(")"); + printf(")\n"); + printDriveBytes(getBytesFree("nand:/")); + printf(" space free"); } else if (dmAssignedOp[dmCursorPosition] == 8) { printf ("[img:] FAT IMAGE"); printf ("\n(Image FAT, "); diff --git a/arm9/source/driveOperations.cpp b/arm9/source/driveOperations.cpp index 91b8e5f..fc4a1e2 100644 --- a/arm9/source/driveOperations.cpp +++ b/arm9/source/driveOperations.cpp @@ -42,41 +42,35 @@ u64 sdSize = 0; u64 fatSize = 0; u64 imgSize = 0; -static int getGbNumber(u64 bytes) { - int gbNumber = 0; - for (u64 i = 0; i <= bytes; i += 0x40000000) { - gbNumber++; +static float getGbNumber(u64 bytes) { + float gbNumber = 0.0f; + for (u64 i = 0; i <= bytes; i += 0x6666666) { + gbNumber += 0.1f; } return gbNumber; } -static int getTbNumber(u64 bytes) { - int tbNumber = 0; - for (u64 i = 0; i <= bytes; i += 0x10000000000) { - tbNumber++; +static float getTbNumber(u64 bytes) { + float tbNumber = 0.0f; + for (u64 i = 0; i <= bytes; i += 0x1999999999) { + tbNumber += 0.01f; } return tbNumber; } void printDriveBytes(u64 bytes) { - if (bytes == 1) - iprintf("%d Byte", (int)bytes); - - else if (bytes >= 0 && bytes < 1024) - iprintf("%d Bytes", (int)bytes); - - else if (bytes >= 1024 && bytes < (1024 * 1024)) + if (bytes < (1024 * 1024)) printf("%d KB", (int)bytes / 1024); else if (bytes >= (1024 * 1024) && bytes < (1024 * 1024 * 1024)) printf("%d MB", (int)bytes / 1024 / 1024); else if (bytes >= 0x40000000 && bytes < 0x10000000000) - printf("%d GB", getGbNumber(bytes)); + printf("%.1f GB", getGbNumber(bytes)); else - printf("%d TB", getTbNumber(bytes)); + printf("%.1f TB", getTbNumber(bytes)); } const char* getDrivePath(void) { @@ -169,6 +163,12 @@ bool sdMount(void) { return false; } +u64 getBytesFree(const char* drivePath) { + struct statvfs st; + statvfs(drivePath, &st); + return (u64)st.f_bsize * (u64)st.f_bavail; +} + void sdUnmount(void) { fatUnmount("sd"); sdLabel[0] = '\0'; diff --git a/arm9/source/driveOperations.h b/arm9/source/driveOperations.h index 11cd0e2..c2546d3 100644 --- a/arm9/source/driveOperations.h +++ b/arm9/source/driveOperations.h @@ -44,5 +44,6 @@ extern void ramdrive2Mount(void); extern void nitroUnmount(void); extern bool imgMount(const char* imgName); extern void imgUnmount(void); +extern u64 getBytesFree(const char* drivePath); #endif //FLASHCARD_H