3

I have an exfat formatted sdcard. It went into a mac, some files were pulled off of it, then it went back into a linux machine. The filesystem still appears to be mostly full even though there's nothing left on it. I deleted the remaining files from it (just the empty DCIM directory) and it still reports 55% full. For instance running df -h

/dev/mmcblk2p1   60G   32G   29G  53% /mnt/sdcard

Even though ls -lsa shows:

total 132
128 drwxrwxrwx  1 user user 131072 Dec 31  1969 .
  4 drwxrwxr-x 12 user user   4096 Feb 26 10:31 ..

If I umount it and use exfatfsck I see that it has zero files and directories but still 31GB of used space:

fsck from util-linux 2.27.1
exfatfsck 1.2.3
Checking file system on /dev/mmcblk2p1.
File system version           1.0
Sector size                 512 bytes
Cluster size                128 KB
Volume size                  59 GB
Used space                   31 GB
Available space              28 GB
Totally 0 directories and 0 files.
File system checking finished. No errors found.

I had to reformat the partition to get the space back: mkfs.exfat /dev/mmcblk2p1.

fsck from util-linux 2.27.1
exfatfsck 1.2.3
Checking file system on /dev/mmcblk2p1.
File system version           1.0
Sector size                 512 bytes
Cluster size                128 KB
Volume size                  59 GB
Used space                 2688 KB
Available space              59 GB
Totally 0 directories and 0 files.
File system checking finished. No errors found.

How does this happen? Is there any way to recover the space without reformatting the entire disk? I'm concerned about running into this situation again and the sdcard being not-entirely-empty.

  • 1
    Mac puts 'trashed' files into a .Trash folder. It sounds to me like you had leftover Trash items lying around, because Mac doesn't truly 'delete' them until you also nuke the Trash folder manually (from other OSes' perspectives) This is, however, not an Ubuntu question, but more of a "Why does this happen when I deleted things with my Mac OS", and that belongs probably on Ask Different or one of the other sites. – Thomas Ward Feb 26 '18 at 21:28
  • 2
    I checked for the .Trash folder, there was none! ls -lsa showed nothing. fsck says 0 files and 0 folders! It's more of a "why does ubuntu's exfat implementation do this inconsistent thing" (and what can I do about it). – cheshirekow Feb 26 '18 at 21:47
  • 3
    I might be off base here, but I am thinking that the volume bitmap was probably storing the old information and wasn't cleared when the files were removed on the Mac. Too bad you already reformatted the drive, but I would have been highly interested in if running the fsck -fy /dev/mmcblk2 would have been able to fix the bitmap while the drive was not mounted. – Terrance Feb 26 '18 at 23:00
  • Sorry, I meant allocation bitmap. See: ntfs.com/exfat-allocation-bitmap.htm – Terrance Feb 26 '18 at 23:05
  • 1
    Close voters. Crafting an answer. – Elder Geek Mar 10 '18 at 21:45
3

It appears that you didn't properly eject the removable storage when you had it connected to the Mac, resulting in a corrupted file-system. Regardless of Operating system (this applies to Ubuntu as well) it's important to sync to flush the buffers and/or safely eject removable storage to avoid corruption and possible data loss.

Some USB devices, such as a flash drive or a memory card connected with a USB card reader, must first be ejected before they can be removed from your computer or shut off. The device is ejected to ensure that nothing is being written to the memory card when it’s removed. If you remove the device without first ejecting it the information on it can be corrupted.

Note: emphasis mine.

Source: How do I safely remove a USB device from my computer? - Tech Ease

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.