ramdrive.cpp

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 <stdlib.h>
00031 #include <stdio.h>
00032 #include <string.h>
00033 #include <assert.h>
00034 #include "device.h"
00035 
00036 
00037 static char *ram_data = 0x0;
00038 
00039 #define RAM_DRIVE_SIZE 1024*1024*100
00040 
00041 static 
00042 int 
00043 ramDrive_read(device_t *dev,void *ptr,off_t offset,size_t length) {
00044   char *data = ram_data + (offset*512);
00045   assert(ram_data);
00046   assert(offset+length <= dev->sectors); 
00047   memcpy(ptr, data, length * 512);
00048   
00049   return(length);
00050 }
00051   
00052 static 
00053 int  
00054 ramDrive_write(device_t *dev,void *ptr,off_t offset,size_t length) {
00055   char *data = ram_data + (offset*512);
00056   assert(ram_data);
00057 
00058   assert(offset+length <= dev->sectors); 
00059   
00060   memcpy(data, ptr, length * 512);
00061   
00062   return(length);
00063 }
00064   
00065 device_t *
00066 dev_ramDrive(void) {
00067   device_t *ramDrive = 0x0;
00068   
00069   FILE *ramDisk;
00070   
00071   ramDisk = fopen("./ram.dsk","rb");
00072 
00073   ramDrive = (device_t *)malloc(sizeof(device_t));
00074   
00075   ram_data = (char *)malloc(RAM_DRIVE_SIZE);
00076   
00077   if (ramDisk != 0x0) {
00078     printf("Loaded Ram Disk\n");
00079     fread(ram_data,RAM_DRIVE_SIZE,1,ramDisk);
00080     fclose(ramDisk);
00081     }
00082   
00083   ramDrive->major = 0x1;
00084   ramDrive->sectors = RAM_DRIVE_SIZE / 512;
00085   
00086   ramDrive->read = ramDrive_read;
00087   ramDrive->write = ramDrive_write;
00088   
00089   printf("leaving dev_ramDrive()\n");
00090   return(ramDrive);
00091 
00092 } // dev_ramDrive
00093   
00094 int 
00095 dev_ramDestroy(void) {
00096   printf("dev_ramDestroy()\n");
00097   FILE *ramDisk;
00098   
00099   ramDisk = fopen("./ram.dsk","wb");
00100   
00101   fwrite(ram_data, RAM_DRIVE_SIZE ,1,ramDisk);
00102   
00103   fclose(ramDisk);
00104   
00105   printf("Saved Ram Disk\n");
00106   
00107   return(0x0);
00108 } // dev_ramDestroy
00109 
00110 /***
00111  $Log$
00112  Revision 1.1.1.1  2006/06/01 12:46:15  reddawg
00113  ubix2
00114 
00115  Revision 1.2  2005/10/12 00:13:38  reddawg
00116  Removed
00117 
00118  Revision 1.1.1.1  2005/09/26 17:24:45  reddawg
00119  no message
00120 
00121  Revision 1.5  2004/09/20 00:53:04  flameshadow
00122  chg: UbixFS::vfs_read() now works for direct block extents
00123  chg: UbixFS::vfs_read() returns ~0 on error, or the size read in on success
00124  chg: UbixFS::root member is now a fileDescriptor
00125  chg: UbixFS::vfs_init() creates a file descriptor for the root dir
00126  chg: UbixFS::vfs_format() now sets all values in the bTreeHeader before writing
00127  chg: UbixFS::vfs_format() sets the inode magic number
00128  chg: device_t::read(device_t *, void *, off_t, size_t)
00129  chg: device_t::write(device_t *, void *, off_t, size_t)
00130  chg: vfs_abstract::vfs_read(fileDescriptor *, void *, off_t, size_t)
00131  chg: vfs_abstract::vfs_write(fileDescriptor *, void *, off_t, size_t)
00132  chg: ramDrive_read(device_t *dev,void *ptr,off_t offset,size_t length)
00133  chg: ramDrive_write(device_t *dev,void *ptr,off_t offset,size_t length)
00134 
00135  Revision 1.4  2004/09/13 20:10:11  flameshadow
00136  chg: UbixFS::vfs_format() works
00137  chg: UbixFS::vfs_init() works
00138 
00139  Revision 1.3  2004/09/13 15:48:29  flameshadow
00140  chg: oops, the ramDrive is 100MB, not 512MB
00141 
00142  Revision 1.2  2004/09/13 15:21:26  flameshadow
00143  add: ramdrive.h
00144  chg: renamed device_t.size to sectors
00145  chg: made #define for size of ramdisk
00146  chg: calculated sectors of ramdisk and stored in the device_t struct
00147 
00148  Revision 1.1  2004/09/13 14:37:49  flameshadow
00149  add: ramdrive.cpp
00150  chg: added ramdrive to the makefile
00151  chg: finished root dir inode initialization and saving in UbixFS::format()
00152 
00153  Revision 1.8  2004/08/30 13:29:08  reddawg
00154  Fixed ramdisk to write/read 512 blocks
00155 
00156  Revision 1.7  2004/08/13 22:06:54  reddawg
00157  UbixFS: fixed the test shell
00158 
00159  Revision 1.6  2004/08/13 21:47:49  reddawg
00160  Fixed
00161 
00162  Revision 1.5  2004/08/13 17:25:06  reddawg
00163  Testing better
00164 
00165  Revision 1.4  2004/08/13 17:07:32  reddawg
00166  Works
00167 
00168  Revision 1.3  2004/08/13 16:58:57  reddawg
00169  test
00170 
00171  Revision 1.2  2004/08/13 16:54:14  reddawg
00172  fixed
00173 
00174  Revision 1.1  2004/08/13 16:51:55  reddawg
00175  Start of ubixfs shell
00176 
00177  END
00178  ***/
00179 

Generated on Tue Dec 5 23:34:58 2006 for UbixOS V2 by  doxygen 1.4.7