ramdrive.cpp
stdlib.h
stdio.h
string.h
assert.h
device.h
stdlib.h
ubixos/types.h
sys/_types.h
string.h
sys/types.h
types.h
device.h
assert.h
src/sys/ubixfsv2/ramdrive.cpp
stdio.h
RAM_DRIVE_SIZE
1024*1024*100
dev_ramDestroy
dev_ramDrive
int int dev_ramDestroy (void) dev_ramDestroy void fclose fopen fwrite ram_data RAM_DRIVE_SIZE main
device_t * device_t* dev_ramDrive (void) dev_ramDrive void fclose fopen fread device_t::major ram_data RAM_DRIVE_SIZE ramDrive_read ramDrive_write device_t::read device_t::sectors device_t::write main
int static int ramDrive_read (device_t *dev, void *ptr, off_t offset, size_t length) ramDrive_read device_t * dev void * ptr off_t offset size_t length assert memcpy ram_data dev_ramDrive
int static int ramDrive_write (device_t *dev, void *ptr, off_t offset, size_t length) ramDrive_write device_t * dev void * ptr off_t offset size_t length assert memcpy ram_data dev_ramDrive
char * char* ram_data ram_data 0x0 dev_ramDestroy dev_ramDrive ramDrive_read ramDrive_write

    /*****************************************************************************************
    Copyright(c)2002-2004TheUbixOSProject
    Allrightsreserved.

    Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,are
    permittedprovidedthatthefollowingconditionsaremet:

    Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistof
    conditions,thefollowingdisclaimerandthelistofauthors.Redistributionsinbinary
    formmustreproducetheabovecopyrightnotice,thislistofconditions,thefollowing
    disclaimerandthelistofauthorsinthedocumentationand/orothermaterialsprovided
    withthedistribution.NeitherthenameoftheUbixOSProjectnorthenamesofits
    contributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftware
    withoutspecificpriorwrittenpermission.

    THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANY
    EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF
    MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALL
    THECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
    SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENT
    OFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
    TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHIS
    SOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

    $Id: ramdrive_8cpp.xml 88 2016-01-12 00:11:29Z reddawg $

    *****************************************************************************************/

    #include<stdlib.h>
    #include<stdio.h>
    #include<string.h>
    #include<assert.h>
    #include"device.h"

    staticchar*ram_data=0x0;

    #defineRAM_DRIVE_SIZE1024*1024*100

    static
    int
    ramDrive_read(device_t*dev,void*ptr,off_toffset,size_tlength){
    char*data=ram_data+(offset*512);
    assert(ram_data);
    assert(offset+length<=dev->sectors);
    memcpy(ptr,data,length*512);

    return(length);
    }

    static
    int
    ramDrive_write(device_t*dev,void*ptr,off_toffset,size_tlength){
    char*data=ram_data+(offset*512);
    assert(ram_data);

    assert(offset+length<=dev->sectors);

    memcpy(data,ptr,length*512);

    return(length);
    }

    device_t*
    dev_ramDrive(void){
    device_t*ramDrive=0x0;

    FILE*ramDisk;

    ramDisk=fopen("./ram.dsk","rb");

    ramDrive=(device_t*)malloc(sizeof(device_t));

    ram_data=(char*)malloc(RAM_DRIVE_SIZE);

    if(ramDisk!=0x0){
    printf("LoadedRamDisk\n");
    fread(ram_data,RAM_DRIVE_SIZE,1,ramDisk);
    fclose(ramDisk);
    }

    ramDrive->major=0x1;
    ramDrive->sectors=RAM_DRIVE_SIZE/512;

    ramDrive->read=ramDrive_read;
    ramDrive->write=ramDrive_write;

    printf("leavingdev_ramDrive()\n");
    return(ramDrive);

    }//dev_ramDrive

    int
    dev_ramDestroy(void){
    printf("dev_ramDestroy()\n");
    FILE*ramDisk;

    ramDisk=fopen("./ram.dsk","wb");

    fwrite(ram_data,RAM_DRIVE_SIZE,1,ramDisk);

    fclose(ramDisk);

    printf("SavedRamDisk\n");

    return(0x0);
    }//dev_ramDestroy

    /***
    $Log: ramdrive_8cpp.xml,v $
    Revision 1.4  2006/12/12 14:09:15  reddawg
    Changes

    Revision1.1.1.12006/06/0112:46:15reddawg
    ubix2

    Revision1.22005/10/1200:13:38reddawg
    Removed

    Revision1.1.1.12005/09/2617:24:45reddawg
    nomessage

    Revision1.52004/09/2000:53:04flameshadow
    chg:UbixFS::vfs_read()nowworksfordirectblockextents
    chg:UbixFS::vfs_read()returns~0onerror,orthesizereadinonsuccess
    chg:UbixFS::rootmemberisnowafileDescriptor
    chg:UbixFS::vfs_init()createsafiledescriptorfortherootdir
    chg:UbixFS::vfs_format()nowsetsallvaluesinthebTreeHeaderbeforewriting
    chg:UbixFS::vfs_format()setstheinodemagicnumber
    chg:device_t::read(device_t*,void*,off_t,size_t)
    chg:device_t::write(device_t*,void*,off_t,size_t)
    chg:vfs_abstract::vfs_read(fileDescriptor*,void*,off_t,size_t)
    chg:vfs_abstract::vfs_write(fileDescriptor*,void*,off_t,size_t)
    chg:ramDrive_read(device_t*dev,void*ptr,off_toffset,size_tlength)
    chg:ramDrive_write(device_t*dev,void*ptr,off_toffset,size_tlength)

    Revision1.42004/09/1320:10:11flameshadow
    chg:UbixFS::vfs_format()works
    chg:UbixFS::vfs_init()works

    Revision1.32004/09/1315:48:29flameshadow
    chg:oops,theramDriveis100MB,not512MB

    Revision1.22004/09/1315:21:26flameshadow
    add:ramdrive.h
    chg:renameddevice_t.sizetosectors
    chg:made#defineforsizeoframdisk
    chg:calculatedsectorsoframdiskandstoredinthedevice_tstruct

    Revision1.12004/09/1314:37:49flameshadow
    add:ramdrive.cpp
    chg:addedramdrivetothemakefile
    chg:finishedrootdirinodeinitializationandsavinginUbixFS::format()

    Revision1.82004/08/3013:29:08reddawg
    Fixedramdisktowrite/read512blocks

    Revision1.72004/08/1322:06:54reddawg
    UbixFS:fixedthetestshell

    Revision1.62004/08/1321:47:49reddawg
    Fixed

    Revision1.52004/08/1317:25:06reddawg
    Testingbetter

    Revision1.42004/08/1317:07:32reddawg
    Works

    Revision1.32004/08/1316:58:57reddawg
    test

    Revision1.22004/08/1316:54:14reddawg
    fixed

    Revision1.12004/08/1316:51:55reddawg
    Startofubixfsshell

    END
    ***/