Skip to content

Commit a60b11b

Browse files
committed
Fixed debug log to display total and free drive space.
1 parent 3fb3a73 commit a60b11b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

fatfs/src/dc.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -1127,30 +1127,34 @@ int fs_fat_mount(const char *mp, kos_blockdev_t *dev_pio, kos_blockdev_t *dev_dm
11271127
goto error;
11281128
}
11291129

1130+
uint32_t sect_size = (1 << mnt->dev->l_block_size);
1131+
11301132
#ifdef FATFS_USE_DMA_BUF
11311133
if (mnt->dev_dma) {
1132-
DBG((DBG_DEBUG, "FATFS: Allocating %d bytes for DMA buffer\n", mnt->fs->csize * _MAX_SS));
1133-
if (!(mnt->dmabuf = (uint8_t *)memalign(32, mnt->fs->csize * _MAX_SS))) {
1134+
DBG((DBG_DEBUG, "FATFS: Allocating %d bytes for DMA buffer\n", mnt->fs->csize * sect_size));
1135+
if (!(mnt->dmabuf = (uint8_t *)memalign(32, mnt->fs->csize * sect_size))) {
11341136
dbglog(DBG_ERROR, "FATFS: Out of memory for DMA buffer\n");
11351137
}
11361138
else {
11371139
DBG((DBG_DEBUG, "FATFS: Allocated %d bytes for DMA buffer at %p\n",
1138-
mnt->fs->csize * _MAX_SS, mnt->dmabuf));
1140+
mnt->fs->csize * sect_size, mnt->dmabuf));
11391141
}
11401142
}
11411143
#endif
11421144

11431145
FATFS *fs;
1144-
DWORD fre_clust, fre_sect, tot_sect;
1146+
DWORD fre_clust;
1147+
uint64_t fre_sect, tot_sect;
11451148
rc = f_getfree(mnt->dev_path, &fre_clust, &fs);
11461149

11471150
/* Get total sectors and free sectors */
1148-
tot_sect = (fs->n_fatent - 2) * fs->csize;
1151+
tot_sect = mnt->dev->count_blocks(mnt->dev);
11491152
fre_sect = fre_clust * fs->csize;
11501153

11511154
if (rc == FR_OK) {
1152-
dbglog(DBG_DEBUG, "FATFS: %lu KiB total drive space and %lu KiB available.\n",
1153-
tot_sect / 2, fre_sect / 2);
1155+
dbglog(DBG_DEBUG, "FATFS: %lu MB total, %lu MB free.\n",
1156+
(uint32_t)((tot_sect * sect_size) / 1024 / 1024),
1157+
(uint32_t)((fre_sect * sect_size) / 1024 / 1024));
11541158
}
11551159

11561160
DBG((DBG_DEBUG, "FATFS: FAT start sector: %ld\n", mnt->fs->fatbase));

0 commit comments

Comments
 (0)