-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileSystem.h
99 lines (88 loc) · 3.26 KB
/
fileSystem.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
/*
* fileSystem.h
*
* Modified on: 24/03/2023
* Author: Robert Sheehan
*/
#define EBADVOLNAME 101 // bad volume name
#define EBADDEV 102 // something bad reported by the device
#define ENOROOM 103 // no more room on the device
#define ENOSUCHFILE 104 // the file does not exist
#define EOTHER 105 // any other file system error
/*
* This should be declared in system.c.
* When any of the functions cause an error to occur
* this should be filled in with a suitable value from
* the #defines above.
*/
extern int file_errno;
/*
* Formats the device for use by this file system.
* The volume name must be < 64 bytes long.
* All information previously on the device is lost.
* Also creates the root directory "/".
* Returns 0 if no problem or -1 if the call failed.
*/
int format(char *volumeName);
/*
* Places the volume's name in the result.
* Returns 0 if no problem or -1 if the call failed.
*/
int volumeName(char *result);
/*
* Makes a file with a fully qualified pathname starting with "/".
* It automatically creates all intervening directories.
* Pathnames can consist of any printable ASCII characters (0x20 - 0x7e)
* including the space character.
* The occurrence of "/" is interpreted as starting a new directory
* (or the file name).
* Each section of the pathname must be between 1 and 7 bytes long (not
* counting the "/"s).
* The pathname cannot finish with a "/" so the only way to create a directory
* is to create a file in that directory. This is not true for the root
* directory "/" as this needs to be created when format is called.
* The total length of a pathname is limited only by the size of the device.
* Returns 0 if no problem or -1 if the call failed.
*/
int create(char *pathName);
/*
* Returns a list of all files in the named directory.
* The "result" string is filled in with the output.
* The result looks like this
/dir1:
file1 42
file2 0
* The fully qualified pathname of the directory followed by a colon and
* then each file name followed by a tab "\t" and then its file size.
* Each file on a separate line.
* The directoryName is a full pathname.
*/
void list(char *result, char *directoryName);
/*
* Writes data onto the end of the file.
* Copies "length" bytes from data and appends them to the file.
* The filename is a full pathname.
* The file must have been created before this call is made.
* Returns 0 if no problem or -1 if the call failed.
*/
int a2write(char *fileName, void *data, int length);
/*
* Reads data from the start of the file.
* Maintains a file position so that subsequent reads continue
* from where the last read finished.
* The filename is a full pathname.
* The file must have been created before this call is made.
* Returns 0 if no problem or -1 if the call failed.
*/
int a2read(char *fileName, void *data, int length);
/*
* Repositions the file pointer for the file at the specified location.
* All positive integers are byte offsets from the start of the file.
* 0 is the beginning of the file.
* If the location is after the end of the file, move the location
* pointer to the end of the file.
* The filename is a full pathname.
* The file must have been created before this call is made.
* Returns 0 if no problem or -1 if the call failed.
*/
int seek(char *fileName, int location);