0% found this document useful (0 votes)
90 views2 pages

Super Block

This C program reads and summarizes the contents of the super block of a UNIX file system. It opens the specified device, reads the first 1024 bytes which contains the super block, and then prints out key fields like the inode count, block count, free block count, volume name, mount time, and magic signature. This provides an overview of metadata stored in the file system super block.

Uploaded by

Tapas Trivedi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views2 pages

Super Block

This C program reads and summarizes the contents of the super block of a UNIX file system. It opens the specified device, reads the first 1024 bytes which contains the super block, and then prints out key fields like the inode count, block count, free block count, volume name, mount time, and magic signature. This provides an overview of metadata stored in the file system super block.

Uploaded by

Tapas Trivedi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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