store SD card size in an unsigned long long

Fixes compatibility with >64GB cards?
This commit is contained in:
JeffRuLz 2018-11-07 21:23:37 -06:00 committed by GitHub
parent aa64efd0e2
commit 370be53528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 30 deletions

View File

@ -307,7 +307,7 @@ void install(Menu* m)
}
//Print file size
int fileSize = -1;
unsigned long long fileSize = 0;
{
iprintf("File Size: ");

View File

@ -2,7 +2,7 @@
#include "menu.h"
#include <time.h>
#define VERSION "0.5.1"
#define VERSION "0.5.2"
enum {
MAIN_MENU_INSTALL,
@ -18,6 +18,10 @@ int main(int argc, char **argv)
{
srand(time(0));
//Setup top screen
REG_DISPCNT = MODE_FB0;
VRAM_A_CR = VRAM_ENABLE;
videoSetMode(MODE_0_2D);
videoSetModeSub(MODE_0_2D);
@ -30,13 +34,18 @@ int main(int argc, char **argv)
consoleSelect(&bottomScreen);
consoleClear();
VRAM_A[100] = 0xFFFF;
if (!fatInitDefault())
{
consoleSelect(&bottomScreen);
consoleClear();
iprintf("fatInitDefault...Failed\n");
iprintf("\nPress B to exit.\n");
//iprintf("fatInitDefault...Failed\n");
//iprintf("\nPress B to exit.\n");
for (int i = 0; i < 32*24; i++)
iprintf("%c", i);
keyWait(KEY_B | KEY_A | KEY_START);
}

View File

@ -8,15 +8,15 @@
#define TITLE_LIMIT 39
//Printing
void printBytes(int bytes)
void printBytes(unsigned long long bytes)
{
if (abs(bytes) < 1024)
iprintf("%dB", bytes);
if (bytes < 1024)
iprintf("%dB", (unsigned int)bytes);
else if (abs(bytes) < 1024 * 1024)
else if (bytes < 1024 * 1024)
printf("%.2fKB", (float)bytes / 1024);
else if (abs(bytes) < 1024 * 1024 * 1024)
else if (bytes < 1024 * 1024 * 1024)
printf("%.2fMB", (float)bytes / 1024 / 1024);
else
@ -209,25 +209,25 @@ int copyFile(const char* in, char* out)
return result;
}
int getFileSize(FILE* f)
unsigned long long getFileSize(FILE* f)
{
if (!f)
return 0;
fseek(f, 0, SEEK_END);
int size = ftell(f);
unsigned long long size = ftell(f);
fseek(f, 0, SEEK_SET);
return size;
}
int getFileSizePath(const char* path)
unsigned long long getFileSizePath(const char* path)
{
if (path == NULL)
return -1;
FILE* f = fopen(path, "rb");
int size = getFileSize(f);
unsigned long long size = getFileSize(f);
fclose(f);
return size;
@ -372,12 +372,12 @@ int deleteDir(const char* path)
return 1;
}
int getDirSize(const char* path)
unsigned long long getDirSize(const char* path)
{
if (path == NULL)
return 0;
int size = 0;
unsigned long long size = 0;
DIR* dir;
struct dirent *ent;
@ -472,7 +472,7 @@ int sdIsInserted()
return 1;
}
int getSDCardSize()
unsigned long long getSDCardSize()
{
if (sdIsInserted())
{
@ -484,7 +484,7 @@ int getSDCardSize()
return 0;
}
int getSDCardFree()
unsigned long long getSDCardFree()
{
if (sdIsInserted())
{

View File

@ -9,7 +9,7 @@
#define BYTES_PER_BLOCK (1024*128)
//Printing
void printBytes(int bytes);
void printBytes(unsigned long long bytes);
void printFileInfo(const char* path);
//Progress bar
@ -18,15 +18,15 @@ void clearProgressBar();
//Files
int copyFile(const char* in, char* out);
int getFileSize(FILE* f);
int getFileSizePath(const char* path);
unsigned long long getFileSize(FILE* f);
unsigned long long getFileSizePath(const char* path);
int padFile(const char* path, int size);
//Directories
int dirExists(const char* path);
//int copyDir(const char* in, char* out);
int deleteDir(const char* path);
int getDirSize(const char* path);
unsigned long long getDirSize(const char* path);
//Home menu
int getMenuSlots();
@ -36,8 +36,8 @@ int getMenuSlotsFree();
//SD Card
int sdIsInserted();
int getSDCardSize();
int getSDCardFree();
unsigned long long getSDCardSize();
unsigned long long getSDCardFree();
#define getSDCardUsedSpace() (getSDCardSize() - getSDCardFree())
//Internal storage

View File

@ -12,8 +12,8 @@ void testMenu()
consoleSelect(&bottomScreen);
consoleClear();
int free = -1;
int size = -1;
unsigned int free = 0;
unsigned int size = 0;
//Home menu slots
{
@ -30,15 +30,15 @@ void testMenu()
{
iprintf("\nFree SD Space:\n\t"); swiWaitForVBlank();
free = getSDCardFree();
printBytes(free);
unsigned long long sdfree = getSDCardFree();
printBytes(sdfree);
iprintf(" / "); swiWaitForVBlank();
size = getSDCardSize();
printBytes(size);
unsigned long long sdsize = getSDCardSize();
printBytes(sdsize);
iprintf("\n"); swiWaitForVBlank();
printf("\t%.0f / %.0f blocks\n", (float)free / BYTES_PER_BLOCK, (float)size / BYTES_PER_BLOCK);
printf("\t%d / %d blocks\n", (unsigned int)(sdfree / BYTES_PER_BLOCK), (unsigned int)(sdsize / BYTES_PER_BLOCK));
}
//Emunand