diff --git a/sys/arch/i386/i386_exec.c b/sys/arch/i386/i386_exec.c index 6f904e9..e78a2a8 100644 --- a/sys/arch/i386/i386_exec.c +++ b/sys/arch/i386/i386_exec.c @@ -291,13 +291,13 @@ /* If We Dont Find the File Return */ if (newProcess->files[0] == 0x0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); + kprintf("Exec Format Error: Binary File Not Executable1.\n"); fclose(newProcess->files[0]); return; } if (newProcess->files[0]->perms == 0x0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); + kprintf("Exec Format Error: Binary File Not Executable2.\n"); fclose(newProcess->files[0]); return; } @@ -309,19 +309,19 @@ /* Check If App Is A Real Application */ if ((binaryHeader->e_ident[1] != 'E') && (binaryHeader->e_ident[2] != 'L') && (binaryHeader->e_ident[3] != 'F')) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); + kprintf("Exec Format Error: Binary File Not Executable3.\n"); kfree(binaryHeader); fclose(newProcess->files[0]); return; } else if (binaryHeader->e_type != 2) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); + kprintf("Exec Format Error: Binary File Not Executable4.\n"); kfree(binaryHeader); fclose(newProcess->files[0]); return; } else if (binaryHeader->e_entry == 0x300000) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); + kprintf("Exec Format Error: Binary File Not Executable5.\n"); kfree(binaryHeader); fclose(newProcess->files[0]); return; @@ -532,7 +532,7 @@ /* Test If Executable */ if (fd->perms == 0) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); + kprintf("Exec Format Error: Binary File Not Executable6.\n"); fclose(fd); return (-1); } @@ -573,19 +573,19 @@ /* Check If App Is A Real Application */ if ((binaryHeader->e_ident[1] != 'E') && (binaryHeader->e_ident[2] != 'L') && (binaryHeader->e_ident[3] != 'F')) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); + kprintf("Exec Format Error: Binary File Not Executable7.\n"); kfree(binaryHeader); fclose(fd); return (-1); } else if (binaryHeader->e_type != ET_EXEC) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); + kprintf("Exec Format Error: Binary File Not Executable8.\n"); kfree(binaryHeader); fclose(fd); return (-1); } else if (binaryHeader->e_entry == 0x300000) { - kprintf("Exec Format Error: Binary File Not Executable.\n"); + kprintf("Exec Format Error: Binary File Not Executable9.\n"); kfree(binaryHeader); fclose(fd); return (-1); diff --git a/sys/fs/fat/fat.c b/sys/fs/fat/fat.c new file mode 100644 index 0000000..0eab1cd --- /dev/null +++ b/sys/fs/fat/fat.c @@ -0,0 +1,187 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id: ubixfs.c 79 2016-01-11 16:21:27Z reddawg $ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fat_filelib.h" +#include "fat_access.h" + +fileDescriptor_t *_fd; +struct vfs_mountPoint *_mp; + +int media_read(unsigned long sector, unsigned char *buffer, unsigned long sector_count) +{ + _mp->device->devInfo->read(_mp->device->devInfo->info, buffer, sector, sector_count); + + return 1; +} + +int media_write(unsigned long sector, unsigned char *buffer, unsigned long sector_count) +{ + _mp->device->devInfo->write(_mp->device->devInfo->info, buffer, sector, sector_count); + + return 1; +} + + +int fat_initialize(struct vfs_mountPoint *mp) { + FL_FILE *file; + _mp = mp; + // Attach media access functions to library + if (fl_attach_media(media_read, media_write) != FAT_INIT_OK) + { + kprintf("ERROR: Media attach failed\n"); + return(0); + } + + // List root directory + fl_listdirectory("/"); + // Create File + /* + file = fl_fopen("/file.bin", "w"); + unsigned char data[] = { 1, 2, 3, 4 }; + if (file) + { + // Write some data + if (fl_fwrite(data, 1, sizeof(data), file) != sizeof(data)) + kprintf("ERROR: Write file failed\n"); + } + else + kprintf("ERROR: Create file failed\n"); + + // Close file + fl_fclose(file); + + fl_listdirectory("/"); + + // Delete File + if (fl_remove("/file.bin") < 0) + kprintf("ERROR: Delete file failed\n"); + + // List root directory + fl_listdirectory("/"); + + size_t size; + + file = fl_fopen("/shell", "r"); + size = fl_fread(data, 1, sizeof(data), file); + kprintf("READ: %i", size); + fl_fclose(file); + */ + return(1); +} + +int read_fat(fileDescriptor_t *fd,char *data,uInt32 offset,long size) { + FL_FILE *_file = (FL_FILE *)fd->res; + + kprintf("Reading: %i[%i]\n", size, offset); + fl_fseek(_file, offset, 0); + size = fl_fread(data, size, 1, _file); + + kprintf("Read: %i\n", size); + + /* Return */ + return(size); + } + + +int write_fat() { + return(0); +} + +int open_fat(const char *file, fileDescriptor_t *fd) { + FL_FILE *_file; + + assert(fd); + assert(fd->mp); + assert(fd->mp->device); + assert(fd->mp->device->devInfo); + assert(fd->mp->device->devInfo->read); + assert(file); + + kprintf(file); + + _file = fl_fopen(file, "r"); + if (!_file) { + kprintf("ERROR: Open file failed\n"); + return(0x0); + } + else { + fd->res = _file; + fd->perms = 0x1; + } + + return(0x1); +} + + + +int unlink_fat() { + return(0); +} + +int mkdir_fat() { + return(0); +} + +int fat_init() { + // Initialise File IO Library + fl_init(); + + /* Set up our file system structure */ + struct fileSystem ubixFileSystem = + {NULL, /* prev */ + NULL, /* next */ + (void *)fat_initialize, /* vfsInitFS */ + (void *)read_fat, /* vfsRead */ + (void *)write_fat, /* vfsWrite */ + (void *)open_fat, /* vfsOpenFile */ + (void *)unlink_fat, /* vfsUnlink */ + (void *)mkdir_fat, /* vfsMakeDir */ + NULL, /* vfsRemDir */ + NULL, /* vfsSync */ + 0xFA /* vfsType */ + }; /* ubixFileSystem */ + + /* Add UbixFS */ + if (vfsRegisterFS(ubixFileSystem) != 0x0) { + kpanic("Unable To Enable UbixFS"); + return(0x1); + } + + /* Return */ + return(0x0); + } diff --git a/sys/include/vfs/file.h b/sys/include/vfs/file.h index eee6c04..29e8dea 100644 --- a/sys/include/vfs/file.h +++ b/sys/include/vfs/file.h @@ -79,6 +79,7 @@ uint32_t resid; struct inode inode; int fd_type; + void *res; } fileDescriptor_t; typedef struct userFileDescriptorStruct { diff --git a/sys/init/main.c b/sys/init/main.c index 11a825b..7e757e7 100644 --- a/sys/init/main.c +++ b/sys/init/main.c @@ -187,7 +187,7 @@ execThread(systemTask, 0x2000, 0x0); //execFile("sys:/bin/init", argv_init, envp_init, 0x0); /* OS Initializer */ - execFile("fat:/shell", argv_init, envp_init, 0x0); + execFile("fat:/init", argv_init, envp_init, 0x0); irqEnable(0x0);