forked from wtakuo/opfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libfs.h
85 lines (67 loc) · 2.33 KB
/
libfs.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
/*
* opfs: a simple utility for manipulating xv6 file system images
* Copyright (c) 2015-2019 Takuo Watanabe
*/
// xv6 header files
#include "types.h"
#include "fs.h"
// utitlity macros
// array length
#define ALEN(a) (sizeof (a) / sizeof (a)[0])
#define UNUSED(x) (void)(x)
// file types (copied from xv6/stat.h)
// Including xv6/stat.h causes a name clash (with struct stat)
#define T_DIR 1 // Directory
#define T_FILE 2 // File
#define T_DEV 3 // Device
#define MAXFILESIZE (MAXFILE * BSIZE)
#define BUFSIZE 1024
#define ddebug(...) debug_message("DEBUG", __VA_ARGS__)
#define derror(...) debug_message("ERROR", __VA_ARGS__)
#define dwarn(...) debug_message("WARNING", __VA_ARGS__)
extern char *progname;
extern jmp_buf fatal_exception_buf;
uint bitcount(uint x);
void debug_message(const char *tag, const char *fmt, ...);
void error(const char *fmt, ...);
void fatal(const char *fmt, ...);
char *typename(int type);
// a disk image as an array of blocks
// a block is a uchar array of size BSIZE
typedef uchar (*img_t)[BSIZE];
// super block
#define SBLK(img) ((struct superblock *)(img)[1])
#define SBLKS(img) (*(SBLK(img)))
bool valid_data_block(img_t img, uint b);
uint balloc(img_t img);
int bfree(img_t img, uint b);
// inode
typedef struct dinode *inode_t;
// inode of the root directory
extern const uint root_inode_number;
extern inode_t root_inode;
inode_t iget(img_t img, uint inum);
uint geti(img_t img, inode_t ip);
inode_t ialloc(img_t img, uint type);
int ifree(img_t img, uint inum);
uint bmap(img_t img, inode_t ip, uint n);
int iread(img_t img, inode_t ip, uchar *buf, uint n, uint off);
int iwrite(img_t img, inode_t ip, uchar *buf, uint n, uint off);
int itruncate(img_t img, inode_t ip, uint size);
bool is_empty(char *s);
bool is_sep(char c);
char *skipelem(char *path, char *name);
char *splitpath(char *path, char *dirbuf, uint size);
inode_t dlookup(img_t img, inode_t dp, char *name, uint *offp);
int daddent(img_t img, inode_t dp, char *name, inode_t ip);
int dmkparlink(img_t img, inode_t pip, inode_t cip);
inode_t ilookup(img_t img, inode_t rp, char *path);
inode_t icreat(img_t img, inode_t rp, char *path, uint type, inode_t *dpp);
bool emptydir(img_t img, inode_t dp);
int iunlink(img_t img, inode_t rp, char *path);
/* For Emacs
* Local Variables: ***
* c-file-style: "gnu" ***
* c-basic-offset: 4 ***
* End: ***
*/