Silly Hack of the Day: Mount the Obj-C Runtime as a Filesystem

Update: CocoaHacks was quite a bit of fun. Not only did I demonstrate the rather silly little hack, but I ran it fully garbage collected. With one simple change (that should be in the next release), the MacFUSE framework works just fine with Garbage Collection enabled!

The best compliment came from Amit Singh; something along the lines of “That is absolutely the strangest filesystem I have seen.”

In any case, my little hack repository has been updated to be GC only. retain/release/autorelease/dealloc are dead to me (in this project, anyway).

If you want to build MacFUSE with GC enabled, simply set Objective-C Garbage Collection to “Supported” in Xcode in the MacFUSE framework project’s build settings.

Browsing Classes_tn.png

At left, is a screenshot of the Finder browsing the Objective-C classes active in the runtime of a little Cocoa app that I wrote this evening.

The little app is called RuntimeFS and it contains a simple bit of code that traipses through the Objective-C runtime and collects information about the Objective-C classes encountered. This information is then barfed up by the elegantly simple delegate like API required by MacFuse to create a filesystem.

Let me restate that: MacFuse kicks ass. The Objective-C API is trivially easy to use. Trivially easy. I implemented this little hack in less than two hours, not having looked at the MacFuse API before. Nor did I read the docs; just looked at this example and one header file. I have implemented filesystems in a couple of different languages. Filesystems are hard. Or was. Not anymore.

I dropped the source code in the “Silly” directory of my public SVN repository.

Because, really, this is quite a silly hack. And hack it is — it doesn’t crash, but that is about all the quality assurance analysis I have done.

Free as in “MIT License” free. Have fun. I’m accepting patches, of course.

Future Stuff

If I were to go anywhere with this, the first thing I would do would be to move the subclasses into a subdirectory and then add other subdirectories to contain additional data.

Specifically, I would add directories like -1- Instance Variables, -2- Class Methods, -3- Instance Methods, -4- Subclasses, -5- Documentation (or something), etc…

The naming convention serves two purposes. First, it sorts nice like. Secondly, the names are invalid as class names and, thus, it makes handling the metadata vs. class directories trivially easy while also eliminating potential namespace conflicts.



14 Responses to “Silly Hack of the Day: Mount the Obj-C Runtime as a Filesystem”

  1. beatworm.co.uk » Blog Archive » Mount the Objective-C as a runtime. says:

    [...] filesystem development in user space. Now bbum has written a MacFuse app which allows you to mount the live Objective C runtime as a [...]

  2. Tom Davies says:

    Question: can Spotlight index a MacFuse filesystem? If it could, that would be a clever way around the limitation that spotlight can search only with file level granularity.

  3. John C. Randolph says:

    Silly perhaps, but definitely cool.

    -jcr

  4. Michael Tsai - Blog - RuntimeFS says:

    [...] Bill Bumgarner uses the new, ultra-simple Objective-C API for MacFUSE to create a filesystem for browsing Objective-C class hierarchies. [...]

  5. Bruce Fancher says:

    Dude. That is so fucking cool.

  6. ACoolie says:

    If you did extend this as stated to include methods, variables, and subclasses (which you might want to symbolically link to a top-level class directory), it could easily replace the now unreliable Docoa Browser.

  7. will says:

    That’s one of the coolest things I’ve seen in a long, long time. I can’t think of any real serious use for it, but that just makes me admire its awesomeness all the more.

  8. Rob Rix says:

    You could make individual methods show up as files, with the contents being the documentation for that particular method (:

  9. Sean Todd says:

    What was the change you made to the framework? I looked through the header files and didn’t see anything mentioning release or retain (since that is what gcc is complaining about). Did you have to recompile the framework itself?

  10. Garrett Albright says:

    Something I’d love to see, either by MacFUSE or some other project, is a way to browse my cell phone’s contents via Bluetooth using the Finder instead of the gimpy little Bluetooth File Exchange app. Any coders smarter than me up for taking up that project?

  11. Macinsoft - Silly Hack of the Day: Mount the Obj-C Runtime as a Filesystem says:

    [...] bbum: “MacFuse kicks ass. The Objective-C API is trivially easy to use. Trivially easy. I implemented this little hack in less than two hours, not having looked at the MacFuse API before.” Comments RSS | Trackback URL [...]

  12. GoogleRumours.com » Blog Archive » Developing for MacFUSE says:

    [...] addition to the talk, there were mind-bending demos of file systems written in Objective-C, such as RunTimeFS and AccessiblityFS. I really enjoyed the CocoaHeads meeting and encourage my fellow Mac developers [...]

  13. GoogleRumours.com » Blog Archive » Developing for MacFUSE says:

    [...] addition to the talk, there were mind-bending demos of file systems written in Objective-C, such as RunTimeFS and AccessiblityFS. I really enjoyed the CocoaHeads meeting and encourage my fellow Mac developers [...]

  14. Alex says:

    “The strangest filesystem I’ve ever seen” – can’t help but agree with that one. I’m really impressed with what you’ve done here, how long did it take you to throw this together?

    [Ed: comment appeared to be to drive traffic to a dieting site. Interesting question, though. It took an hour or so.]

Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>