From 0c0dcc3e5eb567e12cff3e646c18e68da7b3199a Mon Sep 17 00:00:00 2001 From: Pk11 Date: Sat, 15 Jan 2022 01:01:59 -0600 Subject: [PATCH] Use real free space if smaller than DSiWare limit --- arm9/src/storage.c | 20 +++++++++++--------- arm9/src/storage.h | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arm9/src/storage.c b/arm9/src/storage.c index cfe03f5..c8df794 100644 --- a/arm9/src/storage.c +++ b/arm9/src/storage.c @@ -512,6 +512,15 @@ unsigned long long getDsiSize() return 1024 * BYTES_PER_BLOCK; } +unsigned long long getDsiRealFree() +{ + struct statvfs st; + if (statvfs(sdnandMode ? "sd:/" : "nand:/", &st) == 0) + return st.f_bsize * st.f_bavail; + + return 0; +} + unsigned long long getDsiFree() { u32 blockSize = getDsiClusterSize(); @@ -530,16 +539,9 @@ unsigned long long getDsiFree() size -= appSize; } - return size; -} + unsigned long long realFree = getDsiRealFree(); -unsigned long long getDsiRealFree() -{ - struct statvfs st; - if (statvfs(sdnandMode ? "sd:/" : "nand:/", &st) == 0) - return st.f_bsize * st.f_bavail; - - return 0; + return (realFree < size) ? realFree : size; } u32 getDsiClusterSize() diff --git a/arm9/src/storage.h b/arm9/src/storage.h index d99a6d3..ace54be 100644 --- a/arm9/src/storage.h +++ b/arm9/src/storage.h @@ -41,8 +41,8 @@ unsigned long long getSDCardFree(); //internal storage unsigned long long getDsiSize(); -unsigned long long getDsiFree(); unsigned long long getDsiRealFree(); +unsigned long long getDsiFree(); u32 getDsiClusterSize(); #define getDsiUsed() (getDSIStorageSize() - getDSIStorageFree())