Inode program in java

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 Java:
import java.io.*;
public class INode {

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Please enter the Block Size in KB: ");
        int block_size = Integer.parseInt(br.readLine());
        block_size = 1024 * block_size;
        System.out.println("Please enter the address: ");
        long addr = Integer.parseInt(br.readLine());
        long dir_size = 10 * block_size;
        long sing_size = 256 * block_size;
        long sing_end = sing_size + dir_size;
        long doub_size = 256 * sing_size;
        long doub_end = sing_end + doub_size;
        long trip_size = 256 * doub_size;
        long trip_end = doub_end + trip_size;
        
        if(addr < dir_size)
        {
            int b = (int)addr/block_size;
            System.out.println("Direct Block number " + b);
            int byt = (int)(addr - (b * block_size));
            System.out.println("Byte number " + byt);
        }
        else if(addr < sing_end)
        {
            long temp_addr = addr - dir_size;
            long b = temp_addr/block_size;
            System.out.println("Block number " + b);
            long byt = temp_addr - (b * block_size);
            System.out.println("Byte number " + byt);
        }
        else if(addr < doub_end)
        {
            long temp_addr = addr - sing_end;
            long b = temp_addr/(256 * block_size);
            System.out.println("Single Indirect Block number " + b);
            b = temp_addr/block_size;
            System.out.println("Direct Block number " + b);
            long byt = temp_addr - (b * block_size);
            System.out.println("Byte number " + byt);
        }
        else if(addr < trip_end)
        {
            long temp_addr = addr - doub_end;
            long b = temp_addr/(256 * 256 * block_size);
            System.out.println("Double Indirect Block number " + b);
            temp_addr = temp_addr - (doub_size * b);
            b = temp_addr/(256 * block_size);
            System.out.println("Single Indirect Block number " + b);
            b = temp_addr/block_size;
            System.out.println("Direct Block number " + b);
            long byt = temp_addr - (b * block_size);
            System.out.println("Byte number " + byt);
        }
    }
    
}
output:-
Please enter the Block Size in KB: 
1
Please enter the address: 
350000
Single Indirect Block number 0
Direct Block number 75
Byte number 816
--------------------------------

0 comments: