## Class Inode

- java.lang.Object
- - Inode

-     public class Inode
      extends java.lang.Object

  This class reads an Inode and all the metadata it provides
  Author:
    Petros Soutzis (p.soutzis@lancaster.ac.uk)

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private java.nio.ByteBuffer` | `buffer`
    `private int` | `i_atime`
    `private int[]` | `i_block_pointer`
    `private int` | `i_ctime`
    `private int` | `i_dtime`
    `private short` | `i_gid`
    `private short` | `i_links_count`
    `private short` | `i_mode`
    `private int` | `i_mtime`
    `private int` | `i_size_lower`
    `private int` | `i_size_upper`
    `private short` | `i_uid`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Inode(byte[] bytes)` Constructor of the inode class

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `private static int` | `findInodeOffset(java.lang.String path, Inode inode, Ext2File ext2)` This class calculates the inode number, needed to readBytes the data contained in the block that the inode points to If there was no match, method returns integer 0
    `(package private) int[]` | `getBlockPointers()`
    `(package private) static int` | `getContainingBlock(int rootInodeOffset, Superblock superblock, GroupDescriptor groupDescriptor)` A static method, used for fetching the block number (offset), that an inode points to.
    `(package private) static Inode` | `getContainingInode(java.lang.String[] pathArray, int inodeSize, Ext2File ext2, Inode inode, Superblock superblock, GroupDescriptor groupDescriptor)` This method will get the number of the inode, if the names in pathArray array match the names in the volume If the inode number is 0, the program will be terminated.
    `java.util.Date` | `getDate()`
    `(package private) java.lang.String` | `getGid()`
    `(package private) short` | `getHardLinks()`
    `(package private) int` | `getSizeLower()`
    `(package private) int` | `getSizeUpper()`
    `(package private) java.lang.String` | `getUid()`
    `boolean` | `isFile()`
    `private void` | `read()` This method will readBytes all the data that is contained in the inode, from the buffer, in which the byte array was parsed
    `(package private) java.lang.String` | `readPermissions()` This method uses bitwise ANDing on FileSystem's i_mode variable value, to determine what permissions a directory or file has.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### i_mode

          private short i_mode

    - #### i_uid

          private short i_uid

    - #### i_size_lower

          private int i_size_lower

    - #### i_atime

          private int i_atime

    - #### i_ctime

          private int i_ctime

    - #### i_mtime

          private int i_mtime

    - #### i_dtime

          private int i_dtime

    - #### i_gid

          private short i_gid

    - #### i_links_count

          private short i_links_count

    - #### i_block_pointer

          private int[] i_block_pointer

    - #### i_size_upper

          private int i_size_upper

    - #### buffer

          private java.nio.ByteBuffer buffer

  - ### Constructor Detail

    - #### Inode

          public Inode(byte[] bytes)

      Constructor of the inode class
      Parameters:
        `bytes` - is the byte array that contains the inode's data

  - ### Method Detail

    - #### read

          private void read()

      This method will readBytes all the data that is contained in the inode, from the buffer, in which the byte array was parsed

    - #### readPermissions

          java.lang.String readPermissions()

      This method uses bitwise ANDing on FileSystem's i_mode variable value, to determine what permissions a directory or file has.
      Returns:
        a String with the full permissions of a file or directory

    - #### findInodeOffset

          private static int findInodeOffset(java.lang.String path,
                                             Inode inode,
                                             Ext2File ext2)
                                      throws java.io.IOException

      This class calculates the inode number, needed to readBytes the data contained in the block that the inode points to If there was no match, method returns integer 0
      Parameters:
        `path` - is the name of the directory or file to look for
      Returns:
        the inode number that points to the data requested in the path
      Throws:
        `java.io.IOException` - e

    - #### getContainingInode

          static Inode getContainingInode(java.lang.String[] pathArray,
                                          int inodeSize,
                                          Ext2File ext2,
                                          Inode inode,
                                          Superblock superblock,
                                          GroupDescriptor groupDescriptor)
                                   throws java.io.IOException

      This method will get the number of the inode, if the names in pathArray array match the names in the volume If the inode number is 0, the program will be terminated. The method will then parse the bytes to readBytes, to the Inode instance, by calculating the offset based on the inode number that the path returns. If data exists, this method will call the readBlockData() method, to readBytes and print the data in a human-readable way and then it will call the readHexData, in order to readBytes and print that same data in Hexadecimal format
      Parameters:
        `pathArray` - is the array of names of directories and files, that the
      Throws:
        `java.io.IOException` - ioe

    - #### getContainingBlock

          static int getContainingBlock(int rootInodeOffset,
                                        Superblock superblock,
                                        GroupDescriptor groupDescriptor)

      A static method, used for fetching the block number (offset), that an inode points to. Otherwise, it returns 0
      Parameters:
        `rootInodeOffset` - The number of the inode, with which this method will calculate the containing block number
      Returns:
        the offset of the containing block

    - #### getBlockPointers

          int[] getBlockPointers()

      Returns:
        the array of all the data pointers in an inode

    - #### getUid

          java.lang.String getUid()

      Returns:
        If the user has root access or not

    - #### getGid

          java.lang.String getGid()

      Returns:
        If the guest has root access or not

    - #### getSizeLower

          int getSizeLower()

      Returns:
        the file size (lower 32 bits)

    - #### getSizeUpper

          int getSizeUpper()

      Returns:
        the file size (upper 32 bits)

    - #### isFile

          public boolean isFile()

      Returns:
        true, if this is a file. Otherwise, return false.

    - #### getDate

          public java.util.Date getDate()

      Returns:
        the date that this file was lastly modified

    - #### getHardLinks

          short getHardLinks()

      Returns:
        the number of hard link references to a file