LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Defragmenting files.. (https://www.linuxquestions.org/questions/programming-9/defragmenting-files-26132/)

udayan 07-19-2002 06:53 AM

Defragmenting files..
 
Hi,
We were trying to defragment a filesystem (Ext2) from the user mode on Linux RedHat 7.0.
This is what we did for every file(only regular)-
1. From the user mode we opened the hard disk.
2. Read the inode bitmap to find if the inode is allocated.
3. Found the block numbers that were allocated to it by reading the inode bitmap table.
4. Found required number of free data blocks from Block Bitmap.
5. Copied the data from the source block to the required block.
6. Updated the block bitmap table to appropriate flags.
7. Updated the inode table to the required block numbers.


But the point is on rebooting the system is crashing ..

One idea that struck me is when we are switching off the system then the kernel copies the data back from the kernel buffer to the hard disk. Its possible that system crashed due to this reason.

Ne ideas..
thanx..

Mik 07-19-2002 07:45 AM

Have you gone to singleuser mode before running the program which does this? There shouldn't be any other programs which access the filesystem running when you are changing this.

I don't know all the details of how an ext2 filesystem works. But I thought it was possible for an inode to not only point directly to a data block but also to another inode which points to a bunch of blocks. Making it possible to get a tree structure. So you would probably have to do more then you are describing there.

But why would you want to defragment an ext2 filesystem? It's designed to keep fragmentation to a minimum.

udayan 07-19-2002 08:15 AM

well what we are trying is for files having block size less than 4096 x 12 bytes..

Now what we tried was that we made two partitions and from the active one we defragmented the inactive partition but when we mounted the partition the we got following errors:


EXt2-fs error (device sd(8,17)):ext2_check_block_bitmap: Block bitmap for group number 7 is marked free

EXt2-fs error (device sd(8,17)):ext2_check_inode_bitmap: wrong free inode count in super block, stored = 55360, counted = 69882

EXt2-fs error (device sd(8,17)):ext2_check_inode_bitmap: Block #283 of the inode table in group 0 is marked free.


well we are trying to understand the linux ext2 filesystem completely and trying some experiments on it..
ne ideas.. whats happeneing..:Pengy:


All times are GMT -5. The time now is 06:14 PM.