Inode program in c
On-campus and online computer science courses to Learn the basic concepts of Computer Science.This tutorial will cover c ,c++, java, data structure and algorithm,computer graphics,microprocessor,analysis of algorithms,Digital Logic Design and Analysis,computer architecture,computer networks,operating system.
code in C:#include <stdio.h>
int main()
{
long addr,bsize,singlesize,doublesize,triplesize,directsize,singleend,doubleend,tripleend,blockno,byteno,tempaddr;
printf("Enter block size(kb)\n");
scanf("%ld",&bsize);
bsize*=1024;
printf("Enter the address:\n");
scanf("%ld",&addr);
singlesize=256*bsize;
doublesize=256*singlesize;
triplesize=256*doublesize;
directsize=10*bsize;
singleend=singlesize+directsize;
doubleend=doublesize+singleend;
tripleend=triplesize+doubleend;
if(addr<directsize)
{
blockno=addr/bsize;
byteno=addr-blockno*bsize;
printf("Direct Block number: %ld\n",blockno);
printf("Byte number: %ld\n",byteno);
}
else
{
if(addr<singleend)
{
tempaddr=addr-directsize;
blockno=tempaddr/bsize;
byteno=tempaddr-blockno*bsize;
printf("Direct Block number: %ld\n",blockno);
printf("Byte number: %ld\n",byteno);
}
else
{
if(addr<doubleend)
{
tempaddr=addr-singleend;
blockno=tempaddr/(singlesize);
printf("Single Indirect Block number: %ld\n",blockno);
blockno=tempaddr/(bsize);
printf("Direct Block number: %ld\n",blockno);
byteno= tempaddr-blockno*bsize;
printf("Byte number: %ld\n",byteno);
}
else
{
if(addr<tripleend)
{
tempaddr=addr-doubleend;
blockno=tempaddr/(doublesize);
printf("Double Indirect Block number: %ld\n",blockno);
tempaddr= tempaddr-blockno*doublesize;
blockno=tempaddr/(singlesize);
printf("Single Indirect Block number: %ld\n",blockno);
blockno=tempaddr/bsize;
printf("Direct Block number: %ld\n",blockno);
byteno=tempaddr-blockno*bsize;
printf("Byte number: %ld\n",byteno);
}
}
}
}
return 0;
}
output:-Enter block size(kb) 1 Enter the address: 350000 Single Indirect Block number: 0 Direct Block number: 75 Byte number: 816 --------------------------------

0 comments: