-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbfs.h
92 lines (72 loc) · 2.35 KB
/
bfs.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
#ifndef BFS_H
#define BFS_H
// ===================================================================
// bfs.h - API to Bothell File System
// ===================================================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "alias.h"
#include "bio.h"
#include "errors.h"
#define BYTESPERBLOCK 512
#define I16SPERBLOCK 256
#define BLOCKSPERDISK 100
#define BYTESPERDISK (BLOCKSPERDISK * BYTESPERBLOCK)
#define NUMINODES 8
#define MAXINUM NUMINODES - 1
#define NUMMETA 3
#define MINDBN 3
#define BFSDISK "BFSDISK"
#define NUMDIRECT 5
#define NUMINDIRECT BYTESPERBLOCK / sizeof(i16)
#define MAXFBN NUMDIRECT + NUMINDIRECT
#define FNAMESIZE 16
#define DBNSUPER 0
#define DBNINODES 1
#define DBNDIR 2
#define INUMTOFD 5
#define NUMOFTENTRIES 20
typedef struct { // SuperBlock
i16 numBlocks; // total # of blocks in BFSDISK = 1,000
i16 numInodes; // total # of inodes = 8
i16 firstFree; // DBN of first free block
} Super;
typedef struct { // Inode
i32 size; // # of bytes in file
i16 direct[NUMDIRECT]; // DBNs for first 5 FBNs
i16 indirect; // DBN of the indirect table
} Inode;
typedef struct { // Dir
char fname[NUMINODES][FNAMESIZE];
} Dir;
typedef struct { // Open File Table Entry
i32 inum; // inum of file. O => slot not used
i32 refs; // # processes fsOpen'd this file
i32 curs; // cursor into file
} OFTE;
OFTE g_oft[NUMOFTENTRIES];
i32 bfsAllocBlock(i32 inum, i32 fbn);
i32 bfsCreateFile(str fname);
i32 bfsDerefOFT(i32 inum);
i32 bfsExtend(i32 inum, i32 fbn);
i32 bfsFbnToDbn(i32 inum, i32 fbn);
i32 bfsFdToInum(i32 fd);
i32 bfsFindFreeBlock();
i32 bfsFindOFTE(i32 inum);
i32 bfsGetSize(i32 inum);
i32 bfsInitDir();
i32 bfsInitFreeList();
i32 bfsInitInodes();
i32 bfsInitOFT();
i32 bfsInitSuper(FILE* fp);
i32 bfsInumToFd(i32 inum);
i32 bfsLookupFile(str fname);
i32 bfsRead(i32 inum, i32 fbn, i8* buf);
i32 bfsReadInode(i32 inum, Inode* inode);
i32 bfsRefOFT(i32 inum);
i32 bfsSetCursor(i32 inum, i32 newCurs);
i32 bfsSetSize(i32 inum, i32 size);
i32 bfsTell(i32 fd);
i32 bfsWriteInode(i32 inum, Inode* inode);
#endif