Minix free zones

i am trying to develop a code to show all the free zones in a given minix file system, should i be using the bitmap or not if so how?
thegameskeeperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sunnycoderCommented:
using bitmaps may infact be the best way.... you already have the information in the super block
let each block be represented by a bit ... bit = 0 means free and bit = 1 means taken
0
thegameskeeperAuthor Commented:
but i want the user to enter the filesystem in command line so how do i take this argument and get the bitmap to read from it.
0
sunnycoderCommented:
>the user to enter the filesystem in command line
>so how do i take this argument and get the bitmap to read from it.
I do not understand what you are trying to ask ... can you elaborate a bit
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

thegameskeeperAuthor Commented:
well the my program should take a file system as an argument, then the program should list all the free block(zones) on that file system. I have been doing more research, i think i sould be using the readfs.c which is part of minix, hope that helps
0
sunnycoderCommented:
>i think i sould be using the readfs.c which is part of minix,
yes you have to use the functions as an interface

>then the program should list all the free block(zones) on that file system
Some information regarding this is contaied in the superblock ... as far as I remember, it had some free zone member ... look for struct of superblock
the system is already maintaining the required information ... you just need to retrieve it and show it in a desirable format
0
thegameskeeperAuthor Commented:
how do i output the super block information using C language
0
sunnycoderCommented:
struct super s;
FILE * dev;

dev = fopen ( "device_on_which_you_have_filesystem", "r" );

fread ( &s, sizeof (struct super), 1, dev );

super block will be the first block on the disk (for that fs )...

the names of the struct may not be exactly super, check the header file for exact name and format
0
thegameskeeperAuthor Commented:
s_nzones //free data blocks
s_zmap_blocks //small list of free data block numbers

how and which do i use if i want to produce a list like this for example
block
1    free
2    used
3  free
..

what should i write as the if statement
e.g
for (i=? ; i < ? ; i++)
if(? = 1)
printf("block %d",i is used)
etc..
0
sunnycoderCommented:
I do not remember the exact format ... look up the documentation ... assuming that these fields are bitmaps 0th bit represing 0th block, 1st bit representing first block and so on (there was no 0 block ... was there ? )...

0  0  0  1  0  0  0  0  0  1  0  0  1  1  1  0  0  1  1  1  0
0  1  2  3  4  5  6  7  8  9 10 .....

your code would be like

for ( i = 0; i <= NUM_BLOCKS; i++ )
{
         if (  (curr << i) & 0x80000000 )
                  printf ( "%d   used\n", i );
         else
                  printf ( "%d   free\n", i );
}

curr is assumed to be 4 bytes (int/unsigned int) .... if you read 4 bytes at a time into an unsigned int , then it would be organized as

for ( i = 0; i <= NUM_BLOCKS/(sizeof(int)*8) ; i++ )
{
         //read next 4 bytes into curr

         for ( j = 0; j < sizeof(int) * 8; j++  )
         {
                 if (  (curr << i) & 0x80000000 )
                       printf ( "%d   used\n", i );
                 else
                       printf ( "%d   free\n", i );
         }
}

ofcourse code can be optimized by
1. using bigger size quantities (long, long long)
2. saving value of curr in inner loop ... that will necessiate only one shift per iteration
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thegameskeeperAuthor Commented:
thanx SUNNYCODER have a look at this                     http://www.experts-exchange.com/Operating_Systems/Q_20799661.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.