<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mnemonikk.org</title>
	<atom:link href="http://mnemonikk.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://mnemonikk.org</link>
	<description>My life with the machine</description>
	<lastBuildDate>Sun, 26 Apr 2009 13:23:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Recovering data from a broken NTFS hard drive</title>
		<link>http://mnemonikk.org/2009/04/26/recovering-data-from-a-broken-ntfs-hard-drive/</link>
		<comments>http://mnemonikk.org/2009/04/26/recovering-data-from-a-broken-ntfs-hard-drive/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 13:23:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[recovery]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://mnemonikk.org/?p=10</guid>
		<description><![CDATA[Today I want to tell you about my recent adventure in data recovery. A friend of mine had a broken USB disk that was no longer readable. The single 230 GB partition was formatted with NTFS and neither Windows nor Ubuntu (with the NTFS-3g driver, I assume) were willing to read it. This disk contained [...]]]></description>
			<content:encoded><![CDATA[<p>Today I want to tell you about my recent adventure in data recovery. A friend of mine had a broken USB disk that was no longer readable. The single 230 GB partition was formatted with NTFS and neither Windows nor Ubuntu (with the NTFS-3g driver, I assume) were willing to read it. This disk contained photos, audio files and videos, the mission was to at least restore the photos.</p>
<h2>Make a disk image</h2>
<p>The first step for a data recovery project should be to make an image of the drive or partition: when a drives starts to lose data because of physical errors on the disk these errors tend to spread, things are getting worse and you will not get any data out of anymore at some point. And every tool will encounter the same problems when trying to read defective sectors on disk, and it will not be possible to repair these. </p>
<p>By the way, if your data is really valuable you shouldn&#8217;t even try to recover it yourself, that is, if the drive shows signs of some physical damage. You should disconnect it as soon as possible and hand it to a professional data recovery company &#8211; if it is worth a few  hundred or thousand Euros. </p>
<p>The data I was working with, however, wasn&#8217;t business critical. So, after consulting $SEARCH_ENGINE, I did an image of the drive with dd_rescue &#8211; this works similar to a normal &#8220;dd&#8221; but handles I/O errors more gracefully. But here things started to get confusing: there are two programs for this purpose with an almost identical name:</p>
<ul>
<li>Kurt Garloff&#8217;s original dd_rescue tool uses the executable named &#8220;dd_rescue&#8221;, the Debian/Ubuntu package is named &#8220;ddrescue&#8221;.</li>
<li>Antonio Diaz Diaz new and improved GNU ddrescue provides an executable named &#8220;ddrescue&#8221;, the Debian/Ubuntu package carries the name &#8220;gddrescue&#8221;.</li>
</ul>
<p>The latter is the one to choose: you get much better progress information &#8211; copying hundreds of gigabytes takes quite some time, so you want to know what&#8217;s going on &#8211; and the capability to interrupt the process and continue where you left off with the help of a log file. After finding out about that the hard way I got my image with</p>
<blockquote><p>sudo ddrescue -r3 /dev/sdb1 hdimage logfile</p></blockquote>
<p>where &#8220;-r3&#8243; means: &#8220;in case of an error, retry 3 times&#8221; and /dev/sdb1 is the name of the partition of the USB disk, obviously.</p>
<p>Unfortunately, the resulting image still couldn&#8217;t be mounted. &#8220;ddrescue&#8221; only reported a few bad sectors on the disk, but it was obviously enough to make file access impossible. Another idea that I wasn&#8217;t able to pursue: it might have been possible to repair the NTFS filesystem with a virtualized windows instance running in VirtualBox &#8211; but VirtualBox only takes complete disks as images, not single partitions. If I had done an image of the complete disk instead, including the partition table, this might have worked out. I didn&#8217;t feel like copying the 230 GB over into a new image with a partition table and also didn&#8217;t have enough free disk space to do it.</p>
<h2>Recovery tools: file carvers</h2>
<p>The next step was trying to recover as much of the data as possible. I had successfully used a &#8220;file carver&#8221; before to recover images from my digital camera&#8217;s memory card after the FAT filesystem became corrupted. A file carver is a program that scans a raw binary stream for the headers of known file types, like that of JPEG images or MP3 audio files, and tries to extract the contents, completely ignoring the file system. The advantage is that it doesn&#8217;t matter how broken your filesystem is &#8211; the program doesn&#8217;t have to know anything about the filesystem&#8217;s structure. It can also recover deleted files. The disadvantage is that you lose all information that is stored in the filesystem, the file name and directory structure. It&#8217;s also prone to errors for fragmented file systems, which also means that you&#8217;re less likely to succeed when recovering large files.</p>
<p>I tried two tools from this category, &#8220;foremost&#8221; and &#8220;photorec&#8221;. &#8220;foremost&#8221; is a simple command line tool, you call it like this:</p>
<blockquote><p>foremost -i hdimage -o recovered -v</p></blockquote>
<p>and it will sort the files it can find by file type into sub folders of &#8220;recovered&#8221;.</p>
<p>Photorec has a curses interface. It also takes hints about the structure of the image, like presence of a partition table or filesystem type. It is part of the &#8220;testdisk&#8221; package. The command line invocation shows that this tool was ported from DOS:</p>
<blockquote><p>photorec /log /debug /d output-directory hdimage</p></blockquote>
<h2>Recovery tools: Sleuth Kit</h2>
<p>Researching further, I stumbled upon the Sleuth Kit and Autopsy. These are forensic analysis tools and therefore are designed to recover data that someone deliberately tried to hide or destroy. The Sleuth Kit is a suite of command line tools which Autopsy is a web frontend for. Autopsy comes with its own web server. I started it with these commands:</p>
<blockquote>
<pre class="wp-syntax">
mkdir my-autopsy-dir/
autopsy -d my-autopsy-dir/
firefox http://localhost:9999/autopsy
</pre>
</blockquote>
<p>Getting around the web interface can be a bit confusing: you have to create a &#8220;case&#8221; first, then add a host to investigate and finally a hd image to look at. Anyway, the time it took me to get used to autopsy wasn&#8217;t wasted because I now was able to see the complete contents of the original NTFS filesystem! I was able to look at the data, browse the filesystem, download single files and compute MD5 sums. However, autopsy offers no feature for copying whole directory trees. This is because it is intended for forensic analysis rather than data recovery. So you, the computer forensics expert, are supposed to look at every single file and make notes about it which in turn are then recorded in the &#8220;case&#8221;.</p>
<p>I wasn&#8217;t really interested in a forensic analysis of the contents of my friend&#8217;s drive so I took a closer look at the command line tools. The relevant commands from the Sleuth Kit are &#8220;fls&#8221; for listing files in an image and &#8220;icat&#8221; for getting at the contents. You use &#8220;fls&#8221; like this:</p>
<blockquote><p>fls -urp hdimage</p></blockquote>
<p>where -u means that I&#8217;m not interested in deleted files, -r that I want a recursive listing and -p that I need to have the full path for every file. The output looks something like this:</p>
<blockquote>
<pre>
d/d 180-144-8:  some-dir
d/d 5192-144-1: some-dir/some sub dir
r/r 5190-128-3: some-dir/some sub dir/some_file.exe
r/r 5188-128-3: some-dir/some sub dir/another_file.jpg
</pre>
</blockquote>
<p>The funny numbers in the second column are the &#8220;inode&#8221; of the file, which you need to feed into &#8220;icat&#8221; to get the contents. So how do you recover a whole directory tree with these tools? What I should have done is using a script like this one:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">IMAGE</span>=hdimage
fls <span style="color: #660033;">-urp</span> <span style="color: #007800;">$IMAGE</span> <span style="color: #000000; font-weight: bold;">|</span> 
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #7a0874; font-weight: bold;">type</span> inode name; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$type</span> <span style="color: #000000; font-weight: bold;">in</span>
        d<span style="color: #000000; font-weight: bold;">/</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$name</span>&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span>
        r<span style="color: #000000; font-weight: bold;">/</span>r<span style="color: #7a0874; font-weight: bold;">&#41;</span> icat <span style="color: #007800;">$IMAGE</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$inode</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/://g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$name</span>&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>But I was lazy and so I saved the file listing in a text file which I turned into a big shell script using Emacs&#8217; rectangle functions, regular expressions and keyboard macros. This wasn&#8217;t working so well: there were some funny characters in the file names I forgot to escape, like single quotes and backticks. So, as always, it turned out to be more work doing it &#8220;the easy way&#8221;. However, in the end I was able to completely recover the data from the partition.</p>
<h2>Analyzing the data</h2>
<p>Since now I got all the data back, having already tried other methods of recovery before, this can serve as a nice real world benchmark of the usefulness of the file carving tools I used.</p>
<p>Just counting how many files these tools think they&#8217;ve found doesn&#8217;t help us much, we also need to know if the recovered files were really complete and undamaged. I did a quick check with the files the Sleuth Kit recovered, and all files I checked seemed to be ok: the photos were fine and the videos and mp3s played without any hiccups. So, let&#8217;s assume that the data I got from the Sleuth Kit is really genuine. To find out about the identity of the recovered files, I computed the MD5 hash for all of them with this little script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> tool <span style="color: #000000; font-weight: bold;">in</span> foremost photorec sleuthkit; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #007800;">$tool</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-print0</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-0</span> md5sum <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> md5sums<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${tool}</span>.txt
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>And here&#8217;s a script I hacked together to do some analysis on these files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
md5s_by_ext<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">ext</span>=$<span style="color: #000000;">1</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
    <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-hi</span> <span style="color: #ff0000;">&quot;\.<span style="color: #007800;">${ext}</span><span style="color: #000099; font-weight: bold;">\$</span>&quot;</span> <span style="color: #ff0000;">&quot;$@&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $1 }'</span> 
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
unique_md5s_by_ext<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    md5s_by_ext <span style="color: #ff0000;">&quot;$@&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
unique_md5s<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;$@&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $1 }'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
clean_wc<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/ //g'</span> 
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
common_files<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">ext</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${ext}</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-ne</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s_by_ext <span style="color: #007800;">$ext</span> sleuthkit <span style="color: #000000; font-weight: bold;">|</span> clean_wc<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>
    <span style="color: #000000; font-weight: bold;">for</span> tools <span style="color: #000000; font-weight: bold;">in</span> photorec foremost <span style="color: #ff0000;">&quot;photorec foremost&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-ne</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s_by_ext <span style="color: #007800;">$ext</span> <span style="color: #007800;">$tools</span> <span style="color: #000000; font-weight: bold;">|</span> clean_wc<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> \
            $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">comm</span> <span style="color: #660033;">-12</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s             <span style="color: #007800;">$tools</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s_by_ext <span style="color: #007800;">$ext</span> sleuthkit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> clean_wc<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>\
            $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">comm</span> <span style="color: #660033;">-12</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s_by_ext <span style="color: #007800;">$ext</span> <span style="color: #007800;">$tools</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s_by_ext <span style="color: #007800;">$ext</span> sleuthkit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> clean_wc<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>
    <span style="color: #000000; font-weight: bold;">done</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
common_files_total<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;total<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>\
         $<span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s sleuthkit         <span style="color: #000000; font-weight: bold;">|</span> clean_wc<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>\
         $<span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s photorec          <span style="color: #000000; font-weight: bold;">|</span> clean_wc<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>\
         $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">comm</span> <span style="color: #660033;">-12</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s photorec<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s sleuthkit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> clean_wc<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>\
         $<span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s foremost          <span style="color: #000000; font-weight: bold;">|</span> clean_wc<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>\
         $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">comm</span> <span style="color: #660033;">-12</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s foremost<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s sleuthkit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> clean_wc<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>\
         $<span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s photorec foremost <span style="color: #000000; font-weight: bold;">|</span> clean_wc<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>\
         $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">comm</span> <span style="color: #660033;">-12</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s foremost photorec<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>unique_md5s sleuthkit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> clean_wc<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>    
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>sleuthkit<span style="color: #000099; font-weight: bold;">\t</span>photorec<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>foremost<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>photorec+foremost&quot;</span>
&nbsp;
common_files_total
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> jpg gif mp3 avi mpg <span style="color: #c20cb9; font-weight: bold;">zip</span> rar exe cab dll txt htm rtf pdf doc xls; <span style="color: #000000; font-weight: bold;">do</span>
    common_files <span style="color: #007800;">$i</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>And here are the results as a really ugly table:</p>
<table border="1" cellpadding="2" style="font-size:90%">
<tr>
<th></th>
<th align="left">sleuthkit</th>
<th align="left" colspan="3">photorec</th>
<th align="left" colspan="3">foremost</th>
<th align="left" colspan="3">photorec+foremost</th>
</tr>
<tr>
<th valign="top"></th>
<th valign="top"></th>
<th valign="top">found</th>
<th valign="top">matching</th>
<th valign="top">matching<br />+ext</th>
<th valign="top">found</th>
<th valign="top">matching</th>
<th valign="top">matching<br />+ext</th>
<th valign="top">found</th>
<th valign="top">matching</th>
<th valign="top">matching<br />+ext</th>
</tr>
<tr>
<td>total</td>
<td>4391</td>
<td>6600</td>
<td>3669</td>
<td></td>
<td>1210</td>
<td>771</td>
<td></td>
<td>6960</td>
<td>3718</td>
<td></td>
</tr>
<tr>
<td>jpg</td>
<td>831</td>
<td>768</td>
<td>711</td>
<td>711</td>
<td>853</td>
<td>747</td>
<td>747</td>
<td>901</td>
<td>755</td>
<td>755</td>
</tr>
<tr>
<td>gif</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>46</td>
<td>1</td>
<td>1</td>
<td>47</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>mp3</td>
<td>3218</td>
<td>4697</td>
<td>2851</td>
<td>2851</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>4697</td>
<td>2851</td>
<td>2851</td>
</tr>
<tr>
<td>avi</td>
<td>128</td>
<td>5</td>
<td>0</td>
<td>0</td>
<td>5</td>
<td>0</td>
<td>0</td>
<td>10</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>mpg</td>
<td>1</td>
<td>207</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>208</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>zip</td>
<td>5</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>13</td>
<td>0</td>
<td>0</td>
<td>16</td>
<td>3</td>
<td>3</td>
</tr>
<tr>
<td>rar</td>
<td>25</td>
<td>29</td>
<td>24</td>
<td>24</td>
<td>30</td>
<td>8</td>
<td>8</td>
<td>50</td>
<td>24</td>
<td>24</td>
</tr>
<tr>
<td>exe</td>
<td>37</td>
<td>60</td>
<td>4</td>
<td>4</td>
<td>78</td>
<td>6</td>
<td>6</td>
<td>83</td>
<td>6</td>
<td>6</td>
</tr>
<tr>
<td>cab</td>
<td>0</td>
<td>3</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>3</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>dll</td>
<td>10</td>
<td>69</td>
<td>6</td>
<td>6</td>
<td>71</td>
<td>7</td>
<td>7</td>
<td>80</td>
<td>8</td>
<td>8</td>
</tr>
<tr>
<td>txt</td>
<td>12</td>
<td>699</td>
<td>4</td>
<td>4</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>700</td>
<td>4</td>
<td>4</td>
</tr>
<tr>
<td>htm</td>
<td>6</td>
<td>0</td>
<td>2</td>
<td>0</td>
<td>3</td>
<td>1</td>
<td>1</td>
<td>3</td>
<td>2</td>
<td>1</td>
</tr>
<tr>
<td>rtf</td>
<td>1</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>2</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>pdf</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>doc</td>
<td>7</td>
<td>15</td>
<td>6</td>
<td>5</td>
<td>16</td>
<td>0</td>
<td>0</td>
<td>31</td>
<td>6</td>
<td>5</td>
</tr>
<tr>
<td>xls</td>
<td>0</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>2</td>
<td>0</td>
<td>0</td>
</tr>
</table>
<p>This table needs a bit of an explanation: </p>
<ul>
<li>&#8220;found&#8221; means the number of files the tool extracted from the image</li>
<li>&#8220;matching&#8221; means the number of files the tool found that are identical with files recovered with the sleuth kit</li>
<li>&#8220;matching+ext&#8221; means that we&#8217;ve also got the extension right</li>
</ul>
<p>Foremost recovered almost 90% of the images, Photorec following close behind 85%, and it found only 8 photos that foremost couldn&#8217;t identify. Looking at other data types, Photorec is clearly superior: it found 24 of the 25 RAR files present in the image, foremost only got 8 of them right. And only photorec was able to recover any mp3s: it found 89% of them, but we also got quite some false positives here. Neither of the tools was able to recover any movies &#8211; possibly because they were fragmented on disk. </p>
<h2>Conclusion</h2>
<p>So here comes the take home message: </p>
<ul>
<li>Use GNU ddrescue to make a hard drive image first.</li>
<li>If your filesystem is not mountable, try the sleuth kit &#8211; you might get all your data back including the file names and directory structure.</li>
<li>If the sleuth kit fails and you&#8217;re trying to recover some photos, &#8220;foremost&#8221; might help you.</li>
<li>If the sleuth kit fails and you&#8217;re looking for something other than images, give &#8220;photorec&#8221; a shot. Anyway, it&#8217;s less likely in this case that you&#8217;ll get your data back.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mnemonikk.org/2009/04/26/recovering-data-from-a-broken-ntfs-hard-drive/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tiling window managers talk</title>
		<link>http://mnemonikk.org/2009/03/31/tiling-window-managers-talk/</link>
		<comments>http://mnemonikk.org/2009/03/31/tiling-window-managers-talk/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 22:48:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mnemonikk.org/?p=27</guid>
		<description><![CDATA[I just finished the english translation of the speaker notes for my talk about tiling window managers I gave at the C-Base for the Ubuntu Berlin user group last thursday. Here are the original notes in german and here&#8217;s the english translation.
As for my last few talks, I took my notes down with org-mode, and [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished the english translation of the speaker notes for my talk about tiling window managers I gave at the <a href="http://c-base.org/">C-Base</a> for the <a href="http://www.ubuntu-berlin.de/node/160">Ubuntu Berlin</a> user group last thursday. Here are the <a href="http://mnemonikk.org/talks/tiling-wm.de.html">original notes in german</a> and here&#8217;s the <a href="http://mnemonikk.org/talks/tiling-wm.en.html">english translation</a>.<br />
As for my last few talks, I took my notes down with org-mode, and I&#8217;m deeply impressed with how easy it is to get a gook-looking HTML page out of it. And the javascript-interface just rocks!<br />
For those who couldn&#8217;t attend I will update my notes with some screenshots of the window managers I presented when I find the time do so, so watch this space for updates. </p>
]]></content:encoded>
			<wfw:commentRss>http://mnemonikk.org/2009/03/31/tiling-window-managers-talk/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Finally putting my personal configuration files under version control</title>
		<link>http://mnemonikk.org/2009/03/23/finally-putting-my-personal-configuration-files-under-version-control/</link>
		<comments>http://mnemonikk.org/2009/03/23/finally-putting-my-personal-configuration-files-under-version-control/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 11:36:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[administration]]></category>

		<guid isPermaLink="false">http://mnemonikk.org/?p=22</guid>
		<description><![CDATA[Version controlling your config files, it seems to be like flossing: everyone knows it&#8217;s a good idea and they should be doing it, but never get around to do so. I finally got around to put my files under version control &#8211; again. I used to use darcs, but I ran into the dreaded exponential [...]]]></description>
			<content:encoded><![CDATA[<p>Version controlling your config files, it seems to be like flossing: everyone knows it&#8217;s a good idea and they should be doing it, but never get around to do so. I finally got around to put my files under version control &#8211; again. I used to use darcs, but I ran into the dreaded exponential merge issues, so this time I&#8217;ll try git for this. Mercurial would have been an even nicer choice, but git seems to have a bigger mind share these days and is a bit more difficult to learn, so I&#8217;d rather learn some git.</p>
<p>While having your personal config files under version control is a good idea, making your home directory version controlled isn&#8217;t &#8211; it&#8217;s not easy to see what files are under version control, and some operations just take ages because they have to crawl through your all your personal files. So I created a git controlled directory, named &#8220;.vc&#8221; and did symbolic links from there to the config files locations. As I add more files to version control, this will get tedious to do by hand, so I wrote a little script to help me that I want to share with you: I just called it &#8220;setup&#8221; and put it into .vc as well:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> $<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">VC_DIR</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> . \<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #660033;">-path</span> \<span style="color: #000000; font-weight: bold;">*/</span>.git \<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #660033;">-prune</span> <span style="color: #660033;">-o</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-not</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(basename $0)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> \
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> path; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;X<span style="color: #007800;">$(basename &quot;$path&quot;)</span>&quot;</span> = <span style="color: #ff0000;">&quot;X.git&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #7a0874; font-weight: bold;">continue</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #007800;">destination</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/<span style="color: #007800;">$path</span>&quot;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$destination</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-L</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$destination</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Symlink for <span style="color: #007800;">$path</span> exists, skipping.&quot;</span>
                <span style="color: #7a0874; font-weight: bold;">continue</span>
            <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;backing up existing <span style="color: #007800;">$destination</span> to <span style="color: #007800;">${destination}</span>.vc_backup&quot;</span>
                <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$destination</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${destination}</span>.vc_backup&quot;</span>
            <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;doing symlink for <span style="color: #007800;">$path</span>&quot;</span>
        <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VC_DIR</span>/<span style="color: #007800;">$path</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/<span style="color: #007800;">$path</span>&quot;</span>
    <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mnemonikk.org/2009/03/23/finally-putting-my-personal-configuration-files-under-version-control/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Showing the current directory in Emacs&#8217; mode line</title>
		<link>http://mnemonikk.org/2008/05/23/showing-the-current-directory-in-emacs-mode-line/</link>
		<comments>http://mnemonikk.org/2008/05/23/showing-the-current-directory-in-emacs-mode-line/#comments</comments>
		<pubDate>Fri, 23 May 2008 13:28:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[emacs]]></category>

		<guid isPermaLink="false">http://mnemonikk.org/?p=7</guid>
		<description><![CDATA[Today I got tired of always looking up, where all these little files named &#8220;_show.rhtml&#8221;, &#8220;_list.rhtml&#8221; and their ilk are living, and patched the emacs mode line to include the last element of the current buffer&#8217;s directory. http://www.emacswiki.org/cgi-bin/wiki/ModeLineDirtrack describes something very similar, but it repeats the whole mode line definition of mode-line-format, which might break [...]]]></description>
			<content:encoded><![CDATA[<p>Today I got tired of always looking up, where all these little files named &#8220;_show.rhtml&#8221;, &#8220;_list.rhtml&#8221; and their ilk are living, and patched the emacs mode line to include the last element of the current buffer&#8217;s directory. <a title="This page on EmacsWiki" href="http://www.emacswiki.org/cgi-bin/wiki/ModeLineDirtrack">http://www.emacswiki.org/cgi-bin/wiki/ModeLineDirtrack</a> describes something very similar, but it repeats the whole mode line definition of mode-line-format, which might break with the next version of Emacs. It&#8217;s much cleaner to add to a variable that is used in the mode line:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>setq-default mode-line-buffer-identification
              <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span>
               '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #b1b100;">eval</span> <span style="color: #66cc66;">&#40;</span>replace-regexp-in-string <span style="color: #ff0000;">&quot;^.*/<span style="color: #000099; font-weight: bold;">\\</span>(.*<span style="color: #000099; font-weight: bold;">\\</span>)/&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>1/&quot;</span> default-directory<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
               mode-line-buffer-identification<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mnemonikk.org/2008/05/23/showing-the-current-directory-in-emacs-mode-line/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Live syntax-checking JavaScript with Emacs</title>
		<link>http://mnemonikk.org/2008/05/06/live-syntax-checking-javascript-with-emacs/</link>
		<comments>http://mnemonikk.org/2008/05/06/live-syntax-checking-javascript-with-emacs/#comments</comments>
		<pubDate>Tue, 06 May 2008 08:00:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[emacs]]></category>
		<category><![CDATA[flymake]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://mnemonikk.org/?p=6</guid>
		<description><![CDATA[There are quite some options for doing live syntax checks from within Emacs. A good one is using Steve Yegge&#8217;s relatively new js2-mode for javascript editing which has a javascript parser built in. But that is not what this blog post will be about.
The other option is to use flymake with some command line javascript [...]]]></description>
			<content:encoded><![CDATA[<p>There are quite some options for doing live syntax checks from within Emacs. A good one is using Steve Yegge&#8217;s relatively new <a href="http://code.google.com/p/js2-mode/">js2-mode</a> for javascript editing which has a javascript parser built in. But that is not what this blog post will be about.</p>
<p>The other option is to use flymake with some command line javascript syntax checker. Two possible syntax checkers are Mozilla&#8217;s stand alone SpiderMonkey interpreter &#8220;smjs&#8221; with the &#8220;-s&#8221; (strict) option and Douglas Crockford&#8217;s JsLint running under Rhino. There are reasons to use each of them:</p>
<ul>
<li>SpiderMonkey is the javascript engine currently used in Firefox. So, if it can not parse your javascript, neither can Firefox.</li>
<li>JsLint does more than just syntax checking, it also checks for bad style and possible programming errors, like missing semicolons and braces, assignment in an if conditions. This can be good, but it&#8217;s also a hinderance when you&#8217;re working on code that was not written to make JsLint happy and you don&#8217;t want to refactor it. Furthermore, the style enforced by JsLint might differ from your programming style, as it says on the web page: &#8220;Warning! JSLint will hurt your feelings.&#8221;<br />
I, for instance, like to leave out the braces after an if statement if the executed block is itself just one statement &#8211; it takes up less space, and if I ever want to add to this block Emacs will indent the code correctly, so I won&#8217;t forget to add the braces afterwards. However, maybe JsLint is right, because you sometimes have to collaborate with people that don&#8217;t use Emacs &#8211; maybe I should do them the favor.</li>
</ul>
<h3>Setting up SpiderMonkey</h3>
<p>On an Ubuntu system the stand alone SpiderMonkey interpreter is provided by the package &#8220;spidermonkey-bin&#8221;. SpiderMonkey has the problem that it is just the javascript engine, but does not include the DOM, and there is no global window object. So if your javascript code does more than just defining functions you need to do some mocking. This is fortunately very easy to do.</p>
<p>The code I wanted to check also installs event handlers with prototype&#8217;s Event.observe method, so I had to mock that, too:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// fake the global window object</span>
<span style="color: #003366; font-weight: bold;">var</span> window <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> Event <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> observe<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You will most probably need to extend this for your code. Now you can do a syntax check from the command line like this:</p>
<pre>smjs -s -e "(load '/path/to/mock.js')" file-to-check.js</pre>
<h3>Setting up JsLint</h3>
<p>JsLint is itself written in javascript. To use it from the command line you need the javascript interpreter Rhino. It is, not surprisingly, provided on Ubuntu by the package &#8220;rhino&#8221;. JsLint for rhino is avaiable <a href="http://www.jslint.com/rhino/index.html">here</a>. To check a javascript file with rhino, just call it like this:</p>
<pre>rhino /path/to/jslint.js file-to-check.js</pre>
<h3>Integrating both into Emacs</h3>
<p>The following code allows you to do live syntax checking from within Emacs with either SpiderMonkey or JsLint. You can switch between them using &#8220;C-c t&#8221;. The code uses a circular list structure to keep the list of available methods, just for the heck of it.</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> flymake-js-method 'spidermonkey<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> flymake-js-toggle-method <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>interactive<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>methods '#<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">=</span><span style="color: #66cc66;">&#40;</span>spidermonkey jslint <span style="color: #66cc66;">.</span> #<span style="color: #cc66cc;">1</span>#<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> flymake-js-method <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cadr</span> <span style="color: #66cc66;">&#40;</span>memq flymake-js-method methods<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>flymake-start-syntax-check<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> flymake-js-init <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span>* <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>temp-file <span style="color: #66cc66;">&#40;</span>flymake-init-create-temp-buffer-copy
		     'flymake-create-temp-inplace<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
         <span style="color: #66cc66;">&#40;</span>local-file <span style="color: #66cc66;">&#40;</span>file-relative-<span style="color: #b1b100;">name</span>
		      temp-file
		      <span style="color: #66cc66;">&#40;</span>file-name-directory buffer-file-<span style="color: #b1b100;">name</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq</span> flymake-js-method 'spidermonkey<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #ff0000;">&quot;smjs&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #ff0000;">&quot;-s&quot;</span> <span style="color: #ff0000;">&quot;-e&quot;</span> <span style="color: #66cc66;">&#40;</span>format <span style="color: #ff0000;">&quot;load('%s')&quot;</span> <span style="color: #66cc66;">&#40;</span>expand-file-<span style="color: #b1b100;">name</span> <span style="color: #ff0000;">&quot;/path/to/mock.js&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> local-file<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #ff0000;">&quot;rhino&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>expand-file-<span style="color: #b1b100;">name</span> <span style="color: #ff0000;">&quot;/path/to/jslint.js&quot;</span><span style="color: #66cc66;">&#41;</span> local-file<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>eval-after-load <span style="color: #ff0000;">&quot;flymake&quot;</span>
  '<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">progn</span>
     <span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'flymake-allowed-file-name-masks
                  '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>.js<span style="color: #000099; font-weight: bold;">\\</span>(on<span style="color: #000099; font-weight: bold;">\\</span>)?$&quot;</span> flymake-js-init flymake-simple-cleanup flymake-get-real-file-<span style="color: #b1b100;">name</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'flymake-err-line-patterns
                  '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;^<span style="color: #000099; font-weight: bold;">\\</span>(.+<span style="color: #000099; font-weight: bold;">\\</span>)<span style="color: #000099; font-weight: bold;">\:</span><span style="color: #000099; font-weight: bold;">\\</span>([0-9]+<span style="color: #000099; font-weight: bold;">\\</span>)<span style="color: #000099; font-weight: bold;">\:</span> <span style="color: #000099; font-weight: bold;">\\</span>(SyntaxError<span style="color: #000099; font-weight: bold;">\:</span>.+<span style="color: #000099; font-weight: bold;">\\</span>)<span style="color: #000099; font-weight: bold;">\:</span>$&quot;</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #b1b100;">nil</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'flymake-err-line-patterns
                  '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;^<span style="color: #000099; font-weight: bold;">\\</span>(.+<span style="color: #000099; font-weight: bold;">\\</span>)<span style="color: #000099; font-weight: bold;">\:</span><span style="color: #000099; font-weight: bold;">\\</span>([0-9]+<span style="color: #000099; font-weight: bold;">\\</span>)<span style="color: #000099; font-weight: bold;">\:</span> <span style="color: #000099; font-weight: bold;">\\</span>(strict warning: trailing comma.+<span style="color: #000099; font-weight: bold;">\\</span>)<span style="color: #000099; font-weight: bold;">\:</span>$&quot;</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #b1b100;">nil</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'flymake-err-line-patterns
                   '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;^Lint at line <span style="color: #000099; font-weight: bold;">\\</span>([[:digit:]]+<span style="color: #000099; font-weight: bold;">\\</span>) character <span style="color: #000099; font-weight: bold;">\\</span>([[:digit:]]+<span style="color: #000099; font-weight: bold;">\\</span>): <span style="color: #000099; font-weight: bold;">\\</span>(.+<span style="color: #000099; font-weight: bold;">\\</span>)$&quot;</span> <span style="color: #b1b100;">nil</span> <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> my-js-setup-flymake <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>flymake-mode <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>local-set-key <span style="color: #66cc66;">&#40;</span>kbd <span style="color: #ff0000;">&quot;C-c n&quot;</span><span style="color: #66cc66;">&#41;</span> 'flymake-goto-next-<span style="color: #b1b100;">error</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>local-set-key <span style="color: #66cc66;">&#40;</span>kbd <span style="color: #ff0000;">&quot;C-c p&quot;</span><span style="color: #66cc66;">&#41;</span> 'flymake-goto-prev-<span style="color: #b1b100;">error</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>local-set-key <span style="color: #66cc66;">&#40;</span>kbd <span style="color: #ff0000;">&quot;C-c t&quot;</span><span style="color: #66cc66;">&#41;</span> 'flymake-js-toggle-method<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>add-hook 'javascript-mode-hook 'my-js-setup-flymake<span style="color: #66cc66;">&#41;</span></pre></div></div>

<h3>The result</h3>
<p>And here is what it looks like with SpiderMonkey:</p>
<p><img src="http://mnemonikk.org/images/emacs-flymake-spidermonkey.png" alt="Emacs with flymake running spidermonkey" width="598" height="135" /></p>
<p>And here an example of some code and what opinion JsLint has about it:</p>
<p><img src="http://mnemonikk.org/images/emacs-flymake-jslint.png" alt="Emacs with flymake running jslint" width="474" height="182" /></p>
]]></content:encoded>
			<wfw:commentRss>http://mnemonikk.org/2008/05/06/live-syntax-checking-javascript-with-emacs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Varnish, a faster Squid</title>
		<link>http://mnemonikk.org/2008/05/05/varnish-a-faster-squid/</link>
		<comments>http://mnemonikk.org/2008/05/05/varnish-a-faster-squid/#comments</comments>
		<pubDate>Mon, 05 May 2008 15:09:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://mnemonikk.org/?p=3</guid>
		<description><![CDATA[I just stumbled across Varnish, an HTTP cache and modern alternative to Squid. The config file is compiled into a shared library at startup, logging is done in-memory and paging out unused pages to disk is left to the OS. With squid, an unused cached page is explicitly written to disk by the proxy, while [...]]]></description>
			<content:encoded><![CDATA[<p>I just stumbled across <a title="The Varnish HTTP Cache" href="http://varnish.projects.linpro.no/">Varnish</a>, an HTTP cache and modern alternative to Squid. The config file is compiled into a shared library at startup, logging is done in-memory and paging out unused pages to disk is left to the OS. With squid, an unused cached page is explicitly written to disk by the proxy, while the OS most probably already swapped it out anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://mnemonikk.org/2008/05/05/varnish-a-faster-squid/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
