0

I am trying to build a bash like script provides some functionalities such as ls,pwd,cat etc. working on NTFS in a linux system. Suppose that I have an NTFS image and I open that as a file with fopen. Then, I read some sectors such as BPB residing at 0x0B and fetched some general info about the NTFS image. I need to reach to the root directory pointer then traverse through the filesystem in order to implement those functions especially for ls and pwd. I google'd a lot about internal details and offsets of NTFS but I could not find out how to achieve the goal. I can not progress further without understandable documentation or samples.

Any help, documentation, hint, offset table etc. would be highly appreciated.

Thank you.

Osman Yildiz
  • 103
  • 4
  • 2
    Rather than re-invent the world, you might wish to get a copy of [Cygwin](http://www.cygwin.com/) If you really want to get in to the gory details, you should find just about everything you need to know about Windows filesystem internals (including, but not limited to, NTFS) from MSDN and SysInternals. – paulsm4 Jun 05 '12 at 21:37
  • 1
    It seems like it would be easier to use `libntfs` or `ntfsprogs` rather than rewrite them from scratch. You're making a lot of extra work for yourself. – Dietrich Epp Jun 05 '12 at 21:38
  • Is there a reason you can't use Linux's NTFS file system driver? – twalberg Jun 05 '12 at 21:42
  • 1
    Most modern Linux kernels can mount NTFS natively, so there's no need to write anything. –  Jun 05 '12 at 21:42
  • Yes, I am aware of that I can achieve that using high level libraries or tools. It is just I am trying to get familiar with the filesystems and I have done the same project on ext3 which I know perfectly right now. Thank you anyway. – Osman Yildiz Jun 05 '12 at 21:46
  • While I won't say "don't re-invent the wheel", I do think the other comment have merit: look at how it was done elsewhere (which magical constants and bit-twiddles, etc). It appears [the specification can be licensed](http://social.msdn.microsoft.com/Forums/en-US/os_standocs/thread/c3ee3c24-dd5a-472d-baa1-8e2e559834e0) (or not). –  Jun 05 '12 at 21:48
  • @pst I am trying to understand the internals of some open source drivers right now but they seem a little bit too complicated for me. – Osman Yildiz Jun 05 '12 at 21:50

1 Answers1

5

I'm guessing this is a learning exercise. So, first:

  1. Writing a bashlike interpreter for a specific filesystem is the wrong thing to do. You should be concentrating on understanding the details of the NTFS filesystem instead.

  2. Writing ls, cat to be able to work with files in a specific filesystem is the wrong thing to do. You should be concentrating on understanding the details of the NTFS filesystem instead.

  3. If you write a filesystem driver (say using FUSE), then the original bash, ls, cat will automatically work with that filesystem. Because the driver will be able to translate system calls like open and read into the filesystem specific procedure.

Finally:

  1. Learn about FUSE. It is awesome. See this Hello World FUSE module. Run it, play with it.

  2. Download the sources for NTFS-3G, which is the NTFS driver used by most GNU/Linux distros these days. It uses FUSE. Learn how it works.

ArjunShankar
  • 23,020
  • 5
  • 61
  • 83