<?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>R. Matthew Emerson</title>
	<atom:link href="http://www.thoughtstuff.com/rme/weblog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.thoughtstuff.com/rme/weblog</link>
	<description>Matters of minor import</description>
	<lastBuildDate>Wed, 01 Apr 2009 20:14:10 +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>Slides from my ILC09 lightning talk</title>
		<link>http://www.thoughtstuff.com/rme/weblog/?p=17</link>
		<comments>http://www.thoughtstuff.com/rme/weblog/?p=17#comments</comments>
		<pubDate>Wed, 01 Apr 2009 20:13:48 +0000</pubDate>
		<dc:creator>rme</dc:creator>
				<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://www.thoughtstuff.com/rme/weblog/?p=17</guid>
		<description><![CDATA[I gave a lightning talk at ILC09 on threads and GC implementation in Clozure CL.
I put the slides and the one-page paper (as seen in the ILC09 proceedings) at http://www.clozure.com/~rme/.
]]></description>
			<content:encoded><![CDATA[<p>I gave a lightning talk at ILC09 on threads and GC implementation in Clozure CL.</p>
<p>I put the slides and the one-page paper (as seen in the ILC09 proceedings) at <a href="http://www.clozure.com/~rme/">http://www.clozure.com/~rme/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thoughtstuff.com/rme/weblog/?feed=rss2&amp;p=17</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CCL on x8632: more registers, please</title>
		<link>http://www.thoughtstuff.com/rme/weblog/?p=16</link>
		<comments>http://www.thoughtstuff.com/rme/weblog/?p=16#comments</comments>
		<pubDate>Fri, 19 Sep 2008 21:40:41 +0000</pubDate>
		<dc:creator>rme</dc:creator>
				<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://www.thoughtstuff.com/rme/weblog/?p=16</guid>
		<description><![CDATA[The biggest problem with porting CCL to the x8632 architecture is that the architecture has so few registers.  I need to talk a little bit about how CCL&#8217;s GC works in order to explain why the small number of registers is a problem.
CCL is designed to use pre-emptively scheduled OS threads.  This means [...]]]></description>
			<content:encoded><![CDATA[<p>The biggest problem with porting CCL to the x8632 architecture is that the architecture has so few registers.  I need to talk a little bit about how CCL&#8217;s GC works in order to explain why the small number of registers is a problem.</p>
<p>CCL is designed to use pre-emptively scheduled OS threads.  This means that a context switch can happen at any instruction boundary.  Since other threads might allocate memory, this means that a GC can happen between any two instructions, too.</p>
<p>(The following summarizes information found in the <a href="http://ccl.clozure.com/manual/chapter16.html">Implementation Details of Clozure CL</a> chapter of the CCL manual.)</p>
<p>The GC in CCL is precise.  That is, it believes that it can always tell whether a register or a stack location contains a lisp value or just raw bits.  In order it to enable it to do this, we have to adopt and follow strict conventions on register and stack usage.</p>
<p>What we do is to partition the machine registers into two sets: one that will always contain raw, unboxed values (&#8220;immediates&#8221;), and another that will always contain tagged lisp objects (&#8220;nodes&#8221;).</p>
<p>This works fine on architectures that have a reasonable number of registers.  On x8632, we&#8217;re so register-starved that it&#8217;s impossible to get by with a static partitioning of registers.</p>
<p>We therefore keep a bit mask in thread-local memory that indicates whether a given register is a node or an immediate, and have the GC consult these bits when it runs.  This allows us to switch the class of a register at run time.</p>
<p>The default register partitioning looks like this:</p>
<ul>
<li>We have a single &#8220;immediate&#8221; register.  EAX is given the symbolic name %imm0.
<li>There are two &#8220;dedicated&#8221; registers.  ESP and EBP have dedicated functionality dictated by the hardware and calling conventions.
<li>The remaining 5 registers are &#8220;node&#8221; registers (%temp0, %temp1, %arg_y, %arg_z, and %fn).  We don&#8217;t use the x86 string instructions which implicitly use ESI and EDI.
</ul>
<p>Most of the time, all we need to do is to steal a node register and mark it as an immediate for a couple of instructions.  Typically this is because we need to index some foreign pointer, or use MUL or DIV to produce extended-precision results.</p>
<p>Here&#8217;s an example of a case where we have to do this.</p>
<pre>
(defx8632lapfunction %%get-unsigned-longlong ((ptr arg_y) (offset arg_z))
  (trap-unless-typecode= ptr x8632::subtag-macptr)
  (mark-as-imm temp0)
  (let ((imm1 temp0))
    (macptr-ptr ptr imm1)
    (unbox-fixnum offset imm0)
    (movq (@ (% imm1) (% imm0)) (% mm0)))
  (mark-as-node temp0)
  (jmp-subprim .SPmakeu64))
</pre>
<p>The mark-as-imm macro expands to something like this:</p>
<pre>
(andb ($ bit-for-temp0) (@ (% :rcontext) x8632::tcr.node-regs-mask))
</pre>
<p>Here, :rcontext is the register that points to a block of thread-local storage (the thread context record).  On x8632, it&#8217;s an otherwise useless segment register, typically %fs.  (We&#8217;d be in real trouble if we had to dedicate a GPR to point to thread-local storage on x8632.)</p>
<p>In simple cases like this, there&#8217;s actually another alternative.  We don&#8217;t use the x86 string instructions, so the direction flag in EFLAGS is otherwise unused.  So, what we do is to say that if DF is set, then %edx is an immediate register.  So, if we used temp1 (aka EDX) instead of temp0 (aka ECX) in the example above, we could actually replace the mark-as-imm/mark-as-node with the (presumably cheaper) std/cld instruction pair.</p>
<p>In fact, I should probably make that change&#8230;</p>
<p>Anyway, many&#8217;s the time I wished for just two more registers.  I thought about sending a bug report to Intel, but I didn&#8217;t figure that I&#8217;d get a response.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thoughtstuff.com/rme/weblog/?feed=rss2&amp;p=16</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Clozure CL 1.2 released</title>
		<link>http://www.thoughtstuff.com/rme/weblog/?p=15</link>
		<comments>http://www.thoughtstuff.com/rme/weblog/?p=15#comments</comments>
		<pubDate>Fri, 19 Sep 2008 00:44:12 +0000</pubDate>
		<dc:creator>rme</dc:creator>
				<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://www.thoughtstuff.com/rme/weblog/?p=15</guid>
		<description><![CDATA[Clozure CL 1.2 is out now.  It runs on x86-64 and PowerPC processors, under Mac OS X, Linux, and FreeBSD.  (I continue to be surprised by how many people think it runs only on Macintosh systems.)  This is the first official release in over two and a half years.
Fast compiler, native threads, convenient FFI, Unicode, [...]]]></description>
			<content:encoded><![CDATA[<p>Clozure CL 1.2 is out now.  It runs on x86-64 and PowerPC processors, under Mac OS X, Linux, and FreeBSD.  (I continue to be surprised by how many people think it runs only on Macintosh systems.)  This is the first official release in over two and a half years.</p>
<p>Fast compiler, native threads, convenient FFI, Unicode, generational GC, etc.  See <a href="http://trac.clozure.com/openmcl/">http://trac.clozure.com/openmcl</a></p>
<p>One major feature that will be in Clozure CL 1.3 is support for the 32-bit x86 platform.  In fact, an experimental 32-bit lisp is already in the trunk for Darwin/x86.  I worked on the 32-bit Intel port.</p>
<p>It&#8217;s probably a little unusual for software to be ported from x86-64 back to x8632.  Anti-progress, as it were.</p>
<p>The existence of an x8664 port made the job quite a bit simpler: one major benefit was that there was already a working assembler (and disassembler, too).  I was also able to use the existing low-level x86-64 assembly language code as a model for what the corresponding 32-bit version should look like.</p>
<p>Another thing I had going for me was that the lisp already ran on the 32-bit PowerPC, so the word size issues were mostly ironed out.</p>
<p>I didn&#8217;t really know (or care to know) the x86 architecture all that well before I started working on the port.  I think other architectures (SPARC, MIPS, PowerPC, &#8230;) are much nicer targets.</p>
<p>However, the hardware engineers at Intel and AMD are brilliant, and it&#8217;s impossible to ignore the performance of the x86 chips that they build.  You just have to hold your nose, study the architecture manuals, and get on with it.</p>
<p>After doing the port, I find it funny that I look on x86-64 as some sort of Nirvana.  (I mentioned this on a private IRC channel, and got the reply &#8220;It&#8217;s not THAT bad.  Of the 8 or so architectures that I can think of that&#8217;re still in use, it&#8217;s in the top 7.&#8221;)</p>
<p>I&#8217;m afraid that it might be a bit boring to read about issues that face the lisp implementer when targeting x8632, but maybe I&#8217;ll write a follow-on post with some more details if there&#8217;s any interest.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thoughtstuff.com/rme/weblog/?feed=rss2&amp;p=15</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clozure CL (née OpenMCL)</title>
		<link>http://www.thoughtstuff.com/rme/weblog/?p=13</link>
		<comments>http://www.thoughtstuff.com/rme/weblog/?p=13#comments</comments>
		<pubDate>Fri, 19 Oct 2007 21:13:17 +0000</pubDate>
		<dc:creator>rme</dc:creator>
				<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://www.thoughtstuff.com/rme/weblog/?p=13</guid>
		<description><![CDATA[OpenMCL is getting renamed to Clozure CL.  Now that regular MCL is going to be released as open source software, this is proabably a good idea.  It&#8217;s already the case that many people think that OpenMCL runs only on the Macintosh.  In reality, it runs on PowerPC hardware under Mac OS X [...]]]></description>
			<content:encoded><![CDATA[<p>OpenMCL is getting renamed to Clozure CL.  Now that regular MCL is going to be released as open source software, this is proabably a good idea.  It&#8217;s already the case that many people think that OpenMCL runs only on the Macintosh.  In reality, it runs on PowerPC hardware under Mac OS X and Linux PPC, and on x86-64 hardware under Mac OS X, Linux, and FreeBSD.</p>
<p>Anyway, OpenMCL has had a kind of proof-of-concept Cocoa-based development environment for a while now, but it&#8217;s starting to get some attention.</p>
<p>A demonstration version of the Clozure CL development environment for the PowerPC Macintosh is available as a double-clickable application.  (There&#8217;s an x86-64 version, too, but it won&#8217;t be released until Leopard comes out.)</p>
<p>See the <a href="http://article.gmane.org/gmane.lisp.mcl.general/2593">announcement</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thoughtstuff.com/rme/weblog/?feed=rss2&amp;p=13</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Playing sounds from the command line</title>
		<link>http://www.thoughtstuff.com/rme/weblog/?p=10</link>
		<comments>http://www.thoughtstuff.com/rme/weblog/?p=10#comments</comments>
		<pubDate>Wed, 06 Jun 2007 03:07:37 +0000</pubDate>
		<dc:creator>rme</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://www.thoughtstuff.com/rme/weblog/?p=10</guid>
		<description><![CDATA[On the NeXT machine, there was a command called sndplay that would play .snd files from the command line.
It&#8217;s not too tough to put together a similar one for Mac OS X.  We can play many more kinds of sounds than the old NeXT sndplay command did. On the other hand, since NSSound uses [...]]]></description>
			<content:encoded><![CDATA[<p>On the NeXT machine, there was a command called sndplay that would play .snd files from the command line.</p>
<p>It&#8217;s not too tough to put together a similar one for Mac OS X.  We can play many more kinds of sounds than the old NeXT sndplay command did. On the other hand, since NSSound uses QuickTime to play some media formats, a run loop is required for sounds to keep playing, so that requires a few gyrations.</p>
<p><a href="wp-content/uploads/2007/06/sndplay.m">sndplay.m</a></p>
<p>(See also <a href="http://lists.apple.com/archives/cocoa-dev/2003/Apr/msg01638.html">this cocoa-dev message</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thoughtstuff.com/rme/weblog/?feed=rss2&amp;p=10</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Command-line compiling of Cocoa code</title>
		<link>http://www.thoughtstuff.com/rme/weblog/?p=8</link>
		<comments>http://www.thoughtstuff.com/rme/weblog/?p=8#comments</comments>
		<pubDate>Wed, 30 May 2007 18:57:44 +0000</pubDate>
		<dc:creator>rme</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://www.thoughtstuff.com/rme/weblog/?p=8</guid>
		<description><![CDATA[I find that tools like Xcode are often too heavyweight when trying out little fragments of code.  In these cases, it can be simpler to use the traditional Unix tools to edit, compile, and run tiny test programs.  (Of course, it might be simpler for me because I&#8217;m used to the traditional Unix [...]]]></description>
			<content:encoded><![CDATA[<p>I find that tools like Xcode are often too heavyweight when trying out little fragments of code.  In these cases, it can be simpler to use the traditional Unix tools to edit, compile, and run tiny test programs.  (Of course, it might be simpler for me because I&#8217;m used to the traditional Unix way.)</p>
<p>For instance, say that you have created a category on NSMutableArray that adds a method to reverse the contents of the array, and you&#8217;re ready to test it out.</p>
<p>You could create an Xcode project for this (you&#8217;d use the Foundation Tool template), but it&#8217;s also possible to use a Unix text editor (like emacs or vi) to create the file that contains your category, together with a simple <code>main()</code> function.  (Here is an <a href="/rme/weblog/wp-content/uploads/2007/05/shuffle-reverse-test.m">example file</a>.)</p>
<p>There are basically two tricks to know.  The first is that you need to create an autorelease pool before you call any methods, or else you&#8217;ll see warning messages about leaking objects.  The other trick is how to compile the file, and that is simply</p>
<blockquote><p> <code>cc file.m -framework Foundation</code></p></blockquote>
<p>Now, just run <code>a.out</code>.  Debug, edit source, re-compile, repeat.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thoughtstuff.com/rme/weblog/?feed=rss2&amp;p=8</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Pleasure of Interactivity</title>
		<link>http://www.thoughtstuff.com/rme/weblog/?p=7</link>
		<comments>http://www.thoughtstuff.com/rme/weblog/?p=7#comments</comments>
		<pubDate>Wed, 21 Feb 2007 20:57:53 +0000</pubDate>
		<dc:creator>rme</dc:creator>
				<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://www.thoughtstuff.com/rme/weblog/?p=7</guid>
		<description><![CDATA[What&#8217;s so great about Lisp?  This question is frequently asked by people who wonder what such a weird-looking language could offer.
The usual response is often &#8220;macros.&#8221;  As a one-liner, this is probably a fair answer.  However, it&#8217;s not very enlightening, since the questioner isn&#8217;t going to have any idea what a Lisp [...]]]></description>
			<content:encoded><![CDATA[<p>What&#8217;s so great about Lisp?  This question is frequently asked by people who wonder what such a weird-looking language could offer.</p>
<p>The usual response is often &#8220;macros.&#8221;  As a one-liner, this is probably a fair answer.  However, it&#8217;s not very enlightening, since the questioner isn&#8217;t going to have any idea what a Lisp macro is, or what it can do.  Telling someone that penicillin is great because it is an antibiotic isn&#8217;t very useful if the questioner has no idea what bacteria are or what role they play in causing illness.</p>
<p>The thing *I* like best about using Lisp is that it&#8217;s interactive.</p>
<p>My current project is a Mac OS X application written in Objective-C.  I am using Apple&#8217;s Xcode developement environment, which contains numerous fancy features.</p>
<p>Yet, I still have an emacs running, talking to an inferior lisp via SLIME.</p>
<p>Sometimes I use the lisp as a calculator.  Sometimes I&#8217;ll get a function working in Lisp and then re-write it in C for insertion into my application.  Sometimes I&#8217;ll re-write some troublesome C function in Lisp and debug it from the lisp.</p>
<p>Having the ability to do this sort of work interactively and incrementally is a real pleasure.  No recompiling files, no special debugger commands, just the whole Lisp environment at your fingertips all the time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thoughtstuff.com/rme/weblog/?feed=rss2&amp;p=7</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Probably prime numbers</title>
		<link>http://www.thoughtstuff.com/rme/weblog/?p=6</link>
		<comments>http://www.thoughtstuff.com/rme/weblog/?p=6#comments</comments>
		<pubDate>Fri, 09 Feb 2007 05:19:21 +0000</pubDate>
		<dc:creator>rme</dc:creator>
				<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://www.thoughtstuff.com/rme/weblog/?p=6</guid>
		<description><![CDATA[I was browsing through a copy of the New Turing Omnibus, and ran across the article on detecting primes.I grabbed an algorithms text, and implemented the Miller-Rabin primality test in Common Lisp.
;;; updated June 9, 2007 incorporating feedback from comments
(defun witness (a n)
  (let ((b (- n 1)))
    (loop for i [...]]]></description>
			<content:encoded><![CDATA[<p>I was browsing through a copy of the <a href="http://www.amazon.com/New-Turing-Omnibus-Turning-Excursions/dp/0716782715">New Turing Omnibus</a>, and ran across the article on detecting primes.I grabbed an <a href="http://www.amazon.com/Introduction-Algorithms-Second-Thomas-Cormen/dp/0262032937">algorithms text</a>, and implemented the <a href="http://en.wikipedia.org/wiki/Miller-Rabin_primality_test">Miller-Rabin primality test</a> in Common Lisp.<span id="more-6"></span></p>
<pre>;;; updated June 9, 2007 incorporating feedback from comments
(defun witness (a n)
  (let ((b (- n 1)))
    (loop for i from (integer-length b) downto 0
       for d = 1 then (mod (* d d) n)
       for x = d
       do
	 (when (and (= d 1) (/= x 1) (/= x (- n 1)))
	   (return-from witness t))
	 (when (logbitp i b)
	   (setf d (mod (* d a) n)))
       finally (return (/= d 1)))))

(defun primep (n &amp;optional (s 50))
  "Miller-Rabin primality test."
  (dotimes (i s t)
    (let ((w (1+ (random (- n 1)))))
      (when (witness w n)
        (return-from primep nil)))))</pre>
<p>Some results:</p>
<pre>; the 15th <a href="http://en.wikipedia.org/wiki/Mersenne_prime">Mersenne Prime</a>
CL-USER&gt; (time (primep (1- (expt 2 1279))))
Evaluation took:
  3.043 seconds of real time
  3.034062 seconds of user run time
  0.005775 seconds of system run time
  [Run times include 0.071 seconds GC run time.]
  0 calls to %EVAL  0 page faults and  151,872,008 bytes consed.
T
CL-USER&gt; (1- (expt 2 1279))
1040793219466439908192524032736408553861526224726670480531911235
0403608059673362980122394417323241848424216139542810077913835662
4832346490813990660567732076292412950938922034577318334966158355
0472959420547689811211693677147548478866962513844382602917323488
8531116082853841658502825560466622483189091880184706822220314052
1026698435488732958028878050869736186900714720710555703168729087
; compare with <a href="http://en.wikipedia.org/wiki/List_of_prime_numbers">list of first 1000 primes</a>
CL-USER&gt; (loop for i from 1000 to 2000
               if (primep i) collect i)
(1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087
 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181
 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279
 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373
 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471
 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559
 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637
 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747
 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867
 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973
 1979 1987 1993 1997 1999)</pre>
<p>Lisp&#8217;s built-in bignums makes playing with this sort of thing easy and fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thoughtstuff.com/rme/weblog/?feed=rss2&amp;p=6</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Determining the default route</title>
		<link>http://www.thoughtstuff.com/rme/weblog/?p=4</link>
		<comments>http://www.thoughtstuff.com/rme/weblog/?p=4#comments</comments>
		<pubDate>Tue, 06 Feb 2007 04:12:23 +0000</pubDate>
		<dc:creator>rme</dc:creator>
				<category><![CDATA[macosx]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.thoughtstuff.com/rme/weblog/?p=4</guid>
		<description><![CDATA[A subscriber on cocoa-dev@lists.apple.com was asking whether there was some way to programmatically determine the default route.
The cheap and sleazy way would be to read the output of netstat, but that&#8217;s not very aesthetically appealing.
 Here is some sample code, derived from the source for netstat, which will find and print the IPv4 default route.
]]></description>
			<content:encoded><![CDATA[<p>A subscriber on cocoa-dev@lists.apple.com was asking whether there was some way to programmatically determine the default route.</p>
<p>The cheap and sleazy way would be to read the output of netstat, but that&#8217;s not very aesthetically appealing.</p>
<p><a href="http://www.thoughtstuff.com/rme/weblog/wp-content/uploads/2007/02/defroute.c" title="defroute.c"> Here is some sample code</a>, derived from the source for netstat, which will find and print the IPv4 default route.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thoughtstuff.com/rme/weblog/?feed=rss2&amp;p=4</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting disk insertion/removal notifications</title>
		<link>http://www.thoughtstuff.com/rme/weblog/?p=3</link>
		<comments>http://www.thoughtstuff.com/rme/weblog/?p=3#comments</comments>
		<pubDate>Tue, 06 Feb 2007 03:03:40 +0000</pubDate>
		<dc:creator>rme</dc:creator>
				<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://www.thoughtstuff.com/rme/weblog/?p=3</guid>
		<description><![CDATA[On Mac OS X, there is a daemon called diskarbitrationd that can notifiy interested clients of the appearance of disks and filesystems.  Users talk to diskarbitrationd via the Disk Arbitration framework.
For some reason, the current developer documentation doesn&#8217;t have much to say about this framework.  It therefore appears to be necessary to grovel [...]]]></description>
			<content:encoded><![CDATA[<p>On Mac OS X, there is a daemon called diskarbitrationd that can notifiy interested clients of the appearance of disks and filesystems.  Users talk to diskarbitrationd via the Disk Arbitration framework.</p>
<p>For some reason, the current developer documentation doesn&#8217;t have much to say about this framework.  It therefore appears to be necessary to grovel through the headers to figure out how to use it.  Fortunately, the headers are well-commented.</p>
<p>I was able to throw together a trivial program in about 15 or 20 minutes from first looking at DiskArbitration.h.  Maybe this will help someone out there.</p>
<pre>
#include &lt;stdio.h&gt;
#include &lt;DiskArbitration/DiskArbitration.h&gt;

void hello_disk(DADiskRef disk, void *context)
{
    printf("disk %s appeared\n", DADiskGetBSDName(disk));
}

void goodbye_disk(DADiskRef disk, void *context)
{
    printf("disk %s disappeared\n", DADiskGetBSDName(disk));
}

main()
{
    DASessionRef session;

    session = DASessionCreate(kCFAllocatorDefault);

    DARegisterDiskAppearedCallback(session, NULL, hello_disk, NULL);
    DARegisterDiskDisappearedCallback(session, NULL, goodbye_disk, NULL);

    DASessionScheduleWithRunLoop(session,
        CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

    CFRunLoopRun();

    CFRelease(session);
    exit(0);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.thoughtstuff.com/rme/weblog/?feed=rss2&amp;p=3</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
