Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* type.h file for CS360 FS */
- #ifndef TYPE_H
- #define TYPE_H
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <ext2fs/ext2_fs.h> // MAY NEED "ext2_fs.h"
- #include <libgen.h>
- #include <string.h>
- #include <sys/stat.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;
- char names[64][64];
- char name[64];
- char line[128], pathname[64], parameter[64];
- int ninodes, nblocks, bmap, imap, inodes_start;
- #define BLOCK_SIZE 1024
- #define BLKSIZE 1024
- // Block number of EXT2 FS on FD
- #define SUPERBLOCK 1
- #define GDBLOCK 2
- #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 READY 1
- #define RUNNING 2
- // Table sizes
- #define NMINODES 100
- #define NMOUNT 10
- #define NPROC 10
- #define NFD 10
- #define NOFT 100
- // Open File Table
- typedef struct oft{
- int mode;
- int refCount;
- struct minode *inodeptr;
- int offset;
- }OFT;
- // PROC structure
- typedef struct proc{
- struct proc *nextProcPtr;
- int uid;
- int pid, gid;
- int status;
- struct minode *cwd;
- OFT *fd[NFD];
- }PROC;
- // In-memory inodes structure
- typedef struct minode{
- INODE INODE; // disk inode
- int dev, ino;
- int refCount;
- int dirty;
- int mounted;
- struct mount *mountptr;
- }MINODE;
- // Mount Table structure
- typedef struct mount{
- int dev;
- int nblocks,ninodes;
- int bmap, imap, iblk;
- MINODE *mounted_inode;
- char name[64];
- }MOUNT;
- typedef struct node{
- char name[64];
- struct node *nxt;
- struct node *prv;
- }NODE;
- typedef struct list{
- NODE *head;
- NODE *tail;
- }LIST;
- void add(char *, LIST *);
- void stack_add(char *, LIST *);
- PROC P0, P1;
- PROC *running;
- MINODE minode[100];
- MINODE *root;
- int dev, fd, done_flag;
- char *disk;
- char base[64];
- char dir[64];
- char buf[BLOCK_SIZE];
- char read_buff[BLOCK_SIZE]; // A special buff for reads
- void init();
- int get_block(int, unsigned long, char buf[]);
- int put_block(int, int, char buf[]);
- void mount_root();
- MINODE *iget(int, int);
- int iput(MINODE *);
- void menu();
- void ls(char *pathname, PROC *parent);
- //void ls(char *);
- //int list_file(MINODE *, char *);
- //int list_dir(MINODE *);
- int getino(int, char *);
- int search(int, INODE *, char *);
- void cd(char *);
- char *my_cwd();
- int do_pwd();
- char *pwd(MINODE *wd, int childIno);
- void build_pathname();
- //void delete_item(LIST *);
- //char *printpath(LIST *);
- //int list_size(LIST *);
- void make_dir();
- void get_dirname(char *);
- void get_basename(char *);
- //void recur_bp(int, LIST *);
- int mymkdir(MINODE *, char *);
- int decFreeInodes(int);
- int decFreeBlocks(int);
- int ialloc(int);
- int balloc(int);
- int idealloc(int, int);
- int bdealloc(int, int);
- int empty_dir(MINODE *);
- int creat_file();
- int mycreat(MINODE *, char *);
- int set_bit(char *, int);
- int clr_bit(char *, int);
- int tst_bit(char *, int);
- void printInode(INODE *);
- int rm_child(MINODE *, char *);
- int link(char *, char *);
- int symlink(char*, char *);
- int unlink(char *);
- void mytouch(char* pathname);
- void mychmod(char *pathname, char * param);
- int pfd();
- int printfilepath(MINODE* mip);
- MINODE* findParent(MINODE* mip, MINODE* pip);
- int falloc(OFT* oftp);
- int open_file(char* path, char mode);
- int close_file(int fd);
- int read_file(int fd, int bytes);
- int myread(int fd, char* m_buff,long nbytes);
- void cat_file(char *filename);
- int lseek_file(int fd, long position);
- void mycp(char *src, char *dest);
- void mymv(char *src, char *dest);
- int deleteChild(MINODE* pip, char* name);
- int rm_file(char* path);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement