Solved

Minix free zones

Posted on 2003-11-09
10
493 Views
Last Modified: 2010-04-21
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
Comment
Question by:thegameskeeper
  • 5
  • 5
10 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9720408
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
 

Author Comment

by:thegameskeeper
ID: 9726303
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
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9730198
>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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:thegameskeeper
ID: 9733367
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
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9747071
>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
 

Author Comment

by:thegameskeeper
ID: 9754082
how do i output the super block information using C language
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9761499
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
 

Author Comment

by:thegameskeeper
ID: 9766485
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
 
LVL 45

Accepted Solution

by:
sunnycoder earned 400 total points
ID: 9769666
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
 

Author Comment

by:thegameskeeper
ID: 9774226
thanx SUNNYCODER have a look at this                     http://www.experts-exchange.com/Operating_Systems/Q_20799661.html
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CPU monthly average? 12 130
text in table need to be center of the box 4 81
bash while loop reading input from data section in script 7 71
Bash Script to Analyze Oracle Schemas 11 117
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

789 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