9bootfat: rename Extend to File as fat files are not really extends anymore :)

This commit is contained in:
glenda 2011-05-09 16:58:29 +00:00
parent 5ca8c7b025
commit 79af8162e8

View file

@ -13,7 +13,7 @@ enum {
Fat32 = 4, Fat32 = 4,
}; };
typedef struct Extend Extend; typedef struct File File;
typedef struct Dir Dir; typedef struct Dir Dir;
typedef struct Pbs Pbs; typedef struct Pbs Pbs;
typedef struct Fat Fat; typedef struct Fat Fat;
@ -31,7 +31,7 @@ struct Fat
ulong datalba; ulong datalba;
}; };
struct Extend struct File
{ {
Fat *fat; Fat *fat;
ulong lba; ulong lba;
@ -113,21 +113,21 @@ unload(void)
} }
static ulong static ulong
readnext(Extend *ex, ulong clust) readnext(File *fp, ulong clust)
{ {
Fat *fat = ex->fat; Fat *fat = fp->fat;
uint b = fat->ver; uint b = fat->ver;
ulong sect, off; ulong sect, off;
sect = clust * b / Sectsz; sect = clust * b / Sectsz;
off = clust * b % Sectsz; off = clust * b % Sectsz;
if(readsect(fat->drive, fat->fatlba + sect, ex->buf)) if(readsect(fat->drive, fat->fatlba + sect, fp->buf))
memset(ex->buf, 0xff, 4); memset(fp->buf, 0xff, 4);
switch(fat->ver){ switch(fat->ver){
case Fat16: case Fat16:
return GETSHORT(&ex->buf[off]); return GETSHORT(&fp->buf[off]);
case Fat32: case Fat32:
return GETLONG(&ex->buf[off])& 0x0fffffff; return GETLONG(&fp->buf[off])& 0x0fffffff;
} }
return 0; return 0;
} }
@ -135,45 +135,45 @@ readnext(Extend *ex, ulong clust)
int int
read(void *f, void *data, int len) read(void *f, void *data, int len)
{ {
Extend *ex = f; File *fp = f;
Fat *fat = ex->fat; Fat *fat = fp->fat;
if(ex->len > 0 && ex->rp >= ex->ep){ if(fp->len > 0 && fp->rp >= fp->ep){
if(ex->clust != ~0U){ if(fp->clust != ~0U){
if(ex->lbaoff % fat->clustsize == 0){ if(fp->lbaoff % fat->clustsize == 0){
if((ex->clust >> 4) == fat->eofmark) if((fp->clust >> 4) == fat->eofmark)
return -1; return -1;
ex->lbaoff = (ex->clust - 2) * fat->clustsize; fp->lbaoff = (fp->clust - 2) * fat->clustsize;
putc('.'); putc('.');
ex->clust = readnext(ex, ex->clust); fp->clust = readnext(fp, fp->clust);
ex->lba = ex->lbaoff + fat->datalba; fp->lba = fp->lbaoff + fat->datalba;
} }
ex->lbaoff++; fp->lbaoff++;
} }
if(readsect(fat->drive, ex->lba++, ex->rp = ex->buf)) if(readsect(fat->drive, fp->lba++, fp->rp = fp->buf))
return -1; return -1;
} }
if(ex->len < len) if(fp->len < len)
len = ex->len; len = fp->len;
if(len > (ex->ep - ex->rp)) if(len > (fp->ep - fp->rp))
len = ex->ep - ex->rp; len = fp->ep - fp->rp;
memmove(data, ex->rp, len); memmove(data, fp->rp, len);
ex->rp += len; fp->rp += len;
ex->len -= len; fp->len -= len;
return len; return len;
} }
void void
open(Fat *fat, void *f, ulong lba) open(Fat *fat, void *f, ulong lba)
{ {
Extend *ex = f; File *fp = f;
ex->fat = fat; fp->fat = fat;
ex->lba = lba; fp->lba = lba;
ex->len = 0; fp->len = 0;
ex->lbaoff = 0; fp->lbaoff = 0;
ex->clust = ~0U; fp->clust = ~0U;
ex->rp = ex->ep = ex->buf + Sectsz; fp->rp = fp->ep = fp->buf + Sectsz;
} }
void void
@ -218,22 +218,22 @@ dirclust(Dir *d)
} }
static int static int
fatwalk(Extend *ex, Fat *fat, char *path) fatwalk(File *fp, Fat *fat, char *path)
{ {
char name[Maxpath], *end; char name[Maxpath], *end;
int i, j; int i, j;
Dir d; Dir d;
if(fat->ver == Fat32){ if(fat->ver == Fat32){
open(fat, ex, 0); open(fat, fp, 0);
ex->clust = fat->dirstart; fp->clust = fat->dirstart;
ex->len = ~0U; fp->len = ~0U;
}else{ }else{
open(fat, ex, fat->dirstart); open(fat, fp, fat->dirstart);
ex->len = fat->dirents * Dirsz; fp->len = fat->dirents * Dirsz;
} }
for(;;){ for(;;){
if(readn(ex, &d, Dirsz) != Dirsz) if(readn(fp, &d, Dirsz) != Dirsz)
break; break;
if((i = dirname(&d, name)) <= 0) if((i = dirname(&d, name)) <= 0)
continue; continue;
@ -243,13 +243,13 @@ fatwalk(Extend *ex, Fat *fat, char *path)
end = path + strlen(path); end = path + strlen(path);
j = end - path; j = end - path;
if(i == j && memcmp(name, path, j) == 0){ if(i == j && memcmp(name, path, j) == 0){
open(fat, ex, 0); open(fat, fp, 0);
ex->clust = dirclust(&d); fp->clust = dirclust(&d);
ex->len = *((ulong*)d.len); fp->len = *((ulong*)d.len);
if(*end == 0) if(*end == 0)
return 0; return 0;
else if(d.attr & 0x10){ else if(d.attr & 0x10){
ex->len = fat->clustsize * Sectsz; fp->len = fat->clustsize * Sectsz;
path = end; path = end;
continue; continue;
} }
@ -354,7 +354,7 @@ start(void *sp)
{ {
char path[Maxpath], *kern; char path[Maxpath], *kern;
int drive; int drive;
Extend ex; File fi;
Fat fat; Fat fat;
void *f; void *f;
@ -366,17 +366,17 @@ start(void *sp)
print("no fat\r\n"); print("no fat\r\n");
halt(); halt();
} }
if(fatwalk(f = &ex, &fat, "plan9.ini")){ if(fatwalk(f = &fi, &fat, "plan9.ini")){
print("no config\r\n"); print("no config\r\n");
f = 0; f = 0;
} }
for(;;){ for(;;){
kern = configure(f, path); f = 0; kern = configure(f, path); f = 0;
if(fatwalk(&ex, &fat, kern)){ if(fatwalk(&fi, &fat, kern)){
print("not found\r\n"); print("not found\r\n");
continue; continue;
} }
print(bootkern(&ex)); print(bootkern(&fi));
print(crnl); print(crnl);
} }
} }