-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib-sfs.h
54 lines (41 loc) · 1.24 KB
/
lib-sfs.h
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
#ifndef LIBSFS_H
#define LIBSFS_H
#include <stdlib.h>
#include <stdio.h>
#define MAX_NAME_LENGTH 150
int sfs_init(int sys_key);
int sfs_declare(int sys_key, int file_num, char *filenames[]);
FILE *sfs_fopen(char *path, char *mode);
int sfs_fclose(FILE *fp);
int sfs_leave(int sys_key);
int sfs_destroy(int sys_key);
struct node_t;
typedef enum {UNVISITED, VISITED, PROCESSED} state_t;
// Only one node type - used for all data structures
typedef struct node_t {
// The state of this node in a running cycle detection algorithm
state_t state;
// A pointer to the next node of the same type as this node
struct node_t *next;
// A pointer to a linked list of outgoing edges
struct node_t *out_edges;
// If this is a resource and it's currently open, a file pointer
FILE *fp;
// If this is a resource, the name of the file
char name[MAX_NAME_LENGTH];
// If this is a process, the pid of that process
pid_t pid;
// If this is a node in a linked list, the data of this element
struct node_t *data;
} node;
typedef struct memory_manager_t {
char *next_free;
node *open_nodes;
node *processes;
node *resources;
pthread_mutexattr_t mutexattr;
pthread_mutex_t mutex;
pthread_condattr_t condattr;
pthread_cond_t no_cycle;
} memory_layout;
#endif