diff --git a/src/sys/boot/boot2/boot2.c b/src/sys/boot/boot2/boot2.c index e2cee62..cc429c5 100755 --- a/src/sys/boot/boot2/boot2.c +++ b/src/sys/boot/boot2/boot2.c @@ -17,7 +17,6 @@ * $ID: src/sys/boot/i386/boot2/boot2.c,v 1.28.2.6 2002/03/31 18:12:50 pb Exp $ */ -#include "ubixfs.h" #include #include @@ -38,6 +37,7 @@ #include "boot2.h" #include "lib.h" +#include "ubixfs.h" #define RBX_ASKNAME 0x0 /* -a */ #define RBX_SINGLE 0x1 /* -s */ @@ -78,6 +78,9 @@ extern uint32_t _end; +struct blockAllocationTableEntry *BAT = 0x0; +struct directoryEntry *rootDir = 0x0; + static const char optstr[NOPT] = "DhaCcdgnPrsv"; static const unsigned char flags[NOPT] = { RBX_DUAL, @@ -119,8 +122,8 @@ static void load(const char *); static int parse(char *); static ino_t lookup(const char *); -static int xfsread(ino_t, void *, size_t); -static ssize_t fsread(ino_t, void *, size_t); +static int xfsread(const char *, void *, size_t); +static ssize_t fsread(const char *, void *, size_t); static int dskread(void *, unsigned, unsigned); static int printf(const char *,...); static int putchar(int); @@ -133,14 +136,18 @@ static int xgetc(int); static int getc(int); -static inline void -readfile(const char *fname, void *buf, size_t size) -{ - ino_t ino; +//My Functions +static void initUbixFS(void); - if ((ino = lookup(fname))) - fsread(ino, buf, size); -} +static inline void readfile(const char *fname, void *buf, size_t size) { + fs_off = 0; + fsread(fname,buf,size); + /* + ino_t ino; + if ((ino = lookup(fname))) + fsread(ino, buf, size); + */ + } static inline int strcmp(const char *s1, const char *s2) @@ -156,9 +163,8 @@ struct dirent *d; char *s; ssize_t n; - fs_off = 0; - while ((n = fsread(*ino, buf, DEV_BSIZE)) > 0) + while ((n = fsread(name, buf, DEV_BSIZE)) > 0) for (s = buf; s < buf + DEV_BSIZE;) { d = (void *)s; if (ls) @@ -239,6 +245,17 @@ v86int(); } +static void initUbixFS() { + int i = 0x0; + BAT = (struct blockAllocationTableEntry *)malloc(4096); + rootDir = (struct directoryEntry *)malloc(4096); + dskread(BAT,0,8); + for (i=0;i<16;i++) { + printf("block: [%u][%u]\n",i,BAT[i].nextBlock); + } + dskread(rootDir,8,8); + } + int main(void) { @@ -257,6 +274,10 @@ for (i = 0; i < N_BIOS_GEOM; i++) bootinfo.bi_bios_geom[i] = drvinfo(i); autoboot = 2; + + //Initialize UbixFS + initUbixFS(); + readfile(PATH_CONFIG, cmd, sizeof(cmd)); if (*cmd) { printf("%s: %s", PATH_CONFIG, cmd); @@ -301,6 +322,7 @@ { } +//woot static void load(const char *fname) { @@ -314,13 +336,15 @@ ino_t ino; uint32_t addr, x; int fmt, i, j; - + fs_off = 0; + /* if (!(ino = lookup(fname))) { if (!ls) printf("No %s\n", fname); return; } - if (xfsread(ino, &hdr, sizeof(hdr))) + */ + if (xfsread(fname, &hdr, sizeof(hdr))) return; if (N_GETMAGIC(hdr.ex) == ZMAGIC) fmt = 0; @@ -334,32 +358,33 @@ addr = hdr.ex.a_entry & 0xffffff; p = PTOV(addr); fs_off = PAGE_SIZE; - if (xfsread(ino, p, hdr.ex.a_text)) + if (xfsread(fname, p, hdr.ex.a_text)) return; p += roundup2(hdr.ex.a_text, PAGE_SIZE); - if (xfsread(ino, p, hdr.ex.a_data)) + if (xfsread(fname, p, hdr.ex.a_data)) return; p += hdr.ex.a_data + roundup2(hdr.ex.a_bss, PAGE_SIZE); bootinfo.bi_symtab = VTOP(p); memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms)); p += sizeof(hdr.ex.a_syms); if (hdr.ex.a_syms) { - if (xfsread(ino, p, hdr.ex.a_syms)) + if (xfsread(fname, p, hdr.ex.a_syms)) return; p += hdr.ex.a_syms; - if (xfsread(ino, p, sizeof(int))) + if (xfsread(fname, p, sizeof(int))) return; x = *(uint32_t *)p; p += sizeof(int); x -= sizeof(int); - if (xfsread(ino, p, x)) + if (xfsread(fname, p, x)) return; p += x; } } else { fs_off = hdr.eh.e_phoff; + printf("e_phoff: [%u]\n",fs_off); for (j = i = 0; i < hdr.eh.e_phnum && j < 2; i++) { - if (xfsread(ino, ep + j, sizeof(ep[0]))) + if (xfsread(fname, ep + j, sizeof(ep[0]))) return; if (ep[j].p_type == PT_LOAD) j++; @@ -367,7 +392,8 @@ for (i = 0; i < 2; i++) { p = PTOV(ep[i].p_paddr & 0xffffff); fs_off = ep[i].p_offset; - if (xfsread(ino, p, ep[i].p_filesz)) + printf("fs_off: [%u][%u]\n",fs_off,ep[i].p_filesz); + if (xfsread(fname, p, ep[i].p_filesz)) return; } p += roundup2(ep[1].p_memsz, PAGE_SIZE); @@ -375,19 +401,21 @@ if (hdr.eh.e_shnum == hdr.eh.e_shstrndx + 3) { fs_off = hdr.eh.e_shoff + sizeof(es[0]) * (hdr.eh.e_shstrndx + 1); - if (xfsread(ino, &es, sizeof(es))) + if (xfsread(fname, &es, sizeof(es))) return; for (i = 0; i < 2; i++) { memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size)); p += sizeof(es[i].sh_size); fs_off = es[i].sh_offset; - if (xfsread(ino, p, es[i].sh_size)) + if (xfsread(fname, p, es[i].sh_size)) return; p += es[i].sh_size; } } addr = hdr.eh.e_entry & 0xffffff; } + printf("addr: [%u]\n",addr); + //while(1); bootinfo.bi_esymtab = VTOP(p); bootinfo.bi_kernelname = VTOP(fname); bootinfo.bi_bios_dev = dsk.drive; @@ -508,15 +536,66 @@ return dt == DT_REG ? ino : 0; } static int -xfsread(ino_t inode, void *buf, size_t nbyte) +xfsread(const char *fname, void *buf, size_t nbyte) { - if (fsread(inode, buf, nbyte) != nbyte) { + if (fsread(fname, buf, nbyte) != nbyte) { printf("Invalid %s\n", "format"); return -1; } return 0; } + +//woot +static ssize_t fsread(const char *fname, void *buf, size_t nbyte) { + int i = 0x0,x = 0x0,block = 0x0,bOffset = 0x0,offset = 0x0,lb = -1; + int fBlock = -1; + char *buffer = 0x0; + char *buffer2 = 0x0; + struct directoryEntry *tmpDir = 0x0; + tmpDir = rootDir; + if (*fname == '/') { fname++; } + for (i=0;i<=(4096/sizeof(struct directoryEntry));i++) { + if (!strcmp(tmpDir[i].fileName,fname)) { + fBlock = tmpDir[i].startCluster; + break; + } + } + if (fBlock == -1) { + nbyte = 0; + return(nbyte); + } + buffer = malloc(4096); + buffer2 = buf; + offset = fs_off; + if (offset < 0) { + printf("Error!!!\n"); + offset = 0; + } + printf("Test: [%u][%u][%u]\n",fs_off,nbyte,(fs_off/4096)); + for (i=0;i> DEV_BSHIFT; @@ -592,13 +671,14 @@ } return nbyte; } +*/ static int dskread(void *buf, unsigned lba, unsigned nblk) { static char *sec; struct dos_partition *dp; - struct disklabel *d; + struct ubixDiskLabel *d; unsigned sl, i; if (!dsk.meta) { @@ -607,10 +687,8 @@ dsk.start = 0; if (drvread(sec, DOSBBSECTOR, 1)) return -1; - printf("w00t\n"); dp = (void *)(sec + DOSPARTOFF); sl = dsk.slice; - printf("sl: [%u]\n",sl); if (sl < BASE_SLICE) { for (i = 0; i < NDOSPART; i++) if (dp[i].dp_typ == DOSPTYP_UBX && @@ -623,13 +701,10 @@ if (dsk.slice == WHOLE_DISK_SLICE) dsk.slice = sl; } - printf("dp_typ: [%u][%u][%u][%u]\n",dp->dp_typ,WHOLE_DISK_SLICE,DOSPTYP_UBX,BASE_SLICE); if (sl != WHOLE_DISK_SLICE) { if (sl != COMPATIBILITY_SLICE) dp += sl - BASE_SLICE; - printf("dp_typ: [%u][%u][%u]\n",dp->dp_typ,WHOLE_DISK_SLICE,DOSPTYP_UBX); if (dp->dp_typ != DOSPTYP_UBX) { - printf("dp_typ: [%u][%u][%u]\n",dp->dp_typ,WHOLE_DISK_SLICE,DOSPTYP_UBX); printf("Invalid %s\n", "slice"); return -1; } @@ -638,24 +713,23 @@ if (drvread(sec, dsk.start + LABELSECTOR, 1)) return -1; d = (void *)(sec + LABELOFFSET); - printf("d_magic: [%u][%s]\n",d->d_magic,sec); - if (d->d_magic != DISKMAGIC || d->d_magic2 != DISKMAGIC) { + if (d->magicNum != UBIXDISKMAGIC || d->magicNum2 != UBIXDISKMAGIC) { if (dsk.part != RAW_PART) { printf("Invalid %s\n", "label"); return -1; } } else { if (!dsk.init) { - if (d->d_type == DTYPE_SCSI) + if (d->driveType == DTYPE_SCSI) dsk.type = TYPE_DA; dsk.init++; } - if (dsk.part >= d->d_npartitions || - !d->d_partitions[dsk.part].p_size) { + if (dsk.part >= d->numPartitions || + !d->partitions[dsk.part].p_size) { printf("Invalid %s\n", "partition"); return -1; } - dsk.start = d->d_partitions[dsk.part].p_offset; + dsk.start = d->partitions[dsk.part].p_offset; } } return drvread(buf, dsk.start + lba, nblk); @@ -748,9 +822,7 @@ { static unsigned c = 0x2d5c7c2f; - //printf("%c\b", c = c << 8 | c >> 24); - //woot - printf("[%u](%u)",lba,nblk); + printf("%c\b", c = c << 8 | c >> 24); v86.ctl = V86_ADDR | V86_CALLF | V86_FLAGS; v86.addr = XREADORG; /* call to xread in boot1 */ v86.es = VTOPSEG(buf); diff --git a/src/tools/Makefile b/src/tools/Makefile index 89de6e3..02a2a8f 100755 --- a/src/tools/Makefile +++ b/src/tools/Makefile @@ -43,6 +43,7 @@ $(REMOVE) $(OBJS) $(BINARY) *.core format-dsk: + (cp ../sys/compile/ubix.elf ./) (cp ../bin/init/init ./) (cp ../bin/shell/shell ./) (cp ../bin/test/test ./) @@ -50,7 +51,8 @@ (cp ../bin/pwd/pwd ./) (cp ../bin/login/login ./) (cp ../bin/cat/cat ./) - (./format 257 2000 init shell test ls pwd userdb login cat) + (./format 50 2000 ubix.elf init shell test ls pwd userdb login cat) + (rm ubix.elf) (rm init) (rm shell) (rm test) diff --git a/src/tools/format.c b/src/tools/format.c index 5a043f7..1120282 100755 --- a/src/tools/format.c +++ b/src/tools/format.c @@ -30,7 +30,7 @@ exit(1); } driveFd = fopen("/dev/fd0","wb"); - startSector = atoi(argv[1]); + startSector = atoi(argv[1])-1; size = atoi(argv[2])*512; structSize = sizeof(struct blockAllocationTableEntry); structSize *= (size/4096); @@ -60,12 +60,14 @@ sprintf(dirEntry[1].fileName,".."); BAT[0].nextBlock = 0x0; BAT[0].attributes = 1; - BAT[0].realSector = (startSector + (batSize/512)); + //BAT[0].realSector = (startSector + (batSize/512)); + BAT[0].realSector = (batSize/512); printf("Real Sector: [%i]\n",BAT[0].realSector); for (i=1;i<(size/4096);i++) { BAT[i].nextBlock = 0x0; BAT[i].attributes = 0x0; - BAT[i].realSector = (startSector + (batSize/512) + (i*8)); + //BAT[i].realSector = (startSector + (batSize/512) + (i*8)); + BAT[i].realSector = ((batSize/512) + (i*8)); BAT[i].reserved = 0x0; } file = 0x2; @@ -79,13 +81,14 @@ dirEntry[file].permissions = 0xEAA; rewind(driveFd); //fseek(driveFd,((BAT[startSector].realSector * 512) + ((batSize/512)+(BAT[block].realSector*4096))),0); - fseek(driveFd,(BAT[block].realSector * 512),0); + fseek(driveFd,((startSector + BAT[block].realSector) * 512),0); while (!feof(fileFd)) { if (4096 == (counter - (blockCount * 4096))) { block = findFreeBlock(block,(size/4096)); + printf("Block: [%i][%s]\n",block,argv[x]); rewind(driveFd); //fseek(driveFd,((startSector * 512) + ((batSize/512)+(BAT[block].realSector*4096))),0); - fseek(driveFd,(BAT[block].realSector * 512),0); + fseek(driveFd,((startSector + BAT[block].realSector) * 512),0); blockCount++; } fputc(fgetc(fileFd),driveFd);