CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2007
    Posts
    56

    Question Creating a simple File System

    Hi everyone,

    I have to ask a favour. I understand a lot of forums do not wish to help with school assignments and I agree, however I ask your indulgence to at least read my problem and if you feel you can assist without answering the problem for me I would appreciate it. I am not looking for someone to give me the solution or do the work for me, but I am completely lost. I am taking a Operating system class at University right now. My prof is less than ideal for assistance or even passing on knowledge so I need to look elsewhere.

    My project requires I create a simple file system. The type will be flat file so no directories are required. It is to work in Linux (note: if you can only assist from a windows point of view I will take what I can and make it work somehow) which also adds to my plight because I am a windows user and developer. I have barely worked in Linux except in school. At work I develop in mostly a Visual Studio environment. So anyways, Simple Flat File file system, for Linux and written in C++. Also, not my strong suit (I am more of a VB developer).

    Some details: Will be using a blocksize of 256 bytes. Overall, size is dependant on our choice. Need a least to perform basics (create a file, open, write to, delete, list all files, etc). I have a good idea about how I want to do that. I even have a good idea how I am going to build my allocation table into my program. Where I am completely lost is how to format the file system, tell it that fileA is using these blocks, and fileB is using these blocks or how to say "Ok, so part 1 of fileA is in block 44 and part 2 is in block 68 and part 3 is in 99. So let's put them together and load up the file" Basically I am not sure how to manage the data.

    I have read a lot about SuperBlocks, but haven't had a chance to research them as of yet (next on my list). I understand they should be used or can be used. I have downloaded the current version of linux and taken a look at a couple of small filesystems on there, but am feeling pretty lost. I was hoping someone might be able to give me a good starting point or point me to a good website with information I could use.

    Please, I am quite lost here and this project is 30% of my mark. I appreciate any assistance you can provide. Again, I am not looking for you to write this for me, but even a few code snippits or some descriptions in layman's terms would be very appreciative.


    Thank you very much

  2. #2
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Creating a simple File System

    Well.
    I didn't pay much attention in Operating Systems I guess because I don't know much about file systems. Here is how I would do it.

    Code:
    Allocation table
    Filename     Location of first block    Length of first block
    myfile          0                                 5
    myotherfile     6                                 3
    You could probably use a vector for this

    in your file system
    Code:
    Block 0 - 4, part of myfile
    Block 5, a continuation pointer, essentially making a linked list
         Location of next block       length
         9                             6
    Block 6 - 8, part of myotherfile
    Block 9 - 15, continuation of myfile
    I really don't know much about file systems though.

  3. #3
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: Creating a simple File System

    Is the size of the flat file constant or does it grow if necessary?
    - Guido

  4. #4
    Join Date
    Mar 2007
    Posts
    56

    Re: Creating a simple File System

    To keep things as simple as possible, the file size will be static.

    Thanks

  5. #5
    Join Date
    Mar 2007
    Posts
    56

    Re: Creating a simple File System

    Quote Originally Posted by ninja9578 View Post
    Well.
    I didn't pay much attention in Operating Systems I guess because I don't know much about file systems. Here is how I would do it.

    Code:
    Allocation table
    Filename     Location of first block    Length of first block
    myfile          0                                 5
    myotherfile     6                                 3
    You could probably use a vector for this

    in your file system
    Code:
    Block 0 - 4, part of myfile
    Block 5, a continuation pointer, essentially making a linked list
         Location of next block       length
         9                             6
    Block 6 - 8, part of myotherfile
    Block 9 - 15, continuation of myfile
    I really don't know much about file systems though.

    I actually have things designed so that my allocation table is filename; block-in-filesystem; block-in-file, ex. Say block A it's contents spread over 3 blocks. It's blocks are in position 3, 4, 6. The allocation table woul be something like:

    Code:
    fname           fsblock        fileblock
    unallocated       1                 
    somefile          2                   1
    FileA             3                   1
    FileA             4                   2
    somefile          5                   2
    FileA             6                   3
    When the file system loads the data is thrown into a struct array to be used by other processes. Where I am lost is, say someone wants to open FileA. How do I load the individual blocks into memory to create the file to open? These are things I take for granted each day during my normal programming cause it is done for me already. I don't know how I will design it to be done.


    Thanks for your input.

  6. #6
    Join Date
    Apr 2009
    Posts
    598

    Re: Creating a simple File System

    How do I load the individual blocks into memory to create the file to open?
    You scan your table, looking for the address of the first block for the given file. You read a block by issuing a call to the disc driver. Then you look for the address of the second block in your table, and load it by issuing a new call to the disc driver, etc.

  7. #7
    Join Date
    Mar 2007
    Posts
    56

    Re: Creating a simple File System

    Quote Originally Posted by olivthill2 View Post
    You scan your table, looking for the address of the first block for the given file. You read a block by issuing a call to the disc driver. Then you look for the address of the second block in your table, and load it by issuing a new call to the disc driver, etc.
    Then I just link them together and I have my file that I can display to the screen, update etc?

    Think I am getting an idea of how to do this now.

    Thanks.

    Any other suggestions please keep them coming. I will appreciate all I can get.

  8. #8
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Creating a simple File System

    I would certainly recommend looking at FAT-16.
    The table is very simple: you have an array of 16-bit words, one for each allocation unit in your file system.
    Then you have your directory, also a simple array of fixed-size file name (remember DOS’s 8.3?), optional attributes and a FAT index of the first allocation unit used by the file.
    Each entry in FAT has either an index of the next unit used by file or some special marker (like 0 for the end-of-file block, 0xFFFF for unallocated blocks, some other markers for bad blocks, etc.).
    Directory listing becomes trivial.
    Formatting will simply consist of initializing of FAT and clearing the directory.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured