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: vfs_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
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 #include <sys/kern_descrip.h>
00036 
00037 /************************************************************************
00038 
00039 Function: void vfs_init();
00040 
00041 Description: This Function Initializes The VFS Layer
00042 
00043 Notes:
00044 
00045 02/20/2004 - Approved for quality
00046 
00047 ************************************************************************/
00048 int vfs_init() {
00049   /* Set up default fileSystems list */
00050   systemVitals->fileSystems = 0x0;
00051 
00052   /* Print information */
00053   kprintf("vfs0: loaded at address: [0x%X]\n",systemVitals->fileSystems);
00054 
00055   /* Return so we know things went well */
00056   return(0x0);
00057   }
00058 
00059 struct fileSystem *vfsFindFS(int vfsType) {
00060   struct fileSystem *tmp = 0x0;
00061 
00062   /* Search For File System */
00063   for (tmp=systemVitals->fileSystems;tmp;tmp=tmp->next) {
00064     /* If Found Return File System */
00065     if (tmp->vfsType == vfsType) {
00066       return(tmp);
00067       }
00068     }
00069 
00070   /* If FS Not Found Return NULL */
00071   return(0x0);
00072   }
00073 
00081 int vfsRegisterFS(struct fileSystem newFS) {
00082 /*
00083 int vfsType,
00084 void *vfsInitFS,
00085 void *vfsRead,
00086 void *vfsWrite,
00087 void *vfsOpenFile,
00088 void *vfsUnlink,
00089 void *vfsMakeDir,
00090 void *vfsRemDir,
00091 void *vfsSync) {
00092  */
00093   struct fileSystem *tmpFs = 0x0;
00094 
00095   if (vfsFindFS(newFS.vfsType) != 0x0) {
00096     kprintf("FS Is already Registered\n"); 
00097     return(0x1);
00098     }
00099 
00100   /* Allocate Memory */
00101   tmpFs = (struct fileSystem *)kmalloc(sizeof(struct fileSystem));
00102   if (tmpFs == NULL) {
00103         kprintf("vfsRegisterFS: memory allocation failed\n");
00104     /* Memory Allocation Failed */
00105     return(0x1);
00106     }
00107 
00108   /* Set Up FS Defaults */
00109 
00110 /* 2004 7-16-2004 mji 
00111  * Old method:
00112  * tmpFs->vfsType       = newFS.vfsType;
00113  * tmpFs->vfsInitFS     = newFS.vfsInitFS;
00114  * tmpFs->vfsRead       = newFS.vfsRead;
00115  * tmpFs->vfsWrite      = newFS.vfsWrite;
00116  * tmpFs->vfsOpenFile   = newFS.vfsOpenFile;
00117  * tmpFs->vfsUnlink     = newFS.vfsUnlink;
00118  * tmpFs->vfsMakeDir    = newFS.vfsMakeDir;
00119  * tmpFs->vfsRemDir     = newFS.vfsRemDir;
00120  * tmpFs->vfsSync       = newFS.vfsSync;
00121  */
00122  /* new method: */
00123 
00124   memcpy(tmpFs, &newFS, sizeof(struct fileSystem)); 
00125   if (!systemVitals->fileSystems) {
00126     tmpFs->prev               = 0x0;
00127     tmpFs->next               = 0x0;
00128     systemVitals->fileSystems = tmpFs;
00129     }
00130   else {
00131     tmpFs->prev                     = 0x0;
00132     tmpFs->next                     = systemVitals->fileSystems;
00133     systemVitals->fileSystems->prev = tmpFs;
00134     systemVitals->fileSystems       = tmpFs;
00135     }
00136 
00137   return(0x0);
00138   }
00139 
00148 int sys_open(struct thread *td, struct open_args *uap) {
00149   int          error = 0x0;
00150   int          index = 0x0;
00151   struct file *nfp   = 0x0;
00152 
00153   error = falloc(td,&nfp,&index);
00154 
00155   if (error)
00156      return(error);
00157 
00158   strcpy(nfp->path,uap->path);
00159 
00160   nfp->fd = fopen(uap->path,"r");
00161   if (nfp->fd == 0x0)
00162     td->td_retval[0] = -1;
00163   else
00164     td->td_retval[0] = index;
00165   return (error);
00166   }
00167 
00168 
00169 /***
00170  END
00171  ***/
00172 

Generated on Fri Dec 15 11:18:55 2006 for UbixOS V2 by  doxygen 1.4.7