-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplefs.h
executable file
·60 lines (46 loc) · 2.39 KB
/
simplefs.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
#pragma once
#include "bitmap.h"
#include "disk_driver.h"
#include "common.h"
#include "simplefs_structures.h"
// initializes a file system on an already made disk
// returns a handle to the top level directory stored in the first block
DirectoryHandle *SimpleFS_init(SimpleFS *fs, DiskDriver *disk);
// creates the initial structures, the top level directory
// has name "/" and its control block is in the first position
// it also clears the bitmap of occupied blocks on the disk
// the current_directory_block is cached in the SimpleFS struct
// and set to the top level directory
void SimpleFS_format(SimpleFS *fs);
// creates an empty file in the directory d
// returns null on error (file existing, no free blocks)
// an empty file consists only of a block of type FirstBlock
FileHandle *SimpleFS_createFile(DirectoryHandle *d, const char *filename);
// reads in the (preallocated) blocks array, the name of all files in a directory
int SimpleFS_readDir(char **names, DirectoryHandle *d);
// opens a file in the directory d. The file should be exisiting
FileHandle *SimpleFS_openFile(DirectoryHandle *d, const char *filename);
// closes a file handle (destroyes it)
void SimpleFS_close(FileHandle *f);
// writes in the file, at current position for size bytes stored in data
// overwriting and allocating new space if necessary
// returns the number of bytes written
int SimpleFS_write(FileHandle *f, void *data, int size);
// reads in the file, at current position size bytes stored in data
// overwriting and allocating new space if necessary
// returns the number of bytes read
int SimpleFS_read(FileHandle *f, void *data, int size);
// returns the number of bytes read (moving the current pointer to pos)
// returns pos on success -1 on error (file too short)
int SimpleFS_seek(FileHandle *f, int pos);
// seeks for a directory in d. If dirname is equal to ".." it goes one level up
// 0 on success, negative value on error
// it does side effect on the provided handle
int SimpleFS_changeDir(DirectoryHandle *d, const char *dirname);
// creates a new directory in the current one (stored in fs->current_directory_block)
// 0 on success -1 on error
int SimpleFS_mkDir(DirectoryHandle *d, const char *dirname);
// removes the file in the current directory
// returns -1 on failure 0 on success
// if a directory, it removes recursively all contained files
int SimpleFS_remove(DirectoryHandle *d, const char *filename);