<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.1" -->
<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/"
	>

<channel>
	<title>Michael Clarke</title>
	<link>http://www.michael-clarke-blog.com</link>
	<description>Me, Operating Systems, Technology, Sun Microsystems and Stuff!</description>
	<pubDate>Wed, 25 Jun 2008 14:37:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
	<language>en</language>
			<item>
		<title>Hmmm</title>
		<link>http://www.michael-clarke-blog.com/2008/06/25/hmmm/</link>
		<comments>http://www.michael-clarke-blog.com/2008/06/25/hmmm/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 14:35:00 +0000</pubDate>
		<dc:creator>Michael Clarke</dc:creator>
		
		<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://www.michael-clarke-blog.com/2008/06/25/hmmm/</guid>
		<description><![CDATA[I don&#8217;t think this needs words&#8230;
&#160;

&#160;
]]></description>
			<content:encoded><![CDATA[<p align="left">I don&#8217;t think this needs words&#8230;</p>
<p align="center">&nbsp;</p>
<p align="center"><a href="http://http://www.flickr.com/photos/trxuk/2610783380/sizes/l/"><img src="http://farm4.static.flickr.com/3262/2610783380_8fe2182261.jpg" height="375" width="500" /></a></p>
<p align="center">&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michael-clarke-blog.com/2008/06/25/hmmm/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bugs that produce oil&#8230;</title>
		<link>http://www.michael-clarke-blog.com/2008/06/18/bugs-that-produce-oil/</link>
		<comments>http://www.michael-clarke-blog.com/2008/06/18/bugs-that-produce-oil/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 21:39:23 +0000</pubDate>
		<dc:creator>Michael Clarke</dc:creator>
		
		<category><![CDATA[Science]]></category>

		<guid isPermaLink="false">http://www.michael-clarke-blog.com/2008/06/18/bugs-that-produce-oil/</guid>
		<description><![CDATA[I was reading a friends blog today and I saw he&#8217;s linked to a truly fascinating news article about Scientists who have managed to genetically modify bugs in such a way that they consume waste and produce crude oil.
I&#8217;m of two minds regarding this &#8216;discovery&#8217;. On the one hand it&#8217;s great knowing that there could [...]]]></description>
			<content:encoded><![CDATA[<p>I was reading a friends blog today and I saw he&#8217;s linked to a truly <a href="http://www.timesonline.co.uk/tol/news/environment/article4133668.ece">fascinating news article</a> about Scientists who have managed to genetically modify bugs in such a way that they consume waste and produce crude oil.</p>
<p>I&#8217;m of two minds regarding this &#8216;discovery&#8217;. On the one hand it&#8217;s great knowing that there could effectively be an unlimited supply of crude oil in the world - could this be the start of the road to free energy? Could this possibly mean an end to wars and and rivalry over oil rich countries?</p>
<p>However, I do have my concerns. Is this really the best thing for the environment - yes, it&#8217;s a way of recycling our waste. It&#8217;s also a means of gaining oil without the hassle of drilling and pumping and who knows whatever else - but is it sustainable for the environment and planet - do we really want to continue to have cars that pump out masses of CO2 or, would we prefer to find alternatives such as hydrogen power etc? Another interesting question - how much oil can these bugs really produce - too little, or as one critique on the news article says &#8220;Suppose some of these bugs mysteriously got out of the laboratory and into the environment. Would they not continue to behave in a similar fashion outside the petrie dish? So now everything around them would slowly be converted to oil. How is this scenario &#8220;environmentally friendly&#8221;?&#8221;. Then there are the moral grounds - is it right to genetically modify bugs for such things? Should we be playing God?</p>
<p>Overall I think it&#8217;s an interesting step, and it may even be a step in the right direction towards sustainable, environmentally friendly fuel - but I still think we&#8217;ve got a long way to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michael-clarke-blog.com/2008/06/18/bugs-that-produce-oil/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MouthOS gets kmem_alloc()&#8230;</title>
		<link>http://www.michael-clarke-blog.com/2008/06/08/mouthos-gets-kmem_alloc/</link>
		<comments>http://www.michael-clarke-blog.com/2008/06/08/mouthos-gets-kmem_alloc/#comments</comments>
		<pubDate>Sun, 08 Jun 2008 20:19:11 +0000</pubDate>
		<dc:creator>Michael Clarke</dc:creator>
		
		<category><![CDATA[MouthOS]]></category>

		<category><![CDATA[Operating Systems]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.michael-clarke-blog.com/2008/06/08/mouthos-gets-kmem_alloc/</guid>
		<description><![CDATA[At last it has happened! I have been putting off writing my memory allocator for MouthOS for some time. Up to now I&#8217;ve been able to survive without one by simply not having any &#8216;undefined&#8217; data structures - everything in the kernel was a known, static size.
So after a interesting Solaris Advanced Crash Dump Analysis [...]]]></description>
			<content:encoded><![CDATA[<p>At last it has happened! I have been putting off writing my memory allocator for MouthOS for some time. Up to now I&#8217;ve been able to survive without one by simply not having any &#8216;undefined&#8217; data structures - everything in the kernel was a known, static size.</p>
<p>So after a interesting Solaris Advanced Crash Dump Analysis course last week (which has really put me back into my OS development mood) I decided it was time to make a move and I spent a large portion of Friday night working out how to allocate memory without overwriting the existing kernel, and at last by about 2am in the morning having messed around with the linker and some cleverly placed assembly labels I finally was able to kmem_alloc() some memory.</p>
<p>At this point I decided I was finished and went to bed. The next morning I awoke, pleased to have kmem_alloc() working, or so I thought. However, as the day progressed and I allocated more and more pages of memory I started to see some strange things happening. Why did that character on screen just go red? I never put a start on the screen&#8230;</p>
<p>After a fair amount of time debugging the issue I managed to isolate the problem. My array of free_pages_t structures were located, not at the end of the kernel stack as I thought (which is currently 8K), but in the last 1K of the stack. Ultimately the problem was a off by one (er, or 1024 depending on how you look at it) error in my programming. At last I was able to kmem_alloc() pretty much as much memory as  I wanted - but how to free.</p>
<p>This proved to be very easy. I simply modified my page_map_t structure to contain a grouping id. As such, when we call kmem_free(void *) we do the following to first make sure that the address we got was on a page boundary.</p>
<pre>	while ( (addr % (PAGE_SIZE * 1024) != 0 )
		addr--;</pre>
<pre>	while ( page-&gt;addr != addr )
		page = page-&gt;next;</pre>
<p>Now we&#8217;re on a page boundary we can just loop through the pages whilst the alloc_id&#8217;s are equal and set the flags to PAGE_FREE&#8230;</p>
<pre>	int alloc_id = page-&gt;alloc_id;

	while ( page-&gt;alloc_id == alloc_id ) {
		page-&gt;alloc_id = 0;
		page-&gt;flags &amp;= PAGE_FREE;
		page = page-&gt;next;
	}</pre>
<p>With that working I then spent a bit more time perfecting and tweaking and now MouthOS is pretty good at allocating and freeing memory - at least, I think it is anyway. In the end it turned out not to be so difficult - you just have to get your head around the whole idea of allocating memory, before you have an allocator. When I thought about it this ended up not to be such an issue after-all&#8230;.  Here is how we can do it.</p>
<ol>
<li>You know the point where your kernel loads.</li>
<li>You can work out where your kernel ends by putting a label in its own section, and then using the linker to put that section at the end of the kernel.</li>
<li>You now know (from the placed label) where a safe place in the memory is to write without overwriting the existing kernel, so write all your required memory structures, of which you can calculate how many you need from the amount of memory in the system.</li>
<li>Finally,go back to your memory structures that you&#8217;ve just written and mark all the kernel space as allocated, including the space the memory structures take - which you know as you know the size of a memory struct, you know where it starts, and you know how many you&#8217;ve got.</li>
</ol>
<p>Easy <img src='http://www.michael-clarke-blog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> You can find the code for the new MouthOS memory allocator at: <a href="http://www.michael-clarke-blog.com/trac/MouthOS">http://www.michael-clarke-blog.com/trac/MouthOS</a>  -  if you&#8217;re remotely interested :p</p>
<p>Until next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michael-clarke-blog.com/2008/06/08/mouthos-gets-kmem_alloc/feed/</wfw:commentRss>
		</item>
		<item>
		<title>blogs.sun.com&#8230;.</title>
		<link>http://www.michael-clarke-blog.com/2008/06/01/blogssuncom/</link>
		<comments>http://www.michael-clarke-blog.com/2008/06/01/blogssuncom/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 09:43:52 +0000</pubDate>
		<dc:creator>Michael Clarke</dc:creator>
		
		<category><![CDATA[Sun Microsystems]]></category>

		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.michael-clarke-blog.com/2008/06/01/blogssuncom/</guid>
		<description><![CDATA[Last night I started my new Sun blog at blogs.sun.com - http://blogs.sun.com/michaelfclarke. So, what does this mean for this blog? Well, nothing really. I&#8217;ll continue to update this blog as I have been doing, putting personal projects and the like up. What this does mean however is that you&#8217;ll now be able to track my [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I started my new Sun blog at blogs.sun.com - <a href="http://blogs.sun.com/michaelfclarke">http://blogs.sun.com/michaelfclarke</a>. So, what does this mean for this blog? Well, nothing really. I&#8217;ll continue to update this blog as I have been doing, putting personal projects and the like up. What this does mean however is that you&#8217;ll now be able to track my progress as a Campus Ambassador Co-ordinator for the UK.</p>
<p>As some of you will know, I was going to be the Campus Ambassador for Aberystwyth University. However, recently Kim Austin (who is in charge of the Campus Ambassador program in the UK) asked if I&#8217;d like to be the Campus Ambassador Co-ordinator instead.   This job basically involves supporting the student ambassadors out in the field with their technical demos and day to day job requirements. Having worked for Sun for a year in the UK head offices I understand what Sun wants from the campus ambassadors, and being a student myself I also understand what students want from the campus ambassador program. It is my job to make sure that both parties get what they want.</p>
<p>So, why the new blog? I thought it would be nice to have an official blog for the Campus Ambassador work so that those who aren&#8217;t interested in MouthOS, or  that my bike tire still hasn&#8217;t been fixed (I&#8217;m waiting for the inner tube, honest&#8230; I&#8217;m not that lazy!) can keep a track of all the stuff that is going on in the world of campus ambassadors.</p>
<p>At the moment I&#8217;ve not got much on my new blog at the moment, but you should check it out for all the latest Campus Ambassador news in the UK.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michael-clarke-blog.com/2008/06/01/blogssuncom/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MouthOS Trac Website</title>
		<link>http://www.michael-clarke-blog.com/2008/05/16/mouthos-trac-website/</link>
		<comments>http://www.michael-clarke-blog.com/2008/05/16/mouthos-trac-website/#comments</comments>
		<pubDate>Fri, 16 May 2008 21:04:18 +0000</pubDate>
		<dc:creator>Michael Clarke</dc:creator>
		
		<category><![CDATA[MouthOS]]></category>

		<category><![CDATA[Operating Systems]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.michael-clarke-blog.com/2008/05/16/mouthos-trac-website/</guid>
		<description><![CDATA[It&#8217;s taken me some time to gather the enthusiasm to do this - but I&#8217;ve finally moved my MouthOS source over to my web server and installed trac. So, you can view the MouthOS wiki and source at:
http://www.michael-clarke-blog.com/trac/MouthOS
The older versions are in /proto. Kernel version 0.0.1, 0.0.2 and 0.0.3 are broken with some pretty big [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s taken me some time to gather the enthusiasm to do this - but I&#8217;ve finally moved my MouthOS source over to my web server and installed trac. So, you can view the MouthOS wiki and source at:</p>
<p><a href="http://www.michael-clarke-blog.com/trac/MouthOS">http://www.michael-clarke-blog.com/trac/MouthOS</a></p>
<p>The older versions are in /proto. Kernel version 0.0.1, 0.0.2 and 0.0.3 are broken with some pretty big bugs (for such small programs) such as triple faults and Kernel panics.</p>
<p>The most stable version at the moment is version 0.0.03 in <strong><em>/releases</em></strong>.</p>
<p>The stuff in /trunk is the current development with all the new HAL (Hardware Abstraction Layer) stuff. I&#8217;m still in the process of porting a lot of the proto-0.0.3 and releases-0.0.3 stuff to /trunk - so this is pretty useless at the moment <img src='http://www.michael-clarke-blog.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> But you&#8217;ll get the general idea as to where the project is heading from /trunk in terms of the HAL, Memory Management etc.</p>
<p>At some point I&#8217;m also going to add anonymous svn access so you&#8217;ll all be able to checkout the source code and have a play - but at least for the moment you can view the code, the wiki etc.</p>
<p>For the moment - enjoy <img src='http://www.michael-clarke-blog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.michael-clarke-blog.com/2008/05/16/mouthos-trac-website/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A bike ride that went wrong&#8230;</title>
		<link>http://www.michael-clarke-blog.com/2008/05/11/a-bike-ride-that-went-wrong/</link>
		<comments>http://www.michael-clarke-blog.com/2008/05/11/a-bike-ride-that-went-wrong/#comments</comments>
		<pubDate>Sun, 11 May 2008 08:24:33 +0000</pubDate>
		<dc:creator>Michael Clarke</dc:creator>
		
		<category><![CDATA[Play]]></category>

		<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://www.michael-clarke-blog.com/2008/05/11/a-bike-ride-that-went-wrong/</guid>
		<description><![CDATA[Yesterday I decided that since the weather was so nice it&#8217;d be a good idea to go for a nice bike ride. One of the guys who works in the  call center, Vlad, showed interest in a bike ride also having been a bit of a keen cyclist before some woman drove over him!
So, [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I decided that since the weather was so nice it&#8217;d be a good idea to go for a nice bike ride. One of the guys who works in the  call center, Vlad, showed interest in a bike ride also having been a bit of a keen cyclist before some woman drove over him!</p>
<p>So, we met at Sun about 3pm with plenty of water and every tool under the sun that we could possible need. The plan was to cycle to Fleet, then around Fleet lake and perhaps pop into The Heron on the Lake for a quick pint before cycling back - no too bad at all.</p>
<p>Things were going excellently - we arrived at fleet and got about 1/2 way around the lake when Vlad pulled up and said  -  &#8220;your back tyre is looking a little low&#8221;. No problem we thought - we&#8217;ll just pump it up a bit and off we go. No such luck - the inner tube had rotated slightly in the tire resulting in the valve being at such a funny angle that no pump would attach to it. No matter what we tried we couldn&#8217;t move the inner tube around so in the end we figured we&#8217;d just have to let the whole tyre down, move the inner tube around, and then pump it up again.</p>
<p>We were soon pumping the tyre up again - but every time we stopped there was a loud hissing - puncture. Unfortunately the puncture turned out to be right on the valve - probably because the inner tube had pinched&#8230; No puncture repair kit was going to fix that and the only inner tube we had was too big for my tyre.</p>
<p>After some debating I decided the best thing to do was to leave my bike nice and hidden in the bushes. Walk home (about 1 1/2 hours), pick up the car and then drive back to pick up my bike. The only problem with this truly cunning plan was that Vlad and I weren&#8217;t entirely sure where we were&#8230; all we knew is we were approximately 1/2 way around the lake (though it later turned out to be 3/4 way around the lake - throwing our directions off slightly).</p>
<p>However, all was not lost. Vlad&#8217;s mobile had GPS on it and so we were able to walk roughly in the direction of home. At one point we slightly overshot our turning and the distance started increasing so I decided to take a shortcut through some woods rather than following the path.  This seemed quite productive until we hit a locked gate next to a road&#8230; wondering why the gate onto the woods we&#8217;d just walked through was closed we climbed over and then saw the &#8216;DANGER! Army Training Grounds. DO NOT ENTER&#8221; signs in bright red coupled with the &#8216;Do NOT pickup suspicious objects&#8221; with a delightful picture of an explosion - oops.</p>
<p>Anyway&#8230; this is basically where the excitement ended. From here on we walked home, got the car, picked up the bike and then decided a BBQ was an excellent idea&#8230; the only think I&#8217;m regretting about the whole experience is that our chosen location for our attempted repairs on my bike was riddled with midgies - I now have rather red, bumpy and itchy legs <img src='http://www.michael-clarke-blog.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> I count approximately 16 bites on one leg and 44 on the other&#8230; time to go to the super market and pick up some cream for insect bites me thinks&#8230;</p>
<p>On a lighter note it turns out that Friday was Fraser&#8217;s (my house mate) birthday. He kept that very quiet - the only reason I found out was because I saw one of his cards&#8230;. As such we bought a cake which we all consumed after the BBQ last night.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michael-clarke-blog.com/2008/05/11/a-bike-ride-that-went-wrong/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Back to Sunny Wales for the Weekend</title>
		<link>http://www.michael-clarke-blog.com/2008/05/07/back-to-sunny-wales-for-the-weekend/</link>
		<comments>http://www.michael-clarke-blog.com/2008/05/07/back-to-sunny-wales-for-the-weekend/#comments</comments>
		<pubDate>Wed, 07 May 2008 17:02:38 +0000</pubDate>
		<dc:creator>Michael Clarke</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.michael-clarke-blog.com/2008/05/07/back-to-sunny-wales-for-the-weekend/</guid>
		<description><![CDATA[Given how this weekend just passed was a bank holiday weekend I decided to go back home to Sunny Wales. Usually it&#8217;s a bit of a joke - &#8216;Sunny Wales&#8217; - but this weekend it was beautiful weather and so we visited Lake Vyrnwy - about a 15 minute drive from home&#8230;
I&#8217;ve got to admit [...]]]></description>
			<content:encoded><![CDATA[<p>Given how this weekend just passed was a bank holiday weekend I decided to go back home to Sunny Wales. Usually it&#8217;s a bit of a joke - &#8216;Sunny Wales&#8217; - but this weekend it was beautiful weather and so we visited Lake Vyrnwy - about a 15 minute drive from home&#8230;</p>
<p>I&#8217;ve got to admit that being down south in Farnborough for the last year really makes you appriciate the views back home that you normally just take for granted.</p>
<p align="center"><a href="http://michael-clarke-blog.com/images/Image066.jpg"></a></p>
<p style="text-align: center"><a href="http://michael-clarke-blog.com/images/Image066.jpg"><img src="http://michael-clarke-blog.com/images/Image066.jpg" height="287" width="385" /></a></p>
<p align="center"><a href="http://michael-clarke-blog.com/images/Image071.jpg"></a></p>
<p style="text-align: center" align="left"><a href="http://michael-clarke-blog.com/images/Image071.jpg"><img src="http://michael-clarke-blog.com/images/Image071.jpg" height="287" width="385" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.michael-clarke-blog.com/2008/05/07/back-to-sunny-wales-for-the-weekend/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Handcuffs!?!</title>
		<link>http://www.michael-clarke-blog.com/2008/04/18/handcuffs/</link>
		<comments>http://www.michael-clarke-blog.com/2008/04/18/handcuffs/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 17:15:57 +0000</pubDate>
		<dc:creator>Michael Clarke</dc:creator>
		
		<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://www.michael-clarke-blog.com/2008/04/18/handcuffs/</guid>
		<description><![CDATA[How bazaar - today Robin announced that the previous occupant of his desk at work had left a pair of handcuffs in the top draw. What is more, on inspection, it appears he was telling the truth - there really was a pair of handcuffs in his top draw. Hmmm&#8230; my mind truly boggles.
]]></description>
			<content:encoded><![CDATA[<p>How bazaar - today Robin announced that the previous occupant of his desk at work had left a pair of handcuffs in the top draw. What is more, on inspection, it appears he was telling the truth - there really was a pair of handcuffs in his top draw. Hmmm&#8230; my mind truly boggles.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michael-clarke-blog.com/2008/04/18/handcuffs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>From bash to ksh&#8230;</title>
		<link>http://www.michael-clarke-blog.com/2008/04/13/from-bash-to-ksh/</link>
		<comments>http://www.michael-clarke-blog.com/2008/04/13/from-bash-to-ksh/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 09:55:23 +0000</pubDate>
		<dc:creator>Michael Clarke</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[Solaris]]></category>

		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.michael-clarke-blog.com/2008/04/13/from-bash-to-ksh/</guid>
		<description><![CDATA[I&#8217;ve finally made the move. For some time now I&#8217;ve been using bash in vi mode - however there is just one little niggle with it, every now and then the display messes up and you start seeing things like this:
le/why/has/this/moved/here?puter ~ $ mplayer /some/long/path/to/some/fi
That is really really really annoying when it happens.
Anyway, a colleague [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally made the move. For some time now I&#8217;ve been using bash in vi mode - however there is just one little niggle with it, every now and then the display messes up and you start seeing things like this:</p>
<pre>le/why/has/this/moved/here?puter ~ $ mplayer /some/long/path/to/some/fi</pre>
<p>That is really really really annoying when it happens.</p>
<p>Anyway, a colleague mentioned some time ago that this was the reason he moved back to Korn Shell&#8230; so I figured I&#8217;d give it a go. So far the only thing I&#8217;ve not managed to get working is coloured ls output&#8230;.  Everything else is working, tab completion (even though I&#8217;m trying to use Esc + \ instead), coloured PS1 prompt etc etc &#8230; most importantly though, vi mode hasn&#8217;t, as of yet, messed up!  <img src='http://www.michael-clarke-blog.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I&#8217;m starting to get a little concerned though - I&#8217;ve moved away from Gnome to Fluxbox at home and to fvwm2 at work&#8230; then on top of this I&#8217;ve now changed my shell from bash to ksh - what is happening!?!</p>
<p><strong>Edit: </strong>I&#8217;ve now got coloured ls working&#8230; I was too involved reading the .bashrc files in Gentoo trying to work out how bash does it&#8230; instead I should have just typed man ls&#8230;.</p>
<pre>  --color[=WHEN]
    control whether color is used to distinguish file types.  WHEN may be `never',
    `always', or `auto'</pre>
<p>Duh!</p>
<pre>michaelfclarke@mikes-computer michaelfclarke $ alias ls
ls='ls --color=always'</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.michael-clarke-blog.com/2008/04/13/from-bash-to-ksh/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C# - Dynamic Class Loading</title>
		<link>http://www.michael-clarke-blog.com/2008/04/05/c-dynamic-class-loading/</link>
		<comments>http://www.michael-clarke-blog.com/2008/04/05/c-dynamic-class-loading/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 18:42:54 +0000</pubDate>
		<dc:creator>Michael Clarke</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.michael-clarke-blog.com/2008/04/05/c-dynamic-class-loading/</guid>
		<description><![CDATA[The other day I wrote a small tutorial on getting dynamic class loading working for Java. In that post I mentioned that it could also be done in C# - but that it was more difficult, and from my personal experience, there is less information available about it - so here is how to do [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I wrote a small tutorial on getting dynamic class loading working for Java. In that post I mentioned that it could also be done in C# - but that it was more difficult, and from my personal experience, there is less information available about it - so here is how to do it!</p>
<p>First, as with the Java, we need to create our API. However, unlike the Java there is an additional requirement - a &#8216;module manager&#8217; class needs to be within the API. As such you will need to create these two files&#8230;</p>
<pre>using System;
using System.Reflection;</pre>
<pre>namespace com.michaelclarkeblog.api {</pre>
<pre>  public static class ModuleManager {</pre>
<pre>    public static Module getInstance(String fileName) {</pre>
<pre>      /* Load in the assembly. */
      Assembly moduleAssembly = Assembly.LoadFile(fileName);</pre>
<pre>      /* Get the types of classes that are in this assembly. */
      Type[] types = moduleAssembly.GetTypes();

      /* Loop through the types in the assembly until we find
       * a class that implements a Module.
       */
      foreach (Type type in types) {

        if (type.GetInterface("Module") != null) {</pre>
<pre>          /* Create a new instance of the 'Module'. */
          return (Module)Activator.CreateInstance(type);</pre>
<pre>        }
      }</pre>
<pre>      return null;
    }
  }
}</pre>
<pre></pre>
<pre>using System; 

namespace com.michaelclarke.dynamic.api {
  public interface Module {
    String getText();
  }</pre>
<pre>}</pre>
<p>Once you&#8217;ve got the two files you can compile them into a library&#8230;.</p>
<p>api $ mcs -t:library Module.cs ModuleManager.cs<br />
api $ ls -a | grep .dll<br />
Module.dll<br />
api $</p>
<p>Now that we&#8217;ve made the API the next thing to write is the application that is going to use it for loading modules. This is a very simple application&#8230;</p>
<pre>using System;
using com.michaelclarkeblog.dynamic.api;</pre>
<pre>namespace com.michaelclarkeblog.dynamic.application {</pre>
<pre>  public class Application {</pre>
<pre>    public static void Main(String[] args) {</pre>
<pre>      if (args.Length &gt; 0 ) {</pre>
<pre>        Module module = ModuleManager.getInstance(args[0]);
        Console.WriteLine(module.getText());</pre>
<pre>      } else {</pre>
<pre>        Console.WriteLine("Usage: mono Application module_name");</pre>
<pre>      }
    }
  }
}</pre>
<p>Now we can compile our &#8216;Application&#8217; against the API&#8230;</p>
<pre>application $ mcs -reference:../api/Module.dll Application.cs
application $ ls -la | grep exe
-rwxr-xr-x 1 michaelfclarke michaelfclarke 3072 Apr  5 19:32 Application.exe
application $</pre>
<p>And now finally we can write a couple of modules!</p>
<pre>using System;
using com.michaelclarkeblog.dynamic.api;

namespace com.michaelclarkeblog.dynamic.modules {
  public class Mike : Module {
    public String getText() {
      return "Hello from Mike's Module!";
    }
  }
}</pre>
<pre>using System;
using com.michaelclarkeblog.dynamic.api;

namespace com.michaelclarkeblog.dynamic.modules {
  public class Another : Module {
    public String getText() {
      return "Hello from Another Module!";
    }
  }
}</pre>
<p>Compile the modules&#8230;</p>
<pre>modules $ mcs -t:library -reference:../api/Module.dll Another.cs
modules $ mcs -t:library -reference:../api/Module.dll Mike.cs
modules $ ls -la | grep dll
-rwxr-xr-x 1 michaelfclarke michaelfclarke 3072 Apr  5 19:36 Another.dll
-rwxr-xr-x 1 michaelfclarke michaelfclarke 3072 Apr  5 19:36 Mike.dll
modules $</pre>
<p>There is just one last thing we need to do before we can run our application. We need to copy the Module.dll API from the api directory into the application directory&#8230;</p>
<pre>modules $ cd ../application
application $ cp ../api/Module.dll .</pre>
<p>And now lets try running our dynamic application&#8230;</p>
<pre>application $ mono Application.exe ../modules/Mike.dll
Hello from Mike's Module!

application $ mono Application.exe ../modules/Another.dll
Hello from Another Module!

application $ mono Application.exe
Usage: mono Application module_name</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.michael-clarke-blog.com/2008/04/05/c-dynamic-class-loading/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
