diff --git a/source/fatdir.c b/source/fatdir.c index c89b384..468bd65 100644 --- a/source/fatdir.c +++ b/source/fatdir.c @@ -463,12 +463,12 @@ int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf) buf->f_bsize = partition->bytesPerCluster; // File system block size. buf->f_frsize = partition->bytesPerCluster; // Fundamental file system block size. - buf->f_blocks = partition->fat.lastCluster - CLUSTER_FIRST; // Total number of blocks on file system in units of f_frsize. + buf->f_blocks = partition->fat.lastCluster - CLUSTER_FIRST + 1; // Total number of blocks on file system in units of f_frsize. buf->f_bfree = freeClusterCount; // Total number of free blocks. buf->f_bavail = freeClusterCount; // Number of free blocks available to non-privileged process. // Treat requests for info on inodes as clusters - buf->f_files = partition->fat.lastCluster - CLUSTER_FIRST; // Total number of file serial numbers. + buf->f_files = partition->fat.lastCluster - CLUSTER_FIRST + 1; // Total number of file serial numbers. buf->f_ffree = freeClusterCount; // Total number of free file serial numbers. buf->f_favail = freeClusterCount; // Number of file serial numbers available to non-privileged process. diff --git a/source/partition.c b/source/partition.c index b752f18..7351da9 100644 --- a/source/partition.c +++ b/source/partition.c @@ -195,12 +195,13 @@ PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cach partition->totalSize = ((uint64_t)partition->numberOfSectors - (partition->dataStart - startSector)) * (uint64_t)partition->bytesPerSector; // Store info about FAT - partition->fat.lastCluster = (partition->numberOfSectors - (uint32_t)(partition->dataStart - startSector)) / partition->sectorsPerCluster; + uint32_t clusterCount = (partition->numberOfSectors - (uint32_t)(partition->dataStart - startSector)) / partition->sectorsPerCluster; + partition->fat.lastCluster = clusterCount + CLUSTER_FIRST - 1; partition->fat.firstFree = CLUSTER_FIRST; - if (partition->fat.lastCluster < CLUSTERS_PER_FAT12) { + if (clusterCount < CLUSTERS_PER_FAT12) { partition->filesysType = FS_FAT12; // FAT12 volume - } else if (partition->fat.lastCluster < CLUSTERS_PER_FAT16) { + } else if (clusterCount < CLUSTERS_PER_FAT16) { partition->filesysType = FS_FAT16; // FAT16 volume } else { partition->filesysType = FS_FAT32; // FAT32 volume