302
|
1 #include "types.h"
|
301
|
2 #include "defs.h"
|
302
|
3 #include "param.h"
|
|
4 #include "stat.h"
|
|
5 #include "mmu.h"
|
|
6 #include "proc.h"
|
|
7 #include "spinlock.h"
|
|
8 #include "buf.h"
|
301
|
9 #include "fs.h"
|
302
|
10 #include "file.h"
|
295
|
11 #interface "fs.dg"
|
294
|
12
|
|
13 // ----
|
|
14 // typedef struct fs_impl<Impl, Isa> impl fs{
|
|
15 // union Data* fs_impl;
|
|
16 //
|
|
17 //
|
|
18 //
|
|
19 //
|
|
20 // } fs_impl;
|
|
21 // ----
|
|
22
|
|
23 fs* createfs_impl(struct Context* cbc_context) {
|
|
24 struct fs* fs = new fs();
|
|
25 struct fs_impl* fs_impl = new fs_impl();
|
|
26 fs->fs = (union Data*)fs_impl;
|
|
27 fs_impl->fs_impl = NULL;
|
|
28 fs->readsb = C_readsbfs_impl;
|
|
29 fs->iinit = C_iinitfs_impl;
|
|
30 fs->ialloc = C_iallocfs_impl;
|
302
|
31 fs_impl->allocinode = C_allocinode;
|
|
32 fs_impl->allocinode_loop = C_allocinode_loop;
|
303
|
33 fs_impl->allocinode_loopcheck = C_allocinode_loopcheck;
|
|
34 fs_impl->allocinode_noloop = C_allocinode_noloop;
|
294
|
35 fs->iupdate = C_iupdatefs_impl;
|
|
36 fs->idup = C_idupfs_impl;
|
|
37 fs->ilock = C_ilockfs_impl;
|
305
|
38 fs_impl->lockinode = C_lockinode;
|
294
|
39 fs->iunlock = C_iunlockfs_impl;
|
|
40 fs->iput = C_iputfs_impl;
|
|
41 fs->iunlockput = C_iunlockputfs_impl;
|
|
42 fs->stati = C_statifs_impl;
|
|
43 fs->readi = C_readifs_impl;
|
|
44 fs->writei = C_writeifs_impl;
|
|
45 fs->namecmp = C_namecmpfs_impl;
|
|
46 fs->dirlookup = C_dirlookupfs_impl;
|
296
|
47 fs->dirlink = C_dirlinkfs_impl;
|
294
|
48 fs->namei = C_nameifs_impl;
|
|
49 fs->nameiparent = C_nameiparentfs_impl;
|
|
50 return fs;
|
|
51 }
|
298
|
52
|
299
|
53 typedef struct superblock superblock;
|
296
|
54 __code readsbfs_impl(struct fs_impl* fs, uint dev, struct superblock* sb, __code next(...)) { //:skip
|
294
|
55
|
301
|
56 struct buf* bp;
|
|
57
|
|
58 bp = bread(dev, 1);
|
|
59 memmove(sb, bp->data, sizeof(*sb));
|
|
60 brelse(bp);
|
|
61
|
294
|
62 goto next(...);
|
|
63 }
|
|
64
|
302
|
65 struct {
|
|
66 struct spinlock lock;
|
|
67 struct inode inode[NINODE];
|
|
68 } icache;
|
|
69
|
294
|
70 __code iinitfs_impl(struct fs_impl* fs, __code next(...)) {
|
|
71
|
302
|
72 initlock(&icache.lock, "icache");
|
|
73
|
294
|
74 goto next(...);
|
|
75 }
|
|
76
|
|
77 __code iallocfs_impl(struct fs_impl* fs, uint dev, short type, __code next(...)) {
|
305
|
78 goto allocinode(fs, dev, sb, next(...));
|
294
|
79 }
|
|
80
|
|
81 __code iupdatefs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
82
|
305
|
83 struct buf *bp;
|
|
84 struct dinode *dip;
|
|
85
|
|
86 bp = bread(ip->dev, IBLOCK(ip->inum));
|
|
87
|
|
88 dip = (struct dinode*) bp->data + ip->inum % IPB;
|
|
89 dip->type = ip->type;
|
|
90 dip->major = ip->major;
|
|
91 dip->minor = ip->minor;
|
|
92 dip->nlink = ip->nlink;
|
|
93 dip->size = ip->size;
|
|
94
|
|
95 memmove(dip->addrs, ip->addrs, sizeof(ip->addrs));
|
|
96 log_write(bp);
|
|
97 brelse(bp);
|
|
98
|
|
99
|
294
|
100 goto next(...);
|
|
101 }
|
|
102
|
|
103 __code idupfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
104
|
305
|
105 acquire(&icache.lock);
|
|
106 ip->ref++;
|
|
107 release(&icache.lock);
|
|
108
|
|
109 goto next(ip, ...);
|
|
110
|
294
|
111 }
|
|
112
|
|
113 __code ilockfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
114
|
305
|
115 goto lockinode(fs, ip, bp, dip, next(...));
|
294
|
116 }
|
|
117
|
|
118 __code iunlockfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
119
|
|
120 goto next(...);
|
|
121 }
|
|
122
|
|
123 __code iputfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
124
|
|
125 goto next(...);
|
|
126 }
|
|
127
|
|
128 __code iunlockputfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
129
|
|
130 goto next(...);
|
|
131 }
|
|
132
|
299
|
133 typedef struct stat stat;
|
296
|
134 __code statifs_impl(struct fs_impl* fs , struct inode* ip, struct stat* st, __code next(...)) { //:skip
|
294
|
135
|
|
136 goto next(...);
|
|
137 }
|
|
138
|
|
139 __code readifs_impl(struct fs_impl* fs, struct inode* ip, char* dst, uint off, uint n, __code next(...)) {
|
|
140
|
|
141 goto next(...);
|
|
142 }
|
|
143
|
|
144 __code writeifs_impl(struct fs_impl* fs, struct inode* ip, char* src, uint off, uint n, __code next(...)) {
|
|
145
|
|
146 goto next(...);
|
|
147 }
|
|
148
|
|
149 __code namecmpfs_impl(struct fs_impl* fs, const char* s, const char* t, __code next(...)) {
|
|
150
|
|
151 goto next(...);
|
|
152 }
|
|
153
|
|
154 __code dirlookupfs_impl(struct inode* dp, char* name, uint* poff, __code next(...)) {
|
|
155
|
|
156 goto next(...);
|
|
157 }
|
|
158
|
296
|
159 __code dirlinkfs_impl(struct fs_impl* fs, struct inode* dp, char* name, uint inum, __code next(...)) {
|
294
|
160
|
296
|
161 goto next(...);
|
294
|
162 }
|
|
163
|
|
164 __code nameifs_impl(struct fs_impl* fs, char* path, __code next(...)) {
|
|
165
|
|
166 goto next(...);
|
|
167 }
|
|
168
|
|
169 __code nameiparentfs_impl(struct fs_impl* fs, char* path, char* name, __code next(...)) {
|
|
170
|
|
171 goto next(...);
|
|
172 }
|
|
173
|