Repository navigation
Expand file tree
/
Copy pathfs.h
More file actions
69 lines (52 loc) · 3.07 KB
/
Copy pathfs.h
File metadata and controls
69 lines (52 loc) · 3.07 KB
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
/* all definitions from the hw */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#define MAX_F_NAME 15
#define MAX_FILDES 32
#define MAX_FILES 64
/* superblock */
/* refers to a number of blocks for directory information
refers to a number of blocks that contain the FAT
reference to first block of file data
*/
struct super_block {
int fat_idx; // first block of the FAT
int fat_len; // length of FAT in blocks
int dir_idx; // first block of directory
int dir_len; // length of directory in blocks
int data_idx; // first block of file-data
}super_block;
/* directory entry (file metadata) */
struct dir_entry {
int used; // is this file-"slot" used?
char name[MAX_F_NAME + 1];
int size; // file size
int head; // first data block of file
int ref_cnt;
// how many open file descriptors are there?
// ref_cnt > 0 -> cannot delete file
}dir_entry;
struct file_descriptor {
int used; // fd in use
int file; // the first block of the file
// (f) to which fd refers to, index of dir_entry
int offset; // position of fd within file
}file_descriptor;
/* functions to manage file system */
int make_fs(char *disk_name); // creates a fresh (and empty) file system on the virtual disk with name disk_name
int mount_fs(char *disk_name); // mounts a file system that is stored on the virtual disk with name disk_name
int umount_fs(char *disk_name); // unmounts the file system from a virtual disk with name disk_name
/* file system functions, require that a file system was previously mounted */
int fs_open(char *name); // file specified by name is opened for reading and writing, and the file descriptor corresponding to this file is returned to the calling function
int fs_close(int fildes); // file descriptor fildes is closed
int fs_create(char *name); // creates a new file with name name in the root directory of the file system. The file is initally empty
int fs_delete(char *name); // deletes the file with name name from the root directory of the file system and frees all data blocks and meta-information that correspond to that file
int fs_read(int fildes, void *buf, size_t nbyte); // attempts to read nbyte bytes from the file referenced by the descriptor fildes into the buffer pointed to by buf
int fs_write(int fildes, void *buf, size_t nbyte); // attempts to write nbyte bytes of datat to the file referenced by the descriptor fildes from the buffer poointed to by buf
int fs_get_filesize(int fildes); // returns current size of the file referenced by the file descriptor fildes
int fs_listfiles(char ***files); // creates and populates an array of all filenames currently known to the file system
int fs_lseek(int fildes, off_t offset); // sets the file pointer (offset used for read and write operations) associated with the file descriptor fildes to the argument offset
int fs_truncate(int fildes, off_t length); // causes the file referenced by fildes to be truncated to length bytes in size