[Ocfs-tools-devel] The tool to find where the data reside in devices

Sunil Mushran Sunil.Mushran at oracle.com
Wed Sep 22 14:50:57 PDT 2004


We don't have a easy-to-use user space library for ocfs like ext3.
However, we will have that for ocfs2, if we don't already.

If you are only interested in getting the fileoffset to diskoffset
mapping, do:

debugocfs -F /relative_path_to_file /dev/XX

On Wed, 2004-09-22 at 14:34, y huang wrote:
> Trying to write a program to map a OCFS file or file
> system to devices level, i.e. giving a file or file
> system, the program tells where (offsets of the
> devices) all the data reside. Anyone has written such
> program. The following is the simple code for EXT3:
> 
> #include "sb_ext3.h"
> #include "gd_ext3.h"
> #include "inode_ext3.h"
> #include <stdio.h>
> #include <fcntl.h>
> 
> main(int argc, char *argv[])
> {
>         int fd, i;
>         struct ext3_super_block sb;
>         struct ext3_group_desc gd;
>         struct ext3_inode inode;
> 
>         if(argc!=2)
>         {
>                 printf("Usage:  %s
> file_system_dev_name\n");
>                 exit(1);
>         }
> 
>         if((fd=open(argv[1],O_RDONLY))<0)
>         {
>                 printf("Could not open
> %s.\n",argv[0]);
>                 exit(1);
>         }
> 
>         lseek(fd,1024,0);
>         if(read(fd,&sb,sizeof(sb))!=sizeof(sb))
>         {
>                 printf("Could not read super
> block\n");
>                 exit(1);
>         }
> 
>         printf("Inode count is
> %d\n",sb.s_inodes_count);
>         printf("Block count is
> %d\n",sb.s_blocks_count);
>         printf("Reserved block count is
> %d\n",sb.s_r_blocks_count);
>         printf("Free block count is
> %d\n",sb.s_free_blocks_count);
>         printf("Free inode count is
> %d\n",sb.s_free_inodes_count);
>         printf("Fisrt data block is
> %d\n",sb.s_first_data_block);
>         printf("Block size is
> %d\n",sb.s_log_block_size);
>         printf("Blocks per group is
> %d\n",sb.s_blocks_per_group);
>         printf("Inodes per group is
> %d\n",sb.s_inodes_per_group);
> 
>         lseek(fd,4096,0);
>         if(read(fd,&gd,sizeof(gd))!=sizeof(gd))
>         {
>                 printf("Could not read group
> descriptor\n");
>                 exit(1);
>         }                                             
>                  
>         printf("Blocks bit map is at
> %d.\n",gd.bg_block_bitmap);
>         printf("Inodes bit map is at
> %d.\n",gd.bg_inode_bitmap);
>         printf("Inode table starts at
> %d.\n",gd.bg_inode_table);
>         printf("Free block count in this BG is
> %d\n",gd.bg_free_blocks_count);
>         printf("Free inode count in this BG is
> %d\n",gd.bg_free_inodes_count);
>         printf("Used dirs count in this BG is
> %d\n",gd.bg_used_dirs_count);
> 
> 
>         printf("\n\nHere is inode 382
> information...\n");
>         lseek(fd,((4096*4)+(381*128)),0);
>         read(fd,&inode,sizeof(inode));
> 
>         printf("The owner is %d\n",inode.i_uid);
>         printf("The size is %d\n",inode.i_size);
>         printf("Data blocks are:\n");
>         for(i=0;i<15;i++)
>         {
>                 if (inode.i_block[i] == 0)
>                         break;
>                 printf("   Logical %d =
> %d\n",i+1,inode.i_block[i]);
>         }
>         close(fd);
> 
> }           
> 
> 
> 
> 
> 		
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail Address AutoComplete - You start. We finish.
> http://promotions.yahoo.com/new_mail
> _______________________________________________
> Ocfs-tools-devel mailing list
> Ocfs-tools-devel at oss.oracle.com
> http://oss.oracle.com/mailman/listinfo/ocfs-tools-devel




More information about the Ocfs-tools-devel mailing list