-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.h
139 lines (121 loc) · 2.42 KB
/
file.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
** @file file.h
**
** @author Utkarsh Dayal CSCI-452 class of 20205
**
** Function definitions for doing operations on one file. This is like an
** interface between the file manager and the block.
*/
#ifndef FILE__H_
#define FILE_H_
/*
** General (C and/or assembly) definitions
**
** This section of the header file contains definitions that can be
** used in either C or assembly-language source code.
*/
#define NUM_BLOCKS 8
#ifndef SP_ASM_SRC
/*
** Start of C-only definitions
**
** Anything that should not be visible to something other than
** the C compiler should be put here.
*/
/*
** Types
*/
/*
** Stores file meta-data, AKA the i-node
*/
typedef struct i_node_s {
uint32_t id; // unique file id
uint32_t bytes; // number of bytes written to the file
uint32_t block; // first of 8 blocks allocated to this file
} file_t;
/*
** Maps file ids to the block that stores its i-node
*/
typedef struct file_block_s {
int file_id;
int block_id;
} filemap_t;
/*
** Globals
*/
/*
** Prototypes
*/
/**
** Name: _fl_init
**
** Initializes global variables and calls the block init function
**
*/
void _fl_init( void );
/**
** Name: _fl_create
**
** Creates a new file, given an id to assign to it
**
** @param id The id of the file
**
** @return 0 if successful, -1 if not
*/
int _fl_create( int id );
/**
** Name: _fl_open
**
** Loads a file i-node so it can be used
**
** @param id The id of the file
**
** @return the i-node
*/
file_t *_fl_open( int id );
/**
** Name: _fl_delete
**
** Deletes a file from the disk
**
** @param id The id of the file
**
** @return 0 if successful, -1 if not
*/
int _fl_delete( int id );
/**
** Name: _fl_close
**
** Saves a file i-node to the disk
**
** @param file The i-node of the file
**
** @return 0 if successful, -1 if not
*/
int _fl_close( file_t *file );
/**
** Name: _fl_read
**
** Reads contents of a file to a buffer
**
** @param file The i-node of the file
** @param buf The buffer to be written to
**
** @return Number of characters written to the buffer
*/
int _fl_read( file_t *file, char *buf);
/**
** Name: _fl_write
**
** Writes contents of the buffer to a file
**
** @param file The i-node of the file
** @param buf The buffer containing stuff to write
** @param buf_size Number of characters in the buffer
**
** @return 0 if successful, -1 if not
*/
int _fl_write( file_t *file, char *buf, int buf_size );
#endif
/* SP_ASM_SRC */
#endif