Thread: Some (Much) help for implementing a flat filesystem

  1. #1
    Registered User Phoenix_Rebirth's Avatar
    Join Date
    Dec 2005
    Location
    Cyprus
    Posts
    68

    Some (Much) help for implementing a flat filesystem

    So I have to implement a flat file system for an assignment I have where I have to make a shell of some kind in which the user has some functions he can use for creating and managing a file system. I gave to also make a file service, a block service and a directory service.
    I made my shell where the user can call some functions (my_mkfs my_mount my_unmount my_quit my_help my_ls my_cp my_mv my_rm( my_df my_cat my_echo ).
    The user decides when calling my_mkfs how many blocks and what size each block has to make the disk (i.e 10240 blocks of 1024 bytes each = 10MB). The block service has to move everything in blocks. So I did up to the point I create the file which will be my file system.
    Now I am stucked. I know I am supposed to create the superblock where I will store my basic structures (a table which will indicate if a block is being used or not so char bitmap[blocks], a file allocation table where each cell is a block and has the index for the next block where the file being stored is continued or EOF if it is the last block - I will use a global index like in dos where it is loaded in ram so int FAT[blocks] and a directory table where I have my records of all the files in my file system)
    but I dont have any idea of how to do anything. Is there any tutorial or any link of how to proceed.

    Currently I am between writing the above directly into the "disk" and since I know how much space it will take to have all the read/write function for data to being done after the
    or making files for these where I store them like any file but I have them hidden... In any case I am stucked as to how I am supposed to write in blocks...
    And how am I to write them? I think that the write function works with char pointers right? Is there any way to write the structures themselves?
    Last edited by Phoenix_Rebirth; 02-02-2009 at 09:22 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So, what sort of a design do you have for this exercise?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User Phoenix_Rebirth's Avatar
    Join Date
    Dec 2005
    Location
    Cyprus
    Posts
    68
    The file system will support certain number of files and the file name will also have a limited length. Free space will be managed by a file allocation table and will have to hand over an API, a library, utilities used by a basic shell. The file system is comprised by a Directory Service, File Service and Block Service. At the highest level the user will issue commands in the shell which will call functions from the directory and file service which in turn will call functions from the block service where they are responcibe for moving to/from the "virtual" disk.
    The shell will be very basic and will show a prompt where the user can input commands. Commands supported will be: my_mkfs, my_ls, my_cp, my_mv, my_rm,
    my_df, my_cat, my_echo, my_mount, my_umount, my_help, my_quit.

    Directory Service will correspond ufid with filenames. It will be a flat file system without access control. Directory service will offer the following methods
    • int my_files (char **filenames);
    • int my_create (const char *filename); create a new file with 0 bytes as size
    • int my_delete (const char *filename);
    • int my_open (const char *filename);

    File Service:
    • int my_close (int ufid);
    • int my_file_size (int ufid);
    • int my_read (int ufid, char *buf, int num, int pos);
    • int my_write (int ufid, char *buf, int num, int pos);

    The file system will have to conserve some basic structures for servicing requests using block service functions. These will be DIrectory table, file allocation table, free block list and file descriptor table. The first three will be stored on the disk and will be loaded on main memory when mounting the system and will be written when unmounting with their changes. The last will be only on the main memory
    Directory Table: filename, size, fat index(first block of file on disk)
    File Allocation Table: global index; int fat[nu,ber of blocks] Each cell/block contains the index for the next block of the file or eof if last one
    Free Block List: char [number of blocks] ; 1:used, 0:unused
    File Descriptor Table: ufid, directory table index

    The disk which is a huge file defined by the user when calling my_mkfs(blocks, blocksize)
    Block Service will supply functions for allocation, deallocation, read and write of a
    block. They will be used by the Directory and File Services
    For bringing the blocks and writing them lseek(), read() and write() from UNIX will be used. We will lseek() in block sizes.

    This is what I have done up to now "http://www.4shared.com/file/83812550/b371d6a5/filesystem.html" which are only the shell recognizing the commands used and I begun trying to make the services but after creating the file/disk I am stucked. I try to make the functions for creating and writing the files but I cant see to grasp how the blocks are written. I mean A file is created with 0 bytes so it's just a record for the time being. Then I open the file. When I write in it do I store the writing in a buffer of sorts in main memory and when closed I calculate the size and accordingly find blocks and write on them. Then I will have to have a large buffer in main memory. And even so say my block size is 512 bytes and I have opened a file where I wrote data worth 1000 bytes how dow I write them in the blocks. I mean how do I write first the first 512 and then only the remaining 498. Also the write works with a poitner to char right.
    And also about the basic structures I want to save which are not character but are int or structs how dow I write them as files...

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It is probably a good idea if you post DIRECT questions - right now, it's hard to know how much you understand and what you need to know.


    So, just like any other file-system, you will have to work in blocks. Appending to a file that is 1000 bytes in a system with 512 byte blocks will mean that you have to read block 2 into memory, add the new data to the 1001st byte of the file, and write back the 512 byte block (and perhaps also another (set of) block(s)).

    Each block is X bytes (equivalent to X char). To write arbitrary data, you need to cast the address of the struct (etc) that holds the data into a char * - just like you would if you were to use fwrite() or fread().

    The next problem consist in knowing which block to write to - that's when your free-list (or whatver you may call it) comes in.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need to know the filesystem on /dev/sda1
    By amit_sahrawat in forum Linux Programming
    Replies: 7
    Last Post: 12-13-2007, 05:29 AM
  2. Filesystem monitoring question
    By rools in forum Linux Programming
    Replies: 2
    Last Post: 11-18-2005, 12:09 PM
  3. flat menu problem
    By valis in forum Windows Programming
    Replies: 0
    Last Post: 07-11-2005, 03:29 PM
  4. Lopping through flat files
    By guestquestion in forum C Programming
    Replies: 5
    Last Post: 06-08-2003, 11:40 AM