Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* type.h for CS360 Project */
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <ext2fs/ext2_fs.h>
- #include <libgen.h>
- #include <string.h>
- #include <time.h>
- #include <sys/timeb.h>
- #include <sys/stat.h>
- #include <errno.h>
- // define shorter TYPES, save typing efforts
- typedef struct ext2_group_desc GD;
- typedef struct ext2_super_block SUPER;
- typedef struct ext2_inode INODE;
- typedef struct ext2_dir_entry_2 DIR; // need this for new version of e2fs
- GD *gp;
- SUPER *sp;
- INODE *ip;
- DIR *dp;
- #define BLOCK_SIZE 1024
- #define BLKSIZE 1024
- #define BITS_PER_BLOCK (8*BLOCK_SIZE)
- #define INODES_PER_BLOCK (BLOCK_SIZE/sizeof(INODE))
- #define RED "\e[0;31m"
- #define GREEN "\x1b[32m"
- #define YELLOW "\x1b[33m"
- #define BLUE "\x1b[34m"
- #define MAGENTA "\x1b[35m"
- #define CYAN "\x1b[36m"
- #define RESET "\x1b[0m"
- #define BOLDRED "\e[1;31m"
- #define BOLDGREEN "\e[1;32m"
- #define BOLDYELLOW "\e[1;33m"
- #define BOLDBLUE "\e[1;34m"
- #define BOLDMAGENTA "\e[1;35m"
- #define BOLDCYAN "\e[1;36m"
- #define RESET "\x1b[0m"
- #define BLOCK_SIZE 1024
- #define BLKSIZE 1024
- #define BITS_PER_BLOCK (8*BLOCK_SIZE)
- #define INODES_PER_BLOCK (BLOCK_SIZE/sizeof(INODE))
- // Block number of EXT2 FS on FD
- #define SUPERBLOCK 1
- #define GDBLOCK 2
- #define BBITMAP 3
- #define IBITMAP 4
- #define INODEBLOCK 5
- #define ROOT_INODE 2
- // Default dir and regulsr file modes
- #define DIR_MODE 0040777
- #define FILE_MODE 0100644
- #define SUPER_MAGIC 0xEF53
- #define SUPER_USER 0
- // Proc status
- #define FREE 0
- #define BUSY 1
- #define KILLED 2
- // Table sizes
- #define NMINODES 100
- #define NMOUNT 10
- #define NPROC 10
- #define NFD 10
- #define NOFT 50
- // Open File Table
- typedef struct Oft{
- int mode; // flags
- int refCount; /* number of processes which share same instance of open file
- when a process opens a file, refCount is set to 1
- when a process forks, the child process inherits all opened fds of parent,
- which increments the refCount of every shared OFT by 1.
- when a process closes a fd, it decrements the OFT refCount by 1. */
- struct Minode *inodeptr; // pointer to inode in-memory
- long offset; /* conceptual pointer to the current byte position in the file for read/write
- initially set to 0 for R|R|RW or to file size for append */
- } OFT;
- // PROC structure
- typedef struct Proc{
- int uid; // user id, 0 super user, 1 basic user
- int pid; // process id
- int gid; // group id
- int ppid; // parent process id
- int status; // indicates FREE, BUSY, or WAITING
- struct Minode *cwd; // in-memory inode that points to the current working directory
- OFT *fd[NFD]; // array of file descriptors which point to opened file instances
- struct Proc *next; // pointer to next process
- struct Proc *parent; // pointer to parent process
- struct Proc *child; // pointer to child process
- struct Proc *sibling; // pointer to sibling process
- } PROC;
- // In-memory inodes structure
- typedef struct Minode{
- INODE INODE; // disk inode
- int dev, ino; // device number, inode number
- int refCount; // records number of prcesses that are using the minode
- int dirty; // flag that indicates whether the inode has been modified
- int mounted; // flag that indicates whether the inode has been mounted
- struct Mount *mountptr; // points to the mount table entry of the mounted filesystem
- char name[128]; // name string of file
- } MINODE;
- // Mount Table structure
- typedef struct Mount{
- int ninodes; // number of inodes
- int nblocks; // number of blocks
- int bmap; // ?
- int imap; // ?
- int iblock; // ?
- int dev, busy; // device number, busy flag?
- struct Minode *mounted_inode; // pointer to mounted inode in-memory
- char name[256]; // name string of ?
- char mount_name[64]; // name of mount ?
- } MOUNT;
- // function proto types
- //MINODE *iget();
- //OFT *falloc();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement