Monthly Archives: November 2009

Recovering files using TestDisk

I recently had a hard disk go bad. It had a single NTFS partition where the partition was no longer recognized by Windows or Linux.

I managed to recover (I think) all of my files by reading the data off of the disk using TestDisk. It discovered my partition without issue, and the actual file recovery went relatively smoothly.

I believe the way TestDisk was primarily designed to work was by attempting to actually repair the partition. This should be fine if you’re working on a copy of the raw disk bits (you can probably use dd for Windows for this, or write a program that accesses ), but I’d generally be averse to making any further changes to a bad disk. I chose to recover my data just by copying the files directly out. You can do this as follows:

  • go to (your disk) > Intel > Analyse > (your dynamic partition)
  • highlight your partition
  • press P to list files
  • press H to hide deleted files
  • press C to copy the current directory (the directory from which you started TestDisk)

One thing to watch out for when using this approach is to first make sure you press H to hide deleted files. Otherwise, you end up recovering deleted files as well, and sometimes these deleted files (for whatever reason—probably because my data’s sufficiently corrupted) end up pointing back into the root of the file system, leading to cycles in the tree and thus an infinitely recursive file copying procedure.


A while back, I wrote about cooperative threading libraries for C++. Coroutines are a closely related concept—coroutines and cooperative threads can be expressed/implemented in terms of each other.

Conspicuously absent from that coverage is Boost.Coroutine, which I’ll discuss here. The problem with Boost.Coroutine is that it was incomplete, and—last I checked—far from complete. I had spent some time trying to work with the author through its non-starter issues, as I was looking forward to using it in conjunction with Boost.Asio (this was one of Boost.Coroutine’s primary objectives), but the author has not had the time to take his work to the Boost formal review stage.

Re-enabling desktop effects in Windows 7

Every once in a while, Windows 7’s Desktop Window Manager (DWM) spontaneously goes funky on me and loses its effects (transparency, blurring, shadows).

When this happens, you can get your effects back by going to Services and restarting the “Desktop Window Manager Session Manager” service, or by going to an Administrative command prompt and running:

net stop uxsms
net start uxsms

C++0x lambdas in GCC 4.5

Lambdas are coming in GCC 4.5. With this I’ve rid myself of the clamp hack. You can start using lambdas today by just grabbing a GCC snapshot:

svn co -q svn://
sudo aptitude build-dep gcc-4.4 # get prereqs
./configure --program-suffix=-4.5 --disable-libgcj \
sudo make install
# test it out
echo 'int main() { []{}; return 0; }' > /tmp/
g++-4.5 -std=gnu++0x -o /tmp/nop{,.cc}

Here’s a simple program from my C++ sandbox showing off just a few of C++0x’s slew of new features:

#include <functional>
#include <iostream>
#include <string>
#include <thread>
#include <vector>

using namespace std;
int main() {
  // strongly typed enums
  // can specify underlying type
  enum class msg_type : uint8_t { hello, world };
  // initializer lists for easy init
  // no more `>>` misparsing
  const vector<pair<int, string>> xs =
    {{1, "hello"}, {3, "world"}};
  // standard classes for concurrency
  vector<thread> ts;
  // type inference with repurposed `auto`
  // no need for `vector<string>::const_iterator`
  for (auto x = xs.begin(); x != xs.end(); ++x) {
    // new function class
    // could also use `auto` here
    // here's a lambda that captures x by value
    function<void()> f = [=]{
      // new chrono class
      cout << x->second << endl;
  for (auto t = ts.begin(); t != ts.end(); ++t) {
  return 0;

Compile it with:

g++-4.5 -std=gnu++0x -pthread -o c++0x{,.cc}

Other features are coming down the pipe as well. Wikipedia has good high-level overviews of these and more.