Dokan

user-mode file system for Windows    >>English version

25行でファイルシステム

October 6th, 2007 in Dokan, Ruby

Dokan RubyバインディングのFuseFS互換インタフェースを利用すると、25行でファイルシステムを書くことが出来ます。
dokanとdokan-rubyをダウンロードして、dokan.sys dokan.dll mounter.exe dokan_lib.so dokanfs.rbを同じディレクトリに置いて、次のようなプログラムを書きます(dokan-ruby\sample\hello.rbにあります)。

require 'dokanfs'
class Hello
  def initialize
    @msg = "hello, world"
  end
  def contents path
    ["hello.txt"]
  end
  def file? path
    path  =~ /hello.txt/
  end
  def directory? path
    path == "/"
  end
  def read_file path
    @msg
  end
  def size path
    @msg.length
  end
end     

FuseFS.set_root(Hello.new)
FuseFS.mount_under("r")
FuseFS.run

実行してみます。

  > ruby hello.rb

すると、Rドライブが作成され、Rドライブを開くとhello.txtというファイルがあります。これを開くとhello,worldと書かれています。アンマウントするには、

  > dokanctl.exe /u r

を実行します。
Dokan Rubyを使うと、非常に手軽にファイルシステムが作成出来ます。ぜひみなさんも、Rubyを使用してオリジナルファイルシステムを作ってみてください。
hello, world - dokan ruby

3 Responses to “25行でファイルシステム”

  • california costa mesa government jobs
    March 8th, 2011 at 12:47 pm

    Employment JObs…

    [...]here are some links to sites that we link to because we think they are worth visiting[...]…

  • cheap ASICS shoes
    July 15th, 2011 at 6:23 pm

    Nice article , thank you for sharing your article. I genuinely enjoyed it. I place a url to my website to right here so other group men and girls can research it.

  • coogi clothing
    July 16th, 2011 at 2:55 pm

    Hi, I have been searching everywhere for a tutorial on making fabric covered rings. This is the closest thing Ive found. Any suggestions on turning it into a ring? Also, where did you get your kit? Thank you!!