I have just purchased a new CF card for my DSLR. I tested it using Xbench (Mac OS X) and it performs as expected. However, I'd like to do a "surface scan" (moving platter term) to check for "bad sectors" (moving platter term). I could bash script a processes using dd, but I get the feeling that there is a better way out there. My goal is to conclusively know that a memory card (CF, SD, etc.) is safe to use on a photo shoot, and that is doesn't need to be returned before the 30 day vendor policy window expires.

I definitely want Mac solutions given here. I would also like to get a few Linux suggestions. Let's even throw a bone to the windows users just so that this one question can meet everyone's needs.

  • I understand that solid state memory is different than spinning platters. I don't need a lesson in that. What I need is a way to verify devices I own. The process is simple:Fill the device with know content. Read from the device and verify the content. If you get errors reading or writing, obvious failure. If the content your read differs from what you wrote, that's the less obvious failure. The date should be random and multiple cycles should be used. What I need is a tool that does it. I've written one, but it is a hack. Feb 24 '12 at 18:00

As the controller can move the blocks wherever it wants (see wear leveling), the only chance for a whole read/write-test ist to fill the disk up and then compare. Several times with different patterns of course to be sure.

And still you won't catch faulty regions, as they are hidden too by the controller as long as he has spares.


Flash memory does not work the same way as disks with platters. The concept of a "bad sector" does not really exist with flash memory. These days, with flash memory and SSD's, the built-in controller takes care of identifying and marking off unusable blocks of memory, dynamically moving data around to mitigate block write limitations, etc. These features are far more prevalent in SSD's, but some also exist in quality flash cards (such as SanDisk).

Most file system checking tools either make specific assumptions about the physical structure of the storage device (i.e. platter based, with physical cylinders, sectors, clusters, etc.), or work at an abstracted level and make repairs "virtually" using file or directory tables. You would need a tool specifically designed to mark bad blocks on a flash memory device, as anything else is either going to cause more problems (by assuming it can fix the problems the same way it would with a platter-based device) or make virtual fixes that don't take into account dynamic hardware-level features of flash. Even if you could mark a particular "sector" or "cluster" as 'bad', it wouldn't necessarily do any good, since those physical concepts don't actually exist in flash memory. If the flash device is more advanced, and dynamically moves data around to automatically bypass bad blocks and mitigate write limitations, the physical location of data may reside in a bad block one moment, and in a good block a moment later. (Note that the idea of a "bad" block in flash memory is much fuzzier than it is with platter disks...a flash memory block tends to die slowly, rather than suddenly, and may "flicker" between readable/not readable a bit before it becomes entirely unusable.)

Generally speaking, when it comes to flash, let the device manage itself from a bad block perspective. Different manufacturers structure and store data in different ways, and each may have different levels and amounts of dynamic behavior that moves data around to avoid some of the limitations of flash memory. Trying to manage it yourself is likely to cause more problems than it solves, and may render your flash disks useless in the long run.

If you wish to avoid bad flash cards, I highly recommend using reputable brands. I have tried a variety of flash cards in the past, however SanDisk is the only brand that I have used that, at least to date, has never failed. I have several 4, 8, and 16 gig SDHC cards that I use quite heavily, and regularly take out of my camera and insert into my laptop or computer, and they are still working perfectly. (Some are several years old.)

  • 1
    Bad blocks can exist with any block device: if I write some data to a particular block, but I can't read it back, that's a bad block. The controller can hide this problem for writes, by writing the data elsewhere, but not for reads. Aug 16 '14 at 3:59

In Linux, the command you want is badblocks. There appears to be a port of this to Mac OS X as part of this ext2-for-os-x port -- install the whole thing and ignore everything but the /usr/local/sbin/badblocks command.

That said, this will help test, but I don't think it'll be conclusive, because first as Leonidas says, you don't really get raw access to the flash memory so it's hard to do a complete scan, and also because new failures could appear after the test, perhaps even triggered by it.


Reading your comment below the question, I believe F3 does exactly what you want. It compiles on Linux/Mac OS X and is also available via Homebrew.


I found this on google, I'm not using sd cards for cameras' storage but instead I got my class 10 32 gigs sdhc sandisk completely corrupted after less then 2 years of use on my samsung galaxy S2.

I am using badblocks to see where the first badblocks start and then I will make partitions around that area if possible. this is my current, very very bad solution :/

  • could you elaborate on your answer? Based on a quick search, I guess "badblocks" is a Linux program? Does it do what the OP required?
    – MikeW
    Oct 27 '13 at 3:02

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.