LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-03-2002, 08:53 AM   #1
udayan
Member
 
Registered: Apr 2002
Location: India
Distribution: Linux Redhat 7.0
Posts: 62

Rep: Reputation: 16
problem in : program to find which all data blocks are allocated


#include <linux/module.h>
#include <linux/config.h>
#include <linux/fs.h>
#include <linux/ext2_fs.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <asm/uaccess.h>
#include <asm/fcntl.h>
#include <sys/syscall.h>
#include <linux/sched.h>
#include<linux/string.h>
struct bitmap{
unsigned first : 1;
unsigned second : 1;
unsigned third : 1;
unsigned fourth : 1;
unsigned fifth : 1;
unsigned sixth : 1;
unsigned seventh : 1;
unsigned eighth : 1;
};
static int datablk_major = 211;
static int datablk_open(struct inode *inode, struct file *filp);
int init_module(void);
int datablk_init(void);
void cleanup_module(void);
int datablk_release(struct inode *inode, struct file *filp);
void read_datablk(void);

static struct file_operations datablk_fops ={
NULL, /*lseek*/
NULL, /* Read*/
NULL, /*write*/
NULL, /*readdir*/
NULL, /*select*/
NULL, /*ioctl*/
NULL, /*mmap*/
datablk_open, /*open*/
NULL, /*flush */
datablk_release, /*release*/
NULL,
NULL,
NULL,
NULL,
NULL
};

void read_datablk(void)
{
unsigned long block_count;
unsigned long group_count;
struct ext2_group_desc * gd;
unsigned long block_bitmp_block;
int blocksize = BLOCK_SIZE;
int group_flag,k,block_flag;
struct buffer_head *bh;
kdev_t dev = ROOT_DEV;
struct bitmap * bmp;
struct super_block * sa = get_super(dev);
block_count = sa->u.ext2_sb.s_blocks_per_group;
group_count=sa->u.ext2_sb.s_groups_count;
blocksize = get_hardblocksize(dev);
if(blocksize==0 || blocksize < BLOCK_SIZE)
{
blocksize = BLOCK_SIZE;
}
for (group_flag = 0; group_flag<group_count; group_flag++)
{
if((group_flag % EXT2_DESC_PER_BLOCK(sa)) == 0)
gd=(struct ext2_group_desc *) sa->u.ext2_sb.s_group_desc[group_flag]->b_data;
block_bitmp_block=le32_to_cpu(gd->bg_block_bitmap);
bh=bread(dev, block_bitmp_block, sa->s_blocksize);
bmp=(struct bitmap *)(bh->b_data);
if((block_count % 8 )==0)
k=(block_count/8);
if((block_count % 8 )!=0)
k=((block_count/8)+1);
printk("<1> Block Size = %ld\n",sa->s_blocksize);
for(block_flag=0;block_flag<k;block_flag++)
{
if(bmp->first ==1)
{
printk("<1> block allocated %d %d\n ",block_flag,group_flag);
}
else
{
printk("<1> block unallocated%d %d\n ",block_flag,group_flag);
}
if(bmp->second ==1)
{
printk("<1> block allocated ");
}
else
{
printk("<1> block unallocated ");
}
if(bmp->third ==1)
{
printk("<1> block allocated ");
}
else
{
printk("<1> block unallocated ");
}
if(bmp->fourth ==1)
{
printk("<1> block allocated ");
}
if(bmp->fifth ==1)
{
printk("<1> block allocated ");
}
else
{
printk("<1> block unallocated ");
}
if(bmp->sixth ==1)
{
printk("<1> block allocated ");
}
else
{
printk("<1> block unallocated ");
}
if(bmp->seventh ==1)
{
printk("<1> block allocated ");
}
else
{
printk("<1> block unallocated ");
}
if(bmp->eighth==1)
{
printk("<1> block allocated ");
}
else
{
printk("<1> block unallocated ");
}

}
}
}
static int datablk_open(struct inode *inode, struct file *filp)
{
MOD_INC_USE_COUNT;
read_datablk();
printk("<1>\n Device Opened");
return 0;
}

int init_module(void)
{
printk("<1>Module initialised\n");
datablk_init();
return 0;
}

int datablk_init(void)
{
int result_datablk;
result_datablk=register_chrdev(datablk_major, "testdata11", &datablk_fops);
printk("<1>Registered\n");
if(result_datablk <0)
{
printk("<1>SDRV : Can't get Major %d\n",datablk_major);
return -EIO;
}
return 0;
}
void cleanup_module(void)
{
unregister_chrdev(datablk_major,"testdata11");
printk("<1>\nDevice Unregistered");
}
int datablk_release(struct inode *inode, struct file *filp)
{
MOD_DEC_USE_COUNT;
return 0;
}



Hi
i made this program to find which all data blocks are allocated or unallocated in the ext2 filesysem on my Linux 7.0 version. But i found that this program gives all the blocks as allocated.?? any comments . why is this happeneing whereas i have checked that there are data blocks that are free..

 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Data Recovery Program ghrmn Linux - Software 0 10-08-2003 07:37 AM
can't find data mcd Linux - Software 1 08-12-2003 12:12 AM
Data Logger Program viciousfish Linux - Software 3 01-26-2003 11:42 AM
data blocks in ext2fs udayan Programming 1 07-07-2002 04:42 PM
problem in getting free data blocks in filesystem udayan Programming 4 07-07-2002 01:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration