-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssfs.hpp
113 lines (97 loc) · 2.76 KB
/
ssfs.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef SSFS_HPP_G
#define SSFS_HPP_G
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <fstream>
#include <pthread.h>
#include <sstream>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <math.h>
#include "scheduler.hpp"
using namespace std;
/* Constants */
#define MAX_FILENAME_SIZE 32
#define NUM_DIRECT_BLOCKS 12
#define MIN_BLOCK_SIZE 128
#define MAX_BLOCK_SIZE 512
#define MIN_DISK_SIZE 1024
#define MAX_DISK_SIZE 128000 //technically 131,072 but thats a nitpick
#define MAX_INODES 256
//Identifies the io operation in a disk_io_request
enum Operation {
io_READ,
io_WRITE,
io_WRONG
};
//"Low level" request that will be serviced by the disk scheduler
typedef struct disk_io_request
{
int block_number; // Target block
Operation op = io_WRONG; // Indicated whether we are reading or writing data to/from block_number
char* data; // Will either be a pointer to the SOURCE LOCATION to write FROM ||OR|| the DESTINATION LOCATION to read TO
pthread_cond_t waitFor;
pthread_mutex_t lock;
bool done;
} disk_io_request;
//Struct to contain file metadata (1 block in size)
typedef struct {
char fileName[MAX_FILENAME_SIZE]; // Max 32 chars
int fileSize;
int direct[NUM_DIRECT_BLOCKS];
int indirect;
int doubleIndirect;
} inode;
typedef struct
{
queue<disk_io_request*>* requests;
pthread_mutex_t lock;
int fd;
} SCH_struct;
//Request abstraction functions
char* readFromBlock(int i);
void writeToBlock(int i, char* data);
//Access to memory storage metadata
int getNumBlocks();
int getBlockSize();
int getFreeMapStart();
int getFreeMapSize();
int getInodeMapStart();
int getInodeMapSize();
int getInodesStart();
int getUserDataStart();
void print_inode_contents(inode* i);
char* getSUPER();
char* getFREE_MAP();
char* getINODE_MAP();
int getUnusedBlock();
int getFreeByteMapInBlock(int block);
bool getByteMap(int block);
void setByteMap(int block, bool flag);
int getEmptyInode();
int getInode(const char* file);
inode* getInodeFromIndex(int ind);
int getStartOfDataBlocks();
// SSFS Disk operations
void CREATE(const char* filename);
void IMPORT(const char* ssfsFile, const char* unixFilename);
void CAT(const char* fileName);
void DELETE(const char* fileName);
void WRITE(const char* fileName, char c, int start, int num);
void READ(const char* fileName, int start, int num);
char* READ_with_return(const char* fileName, int start, int num);
void READ_file_redirect(const char* fileName, int start, int num);
void LIST();
void SHUTDOWN();
//AUXILIARY FUNCTIONALITY
void CP(const char* fileName, const char* newFileName);
void MV(const char* fileName, const char* newFileName);
void EXPORT(const char* ssfsFileName, const char* unixFileName);
void shutdown();
bool isShutdown();
#endif