Solved

Minix free zones

Posted on 2003-11-09
10
487 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
 

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
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.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

747 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

12 Experts available now in Live!

Get 1:1 Help Now