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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
/* file.c
read files on EFS filesystems
now replaced by generic functions of the kernel:
leaves only mapping of file block number -> disk block number in this file
(C)95,96 Christian Vogelgsang
*/
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/efs_fs.h>
#include <linux/efs_fs_i.h>
#include <linux/efs_fs_sb.h>
#include <linux/stat.h>
#include <asm/uaccess.h>
static struct file_operations efs_file_ops = {
NULL,
generic_file_read,
NULL,
NULL,
NULL,
NULL,
generic_file_mmap,
NULL,
NULL,
NULL
};
struct inode_operations efs_file_in_ops = {
&efs_file_ops,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
generic_readpage,
NULL,
efs_bmap,
NULL,
NULL
};
#define MIN(a,b) ((a)<(b)?(a):(b))
#define CHECK(num) \
eblk = ini->extents[num].ex_bytes[0]; \
epos = ini->extents[num].ex_bytes[1] & 0xffffff; \
elen = ini->extents[num].ex_bytes[1] >> 24; \
if((blk >= epos)&&(blk < (epos+elen))) \
result = (blk - epos) + eblk + sbi->fs_start;
/* ----- efs_getblknum -----
find the disc block number for a given logical file block number
in - inode of file
blk - logical file block number
return - 0 on error, or unmapped block number
*/
static __u32 efs_getblk(struct inode *in,__u32 blk)
{
struct efs_sb_info *sbi = &in->i_sb->u.efs_sb;
struct efs_inode_info *ini = &in->u.efs_i;
struct buffer_head *bh;
__u32 result = 0;
__u32 eblk,epos,elen;
int num,extnum,readahead;
__u32 extblk;
__u16 extoff,pos,cur,tot;
union efs_extent *ptr;
/* first check the current extend */
cur = ini->cur;
tot = ini->tot;
CHECK(cur)
if(result)
return result;
/* if only one extent exists and we are here the test failed */
if(tot==1) {
printk("efs: bmap failed on one extent!\n");
return 0;
}
/* check the stored extents in the inode */
num = MIN(tot,EFS_MAX_EXTENTS);
for(pos=0;pos<num;pos++) {
/* don't check the current again! */
if(pos==cur)
continue;
CHECK(pos)
if(result) {
ini->cur = pos;
return result;
}
}
/* If the inode has only direct extents,
the above tests must have found the block's extend! */
if(tot<=EFS_MAX_EXTENTS) {
printk("efs: bmap failed for direct extents!\n");
return 0;
}
/* --- search in the indirect extensions list blocks --- */
#ifdef DEBUG
printk("efs - indirect search for %lu\n",blk);
#endif
/* calculate block and offset for begin of extent descr and read it */
extblk = ini->extblk;
extoff = 0;
bh = bread(in->i_dev,extblk,EFS_BLOCK_SIZE);
if(!bh) {
printk("efs: read error in indirect extents\n");
return 0;
}
ptr = (union efs_extent *)bh->b_data;
pos = 0; /* number of extend store in the inode */
extnum = 0; /* count the extents in the indirect blocks */
readahead = 10; /* number of extents to read ahead */
while(1) {
/* skip last current extent store in the inode */
if(pos==cur) pos++;
/* read new extent in inode buffer */
ini->extents[pos].ex_bytes[0] = efs_swab32(ptr[pos].ex_bytes[0]);
ini->extents[pos].ex_bytes[1] = efs_swab32(ptr[pos].ex_bytes[1]);
/* we must still search */
if(!result) {
CHECK(pos)
if(result)
ini->cur = pos;
}
/* we found it already and read ahead */
else {
readahead--;
if(!readahead)
break;
}
/* next storage place */
pos++;
extnum++;
/* last extent checked -> finished */
if(extnum==tot) {
if(!result)
printk("efs: bmap on indirect failed!\n");
break;
}
extoff += 8;
/* need new block */
if(extoff==EFS_BLOCK_SIZE) {
extoff = 0;
extblk++;
brelse(bh);
bh = bread(in->i_dev,extblk,EFS_BLOCK_SIZE);
if(!bh) {
printk("efs: read error in indirect extents\n");
return 0;
}
ptr = (union efs_extent *)bh->b_data;
}
}
brelse(bh);
return result;
}
/* ----- efs_bmap -----
bmap: map a file block number to a device block number
in - inode owning the block
block - block number
return - disk block
*/
int efs_bmap(struct inode *in, int block)
{
/* quickly reject invalid block numbers */
if(block<0) {
#ifdef DEBUG
printk("efs_bmap: block < 0\n");
#endif
return 0;
}
/* since the kernel wants to read a full page of data, i.e. 8 blocks
we must check if the block number is not too large */
if(block>((in->i_size-1)>>EFS_BLOCK_SIZE_BITS)) {
#ifdef DEBUG
printk("efs_bmap: block %d > max %d == %d\n",
block,in->i_size>>EFS_BLOCK_SIZE_BITS,in->i_blocks);
#endif
return 0;
}
return efs_getblk(in,block);
}
|