<?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>Mac OS X Internals &#187; Computer Science</title>
	<atom:link href="http://osxbook.com/blog/category/computer-science/feed/" rel="self" type="application/rss+xml" />
	<link>http://osxbook.com/blog</link>
	<description>A Systems Approach</description>
	<lastBuildDate>Fri, 30 Sep 2011 07:20:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>fileXray</title>
		<link>http://osxbook.com/blog/2010/11/01/filexray/</link>
		<comments>http://osxbook.com/blog/2010/11/01/filexray/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 18:19:15 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[fileXray]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://www.osxbook.com/blog/?p=583</guid>
		<description><![CDATA[Does the idea of wielding power&#8212;a lot of power&#8212;intrigue you? Check out fileXray. Start with the ebook. If you are one of the target audiences, it will be worth your time.]]></description>
			<content:encoded><![CDATA[<p>Does the idea of wielding power&mdash;<em>a lot of power</em>&mdash;intrigue you?  Check out <a href="http://filexray.com" title="fileXray Web Site">fileXray</a>.</p>
<p>Start with the ebook. If you are one of the target audiences, it will be worth your time.</p>
]]></content:encoded>
			<wfw:commentRss>http://osxbook.com/blog/2010/11/01/filexray/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A TPM for Everyone</title>
		<link>http://osxbook.com/blog/2009/03/08/a-tpm-for-everyone/</link>
		<comments>http://osxbook.com/blog/2009/03/08/a-tpm-for-everyone/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 06:23:33 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://www.osxbook.com/blog/?p=445</guid>
		<description><![CDATA[Suppose you have a Macintosh without a TPM. This, of course, is highly likely because only the first few x86-based Macintosh models had TPMs. Now suppose you really want to experiment with Trusted Computing or features of the TPM in general. Your needs could be development-related or they could be purely academic. Well, you can [...]]]></description>
			<content:encoded><![CDATA[<p>Suppose you have a Macintosh without a TPM. This, of course, is highly likely because only the first few x86-based Macintosh models had TPMs.  Now suppose you really want to experiment with Trusted Computing or features of the TPM in general. Your needs could be development-related or they could be purely academic. Well, you can do the <a href="http://osxbook.com/software/tpm-emulator/" title="A TPM for Everyone">next best thing to having a real TPM&#8230;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://osxbook.com/blog/2009/03/08/a-tpm-for-everyone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XBinary: Extended Binary Format Support for Mac OS X</title>
		<link>http://osxbook.com/blog/2009/01/20/xbinary-extended-binary-format-support-for-mac-os-x/</link>
		<comments>http://osxbook.com/blog/2009/01/20/xbinary-extended-binary-format-support-for-mac-os-x/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 06:17:51 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://www.osxbook.com/blog/?p=377</guid>
		<description><![CDATA[XBinary is software that lets you add kernel-level support for executing arbitrary binary formats on Mac OS X. To read more about it and to download it, visit the XBinary page.]]></description>
			<content:encoded><![CDATA[<p>XBinary is software that lets you add kernel-level support for executing arbitrary binary formats on Mac OS X. To read more about it and to download it, visit the <a href="http://osxbook.com/software/xbinary/" title="XBinary">XBinary page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://osxbook.com/blog/2009/01/20/xbinary-extended-binary-format-support-for-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AncientFS on Linux and FreeBSD</title>
		<link>http://osxbook.com/blog/2008/12/22/ancientfs-on-linux-and-freebsd/</link>
		<comments>http://osxbook.com/blog/2008/12/22/ancientfs-on-linux-and-freebsd/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 12:41:37 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://www.osxbook.com/blog/?p=363</guid>
		<description><![CDATA[By popular demand, I&#8217;ve &#34;ported&#34; AncientFS to Linux and FreeBSD. It was reasonably straightforward. Largely on purpose, AncientFS depends on the cross-platform interfaces of MacFUSE for the most part. Most people don&#8217;t realize that MacFUSE is much more than a &#34;Mac OS X implementation of the FUSE API.&#34; Of course, the name &#34;MacFUSE&#34; doesn&#8217;t help [...]]]></description>
			<content:encoded><![CDATA[<p>By popular demand, I&#8217;ve &quot;ported&quot; <a href="http://osxbook.com/software/ancientfs/" title="AncientFS">AncientFS</a> to Linux and FreeBSD. It was reasonably straightforward. Largely on purpose, AncientFS depends on the cross-platform interfaces of MacFUSE for the most part.</p>
<div style="background-color: #EAEAF4;">
<p>
Most people don&#8217;t realize that MacFUSE is much more than a &quot;Mac OS X implementation of the FUSE API.&quot; Of course, the name &quot;Mac<strong>FUSE</strong>&quot; doesn&#8217;t help much in that regard.
</p>
</div>
<p>You should now be able to build the AncientFS source tree on Mac OS X, Linux, and FreeBSD. You must have the FUSE implementation for your platform installed to build and use AncientFS. Then, it should take a single <code>make</code> command to build.</p>
<p><code></p>
<pre style="font-size: 85%;">
$ <strong>svn co http://macfuse.googlecode.com/svn/trunk/filesystems/unixfs</strong>
$ <strong>cd unixfs/ancientfs</strong>
$ <strong>make</strong> # GNU make required. Use gmake on FreeBSD.
...
</pre>
<p></code></p>
<p>If it doesn&#8217;t build out-of-the-box on your system, you might want to tweak platform-specific settings in <code>unixfs/ancientfs/Makefile</code> first. The default settings assume that <code>fuse</code> is installed under <code>/usr</code> on Linux and under <code>/usr/local</code> on FreeBSD.</p>
<p>Because <code>libfuse</code> wants to use <code>sem_init()</code>, you will need to ensure on FreeBSD that the POSIX semaphore implementation is either statically compiled into the kernel (<em>not</em> the default on recent FreeBSD systems) or the <code>sem</code> kernel module is loaded. See <code>sem(4)</code> for details.</p>
<p>I&#8217;m traveling and don&#8217;t have good/much access to Linux or FreeBSD machines. Therefore, I haven&#8217;t been able to test this much. I do know that it builds and mounts some things on at least Linux 2.6.18 (Ubuntu) and FreeBSD 7.1-BETA2.</p>
]]></content:encoded>
			<wfw:commentRss>http://osxbook.com/blog/2008/12/22/ancientfs-on-linux-and-freebsd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extended Notes on AncientFS</title>
		<link>http://osxbook.com/blog/2008/12/17/extended-notes-on-ancientfs/</link>
		<comments>http://osxbook.com/blog/2008/12/17/extended-notes-on-ancientfs/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 12:17:01 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MacFUSE]]></category>
		<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://www.osxbook.com/blog/?p=269</guid>
		<description><![CDATA[Here are some extended notes on understanding, compiling, and using AncientFS, the file system I talked about in the previous blog post.]]></description>
			<content:encoded><![CDATA[<p>Here are <a href="http://osxbook.com/software/ancientfs/" title="AncientFS: Ancient Unix File Systems on Mac OS X">some extended notes</a> on understanding, compiling, and using AncientFS, the file system I talked about in the <a href="http://www.osxbook.com/blog/2008/12/16/more-user-space-file-system-goodies/" title="More User-Space File System Goodies">previous blog post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://osxbook.com/blog/2008/12/17/extended-notes-on-ancientfs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More User-Space File System Goodies</title>
		<link>http://osxbook.com/blog/2008/12/16/more-user-space-file-system-goodies/</link>
		<comments>http://osxbook.com/blog/2008/12/16/more-user-space-file-system-goodies/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 20:46:09 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MacFUSE]]></category>
		<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://www.osxbook.com/blog/?p=284</guid>
		<description><![CDATA[There has been much buzz about new features and functionality in MacFUSE 2.0. Besides the MacFUSE 2.0 release, there are still more new and interesting things to be discussed in the realm of user-space file systems. As I described and briefly demonstrated during my recent talk at the Googleplex, I wrote several new user-space file [...]]]></description>
			<content:encoded><![CDATA[<p>There has been much buzz about <a href="http://code.google.com/p/macfuse/wiki/CHANGELOG" title="MacFUSE 2.0 Changes">new features and functionality</a> in MacFUSE 2.0. Besides the MacFUSE 2.0 release, there are still more new and interesting things to be discussed in the realm of user-space file systems. As I described and briefly demonstrated during my recent talk at the Googleplex, I wrote several new user-space file systems to &quot;celebrate&quot; two years of MacFUSE.</p>
<p>Now that the talk&#8217;s video is available. I&#8217;ve written some notes on the new file systems themselves. There is a lot of new information <em>and</em> new code for those interested in file systems, Mac OS X, and operating systems in general. Much of it is academically and practically useful, and some could have significant potential down the road. You could also think of it as a new year gift to the Mac OS X and open-source communities.</p>
<p>This is a meta note on how you can go about discovering and understanding the <em>what</em>, <em>how</em>, and <em>why</em> of everything I&#8217;m talking about.</p>
<h3>1. MacFUSE State of the Union Talk (2008) Video</h3>
<p>If you were not at the talk, <a href="http://www.youtube.com/watch?v=cY8lBOSO3ak" title="MacFUSE State of the Union Talk (2008) Video">watching the video</a> would provide useful context and should help greatly in understanding what follows.</p>
<h3>2. AncientFS</h3>
<p>Next, you could look at AncientFS, which I introduced, among other things, during the talk. AncientFS lets you mount ancient (and in some cases, current-day) &quot;data containers&quot; as regular volumes on Mac OS X. It supports the following formats.</p>
<ul style="list-style: square;">
<li><strong>v1tap</strong>&mdash;DECtape <code>tap</code> tape archive; UNIX V1</li>
<li><strong>v2tap</strong>&mdash;DECtape <code>tap</code> tape archive; UNIX V2</li>
<li><strong>v3tap</strong>&mdash;DECtape <code>tap</code> tape archive; UNIX V3</li>
<li><strong>ntap</strong>&mdash;DECtape/magtape <code>tap</code> tape archive; 1970 epoch</li>
<li><strong>tp</strong>&mdash;DECtape/magtape <code>tp</code> tape archive</li>
<li><strong>itp</strong>&mdash;UNIX <code>itp</code> tape archive</li>
<li><strong>dtp</strong>&mdash;UNIX <code>dtp</code> tape archive</li>
<li><strong>dump</strong>&mdash;Incremental file system dump (512-byte blocks, V7/bsd)</li>
<li><strong>dump1kI</strong>&mdash;Incremental file system dump (1024-byte blocks, V7/bsd)</li>
<li><strong>dump-vn</strong>&mdash;Incremental file system dump (512-byte blocks, bsd-vn)</li>
<li><strong>dump1k-vn</strong>&mdash;Incremental file system dump (1024-byte blocks, bsd-vn)</li>
<li><strong>v1ar</strong>&mdash;Very old (<code>0177555</code>) archive (<code>.a</code>) from First Edition UNIX</li>
<li><strong>v2ar</strong>&mdash;Very old (<code>0177555</code>) archive (<code>.a</code>) from Second Edition UNIX</li>
<li><strong>v3ar</strong>&mdash;Very old (<code>0177555</code>) archive (<code>.a</code>) from Third Edition UNIX</li>
<li><strong>ar</strong>&mdash;Current (<code>!&lt;arch&gt;\n</code>), old (<code>0177545</code>), or very old (<code>0177555</code>) archive (<code>.a</code>); use (v1|v2|v3)ar for UNIX V1/V2/V3 archives</li>
<li><strong>bcpio</strong>&mdash;Binary cpio archive (old); may be byte-swapped</li>
<li><strong>cpio_odc</strong>&mdash;ASCII (odc) cpio archive</li>
<li><strong>cpio_newc</strong>&mdash;New ASCII (newc) cpio archive</li>
<li><strong>cpio_newcrc</strong>&mdash;New ASCII (newc) cpio archive with checksum</li>
<li><strong>tar</strong>&mdash;ustar, pre-POSIX ustar, or V7 tar archive</li>
<li><strong>v1</strong>&mdash;First Edition UNIX file system</li>
<li><strong>v2</strong>&mdash;Second Edition UNIX file system</li>
<li><strong>v3</strong>&mdash;Third Edition UNIX file system</li>
<li><strong>v4</strong>&mdash;Fourth Edition UNIX file system</li>
<li><strong>v5</strong>&mdash;Fifth Edition UNIX file system</li>
<li><strong>v6</strong>&mdash;Sixth Edition UNIX file system</li>
<li><strong>v7</strong>&mdash;Seventh Edition UNIX file system</li>
<li><strong>v10</strong>&mdash;Tenth Edition UNIX file system</li>
<li><strong>32v</strong>&mdash;UNIX/32V file system</li>
<li><strong>bsd</strong>&mdash;BSD file system (V7-style with fixed-length file names; e.g. 2.9BSD or 4.0BSD)</li>
<li><strong>bsd-vn</strong>&mdash;BSD file system (pre fast-file-system &#8220;UFS&#8221; with variable-length file names; e.g. 2.11BSD for PDP-11)</li>
</ul>
<p>To learn more about AncientFS and how to use it, please read the <a href="http://osxbook.com/software/ancientfs/" title="AncientFS: Ancient Unix File Systems on Mac OS X">AncientFS article</a>. Enjoy seeing ancient data seamlessly in the modern namespaces of Mac OS X!</p>
<h3>3. The UnixFS Layer</h3>
<p>AncientFS also led to UnixFS, a general-purpose abstraction layer that proved useful in getting several other &quot;alien&quot; file systems up and running on Mac OS X. It is particularly useful for &quot;Unix-style&quot; file systems, where you need concepts such as on-disk and in-memory superblocks and inodes. As I mentioned during the talk, I used UnixFS in conjunction with ad-hoc &quot;Linux emulation&quot; to bring support for the UFS, System V, and Minix file system families on Mac OS X. That amounts to a large number of new file systems, but it was easier than it sounds because the idea was to take existing Linux kernel implementations of these file system families and make them work <em>in user space</em> on Mac OS X!</p>
<p>UnixFS is currently rather &quot;beta&quot; and not a formal API by any means. Since it is a programming interface and doesn&#8217;t do anything by itself, it will be of interest only to developers at this point. In future, it may also evolve into a &quot;LinuxFS&quot; layer that could make it even easier and faster to <em>systematically</em> make Linux kernel-based file systems work on other platforms with very few code changes. For now, you can browse some <a href="http://code.google.com/p/macfuse/source/browse/#svn/trunk/filesystems/unixfs/common/" title="UnixFS Source Code">bits of code</a>.</p>
<p>You <em>can</em>, however, use the aforementioned UnixFS-based file system families: UFS, System V, and Minix. To do so, check out the relevant part of the MacFUSE source tree and compile one or more (or all) of the UnixFS-based file systems&mdash;it is quite straightforward: a single <code>make</code> in the <code>filesystems/unixfs/</code> subdirectory in the MacFUSE source tree should build all of them. (You must have MacFUSE installed, of course.)</p>
<p><code></p>
<pre style="font-size: 85%;">
$ <strong>svn co http://macfuse.googlecode.com/svn/trunk/filesystems/unixfs</strong>
$ <strong>cd unixfs</strong>
$ <strong>ls -F</strong>
Makefile	common/		sysvfs/
ancientfs/	minixfs/	ufs/
$ <strong>make</strong>
...
$
</pre>
<p></code></p>
<h3>4. The UFS Family</h3>
<p><a href="http://code.google.com/p/macfuse/source/browse/#svn/trunk/filesystems/unixfs/ufs/" title="UFS Source Code">This is a user-space implementation</a> (read-only) of the UFS file system family. Most of the UFS-specific code comes from the Linux kernel and is largely unchanged. Specific UFS flavors supported are as follows.</p>
<ul style="list-style: square;">
<li><code>old</code>&mdash;the oldest UFS format</li>
<li><code>sun</code>&mdash;used in SunOS/Solaris</li>
<li><code>sunx86</code>&mdash;used in the x86 versions of SunOS/Solaris</li>
<li><code>hp</code>&mdash;used in HP-UX</li>
<li><code>nextstep</code>&mdash;used in NEXTSTEP</li>
<li><code>nextstep-cd</code>&mdash;used in NEXTSTEP CDROMs</li>
<li><code>openstep</code>&mdash;used in OPENSTEP</li>
<li><code>44bsd</code>&mdash;used in FreeBSD, NetBSD, OpenBSD, and Mac OS X</li>
<li><code>ufs2</code>&mdash;used in FreeBSD 5.x</li>
</ul>
<h3>5. The System V Family</h3>
<p><a href="http://code.google.com/p/macfuse/source/browse/#svn/trunk/filesystems/unixfs/sysvfs/" title="SysVFS Source Code">This is a user-space implementation</a> (read-only) of the System V file system family. Most of the sysvfs-specific code comes from the Linux kernel and is largely unchanged. Specific sysvfs flavors supported are as follows.</p>
<ul style="list-style: square;">
<li><code>svr2</code>&mdash;used in SVR2</li>
<li><code>svr4</code>&mdash;used in SVR4</li>
<li><code>xenix</code>&mdash;used in Xenix</li>
<li><code>coherent</code>&mdash;used in Coherent Unix</li>
</ul>
<h3>6. The Minix Family</h3>
<p><a href="http://code.google.com/p/macfuse/source/browse/#svn/trunk/filesystems/unixfs/minixfs/" title="MinixFS Source Code">This is a user-space implementation</a> (read-only) of the Minix file system family. Most of the minixfs-specific code comes from the Linux kernel and is largely unchanged.</p>
<p style="border-top: 1px solid #C0C0C0; padding-top: 1em;">
The following image summarizes the new file system capabilities Mac OS X gets as a result of these exercises.
</p>
<p>
<center><br />
<img src="http://osxbook.com/images/blog/manynewfs.png"/><br />
</center>
</p>
<h3>7. The &quot;One More Thing&quot; Thing</h3>
<p>Although it isn&#8217;t directly file system related, the last thing I demonstrated during the talk was the ability to run ancient Unix (PDP-11) binaries seamlessly on Mac OS X. PDP-11 aside, the techniques used to do so are generally useful for research and experimentation because unlike Linux, Mac OS X does <em>not</em> allow developers to extend the set of binary formats that can be &quot;natively&quot; executed by the kernel. The demo shows the Fifth Edition Unix kernel being compiled on Mac OS X using the original C compiler toolchain from a Fifth Edition disk image mounted using AncientFS. Additionally, there&#8217;s an &quot;authentic&quot; reproduction of the following ominous error message by running the original <code>mv</code> executable from Sixth Edition Unix.</p>
<p><code></p>
<pre>
	values of &beta; will give rise to dom!
</pre>
<p></code></p>
<p>For more details, please watch the last section of the talk video. This is very preliminary work for which no source code or binaries are available yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://osxbook.com/blog/2008/12/16/more-user-space-file-system-goodies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending HFSDebug</title>
		<link>http://osxbook.com/blog/2008/07/23/extending-hfsdebug/</link>
		<comments>http://osxbook.com/blog/2008/07/23/extending-hfsdebug/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 08:08:08 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[The Book]]></category>

		<guid isPermaLink="false">http://www.osxbook.com/blog/?p=99</guid>
		<description><![CDATA[Recently, I had a need to know if any files or folders had been modified or created on an HFS+ volume in the past N seconds. There are many ways you could generate this type of information on Mac OS X. To begin with, you could try asking Spotlight. Besides Spotlight, Mac OS X has [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I had a need to know if any files or folders had been modified or created on an HFS+ volume in the past <em>N</em> seconds. There are many ways you could generate this type of information on Mac OS X.</p>
<p>To begin with, you could try asking Spotlight.</p>
<p>Besides Spotlight, Mac OS X has a rich variety of mechanisms and APIs for learning about file system changes.</p>
<p>On Leopard, you could write a program that uses the FSEvents API to learn of <em>directory-level</em> changes that occur on a volume. The FSEvents API is part of <code>CoreServices.framework</code>. &quot;Directory-level&quot; means that this API is best suited for monitoring large directory trees&mdash;it will not tell you when a particular file changes.</p>
<p>To monitor specific files, you could use the <em>kqueues</em> mechanism. (See <code>kqueue(2)</code>.) Being file-level, kqueues don&#8217;t scale like the FSEvents API as you will need to monitor each file system object separately. Therefore, it&#8217;s better suited for situations where you need to monitor only a few specific objects.</p>
<p>You could also directly use the low-level fsevents mechanism (<code>/dev/fsevents</code>) that underlies the FSEvents API and Spotlight&mdash;but <strong>only</strong> if your need is experimental in nature. The <a href="http://osxbook.com/software/fslogger/" title="A File System Change Logger"><code>fslogger</code></a> program is an example of directly using the fsevents mechanism. <code>fslogger</code> will tell you&mdash;in pretty much real time&mdash;when file system objects change. (Make sure to see <a href="http://osxbook.com/book/bonus/chapter11/fslogger/#FSLOGGER_CAVEAT" title="FSLogger: Caveats">caveats</a>.)</p>
<p>Then there is the kauth mechanism that was introduced in Tiger, primarily to help creators of virus scanning software. Kauth allows for <em>extremely</em> fine-grained file system activity monitoring&mdash;you can see vnode-level operations. In fact, monitoring is sort of a side effect of using the kauth mechanism. You can actually allow and deny individual operations, as virus scanning software might need to. However, kauth is not easy to use. (Not that the other APIs mentioned necessarily are!) To use kauth, you need to write a kernel extension. You also need to be extremely careful in what you do so as not to deadlock the operating system.</p>
<p>There also exist tools like <code>fs_usage</code> and <code>dtrace</code> on Mac OS X. <code>fs_usage</code> uses the kernelâ€™s <em>kdebug</em> facility to perform fine-grained tracing of kernel events. In particular, it allows you to trace file system activity. Beginning with Leopard, the DTrace facility, to which <code>dtrace</code> is a front-end, lets you trace all kinds of activity at both the kernel and user levels. You could do some very imaginative things with <code>dtrace</code>.</p>
<p>So, we see that there is no dearth of ways to monitor file system activity on Mac OS X. However, there are caveats associated with each way we looked at so far. Consider Spotlight. To use it, we would be assuming that Spotlight indexing was enabled on the volume in question. Spotlight also doesn&#8217;t look everywhere: your areas of interest on the file system might be outside of Spotlight&#8217;s default or configured search scope. Moreover, to use or the other APIs we talked about, you will need to have the volume <em>mounted</em>&mdash;usually a reasonable requirement, except it may not be an option if, for example, you are trying to recover valuable data from a volume that has been through an accident. Or you could be performing file system forensics. Or the volume could be damaged enough to not be in a mountable state&mdash;at least not without repair. In these situations, you can&#8217;t or wouldn&#8217;t want to mount the volume. That aside, in my case, I didn&#8217;t know until <em>after</em> the volume had been modified that I wanted to know what had changed. That is, I didn&#8217;t happen to be conveniently running any monitoring programs and such.</p>
<p>You can always old plain old Unix-style <code>find</code> and walk the entire file system, examining each file and folder. This still needs the volume to be mounted, but it <em>is</em> exhaustive. Of course, if you have a large volume, exhaustively examining each file and folder through a brute-force <code>find</code> or other programs could take &quot;forever.&quot; (In my case, I had over 4 million files on the volume. I also had little patience.)</p>
<p>Fortunately, Mac OS X lets you exploit the fact that the HFS+ volume format uses a central catalog B-Tree for storing hierarchy: the <code>searchfs()</code> system call can be used to &quot;quickly&quot; search HFS+ volumes. (It <em>is</em> much, much quicker than a typical portable user-space file-tree-walk.) In my case, I could use <code>searchfs()</code> to search for files and folders with creation or modification dates that match my criteria. Well, <em>almost</em>. I actually <em>did</em> require the volume to be unmounted. I also felt more inclined to do something general purpose.</p>
<p><a href="http://osxbook.com/software/hfsdebug/" title="HFSDebug"><code>hfsdebug</code></a> is a tool that can walk the catalog tree even on unmounted volumes. I decided to add filtering capability to <code>hfsdebug</code>. &quot;Filtering&quot; means that <code>hfsdebug</code> can walk the HFS+ catalog B-Tree, examining each file and folder, and produce output based on some matching criteria. The <a href="http://osxbook.com/software/hfsdebug/#DOWNLOAD" title="Download HFSDebug">new version</a> of <code>hfsdebug</code> contains two built-in filters: <em>mtime</em> and <em>crtime</em>. You can use these filters to look for files and folders that have been modified or created, respectively, in the past <em>N</em> seconds. The number of seconds is passed as an argument to these filters. For example, to look for file system objects modified within the past 60 seconds, you would run <code>hfsdebug</code> as follows:</p>
<p><code></p>
<pre style="font-size: 85%;">
$ <span style="color: #0000a0;">sudo hfsdebug --filter=builtin:crtime --filter_args=60</span>
1216795688 [Tue Jul 22 23:48:08 2008]: Macintosh HD:/private/var/log/asl.db
1216795688 [Tue Jul 22 23:48:08 2008]: Macintosh HD:/private/var/log/system.log
...
</pre>
<p></code></p>
<p>Better still, you can write your own filters that <code>hfsdebug</code> can use. A filter is implemented as a dynamic library that implements up to 3 functions: one of them mandatory (<code>hfsdebug_filter_callback()</code>) and two of them optional (<code>hfsdebug_filter_init()</code> and <code>hfsdebug_filter_fini()</code>.) To use your own filter, you would run <code>hfsdebug</code> the same way as in the case of built-in filters:</p>
<p><code></p>
<pre style="font-size: 85%;">
$ <span style="color: #0000a0;">sudo hfsdebug --filter=/path/to/myfilter.dylib --filter_args=string</span>
...
</pre>
<p></code></p>
<p>If your filter implements the <code>hfsdebug_filter_init()</code> function, <code>hfsdebug</code> would call it with the filter argument string, if any, as the argument. You could parse the argument string in the init function and initialize your filter&#8217;s state, if necessary.</p>
<pre style="font-size:85%;"><tt><font color="#009900">int</font>
<b><font color="#000000">hfsdebug_filter_init</font></b><font color="#990000">(</font><b><font color="#0000FF">const</font></b> <font color="#009900">char</font> <font color="#990000">*</font>filter_args<font color="#990000">);</font></tt></pre>
<p>If you return a non-zero value from the init function, <code>hfsdebug</code> will terminate. If your filter doesn&#8217;t have any arguments, you could choose not to implement the init function.</p>
<p>After you return 0 from the init function, <code>hfsdebug</code> will invoke your filter&#8217;s callback function once for each file and folder record in the HFS+ catalog.</p>
<pre style="font-size:85%;"><tt>
<b><font color="#0000FF">typedef</font></b> <font color="#009900">char</font><font color="#990000">*(*</font>hfsdebug_filter_path_retriever_t<font color="#990000">)(</font><font color="#009900">void</font><font color="#990000">);</font>

<font color="#009900">int</font>
<b><font color="#000000">hfsdebug_filter_callback</font></b><font color="#990000">(</font>
    <font color="#009900">void</font> <font color="#990000">*</font>info<font color="#990000">,</font> hfsdebug_filter_path_retriever_t pathRetriever<font color="#990000">);</font>
</tt></pre>
<p>The <code>info</code> argument is a pointer to either an <code>HFSPlusCatalogFile</code> structure or an <code>HFSPlusCatalogFolder</code> structure. (See the xnu kernel source for details of these structures.) You can determine which structure it is based on the first <code>int16_t</code> within the structure: it&#8217;s either <code>kHFSPlusFileRecord</code> or <code>kHFSPlusFolderRecord</code>. Given these structures, your filter can examine various attributes of the file system object.</p>
<p>Note that <code>hfsdebug</code> does <strong>not</strong> pass you the path to the file system object in question. This is because path computation is expensive. Instead, <code>hfsdebug</code> passes you a pointer to a <em>path retriever function</em>. You can invoke this function to make <code>hfsdebug</code> compute the path on demand and return a C string pointer. This pointer is valid for the given file system object only until your callback returns. You should only call the path retriever function if you truly need the path&mdash;doing so for each file system object would be quite time consuming. Note that <code>hfsdebug</code> filters are <em>not</em> multithreaded.</p>
<p>Again, you must return 0 from the callback for <code>hfsdebug</code> to keep calling you as long as there are more file system objects. If you return a non-zero value, <code>hfsdebug</code> will terminate.</p>
<p>Finally, once <code>hfsdebug</code> is done with all file system objects, it will call your filter&#8217;s fini function if one is implemented.</p>
<pre style="font-size:85%;"><tt>
<font color="#009900">void</font>
<b><font color="#000000">hfsdebug_filter_fini</font></b><font color="#990000">(</font><font color="#009900">void</font><font color="#990000">);</font>
</tt></pre>
<p>The following is a complete example of an <code>hfsdebug</code> filter. It does the same things as the built-in <em>mtime</em> filter, that is, it looks for files and folders that were modified within the last <em>N</em> seconds.</p>
<pre style="font-size: 85%;"><tt><i><font color="#9A1900">/*</font></i>
<i><font color="#9A1900"> * myfilter.c</font></i>
<i><font color="#9A1900"> *</font></i>
<i><font color="#9A1900"> * HFSDebug Filter for "mtime"</font></i>
<i><font color="#9A1900"> *</font></i>
<i><font color="#9A1900"> * Look for file system objects that have been modified</font></i>
<i><font color="#9A1900"> * within the past N seconds.</font></i>
<i><font color="#9A1900"> *</font></i>
<i><font color="#9A1900"> * gcc -arch ppc -dynamiclib -I/path/to/xnu/bsd/ -Wall -o myfilter.dylib myfilter.c</font></i>
<i><font color="#9A1900"> */</font></i>

<b><font color="#000080">#include</font></b> <font color="#FF0000">&lt;stdio.h&gt;</font>
<b><font color="#000080">#include</font></b> <font color="#FF0000">&lt;stdlib.h&gt;</font>
<b><font color="#000080">#include</font></b> <font color="#FF0000">&lt;stdint.h&gt;</font>
<b><font color="#000080">#include</font></b> <font color="#FF0000">&lt;errno.h&gt;</font>
<b><font color="#000080">#include</font></b> <font color="#FF0000">&lt;time.h&gt;</font>

<b><font color="#000080">#include</font></b> <font color="#FF0000">&lt;hfs/hfs_format.h&gt;</font>

<b><font color="#000080">#define</font></b> MAC_GMT_FACTOR 2082844800UL

<b><font color="#0000FF">typedef</font></b> <font color="#009900">char</font><font color="#990000">*(*</font>hfsdebug_filter_path_retriever_t<font color="#990000">)(</font><font color="#009900">void</font><font color="#990000">);</font>

<b><font color="#0000FF">static</font></b> uint32_t mtime_seconds <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>

<font color="#009900">int</font>
<b><font color="#000000">hfsdebug_filter_init</font></b><font color="#990000">(</font><b><font color="#0000FF">const</font></b> <font color="#009900">char</font> <font color="#990000">*</font>filter_args<font color="#990000">)</font>
<font color="#FF0000">{</font>
    mtime_seconds <font color="#990000">=</font> <b><font color="#000000">strtoul</font></b><font color="#990000">(</font>filter_args<font color="#990000">,</font> NULL<font color="#990000">,</font> <font color="#993399">10</font><font color="#990000">);</font>
    <b><font color="#0000FF">if</font></b> <font color="#990000">((</font>errno <font color="#990000">==</font> ERANGE<font color="#990000">)</font> <font color="#990000">||</font> <font color="#990000">(</font>errno <font color="#990000">==</font> EINVAL<font color="#990000">))</font> <font color="#FF0000">{</font>
        <b><font color="#000000">fprintf</font></b><font color="#990000">(</font>stderr<font color="#990000">,</font>
                <font color="#FF0000">"invalid argument (%s) to mtime filter</font><font color="#CC33CC">\n</font><font color="#FF0000">"</font><font color="#990000">,</font> filter_args<font color="#990000">);</font>
        <b><font color="#0000FF">return</font></b> errno<font color="#990000">;</font>
    <font color="#FF0000">}</font>

    time_t now <font color="#990000">=</font> <b><font color="#000000">time</font></b><font color="#990000">(</font>NULL<font color="#990000">);</font>

    mtime_seconds <font color="#990000">=</font> now <font color="#990000">-</font> mtime_seconds <font color="#990000">+</font> MAC_GMT_FACTOR<font color="#990000">;</font>

    <b><font color="#0000FF">return</font></b> <font color="#993399">0</font><font color="#990000">;</font>
<font color="#FF0000">}</font>

<font color="#009900">int</font>
<b><font color="#000000">hfsdebug_filter_callback</font></b><font color="#990000">(</font><font color="#009900">void</font> <font color="#990000">*</font>info<font color="#990000">,</font>
                         hfsdebug_filter_path_retriever_t pathRetriever<font color="#990000">)</font>
<font color="#FF0000">{</font>
    int16_t recordType <font color="#990000">=</font> <font color="#990000">*(</font>int16_t<font color="#990000">*)</font>info<font color="#990000">;</font>
    uint32_t modDate<font color="#990000">;</font>

    <b><font color="#0000FF">if</font></b> <font color="#990000">(</font>recordType <font color="#990000">==</font> kHFSPlusFileRecord<font color="#990000">)</font> <font color="#FF0000">{</font>
        HFSPlusCatalogFile <font color="#990000">*</font>file <font color="#990000">=</font> <font color="#990000">(</font>HFSPlusCatalogFile<font color="#990000">*)</font>info<font color="#990000">;</font>
        modDate <font color="#990000">=</font> file<font color="#990000">-&gt;</font>contentModDate<font color="#990000">;</font>
    <font color="#FF0000">}</font> <b><font color="#0000FF">else</font></b> <b><font color="#0000FF">if</font></b> <font color="#990000">(</font>recordType <font color="#990000">==</font> kHFSPlusFolderRecord<font color="#990000">)</font> <font color="#FF0000">{</font>
        HFSPlusCatalogFolder <font color="#990000">*</font>folder <font color="#990000">=</font> <font color="#990000">(</font>HFSPlusCatalogFolder<font color="#990000">*)</font>info<font color="#990000">;</font>
        modDate <font color="#990000">=</font> folder<font color="#990000">-&gt;</font>contentModDate<font color="#990000">;</font>
    <font color="#FF0000">}</font> <b><font color="#0000FF">else</font></b> <font color="#FF0000">{</font>
        <i><font color="#9A1900">/* ignore */</font></i>
        <b><font color="#0000FF">return</font></b> <font color="#993399">0</font><font color="#990000">;</font>
    <font color="#FF0000">}</font>

    <b><font color="#0000FF">if</font></b> <font color="#990000">(</font>modDate <font color="#990000">&gt;</font> mtime_seconds<font color="#990000">)</font> <font color="#FF0000">{</font>
        modDate <font color="#990000">-=</font> MAC_GMT_FACTOR<font color="#990000">;</font>
        <font color="#009900">char</font> <font color="#990000">*</font>tmpTime <font color="#990000">=</font> <b><font color="#000000">asctime</font></b><font color="#990000">(</font><b><font color="#000000">localtime</font></b><font color="#990000">((</font>time_t<font color="#990000">*)&amp;</font>modDate<font color="#990000">));</font>
        <font color="#990000">*(</font>tmpTime <font color="#990000">+</font> <font color="#993399">24</font><font color="#990000">)</font> <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
        <b><font color="#000000">fprintf</font></b><font color="#990000">(</font>stdout<font color="#990000">,</font>
                <font color="#FF0000">"%u [%s]: %s</font><font color="#CC33CC">\n</font><font color="#FF0000">"</font><font color="#990000">,</font> modDate<font color="#990000">,</font> tmpTime<font color="#990000">,</font> <b><font color="#000000">pathRetriever</font></b><font color="#990000">());</font>
    <font color="#FF0000">}</font>

    <b><font color="#0000FF">return</font></b> <font color="#993399">0</font><font color="#990000">;</font>
<font color="#FF0000">}</font>

<font color="#009900">void</font>
<b><font color="#000000">hfsdebug_filter_fini</font></b><font color="#990000">(</font><font color="#009900">void</font><font color="#990000">)</font>
<font color="#FF0000">{</font>
    <b><font color="#0000FF">return</font></b><font color="#990000">;</font>
<font color="#FF0000">}</font>
</tt></pre>
<p>
<span style="text-align: right;"><br />
<a href="http://osxbook.com/software/hfsdebug/#DOWNLOAD">Download HFSDebug 3.20</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://osxbook.com/blog/2008/07/23/extending-hfsdebug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>/bin/aural: The Solution</title>
		<link>http://osxbook.com/blog/2008/07/14/binaural-the-solution/</link>
		<comments>http://osxbook.com/blog/2008/07/14/binaural-the-solution/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 02:56:18 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://www.osxbook.com/blog/?p=100</guid>
		<description><![CDATA[1200 Baud Archaeology]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pagetable.com/?p=32" title="1200 Baud Archeology">1200 Baud Archaeology</a></p>
]]></content:encoded>
			<wfw:commentRss>http://osxbook.com/blog/2008/07/14/binaural-the-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>/bin/aural</title>
		<link>http://osxbook.com/blog/2008/06/30/binaural/</link>
		<comments>http://osxbook.com/blog/2008/06/30/binaural/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 17:28:07 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://www.osxbook.com/blog/?p=98</guid>
		<description><![CDATA[Here is a unique computer puzzle: the audio file (MP3 encoding) contains something that could well be music to many a hacker&#8217;s ears. What is it? Can you &#34;prove&#34; that it is what you say it is?]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pagetable.com/?p=31" title="1200 Baud Archeology">Here</a> is a unique computer puzzle: the audio file (MP3 encoding) contains something that could well be music to many a hacker&#8217;s ears. What is it? Can you &quot;prove&quot; that it <em>is</em> what you say it is?</p>
]]></content:encoded>
			<wfw:commentRss>http://osxbook.com/blog/2008/06/30/binaural/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&quot;TPM DRM&quot; In Mac OS X</title>
		<link>http://osxbook.com/blog/2008/01/31/tpm-drm-in-mac-os-x/</link>
		<comments>http://osxbook.com/blog/2008/01/31/tpm-drm-in-mac-os-x/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 06:40:58 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://www.osxbook.com/blog/2008/01/31/tpm-drm-in-mac-os-x/</guid>
		<description><![CDATA[A Myth That Won&#8217;t Die]]></description>
			<content:encoded><![CDATA[<p><a href="/book/bonus/chapter7/tpmdrmmyth/" title="&quot;TPM DRM&quot; In Mac OS X: A Myth That Won't Die">A Myth That Won&#8217;t Die</a></p>
]]></content:encoded>
			<wfw:commentRss>http://osxbook.com/blog/2008/01/31/tpm-drm-in-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

