Project HELP #1
	types and data structure diagram
	
/************ type.h file ************/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
#include <libgen.h>
#include <sys/stat.h>

#include <ext2fs/ext2_fs.h>

// define shorter TYPES, save typing efforts

typedef struct ext2_super_block SUPER;
typedef struct ext2_group_desc  GD;
typedef struct ext2_inode       INODE;
typedef struct ext2_dir_entry_2 DIR; 

#define BLKSIZE           1024 

#define NPROC                2
#define NMINODE             64
#define NFD                  8
#define NOFT                32

// In-memory inodes structure
typedef struct minode{		
  INODE INODE;            // disk INODE
  int   dev, ino;
  int   cacheCount;       // minode in cache count
  int   shareCount;       // number of users on this minode
  int   modified;         // modified while in memory
  int   id;               // index ID
  struct minode *next;    // pointer to next minode

}MINODE;

// Open File Table
typedef struct oft{
  int   mode;
  int   shareCount;
  struct minode *inodeptr; 
  long  offset;
} OFT;

// PROC structure
typedef struct proc{
  int   uid;            // uid = 0 or nonzero
  int   gid;            // group ID = uid
  int   pid;            // pid = 1 or 2
  struct minode *cwd;   // CWD pointer
  OFT   *fd[NFD];       // file descriptor array
} PROC;
      
/***************** end of type.h file ******************************/

           PROJECT LEVEL-1 Data Structure Diagram:

PROC *running           MINODE *root                          
      |                          |   MINODE         ||*********************
      V                          |  minode[64]       || 
    proc[0]                      V                  ||         Disk dev
 =============  ->pointerToCWD-> |===== 0 =====|    ||   ==================
 |nextProcPtr|  |                |    INODE    |    ||   |  (1024) INODEs   
 |pid = 1    |  |                | ----------  |    ||   ================== 
 |uid = gid=0|  |                |  (dev, 2)   |    || 
 |cwd -------|-->                | cacheCount=1|    ||*********************
 |OFT *fd[8] |                   | shareCount=2|
 =============                   | modified  =0|
                                 |===== 1 =====|  
                                 |    INODE    |
                                 | ----------  |
                                 |  (dev, ino) |         
                                 | cacheCount  |
                                 | shareCount  |
                                 | modified    |  
                                 |============ |   
                                 |    etc      |
                                 |             |
                                 |=============|  

   minode[64] will be used as a CACHE for in-memory INODES from disk

   MINODE *freeList  = a list of FREE minodes;
   MINODE *cacheList = a QUEUE of minodes in CACHE, ordered by cacheCount
	      
                  Concepts of CACHE memory

 USER: need an item  (from a large but SLOW area of items, e.g. a disk)
        |
 try to find item in FAST cache
        |
 ---------------------------------------------------------------
 if found: (hits++): return item for use
 if NOT  : (mis ++): load item to a FREE slot in cache
             OR      if no FREE: replace an item in cache
	             MAY have to write old item back if MODIFIED
---------  hit_ratio = hits/total; can be > 90% ------------------
	      
      Cache in memory                 Items on device  
	      
-- FAST but small number--         == large number SLOW ====  	      
|64 in-memory INODE slots|   <==== |  1024 INODEs on disk  |
---------------------------	   =========================