Chameleon

Chameleon Commit Details

Date:2010-08-01 02:36:56 (13 years 8 months ago)
Author:Tamás Kosárszky
Commit:292
Parents: 291
Message:Added cache support for FAT filesystems. Now booting from an average speed flash drive formatted to FAT32 fs using 512 byte cluster size is about 50 times faster.
Changes:
M/trunk/i386/libsaio/cache.c
M/trunk/i386/libsaio/msdos.c

File differences

trunk/i386/libsaio/cache.c
3939
4040
4141
42
42
4343
4444
4545
......
7474
7575
7676
77
77
7878
7979
8080
#define kCacheSize (0x100000)
#define kCacheMinBlockSize (0x200)
#define kCacheMaxBlockSize (0x4000)
#define kCacheMaxBlockSize (0x8000)
#define kCacheMaxEntries (kCacheSize / kCacheMinBlockSize)
static CICell gCacheIH;
#endif
if ((blockSize < kCacheMinBlockSize) ||
(blockSize >= kCacheMaxBlockSize))
(blockSize > kCacheMaxBlockSize))
return;
gCacheBlockSize = blockSize;
trunk/i386/libsaio/msdos.c
5555
5656
5757
58
5859
5960
6061
......
7475
7576
7677
78
7779
7880
7981
......
151153
152154
153155
154
156
155157
156158
157159
......
220222
221223
222224
223
224225
225
226
227
228
226229
227230
228231
229232
230233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
231249
232250
233251
......
263281
264282
265283
266
267
284
268285
269
286
270287
271
288
289
272290
273
291
274292
275293
276
277
294
278295
279296
280297
#define LABEL_LENGTH11
#define MAX_DOS_BLOCKSIZE2048
#define MAX_CACHE_BLOCKSIZE 32768
#defineCLUST_FIRST2/* reserved cluster range */
#defineCLUST_RSRVD320x0ffffff8/* reserved cluster range */
static CICell msdoscurrent = 0;
static int msdosrootcluster = 0;
static int msdosfatbits = 0;
static int msdosCacheBlockSize = 0;
#if UNUSED
/*
if (msdoscurrent == ih)
{
CacheInit(ih, msdosclustersize);
CacheInit(ih, msdosCacheBlockSize);
return 0;
}
}
msdosclustersize = msdosbps * spc;
msdoscurrent = ih;
CacheInit(ih, msdosclustersize);
msdosCacheBlockSize = (msdosclustersize > MAX_CACHE_BLOCKSIZE) ? msdosclustersize : MAX_CACHE_BLOCKSIZE;
CacheInit(ih, msdosCacheBlockSize);
free (buf);
return 0;
}
static int
readSectorAligned(CICell ih, off_t readOffset, char *buf, int size)
{
long long sectorOffset = (uint64_t)readOffset / msdosCacheBlockSize * msdosCacheBlockSize;
long relOffset = readOffset % msdosCacheBlockSize;
char *cacheBuffer;
cacheBuffer = malloc(msdosCacheBlockSize);
CacheRead(ih, cacheBuffer, sectorOffset, msdosCacheBlockSize, true);
bcopy(cacheBuffer + relOffset, buf, size);
free(cacheBuffer);
return 0;
}
static int
msdosreadcluster (CICell ih, uint8_t *buf, int size, off_t *cluster)
{
off_t readOffset;
/* Read in "cluster" */
if (buf)
{
Seek(ih, readOffset);
Read(ih, (long)buf, size);
readSectorAligned(ih, readOffset, (char *)buf, size);
}
/* Find first sector of FAT */
readOffset = msdosressector*msdosbps;
readOffset = msdosressector * msdosbps;
/* Find sector containing "cluster" entry in FAT */
readOffset += ((uint64_t)*cluster * (uint64_t)msdosfatbits)/8;
readOffset += ((uint64_t)*cluster * (uint64_t)msdosfatbits) / 8;
/* Read one sector of the FAT */
Seek(ih, readOffset);
Read(ih, (long)tmpbuf, 4);
readSectorAligned(ih, readOffset, tmpbuf, 4);
switch (msdosfatbits) {
case 32:

Archive Download the corresponding diff file

Revision: 292