Solved

files &&  file systems

Posted on 2004-04-05
18
214 Views
Last Modified: 2010-04-21
Hi Guys,
I am totally new in programming with C i have few more questions:
1. )How can i check total file length is small enough to be
           represented in MAX_BLOCKS_PER_FILE (known)?

 2.) How can i check there is a free inode

 3.) How can i check there is room in the directory

 4.) How can i update my structure( bitmap, directory, inode, datablocks, superblock) after theses  operations  
Note: I am operating between linux file system and my own file syst. composed of:
SuperBlock
Bit Map
Root Directory
Inodes
DATA Blocks
Thanks
0
Comment
Question by:achille67
  • 8
  • 5
  • 2
18 Comments
 
LVL 12

Expert Comment

by:stefan73
ID: 10757292
1) With ext2fs, this is probably more than HDs than you can mount in your PC :-)
   AFAIK, max file size is 32bit for block x 1K block size = 2^42 = 4TB. 3rd level indirect block should also be sufficient for this.

2.) with "df" command.

3.) There is. As long as you have space on HD and inodes. Directories can grow VERY big.

4) What do you want to do with that?

0
 

Author Comment

by:achille67
ID: 10757693
Thanks Stefan73, but i don't think i make myself clear enough:
The idea is if creat my file own file system in the directory "userfs" using for example the command: ./userfs -reformat 800000 file.system
and that file system has the following structure:
SuperBlock
Bit Map
Root Directory
Inodes
DATA Blocks
Thanks,
1. )How can i check total file length is small enough to be
           represented in MAX_BLOCKS_PER_FILE (known)?

 2.) How can i check there is a free inode

 3.) How can i check there is room in the directory

 4.) How can i update my structure( bitmap, directory, inode, datablocks, superblock) after theses  operations  


0
 
LVL 12

Expert Comment

by:stefan73
ID: 10757920
0
 

Author Comment

by:achille67
ID: 10759885
hey Stefan
this is very broad and there is no specific answers to my questions. I really appreciate it if you porvide me with some pseudocode.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10763379
1. )How can i check total file length is small enough to be
           represented in MAX_BLOCKS_PER_FILE (known)?

In linux filesystem or your own ? If in linux, you can use fstat() or stat() to get the filesize and you can carry out the comparison ... If in your iwn, then you need to maintain the filesize information explicitly or you can calculate it whenever required ... for a file of length n blocks, size on disk will be n * block size and file size will be n-1 * blocksize + bytes occupied in the last block

 2.) How can i check there is a free inode
You have to maintain a bitmap or some sort of data-struture to keep track of free and used inodes

 3.) How can i check there is room in the directory
You mean in a filesystem? Unless you have quotas, you can put as much in a directory as the disk space would permit you to !! Room in a filesystem will depend on how many free blocks you have and you have to keep track of blocks .... free space = number of free blocks * block size

 4.) How can i update my structure( bitmap, directory, inode, datablocks, superblock) after theses  operations  
let us see that data structures you are using

I would suggest that you take off sometime for reading some simple filesystems such as those used in nachos or minix
0
 

Author Comment

by:achille67
ID: 10773687
thanks sunnycoder,
as you recommended i did some reading again, the concept is a little tricky to capture(i am new in this)

1.) thanks for question 1.)
2.)i am using a simple array. could you please give me some pseudocode?
3.) You mean in a filesystem? yes i mean my own file system i allocate by running the command: ./userfs -reformat disk_size file_name
where userfs is the directory in which i am working. Angain some pseudocode will help better?
4.)Let us see that data structures you are using: after executiong
./userfs -reformat disk_size file_name my filesystem looks like this:

SuperBlock
Bit Map
Root Directory
Inodes
DATA Blocks

The detail of the homewok i am solving can be found on page:
http://www.clarkson.edu/~jnm/os/homework/userfs/fs.htm
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10773822
>2.)i am using a simple array. could you please give me some pseudocode?
I will prefer not to give pseudocode... logic development and research are integral parts of assignments of this level ... You are using array of what? ints/chars or an array of chars as a bitmap ?

>3.) You mean in a filesystem? yes i mean my own file system i allocate by running the
>command: ./userfs -reformat disk_size file_name
>where userfs is the directory in which i am working. Again some pseudocode will help
>better?
This information again will be held in your data structures ... It is requirements like these which define the data structures you should be using ... If you are aware that you need to calculate remaining disk space often, you should either devise data structures which always hold this information up-to-date (deletion, creation, append etc. will modify this) or devise such data structures which will allow you to calculate the remaining space in a very short period of time

>4.)Let us see that data structures you are using: after executiong
>./userfs -reformat disk_size file_name my filesystem looks like this:
Data structures would be the structs and unions which you would have written to hold the information that must reside in each of these compenents ... e.g. where do you hold the information that makes a superblock
It is that that information that you should be working on first ...

You need to start *working* towrads the solution and I can help you refine it
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:achille67
ID: 10782555
Hi sunnycoder,
thanks for your help.
>2.You are using array of what? ints/chars or an array of chars as a bitmap ?
in the u_import i am using an array BIT bit_map[BIT_MAP_SIZE] where
BIT is defined as #define BIT  unsigned -------> so an array of assigned bit.


---- Given the overall problem(http://www.clarkson.edu/~jnm/os/homework/userfs/fs.htm) and the implementation of u_import that i have so far(see below) do u think i am on right path?
int u_import(char* linux_file, char* u_file)
{


        int free_space;
        int num_block;
        struct stat st;
        int file_size=0;
        int remainder=0;
        int i;
        int j;

        free_space = u_quota();

        handle = open(linux_file,O_RDONLY);
        if ( -1 == handle ) {
                printf("error, reading file %s\n",linux_file);
                return 0;
        }

        fstat(handle,&st);
        file_size=(int)st.st_size;
        num_block=(int)file_size/BLOCK_SIZE_BYTES;
        if((num_block*BLOCK_SIZE_BYTES)!=file_size)
          {
            num_block++;
            remainder=file_size-(num_block*BLOCK_SIZE_BYTES);
          }
 /* check there is enough free space */

        /* check file name is short enough */


        /* check total file length is small enough to be
           represented in MAX_BLOCKS_PER_FILE */
        assert(sizeof(BIT)* BIT_MAP_SIZE <= BLOCK_SIZE_BYTES);
        /* check there is a free inode */

        /* check there is room in the directory */
        assert(sizeof(dir_struct) <= BLOCK_SIZE_BYTES);

        /* then update the structures: what all needs to be updates?
           bitmap, directory, inode, datablocks, superblock(?) */
        assert(sizeof(superblock) <= BLOCK_SIZE_BYTES);

        /* what order will you update them in? how will you detect
           a partial operation if it crashes part way through? */


        for(i=0;i<num_block;i++)
          {
            lseek(handle,BLOCK_SIZE_BYTES*i,SEEK_SET);
             read(handle,&buffer,BLOCK_SIZE_BYTES);
    //      crash_write(virtual_disk, bit_map, sizeof(BIT)*BIT_MAP_SIZE );

             // bit_map[i] array and finds the next available free bitmap
             //position lseek to that place with
                     for (j=0; j< BIT_MAP_SIZE; j++){
             assert( free_space >= 1);
               allocate_block(i);

                 lseek(virtual_disk,BLOCK_SIZE_BYTES,SEEK_SET);

                     }


               crash_write(virtual_disk, &buffer, BLOCK_SIZE_BYTES);

             //MARK bit_map that which you wrote in as not free
             //ADD that block to the inode.block[i]
          }

        if(remainder > 0)
          //      all writes same excpet BLOCK_SIZE_BYTES is now remainder
                       crash_write(virtual_disk, &buffer, remainder);
          //write file structure
          //write directory structure


        close(handle);
        close(virtual_disk);
retrun 1;
}
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10782638
>in the u_import i am using an array BIT bit_map[BIT_MAP_SIZE] where
>BIT is defined as #define BIT  unsigned -------> so an array of assigned bit

there has to be little more to it ... unsigned int or unsigned char ? most likely it will be unsigned char .. check again :o)

you are on the right track but there is a lot more to be done ... some observations

>        /* check total file length is small enough to be
>           represented in MAX_BLOCKS_PER_FILE */
>        assert(sizeof(BIT)* BIT_MAP_SIZE <= BLOCK_SIZE_BYTES);
I am not too sure about this check .... sizeof bit * bit_map_size will be the total space occupied by your bitmap ... checking it to be less that or equal to block size translates to checking if the bitmap will fit on a single block !!! It has no relationship with file size !!! .... the result will be the same for 0 byte file and for 10Gb file

then again
>      /* check there is room in the directory */
>        assert(sizeof(dir_struct) <= BLOCK_SIZE_BYTES);
Here you do not check how many entries you have left ... all you see is if sizeof directory struct is less than a block ... this will be true/false irrespective of the space left in the directory !!!

Take a pen and paper and design your assignment before you start coding it ... Designing will take sometime but it will save you a lot of coding time and efforts and you will end up with a better quality filesystem
0
 

Author Comment

by:achille67
ID: 10786519
>there has to be little more to it ... unsigned int or unsigned char ? most likely >it will be
This assign. is a piece of code that i am building on. all was given to me is:
#define BIT  unsigned
and used as:
BIT bit_map[BIT_MAP_SIZE]
also i know this is array is find next available free space and then used lseek( )
to seek to that spot as: lseek(virtual_disk,BLOCK_SIZE_BYTES,SEEK_SET);
To do this search of free space in bit_map[] i was doing the following:
 for (j=0; j< BIT_MAP_SIZE; j++){
             assert( free_space >= 1);
               allocate_block(i);
                 lseek(virtual_disk,BLOCK_SIZE_BYTES,SEEK_SET);
                     }
but i wasn't sure i am doing the right thing.


>Take a pen and paper and design your assignment before you start coding >it ...
 You are right on this, but and i have done so. I think i am still not fully picturing what my file system looks like after i runn the command:
./userfs -reformat disk_size file_name
For instance, after all my reading the following concepts are not clear in my mind.
#define SUPERBLOCK_BLOCK 0
#define BIT_MAP_BLOCK 1
#define DIRECTORY_BLOCK 2
#define INODE_BLOCK 3

 I wish you can provide me with a picture with all this means and what exactly i need to do to implement u_import function.

Thanks sunnycoder.


0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 10805063
I'll give it a try ...

step 1 : break down your problem into smaller pieces such that you can imagine what each piece does ... Keep subdividing until you have reached that level .. leave out the fine low level details for the time being

step 2 : identify the components of your system

step 3 : correlate components with your actions of step 1 and you get the functionality

step 4 : design your data structures, interfaces and functions

step 5 : start with programming

Before you embark with Step 1, you need to do some research and study ... Read about a simple filesystem ... What does it "look" like ... what is the hierarchy ? What is the information maintained ? How it is maintained ? What are the operations permitted ? How are they executed and data structures updated ? *Dig* into that tree structure ... Fortunately there are so many well documented filesystems that you can really learn in short time

It is really not possible to describe file systems in this limited space ... But you must have an idea about what is a superblock ... why we need it ... what does it do ... and so on

I know what I just said is too broad, but first things come first ... If you do not have the complete picture, chences are, what you make may not be what you want
0
 

Author Comment

by:achille67
ID: 10809690
i emailed u at <email-id edited by sunnycoder, Page Editor>, did u get it?

achille67
0
 

Author Comment

by:achille67
ID: 10819689
Hi sunnycoder,
I wannted to know if weather or not someone can finally porvide
me with a correction of this homework that was already due.
http://www.clarkson.edu/~jnm/os/homework/userfs/fs.htm
 i have worked on so hard but still not get it working properly.
i would could then use that solution as a learning model, i will
be willing to pay for the time the expert will spend on it. please
contact me at <email id edited by sunnycoder, Page Editor>

achille67
0
 

Author Comment

by:achille67
ID: 10823779
>Please do not post mail-ids in question threads. EE is searched by spammers for mail->ids and you may end up getting tons of spam. I shall be replying to your mail shortly.

thanks for imforming me this. I am no longer using the email address i used to open this account with EE. my new one is <komla30 at hotmail dot com>
you may update this now.

achille67
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10842738
achille67,

I have already replied to your mail ... Seems like either you missed it or your mail filter has filtered it to bulk or trash

sunnycoder
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
qos on linux 3 88
yum update fails 11 372
tallylog file 2 2,600
Error while installing rpm 1 66
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now