Super Block

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

/*Program to read the super block of a UNIX device*/ #include<fcntl.h> #include<stdio.h> #include<sys/types.h> #include<time.

h> struct super { unsigned long s_inodes_count; /* Inodes count */ unsigned long s_blocks_count; /* Blocks count */ unsigned long s_r_blocks_count; /* Reserved blocks count */ unsigned long s_free_blocks_count; /* Free blocks count */ unsigned long s_free_inodes_count; /* Free inodes count */ unsigned long s_first_data_block; /* First Data Block */ unsigned long s_log_block_size; /* Block size */ signed long s_log_frag_size; /* Fragment size */ unsigned long s_blocks_per_group; /* # Blocks per group */ unsigned long s_frags_per_group; /* # Fragments per group*/ unsigned long s_inodes_per_group; /* # Inodes per group */ unsigned long s_mtime; /* Mount time */ unsigned long s_wtime; /* Write time */ unsigned s_mnt_count; /* Mount count */ signed s_max_mnt_count; /* Maximal mount count */ unsigned s_magic; /* Magic signature */ unsigned s_state; /* File system state */ unsigned s_errors; /* Behaviour when detecting erro rs */ unsigned s_minor_rev_level; /* minor revision level */ unsigned long s_lastcheck; /* time of last check */ unsigned long s_checkinterval; /* max. time between checks */ unsigned long s_creator_os; /* OS */ unsigned long s_rev_level; /* Revision level */ unsigned s_def_resuid; /* Default uid for reserved bloc ks */ unsigned s_def_resgid; /* Default gid for reserved bloc ks */ unsigned long s_first_ino; /* First non-reserved inode */ unsigned s_inode_size; /* size of inode structure */ unsigned s_block_group_nr; /* block group # of this superbl ock */ unsigned long s_feature_compat; /* compatible feature set */ unsigned long s_feature_incompat; /* incompatible feature set */ unsigned long s_feature_ro_compat; /* readonly-compatible feature s et */ // unsigned char s_uuid[16]; /* 128-bit uuid for volume*/ char s_volume_name[16]; /* volume name */ char s_last_mounted[64]; /* directory where last mounted */ unsigned long s_algorithm_usage_bitmap; /* For compression */ char s_prealloc_blocks; /* Nr of blocks to try to preall ocate*/ char s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ // unsigned s_padding1; unsigned long s_reserved[204]; /* Padding to the end of the blo ck */ }; main(){ int i,fd; char temp[1024]; struct super *superblk;

fd=open("/dev/mapper/VolGroup00-LogVol00",O_RDONLY); sync(); lseek(fd,1024,0); read(fd,temp,1024); printf("hi%s",temp); superblk=(struct super *)temp; printf("\nSize of superblock %d",sizeof(superblk)); printf("\nInode count %lu",superblk->s_inodes_count); printf("\nBlocks count %lu",superblk->s_blocks_count); printf("\nReserved blocks count %lu",superblk->s_r_blocks_count); printf("\nFree blocks count %lu",superblk->s_free_blocks_count ); printf("\nFree inodes count %lu",superblk->s_free_inodes_count ); printf("\nFirst Data Block %lu",superblk->s_first_data_block); printf("\nBlock size %lu",superblk->s_log_block_size); printf("\nsize of inode structure %u",superblk->s_inode_size); printf("\nMount time %s",ctime(&superblk->s_mtime)); printf("\nWrite time %s",ctime(&superblk->s_wtime)); printf("\nvolume name %s",superblk->s_volume_name[16]); printf("\ndirectory where last mounted %s",superblk->s_last_mounted[64]) ; printf("\n creator os %lu",superblk->s_creator_os); printf("\n magic signature %u",superblk->s_magic); printf("\n"); close(fd); }

You might also like