• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 502
  • Last Modified:

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?
0
thegameskeeper
Asked:
thegameskeeper
  • 5
  • 5
1 Solution
 
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
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
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
 
thegameskeeperAuthor Commented:
thanx SUNNYCODER have a look at this                     http://www.experts-exchange.com/Operating_Systems/Q_20799661.html
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now