vfs.c

Go to the documentation of this file.
00001 /*****************************************************************************************
00002  Copyright (c) 2002-2004 The UbixOS Project
00003  All rights reserved.
00004 
00005  Redistribution and use in source and binary forms, with or without modification, are
00006  permitted provided that the following conditions are met:
00007 
00008  Redistributions of source code must retain the above copyright notice, this list of
00009  conditions, the following disclaimer and the list of authors.  Redistributions in binary
00010  form must reproduce the above copyright notice, this list of conditions, the following
00011  disclaimer and the list of authors in the documentation and/or other materials provided
00012  with the distribution. Neither the name of the UbixOS Project nor the names of its
00013  contributors may be used to endorse or promote products derived from this software
00014  without specific prior written permission.
00015 
00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00017  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00018  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
00019  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00020  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00021  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00023  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00024  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 
00026  $Id$
00027 
00028 *****************************************************************************************/
00029 
00030 #include <vfs/vfs.h>
00031 #include <ubixos/vitals.h>
00032 #include <lib/kmalloc.h>
00033 #include <lib/kprintf.h>
00034 #include <lib/string.h>
00035 
00036 /************************************************************************
00037 
00038 Function: void vfs_init();
00039 
00040 Description: This Function Initializes The VFS Layer
00041 
00042 Notes:
00043 
00044 02/20/2004 - Approved for quality
00045 
00046 ************************************************************************/
00047 int vfs_init() {
00048   /* Set up default fileSystems list */
00049   systemVitals->fileSystems = 0x0;
00050 
00051   /* Print information */
00052   kprintf("vfs0: loaded at address: [0x%X]\n",systemVitals->fileSystems);
00053 
00054   /* Return so we know things went well */
00055   return(0x0);
00056   }
00057 
00058 struct fileSystem *vfsFindFS(int vfsType) {
00059   struct fileSystem *tmp = 0x0;
00060 
00061   /* Search For File System */
00062   for (tmp=systemVitals->fileSystems;tmp;tmp=tmp->next) {
00063     /* If Found Return File System */
00064     if (tmp->vfsType == vfsType) {
00065       return(tmp);
00066       }
00067     }
00068 
00069   /* If FS Not Found Return NULL */
00070   return(0x0);
00071   }
00072 
00080 int vfsRegisterFS(struct fileSystem newFS) {
00081 /*
00082 int vfsType,
00083 void *vfsInitFS,
00084 void *vfsRead,
00085 void *vfsWrite,
00086 void *vfsOpenFile,
00087 void *vfsUnlink,
00088 void *vfsMakeDir,
00089 void *vfsRemDir,
00090 void *vfsSync) {
00091  */
00092   struct fileSystem *tmpFs = 0x0;
00093 
00094   if (vfsFindFS(newFS.vfsType) != 0x0) {
00095     kprintf("FS Is already Registered\n"); 
00096     return(0x1);
00097     }
00098 
00099   /* Allocate Memory */
00100   tmpFs = (struct fileSystem *)kmalloc(sizeof(struct fileSystem));
00101   if (tmpFs == NULL) {
00102         kprintf("vfsRegisterFS: memory allocation failed\n");
00103     /* Memory Allocation Failed */
00104     return(0x1);
00105     }
00106 
00107   /* Set Up FS Defaults */
00108 
00109 /* 2004 7-16-2004 mji 
00110  * Old method:
00111  * tmpFs->vfsType       = newFS.vfsType;
00112  * tmpFs->vfsInitFS     = newFS.vfsInitFS;
00113  * tmpFs->vfsRead       = newFS.vfsRead;
00114  * tmpFs->vfsWrite      = newFS.vfsWrite;
00115  * tmpFs->vfsOpenFile   = newFS.vfsOpenFile;
00116  * tmpFs->vfsUnlink     = newFS.vfsUnlink;
00117  * tmpFs->vfsMakeDir    = newFS.vfsMakeDir;
00118  * tmpFs->vfsRemDir     = newFS.vfsRemDir;
00119  * tmpFs->vfsSync       = newFS.vfsSync;
00120  */
00121  /* new method: */
00122 
00123   memcpy(tmpFs, &newFS, sizeof(struct fileSystem)); 
00124   if (!systemVitals->fileSystems) {
00125     tmpFs->prev               = 0x0;
00126     tmpFs->next               = 0x0;
00127     systemVitals->fileSystems = tmpFs;
00128     }
00129   else {
00130     tmpFs->prev                     = 0x0;
00131     tmpFs->next                     = systemVitals->fileSystems;
00132     systemVitals->fileSystems->prev = tmpFs;
00133     systemVitals->fileSystems       = tmpFs;
00134     }
00135 
00136   return(0x0);
00137   }
00138 
00139 /***
00140  END
00141  ***/
00142 

Generated on Tue Dec 5 11:01:16 2006 for UbixOS V2 by  doxygen 1.4.7