Advertisement
Guest User

types

a guest
Apr 27th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.06 KB | None | 0 0
  1. /* type.h file for CS360 FS */
  2. #ifndef TYPE_H
  3. #define TYPE_H
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <fcntl.h>
  8. #include <ext2fs/ext2_fs.h>   // MAY NEED "ext2_fs.h"
  9. #include <libgen.h>
  10. #include <string.h>
  11. #include <sys/stat.h>
  12.  
  13. // define shorter TYPES, save typing efforts
  14. typedef struct ext2_group_desc  GD;
  15. typedef struct ext2_super_block SUPER;
  16. typedef struct ext2_inode       INODE;
  17. typedef struct ext2_dir_entry_2 DIR;    // need this for new version of e2fs
  18.  
  19. GD    *gp;
  20. SUPER *sp;
  21. INODE *ip;
  22. DIR   *dp;
  23. char names[64][64];
  24. char name[64];
  25. char line[128], pathname[64], parameter[64];
  26. int ninodes, nblocks, bmap, imap, inodes_start;
  27.  
  28. #define BLOCK_SIZE     1024
  29. #define BLKSIZE        1024
  30.  
  31. // Block number of EXT2 FS on FD
  32. #define SUPERBLOCK        1
  33. #define GDBLOCK           2
  34. #define ROOT_INODE        2
  35.  
  36. // Default dir and regulsr file modes
  37. #define DIR_MODE    0040777
  38. #define FILE_MODE   0100644
  39. #define SUPER_MAGIC  0xEF53
  40. #define SUPER_USER        0
  41.  
  42. // Proc status
  43. #define FREE              0
  44. #define READY             1
  45. #define RUNNING           2
  46.  
  47. // Table sizes
  48. #define NMINODES        100
  49. #define NMOUNT           10
  50. #define NPROC            10
  51. #define NFD              10
  52. #define NOFT            100
  53.  
  54. // Open File Table
  55. typedef struct oft{
  56.   int   mode;
  57.   int   refCount;
  58.   struct minode *inodeptr;
  59.   int   offset;
  60. }OFT;
  61.  
  62. // PROC structure
  63. typedef struct proc{
  64.   struct proc *nextProcPtr;
  65.   int   uid;
  66.   int   pid, gid;
  67.   int   status;
  68.   struct minode *cwd;
  69.   OFT   *fd[NFD];
  70. }PROC;
  71.      
  72. // In-memory inodes structure
  73. typedef struct minode{     
  74.   INODE INODE;               // disk inode
  75.   int   dev, ino;
  76.   int   refCount;
  77.   int   dirty;
  78.   int   mounted;
  79.   struct mount *mountptr;
  80. }MINODE;
  81.  
  82. // Mount Table structure
  83. typedef struct mount{
  84.         int    dev;
  85.         int    nblocks,ninodes;
  86.         int    bmap, imap, iblk;
  87.         MINODE *mounted_inode;
  88.         char   name[64];
  89. }MOUNT;
  90.  
  91. typedef struct node{
  92.     char name[64];
  93.     struct node *nxt;
  94.     struct node *prv;
  95. }NODE;
  96.  
  97. typedef struct list{
  98.     NODE *head;
  99.     NODE *tail;
  100. }LIST;
  101.  
  102.  
  103. void add(char *, LIST *);
  104. void stack_add(char *, LIST *);
  105.  
  106. PROC P0, P1;
  107. PROC *running;
  108. MINODE minode[100];
  109. MINODE *root;
  110. int dev, fd, done_flag;
  111. char *disk;
  112. char base[64];
  113. char dir[64];
  114. char buf[BLOCK_SIZE];
  115. char read_buff[BLOCK_SIZE]; // A special buff for reads
  116.  
  117. void init();
  118. int get_block(int, unsigned long, char buf[]);
  119. int put_block(int, int, char buf[]);
  120. void mount_root();
  121. MINODE *iget(int, int);
  122. int iput(MINODE *);
  123. void menu();
  124.  
  125. void ls(char *pathname, PROC *parent);
  126. //void ls(char *);
  127. //int list_file(MINODE *, char *);
  128.  
  129.  
  130. //int list_dir(MINODE *);
  131. int getino(int, char *);
  132. int search(int, INODE *, char *);
  133.  
  134. void cd(char *);
  135. char *my_cwd();
  136.  
  137. int do_pwd();
  138. char *pwd(MINODE *wd, int childIno);
  139.  
  140. void build_pathname();
  141. //void delete_item(LIST *);
  142. //char *printpath(LIST *);
  143. //int list_size(LIST *);
  144. void make_dir();
  145. void get_dirname(char *);
  146. void get_basename(char *);
  147. //void recur_bp(int, LIST *);
  148. int mymkdir(MINODE *, char *);
  149. int decFreeInodes(int);
  150. int decFreeBlocks(int);
  151.  
  152. int ialloc(int);
  153. int balloc(int);
  154. int idealloc(int, int);
  155. int bdealloc(int, int);
  156.  
  157. int empty_dir(MINODE *);
  158. int creat_file();
  159. int mycreat(MINODE *, char *);
  160. int set_bit(char *, int);
  161. int clr_bit(char *, int);
  162. int tst_bit(char *, int);
  163. void printInode(INODE *);
  164. int rm_child(MINODE *, char *);
  165. int link(char *, char *);
  166. int symlink(char*, char *);
  167. int unlink(char *);
  168. void mytouch(char* pathname);
  169. void mychmod(char *pathname, char * param);
  170.  
  171.  
  172. int pfd();
  173. int printfilepath(MINODE* mip);
  174. MINODE* findParent(MINODE* mip, MINODE* pip);
  175. int falloc(OFT* oftp);
  176. int open_file(char* path, char mode);
  177. int close_file(int fd);
  178.  
  179. int read_file(int fd, int bytes);
  180. int myread(int fd, char* m_buff,long nbytes);
  181. void cat_file(char *filename);
  182.  
  183. int lseek_file(int fd, long position);
  184.  
  185. void mycp(char *src, char *dest);
  186. void mymv(char *src, char *dest);
  187.  
  188. int deleteChild(MINODE* pip, char* name);
  189. int rm_file(char* path);
  190.  
  191.  
  192. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement