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;
|
306
|
38 fs_impl->lockinode1 = C_lockinode1;
|
|
39 fs_impl->lockinode_sleepcheck = C_lockinode_sleepcheck;
|
294
|
40 fs->iunlock = C_iunlockfs_impl;
|
|
41 fs->iput = C_iputfs_impl;
|
|
42 fs->iunlockput = C_iunlockputfs_impl;
|
|
43 fs->stati = C_statifs_impl;
|
|
44 fs->readi = C_readifs_impl;
|
|
45 fs->writei = C_writeifs_impl;
|
|
46 fs->namecmp = C_namecmpfs_impl;
|
|
47 fs->dirlookup = C_dirlookupfs_impl;
|
296
|
48 fs->dirlink = C_dirlinkfs_impl;
|
294
|
49 fs->namei = C_nameifs_impl;
|
|
50 fs->nameiparent = C_nameiparentfs_impl;
|
|
51 return fs;
|
|
52 }
|
298
|
53
|
299
|
54 typedef struct superblock superblock;
|
296
|
55 __code readsbfs_impl(struct fs_impl* fs, uint dev, struct superblock* sb, __code next(...)) { //:skip
|
294
|
56
|
301
|
57 struct buf* bp;
|
|
58
|
|
59 bp = bread(dev, 1);
|
|
60 memmove(sb, bp->data, sizeof(*sb));
|
|
61 brelse(bp);
|
|
62
|
294
|
63 goto next(...);
|
|
64 }
|
|
65
|
302
|
66 struct {
|
|
67 struct spinlock lock;
|
|
68 struct inode inode[NINODE];
|
|
69 } icache;
|
|
70
|
294
|
71 __code iinitfs_impl(struct fs_impl* fs, __code next(...)) {
|
|
72
|
302
|
73 initlock(&icache.lock, "icache");
|
|
74
|
294
|
75 goto next(...);
|
|
76 }
|
|
77
|
|
78 __code iallocfs_impl(struct fs_impl* fs, uint dev, short type, __code next(...)) {
|
305
|
79 goto allocinode(fs, dev, sb, next(...));
|
294
|
80 }
|
|
81
|
|
82 __code iupdatefs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
83
|
305
|
84 struct buf *bp;
|
|
85 struct dinode *dip;
|
|
86
|
|
87 bp = bread(ip->dev, IBLOCK(ip->inum));
|
|
88
|
|
89 dip = (struct dinode*) bp->data + ip->inum % IPB;
|
|
90 dip->type = ip->type;
|
|
91 dip->major = ip->major;
|
|
92 dip->minor = ip->minor;
|
|
93 dip->nlink = ip->nlink;
|
|
94 dip->size = ip->size;
|
|
95
|
|
96 memmove(dip->addrs, ip->addrs, sizeof(ip->addrs));
|
|
97 log_write(bp);
|
|
98 brelse(bp);
|
|
99
|
|
100
|
294
|
101 goto next(...);
|
|
102 }
|
|
103
|
|
104 __code idupfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
105
|
305
|
106 acquire(&icache.lock);
|
|
107 ip->ref++;
|
|
108 release(&icache.lock);
|
|
109
|
|
110 goto next(ip, ...);
|
|
111
|
294
|
112 }
|
|
113
|
|
114 __code ilockfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
115
|
306
|
116 goto lockinode1(fs, ip, bp, dip, next(...));
|
294
|
117 }
|
|
118
|
|
119 __code iunlockfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
120
|
|
121 goto next(...);
|
|
122 }
|
|
123
|
|
124 __code iputfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
125
|
|
126 goto next(...);
|
|
127 }
|
|
128
|
|
129 __code iunlockputfs_impl(struct fs_impl* fs, struct inode* ip, __code next(...)) {
|
|
130
|
|
131 goto next(...);
|
|
132 }
|
|
133
|
299
|
134 typedef struct stat stat;
|
296
|
135 __code statifs_impl(struct fs_impl* fs , struct inode* ip, struct stat* st, __code next(...)) { //:skip
|
294
|
136
|
|
137 goto next(...);
|
|
138 }
|
|
139
|
|
140 __code readifs_impl(struct fs_impl* fs, struct inode* ip, char* dst, uint off, uint n, __code next(...)) {
|
|
141
|
|
142 goto next(...);
|
|
143 }
|
|
144
|
|
145 __code writeifs_impl(struct fs_impl* fs, struct inode* ip, char* src, uint off, uint n, __code next(...)) {
|
|
146
|
|
147 goto next(...);
|
|
148 }
|
|
149
|
|
150 __code namecmpfs_impl(struct fs_impl* fs, const char* s, const char* t, __code next(...)) {
|
|
151
|
|
152 goto next(...);
|
|
153 }
|
|
154
|
|
155 __code dirlookupfs_impl(struct inode* dp, char* name, uint* poff, __code next(...)) {
|
|
156
|
|
157 goto next(...);
|
|
158 }
|
|
159
|
296
|
160 __code dirlinkfs_impl(struct fs_impl* fs, struct inode* dp, char* name, uint inum, __code next(...)) {
|
294
|
161
|
296
|
162 goto next(...);
|
294
|
163 }
|
|
164
|
|
165 __code nameifs_impl(struct fs_impl* fs, char* path, __code next(...)) {
|
|
166
|
|
167 goto next(...);
|
|
168 }
|
|
169
|
|
170 __code nameiparentfs_impl(struct fs_impl* fs, char* path, char* name, __code next(...)) {
|
|
171
|
|
172 goto next(...);
|
|
173 }
|
|
174
|