diff --git a/sys/fs/ufs/ufs.c b/sys/fs/ufs/ufs.c index 9ecb3ce..0e4d9bd 100644 --- a/sys/fs/ufs/ufs.c +++ b/sys/fs/ufs/ufs.c @@ -267,10 +267,14 @@ static int ufs_openFile(const char *file, fileDescriptor_t *fd) { char tmp[2]; int ino = 0; + fd->dmadat = (struct dmadat *) kmalloc(sizeof(struct dmadat)); + ino = lookup(file, fd); + fd->offset = 0x0; fd->ino = ino; + if (ino == 0x0) { kfree(fd->dmadat); return (-1); @@ -279,6 +283,7 @@ /* Quick Hack for file size */ fsread(fd->ino, &tmp, 1, fd); fd->offset = 0; + /* Return */ fd->perms = 0x1; return (0x1); diff --git a/sys/fs/vfs/file.c b/sys/fs/vfs/file.c index f27f5db..4001910 100644 --- a/sys/fs/vfs/file.c +++ b/sys/fs/vfs/file.c @@ -51,9 +51,9 @@ if (uap->fd == 0x0) tty_print((char *) uap->buf, _current->term); else { - #ifdef DEBUG_VFS +#ifdef DEBUG_VFS kprintf("uap->size: %i, FD: [0x%X], BUF: [0x%X][%c]\n", uap->nbytes, uap->fd, uap->buf, t[0]); - #endif +#endif fwrite(uap->buf, uap->nbytes, 1, uap->fd->fd); } @@ -67,7 +67,8 @@ void sysFwrite(char *ptr, int size, userFileDescriptor *userFd) { if (userFd == 0x0) { tty_print(ptr, _current->term); - } else { + } + else { fwrite(ptr, size, 1, userFd->fd); } return; @@ -90,7 +91,8 @@ sched_yield(); - } else { + } + else { sched_yield(); } /* @@ -103,7 +105,8 @@ } */ } - } else { + } + else { c = fgetc(args->FILE->fd); td->td_retval[0] = c; return (0); @@ -129,15 +132,15 @@ } switch (args->whence) { - case 0: - args->FILE->fd->offset = args->offset + args->whence; - break; - case 1: - args->FILE->fd->offset += args->offset; - break; - default: - kprintf("seek-whence: %i", args->whence); - break; + case 0: + args->FILE->fd->offset = args->offset + args->whence; + break; + case 1: + args->FILE->fd->offset += args->offset; + break; + default: + kprintf("seek-whence: %i", args->whence); + break; } td->td_retval[0] = args->FILE->fd->offset & 0xFFFFFFFF; @@ -161,19 +164,19 @@ kprintf("loffset(%i): %i:%i, whence: 0x%X", sizeof(off_t), args->offset >> 32, args->offset & 0xFFFFFF, args->whence); switch (args->whence) { - case SEEK_SET: - fd->offset = args->offset; - td->td_retval[0] = fd->offset & 0xFFFFFFFF; - td->td_retval[1] = fd->offset >> 32; - break; - case SEEK_CUR: - fd->offset += args->offset; - td->td_retval[0] = fd->offset & 0xFFFFFFFF; - td->td_retval[1] = fd->offset >> 32; - break; - default: - kprintf("seek-whence: %i", args->whence); - break; + case SEEK_SET: + fd->offset = args->offset; + td->td_retval[0] = fd->offset & 0xFFFFFFFF; + td->td_retval[1] = fd->offset >> 32; + break; + case SEEK_CUR: + fd->offset += args->offset; + td->td_retval[0] = fd->offset & 0xFFFFFFFF; + td->td_retval[1] = fd->offset >> 32; + break; + default: + kprintf("seek-whence: %i", args->whence); + break; } kprintf("loff: %ld", fd->offset); @@ -184,7 +187,8 @@ int sys_chdir(struct thread *td, struct sys_chdir_args *args) { if (strstr(args->path, ":") == 0x0) { sprintf(_current->oInfo.cwd, "%s%s", _current->oInfo.cwd, args->path); - } else { + } + else { sprintf(_current->oInfo.cwd, args->path); } td->td_retval[0] = 0; @@ -202,10 +206,12 @@ if (fdd == 0 || fdd->fd == 0x0) { error = -1; - } else { + } + else { if (strstr(fd->fileName, ":") == 0x0) { sprintf(_current->oInfo.cwd, "%s%s", _current->oInfo.cwd, fd->fileName); - } else { + } + else { sprintf(_current->oInfo.cwd, fd->fileName); } } @@ -381,6 +387,7 @@ ************************************************************************/ fileDescriptor_t *fopen(const char *file, const char *flags) { + int i = 0x0; char *path = 0x0; char *mountPoint = 0x0; @@ -393,11 +400,11 @@ return (NULL); } - /* XXX - Temp */ memset(tmpFd, 0x0, sizeof(fileDescriptor_t)); path = file; + /* Determine if path is relative or absolute */ if (path[0] == "." && path[1] == '\0') strcpy(fileName, _current->oInfo.cwd); else @@ -408,7 +415,8 @@ if (strstr(fileName, ":")) { mountPoint = (char *) strtok((char *) &fileName, ":"); path = strtok( NULL, "\n"); - } else { + } + else { path = fileName; } @@ -420,7 +428,8 @@ /* Find our mount point or set default to sys */ if (mountPoint == 0x0) { tmpFd->mp = vfs_findMount("sys"); - } else { + } + else { tmpFd->mp = vfs_findMount(mountPoint); } @@ -429,33 +438,33 @@ return (0x0); } - //kprintf("[fO: %s]", file); /* This Will Set Up The Descriptor Modes */ tmpFd->mode = 0; for (i = 0; '\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: - kprintf("Invalid mode '%c' for fopen\n", flags[i]); - break; + 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: + kprintf("Invalid mode '%c' for fopen\n", flags[i]); + break; } } + /* Search For The File */ if (tmpFd->mp->fs->vfsOpenFile(tmpFd->fileName, tmpFd) == 0x1) { /* If The File Is Found Then Set Up The Descriptor */ @@ -463,12 +472,14 @@ /* in order to save resources we will allocate the buffer later when it is needed */ tmpFd->buffer = (char *) kmalloc(4096); + if (tmpFd->buffer == 0x0) { kfree(tmpFd); kprintf("Error: tmpFd->buffer == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); spinUnlock(&fdTable_lock); return (0x0); } + /* Set Its Status To Open */ tmpFd->status = fdOpen; @@ -494,7 +505,8 @@ /* Return The FD */ return (tmpFd); - } else { + } + else { //kprintf("Freeing"); kfree(tmpFd->buffer); kfree(tmpFd); @@ -607,7 +619,8 @@ mountPoint = strtok( NULL, "\n"); if (mountPoint == 0x0) { mp = vfs_findMount("sys"); /* _current->oInfo.container; */ - } else { + } + else { mp = vfs_findMount(mountPoint); } if (mp == 0x0) { diff --git a/sys/kernel/vfs_calls.c b/sys/kernel/vfs_calls.c index acc1b86..73574a1 100644 --- a/sys/kernel/vfs_calls.c +++ b/sys/kernel/vfs_calls.c @@ -418,10 +418,13 @@ return (error); } + if (flags | O_CREAT) + kprintf("O_CREAT\n"); + nfp->f_flag = flags & FMASK; - nfp->fd = fopen(args->path, "rb"); + nfp->fd = fopen(args->path, "rwb"); if (nfp->fd == 0x0) {