Easiest way to simulate no free disk space situation?

Ilya Birman picture Ilya Birman · Jan 11, 2010 · Viewed 8.6k times · Source

I need to test my web app in a scenario where there’s no disk space remaining, i.e. I cannot write any more files. But I don’t want to fill my hard drive with junk just to make sure there’s really no space left. What I want is to simulate this situation withing a particular process (actually, a PHP app).

Indeed, temporarily prohibiting disk writes to a process must be enough.

What’s the easiest way to do this? I’m using Mac OS X 10.6.2 with built-in Apache/PHP bundle. Thanks.

Edit: Disk free space check is not going to be reliable since it can change any moment. Many pages are being served simultaneously. There can be enough free space when checking, but none by the moment you actually write something. Also, checking for disk free space will require changing the code everywhere I write a file, which is not what I want :-) Finally, this solution is exactly the opposite of what I’m trying to test: how my app will behave when it cannot write any more.

Answer

Hamish Grubijan picture Hamish Grubijan · Jan 11, 2010

I bet you could also create your own .dmg file with file system of size ... say 2Mb and write to it. If this works, then it is super-easy for testing - you just mount it and switch the path for testing. If the dmg is small enough, you could probably even upload it to the source control.