Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could someone please provide an implementation for this ? package osp.FileSys; i

ID: 3571513 • Letter: C

Question

Could someone please provide an implementation for this ?

package osp.FileSys;


import java.util.Vector;
import osp.IFLModules.*;
import osp.Devices.*;
import osp.Utilities.*;
import osp.Memory.*;

/**
Implements the Unix-like INode data structure, which keeps
information about the storage of the file, the number of hard links
to it, the number of times it is open, etc. Does NOT keep the name
of the file: there can be several hard links to the same INode.

@OSPProject FileSys
*/

public class INode extends IflINode
{
   {
       {
  
   super(deviceID);
   /*
@param deviceID device number to create the inode on

@OSPProject FileSys
*/
public INode(int deviceID)
{
  
   super(deviceID);
  

}

/**
Tests whether a block on a device is free.
@param deviceID device to test the block on
@param block number of block to test
@return true if block is free, false if used or deviceID is invalid

   @OSPProject FileSys
*/
public static boolean do_isFreeBlock(int block, int deviceID)
{
  
}

/**
   Allocates a free block to inode and
   returns the block number of that block.
   Marks that block as used.
  
@return integer in the range from 0 to numberOfBlocks-1
if a free block was found on the inode's device, NONE otherwise.

@OSPProject FileSys
*/
public int do_allocateFreeBlock()
{
// your code goes here

}

/**
Release all blocks allocated to the given inode (i.e., make them free).

@param inode to de-allocate free block on

@OSPProject FileSys
*/
public void do_releaseBlocks()
{
// your code goes here

}


/*
Feel free to add methods/fields to improve the readability of your code
*/

}

/*
Feel free to add local classes to improve the readability of your code
*/
                                                                  

Explanation / Answer

import java.util.*;

import java.lang.*;

import java.io.*;

class INodes {

   

    public boolean used_p;    

    public boolean file_p;     

    public byte name[];        

    public short blockPtr[];   

    public short size;         

  

   

    private int mxFileBlock;

                               

    private int nameSz;        

  

    public INodes(int nameSize, int maxFileBlock) {

                used_p = false;

                file_p = true;

                name = new byte[nameSize];

                blockPtr = new short[maxFileBlock];

                mxFileBlock = maxFileBlock;

                nameSz = nameSize;

                size = 0;

    };

   

    public void list(String base) {

                String tab = "                                                             ";

                String str = base + "/" + getName();

               

                if(file_p) {

                    str += tab.substring(1, tab.length() - str.length()) + size;

                }else{

                    str += "/";

                };

                System.out.println(str);

    };

  

    public void Alloc(String name, boolean file_flag)

                     throws FileSystemException {

                setName(name);

                used_p = true;

                file_p = file_flag;

                size = 0;

    };

   

    public String getName() {

                String out = "";

                try {

                    // Create a new string from the ascii array

                    out = new String(name, "US-ASCII");

                }catch(UnsupportedEncodingException e){

                    System.out.println("INodes::getName(): " + e);

                    System.exit(1);

                };

                // Trim off nulls at the end of the string.

                return(out.trim());

    };

   

   

    public void setName(String str) throws FileSystemException{

                if(!str.matches("^[\w\._]+$")) {

                    throw new FileSystemException("Ill-formed file name (" + str + ").");

                };

               

                // Check string length

                if(str.length() > nameSz) {

                    throw new FileSystemException("Name too long (" + str + ").");

                };

                // Do the translation

                try {

                    byte[] bytes = str.getBytes("US-ASCII");

                    int i;

                    // Copy into the internal byte array

                    for(i = 0; i < str.length(); ++i) {

                                name[i] = bytes[i];

                    };

                    // Zero out remaining elements

                    for(i = str.length(); i < nameSz; ++i) {

                                name[i] = 0;

                    };

                               

                }catch(UnsupportedEncodingException e){

                    System.out.println("INodes::setName(): " + e);

                    System.exit(1);

                };

    };

   

    public void write(RandomAccessFile fp) throws FileSystemException {

                int i;

                try{

                    fp.writeBoolean(used_p); // byte 0->1

                    fp.writeBoolean(file_p); // byte 2->3

                    fp.write(name);           // byte 4->4+nameSize-1

                    fp.writeShort(size);      // next 2 bytes

                    for(i = 0; i < mxFileBlock; ++i) {

                                fp.writeShort(blockPtr[i]);   // 2 bytes each

                    };

                }catch(IOException e) {

                    throw new FileSystemException("INodes::write() error:" + e);

                };

    };

    public void read(RandomAccessFile fp) throws FileSystemException {

                int i;

                try{

                    // Used?

                    used_p = fp.readBoolean();

                    // A file?

                    file_p = fp.readBoolean();

                    // Name of the INodes

                    fp.read(name);

                    // Size of the INodes

                    size = fp.readShort();

                    // Read the set of block pointers

                    for(i = 0; i < mxFileBlock; ++i) {

                                blockPtr[i] = fp.readShort();

                    };

                }catch(IOException e) {

                    throw new FileSystemException("INodes::read() error: " + e);

                };

    };

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote