diff --git a/src/bin/init/main.c b/src/bin/init/main.c index b9fa910..729fd68 100644 --- a/src/bin/init/main.c +++ b/src/bin/init/main.c @@ -74,9 +74,6 @@ while (pidStatus(i) > 0x0) { sched_yield(); } - - printf("test-init\n"); - while (1); startup: i = fork(); @@ -111,6 +108,9 @@ /*** $Log$ + Revision 1.25 2004/09/08 23:19:58 reddawg + hmm + Revision 1.24 2004/08/25 22:02:41 reddawg task switching - We now are using software switching to be consistant with the rest of the world because all of this open source freaks gave me a hard time about something I liked. There doesn't seem to be any gain in performance but it is working fine and flawlessly diff --git a/src/bin/ls/main.c b/src/bin/ls/main.c index 5ab6254..6ae8033 100644 --- a/src/bin/ls/main.c +++ b/src/bin/ls/main.c @@ -124,7 +124,7 @@ next: } } - if (!fclose(fd)) { + if (fclose(fd) != 0x0) { printf("Error Closing Directory\n"); } return(0); diff --git a/src/sys/include/vfs/file.h b/src/sys/include/vfs/file.h index 83c5f4f..44b57c2 100644 --- a/src/sys/include/vfs/file.h +++ b/src/sys/include/vfs/file.h @@ -30,37 +30,38 @@ #define SEEK_SET 0x0 -struct taskFileInfo { - char *cwd; - }; - typedef struct fileDescriptorStruct { struct fileDescriptorStruct *prev; struct fileDescriptorStruct *next; vfs_mountPoint_t *mp; - uInt16 status; - uInt16 mode; - uInt32 offset; - uInt32 size; - uInt16 length; - uInt32 start; - char fileName[512]; - char *buffer; - struct cacheNode *cacheNode; - uInt32 perms; + uInt16 status; + uInt16 mode; + uInt32 offset; + uInt32 size; + uInt16 length; + uInt32 start; + char fileName[512]; + char *buffer; + struct cacheNode *cacheNode; + uInt32 perms; } fileDescriptor; + typedef struct userFileDescriptorStruct { struct fileDescriptorStruct *fd; - uInt32 fdSize; + uInt32 fdSize; } userFileDescriptor; extern fileDescriptor *fdTable; -extern fileDescriptor *lastFd; -fileDescriptor *fopen(const char *file,const char *flags); +fileDescriptor *fopen(const char *,const char *); +int fclose(fileDescriptor *); + + +/* UBU */ + + int unlink(const char *path); -int fclose(fileDescriptor *fd); int feof(fileDescriptor *fd); int fgetc(fileDescriptor *fd); size_t fread(void *ptr, size_t size, size_t nmemb,fileDescriptor *fd); diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 059562e..55743d3 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -111,7 +111,7 @@ /* Initialize the system */ execThread(systemTask,(kmalloc(0x2000)+0x2000),0x0); - execFile("sys:/init",0x0,0x0,0x1); + //execFile("sys:/init",0x0,0x0,0x1); /* execFile("sys:/login",0x0,0x0,0x1); @@ -134,6 +134,9 @@ /*** $Log$ + Revision 1.82 2004/09/07 21:54:38 reddawg + ok reverted back to old scheduling for now.... + Revision 1.81 2004/09/07 20:58:35 reddawg time to roll back i can't think straight by friday diff --git a/src/sys/kernel/file.c b/src/sys/kernel/file.c index 6923fbd..8cba84d 100644 --- a/src/sys/kernel/file.c +++ b/src/sys/kernel/file.c @@ -38,8 +38,6 @@ #include #include -fileDescriptor *fdTable = 0x0; - /* These Are Temporary */ int sprintf(char *buf,const char *fmt, ...); char getch(); @@ -68,15 +66,10 @@ ************************************************************************/ int fputc(int ch,fileDescriptor *fd) { - fileDescriptor *tmpFd = 0x0; - /* Search For File Descriptor */ - for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { - /* If Found Return Next Char */ - if (tmpFd == fd) { - ch = tmpFd->mp->fs->vfsWrite(tmpFd,(char *)ch,tmpFd->offset,1); - tmpFd->offset++; - return(ch); - } + if (fd != 0x0) { + ch = fd->mp->fs->vfsWrite(fd,(char *)ch,fd->offset,1); + fd->offset++; + return(ch); } /* Return NULL If FD Is Not Found */ return(0x0); @@ -91,16 +84,13 @@ ************************************************************************/ int fgetc(fileDescriptor *fd) { int ch = 0x0; - fileDescriptor *tmpFd = 0x0; - /* Search For File Descriptor */ - for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { - /* If Found Return Next Char */ - if (tmpFd == fd) { - tmpFd->mp->fs->vfsRead(tmpFd,(char *)&ch,tmpFd->offset,1); - tmpFd->offset++; - return(ch); - } + /* If Found Return Next Char */ + if (fd != 0x0) { + fd->mp->fs->vfsRead(fd,(char *)&ch,fd->offset,1); + fd->offset++; + return(ch); } + /* Return NULL If FD Is Not Found */ return(0x0); } @@ -121,14 +111,9 @@ } size_t fwrite(void *ptr,int size,int nmemb,fileDescriptor *fd) { - fileDescriptor *tmpFd = 0x0; - /* Search For File Descriptor */ - for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { - /* If Found Return Next Char */ - if (tmpFd == fd) { - tmpFd->mp->fs->vfsWrite(tmpFd,ptr,tmpFd->offset,size * nmemb); - tmpFd->offset += size * nmemb; - } + if (fd != 0x0) { + fd->mp->fs->vfsWrite(fd,ptr,fd->offset,size * nmemb); + fd->offset += size * nmemb; } return(0x0); } @@ -151,21 +136,7 @@ /* Return */ return; } - -#if 0 -size_t fread(void *ptr, int size, int nmemb,fileDescriptor *fd) { - /* YO! what about EOF's in the middle of reading?? */ - - int i = 0x0; - char *data = (char *)ptr; - for (i=0;iterm); } @@ -193,19 +159,6 @@ } return; } - -/************************************************************************ - -Function: void sysFclse(); -Description: Closes A File Descriptor For A User Task -Notes: - -************************************************************************/ -void sysFclose(userFileDescriptor *userFd,int *status) { - *status = fclose(userFd->fd); - /* Return */ - return; - } void sysFgetc(int *ptr,userFileDescriptor *userFd) { fileDescriptor *tmpFd = 0x0; @@ -292,6 +245,9 @@ /*** $Log$ + Revision 1.16 2004/09/08 23:19:58 reddawg + hmm + Revision 1.15 2004/08/09 12:58:05 reddawg let me know when you got the surce diff --git a/src/sys/kernel/sched.c b/src/sys/kernel/sched.c index 65c5357..9bf90d4 100644 --- a/src/sys/kernel/sched.c +++ b/src/sys/kernel/sched.c @@ -223,7 +223,6 @@ void sched_yield() { - //asm("hlt"); sched(); } @@ -255,6 +254,9 @@ /*** $Log$ + Revision 1.51 2004/09/08 22:16:02 reddawg + Fixens + Revision 1.50 2004/09/08 21:19:32 reddawg All good now diff --git a/src/sys/lib/kmalloc.c b/src/sys/lib/kmalloc.c index 0d65317..23554c3 100644 --- a/src/sys/lib/kmalloc.c +++ b/src/sys/lib/kmalloc.c @@ -130,14 +130,12 @@ kpanic("Inserting Descriptor with no limit\n"); if (freeKernDesc != 0x0) { - /* - */ + freeDesc->next = freeKernDesc; freeDesc->prev = 0x0; freeKernDesc->prev = freeDesc; freeKernDesc = freeDesc; - /* - */ + /* for (tmpDesc = freeKernDesc;tmpDesc != 0x0;tmpDesc = tmpDesc->next) { if (freeDesc->limit <= tmpDesc->limit) { @@ -180,7 +178,7 @@ 03/05/03 - We Have A Problem It Seems The First Block Is Limit 0x0 ************************************************************************/ - +#if 0 static void mergeMemBlocks() { struct memDescriptor *tmpDesc1 = 0x0; struct memDescriptor *tmpDesc2 = 0x0; @@ -231,6 +229,7 @@ } return; } +#endif /************************************************************************ @@ -273,7 +272,6 @@ if (usedKernDesc != 0x0) usedKernDesc->prev = tmpDesc1; usedKernDesc = tmpDesc1; - /* if (tmpDesc1->limit > (len + 32)) { tmpDesc2 = getEmptyDesc(); assert(tmpDesc2); @@ -283,7 +281,7 @@ tmpDesc2->next = 0x0; tmpDesc2->prev = 0x0; insertFreeDesc(tmpDesc2); - }*/ + } buf = (char *)tmpDesc1->baseAddr; for (i=0;ilimit;i++) { (char)buf[i] = (char)0x0; @@ -342,6 +340,7 @@ struct memDescriptor *tmpDesc1 = 0x0; spinLock(&mallocSpinLock); + assert(baseAddr); assert(usedKernDesc); @@ -379,6 +378,9 @@ /*** $Log$ + Revision 1.24 2004/09/08 23:19:58 reddawg + hmm + Revision 1.23 2004/09/06 15:13:25 reddawg Last commit before FreeBSD 6.0 diff --git a/src/sys/vfs/file.c b/src/sys/vfs/file.c index 61279a2..5feca74 100644 --- a/src/sys/vfs/file.c +++ b/src/sys/vfs/file.c @@ -39,7 +39,144 @@ #include #include -static spinLock_t fopen_lock = SPIN_LOCK_INITIALIZER; +static spinLock_t fdTable_lock = SPIN_LOCK_INITIALIZER; + + +fileDescriptor *fdTable = 0x0; + +/* USER */ + +/************************************************************************ + +Function: void sysFclse(); +Description: Closes A File Descriptor For A User Task +Notes: + +************************************************************************/ +void sysFclose(userFileDescriptor *userFd,int *status) { + *status = fclose(userFd->fd); + /* Return */ + return; + } + +/* KERNEL */ + +/************************************************************************ + +Function: fileDescriptor *fopen(const char *file,cont char *flags) +Description: This Will Open A File And Return A File Descriptor +Notes: + +08/05/02 - Just Started A Rewrite Of This Function Should Work Out Well + +************************************************************************/ + +fileDescriptor *fopen(const char *file,const char *flags) { + int i = 0x0; + char *path = 0x0; + char *mountPoint = 0x0; + char fileName[1024]; + fileDescriptor *tmpFd = 0x0; + + spinLock(&fdTable_lock); + + /* Allocate Memory For File Descriptor */ + if ((tmpFd = (fileDescriptor *)kmalloc(sizeof(fileDescriptor))) == 0x0) { + kprintf("Error: tmpFd == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); + spinUnlock(&fdTable_lock); + return(0x0); + } + + sprintf(fileName,file); + + if (strstr(file,":")) { + mountPoint = (char *)strtok((char *)&fileName,":"); + path = strtok(NULL,"\n"); + } + else { + path = &fileName; + } + + if (path[0] == '/') { + sprintf(tmpFd->fileName,path); + } + else { + sprintf(tmpFd->fileName,"/%s",path); + } + + /* Find our mount point or set default to sys */ + if (mountPoint == 0x0) { + tmpFd->mp = vfs_findMount("sys"); + } + else { + tmpFd->mp = vfs_findMount(mountPoint); + } + + if (tmpFd->mp == 0x0) { + kprintf("Mount Point Bad\n"); + spinUnlock(&fdTable_lock); + return(0x0); + } + + /* This Will Set Up The Descriptor Modes */ + tmpFd->mode = 0x0; + for (i = 0x0;'\0' != flags[i];i++) { + switch(flags[i]) { + case 'w': + case 'W': + tmpFd->mode |= fileWrite; + break; + case 'r': + case 'R': + tmpFd->mode |= fileRead; + break; + case 'b': + case 'B': + tmpFd->mode |= fileBinary; + break; + case 'a': + case 'A': + tmpFd->mode |= fileAppend; + break; + default: + break; + } + } + /* Search For The File */ + if (tmpFd->mp->fs->vfsOpenFile(tmpFd->fileName,tmpFd) == 0x1) { + /* If The File Is Found Then Set Up The Descriptor */ + tmpFd->buffer = (char *)kmalloc(0x1000); + + /* Set Its Status To Open */ + tmpFd->status = fdOpen; + + /* Initial File Offset Is Zero */ + tmpFd->offset = 0x0; + + /* Increment Number Of Open Files */ + systemVitals->openFiles++; + + tmpFd->prev = 0x0; + tmpFd->next = fdTable; + + if (fdTable != 0x0) + fdTable->prev = tmpFd; + + fdTable = tmpFd; + + /* Return The FD */ + spinUnlock(&fdTable_lock); + return(tmpFd); + } + else { + /* If The File Was Not Found Free The Memory */ + kfree(tmpFd); + } + + /* Return NULL */ + spinUnlock(&fdTable_lock); + return(0x0); + } /************************************************************************ @@ -51,36 +188,32 @@ int fclose(fileDescriptor *fd) { fileDescriptor *tmpFd = 0x0; assert(fd); - /* Search For File Descriptor */ - for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { + + spinLock(&fdTable_lock); + + for (tmpFd = fdTable;tmpFd != 0x0;tmpFd = tmpFd->next) { if (tmpFd == fd) { - /* If Fd Is The First FD Then Reset fdTable */ - if (tmpFd == fdTable) { + if (tmpFd->prev) + tmpFd->prev->next = tmpFd->next; + if (tmpFd->next) + tmpFd->next->prev = tmpFd->prev; + + if (tmpFd == fdTable) fdTable = tmpFd->next; - if (fdTable != 0x0) { - fdTable->prev = 0x0; - } - kfree(fd->buffer); - kfree(fd); - systemVitals->openFiles--; - return(0x1); - } - else { - if (tmpFd->prev) - tmpFd->prev->next = tmpFd->next; - if (tmpFd->next) - tmpFd->next->prev = tmpFd->prev; - kfree(fd->buffer); - kfree(fd); - systemVitals->openFiles--; - return(0x1); - } - } + + kfree(tmpFd->buffer); + kfree(tmpFd); + spinUnlock(&fdTable_lock); + return(0x0); + } } - /* Return NULL If Descriptor Was Not Found */ - return(0x0); + + spinUnlock(&fdTable_lock); + return(0x1); } +/* UBU */ + /************************************************************************ Function: void sysMkDir(const char *path) @@ -120,7 +253,6 @@ fclose(tmpFD); - //kprintf("Dir: %s,Mount Point: %s\n",dir,mountPoint); return; } @@ -154,128 +286,11 @@ } -/************************************************************************ - -Function: fileDescriptor *fopen(const char *file,cont char *flags) -Description: This Will Open A File And Return A File Descriptor -Notes: - -08/05/02 - Just Started A Rewrite Of This Function Should Work Out Well - -************************************************************************/ - -fileDescriptor *fopen(const char *file,const char *flags) { - int i = 0; - fileDescriptor *tmpFd = 0x0; - char *path = 0x0,*mountPoint = 0x0; - - spinLock(&fopen_lock); - - /* Allocate Memory For File Descriptor */ - if ((tmpFd = (fileDescriptor *)kmalloc(sizeof(fileDescriptor))) == 0x0) { - kprintf("Error: tmpFd == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); - } - path = tmpFd->fileName; - - if (strstr(file,":")) { - sprintf(tmpFd->fileName,file); - mountPoint = (char *)strtok((char *)tmpFd->fileName,":"); - path = strtok(NULL,"\n"); - } - else { - if (file[0] == '/') { - sprintf(tmpFd->fileName,file); - } - else { - sprintf(tmpFd->fileName,"/%s",file); - } - } - - i = strlen(path); - if (i > 2) { - if (path[i-1] == '/') - path[i-1] = '\0'; - } - - if (mountPoint == 0x0) { - tmpFd->mp = vfs_findMount("sys"); - } - else { - tmpFd->mp = vfs_findMount(mountPoint); - } - if (tmpFd->mp == 0x0) { - kprintf("Mount Point Bad\n"); - spinUnlock(&fopen_lock); - return(0x0); - } - /* This Will Set Up The Descriptor Modes */ - tmpFd->mode = 0x0; - for (i = 0x0;'\0' != flags[i];i++) { - switch(flags[i]) { - case 'w': - case 'W': - tmpFd->mode |= fileWrite; - break; - case 'r': - case 'R': - tmpFd->mode |= fileRead; - break; - case 'b': - case 'B': - tmpFd->mode |= fileBinary; - break; - case 'a': - case 'A': - tmpFd->mode |= fileAppend; - break; - default: - break; - } - } - /* Search For The File */ - - if (tmpFd->mp->fs->vfsOpenFile((char *)path,tmpFd) == 1) { - /* If The File Is Found Then Set Up The Descriptor */ - tmpFd->buffer = (char *)kmalloc(4096); - //sprintf(tmpFd->fileName,"%s",file); - /* Set Its Status To Open */ - tmpFd->status = fdOpen; - /* Initial File Offset Is Zero */ - tmpFd->offset = 0x0; - /* Pointer To Next Descriptor Is NULL */ - tmpFd->prev = 0x0; - /* If This Is The First File Descriptor Then Set It Up To Be Starting Fd */ - if (fdTable == 0x0) { - fdTable = tmpFd; - tmpFd->next = 0x0; - tmpFd->prev = 0x0; - } - else { - /* If There Is Already A Starting FD Set This Up As The Last One */ - tmpFd->next = fdTable; - fdTable->prev = tmpFd; - tmpFd->prev = 0x0; - fdTable = tmpFd; - } - /* Increment Number Of Open Files */ - systemVitals->openFiles++; - - /* Return The FD */ - spinUnlock(&fopen_lock); - return(fdTable); - } - else { - /* If The File Was Not Found Free The Memory */ - kfree(tmpFd); - } - - /* Return NULL */ - spinUnlock(&fopen_lock); - return(0x0); - } - /*** $Log$ + Revision 1.21 2004/08/21 17:36:57 reddawg + updates: converted to software task switching however it is not working yet + Revision 1.20 2004/08/14 11:23:02 reddawg Changes