Annotation of qemu/roms/openbios/arch/ppc/mol/pseudodisk.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *   Creation Date: <2003/11/26 16:55:47 samuel>
        !             3:  *   Time-stamp: <2004/01/07 19:41:54 samuel>
        !             4:  *
        !             5:  *     <pseudodisk.c>
        !             6:  *
        !             7:  *     pseudodisk (contains files exported from linux)
        !             8:  *
        !             9:  *   Copyright (C) 2003, 2004 Samuel Rydh ([email protected])
        !            10:  *
        !            11:  *   This program is free software; you can redistribute it and/or
        !            12:  *   modify it under the terms of the GNU General Public License
        !            13:  *   version 2
        !            14:  *
        !            15:  */
        !            16: 
        !            17: #include "config.h"
        !            18: #include "libopenbios/bindings.h"
        !            19: #include "osi_calls.h"
        !            20: #include "libc/string.h"
        !            21: #include "libopenbios/ofmem.h"
        !            22: #include "mol/prom.h"
        !            23: #include "mol/mol.h"
        !            24: #include "osi_calls.h"
        !            25: #include "pseudofs_sh.h"
        !            26: 
        !            27: typedef struct {
        !            28:        int     seekpos;
        !            29:        int     fd;
        !            30:        char    *myargs;
        !            31:        char    *name;
        !            32:        int     size;
        !            33: } pdisk_data_t;
        !            34: 
        !            35: 
        !            36: DECLARE_NODE( pdisk, INSTALL_OPEN, sizeof(pdisk_data_t), "/mol/pseudo-disk/disk" );
        !            37: 
        !            38: static void
        !            39: pdisk_open( pdisk_data_t *pb )
        !            40: {
        !            41:        char *ep, *name = NULL;
        !            42:        int part;
        !            43: 
        !            44:        pb->myargs = my_args_copy();
        !            45:        /* printk("pdisk-open: %s\n", pb->myargs ); */
        !            46: 
        !            47:        part = strtol( pb->myargs, &ep, 10 );
        !            48:        if( *ep ) {
        !            49:                if( (name=strchr(pb->myargs, ',')) ) {
        !            50:                        *name = 0;
        !            51:                        name++;
        !            52:                } else {
        !            53:                        name = pb->myargs;
        !            54:                }
        !            55:        }
        !            56:        if( part )
        !            57:                goto err;
        !            58: 
        !            59:        if( !name || !strlen(name) )
        !            60:                pb->fd = -1;
        !            61:        else {
        !            62:                if( (pb->fd=PseudoFSOpen(name)) < 0 )
        !            63:                        goto err;
        !            64:                pb->size = PseudoFSGetSize( pb->fd );
        !            65:        }
        !            66:        pb->name = name;
        !            67:        RET( -1 );
        !            68:  err:
        !            69:        free( pb->myargs );
        !            70:        RET(0);
        !            71: }
        !            72: 
        !            73: /* ( addr len -- actual ) */
        !            74: static void
        !            75: pdisk_read( pdisk_data_t *pb )
        !            76: {
        !            77:        int len = POP();
        !            78:        char *dest = (char*)POP();
        !            79:        int cnt;
        !            80: 
        !            81:        if( pb->fd < 0 ) {
        !            82:                memset( dest, 0, len );
        !            83:                PUSH(len);
        !            84:                return;
        !            85:        }
        !            86:        /* dest is not "mol-DMA" safe (might have a nontrivial mapping) */
        !            87:        for( cnt=0; cnt<len; ) {
        !            88:                char buf[2048];
        !            89:                int n = MIN( len-cnt, sizeof(buf) );
        !            90: 
        !            91:                n = PseudoFSRead( pb->fd, pb->seekpos, buf, n );
        !            92:                if( n <= 0 )
        !            93:                        break;
        !            94: 
        !            95:                memcpy( dest+cnt, buf, n );
        !            96:                cnt += n;
        !            97:                pb->seekpos += n;
        !            98:        }
        !            99:        PUSH( cnt );
        !           100: }
        !           101: 
        !           102: /* ( addr len -- actual ) */
        !           103: static void
        !           104: pdisk_write( pdisk_data_t *pb )
        !           105: {
        !           106:        POP(); POP(); PUSH(-1);
        !           107:        printk("pdisk write\n");
        !           108: }
        !           109: 
        !           110: /* ( pos.lo pos.hi -- status ) */
        !           111: static void
        !           112: pdisk_seek( pdisk_data_t *pb )
        !           113: {
        !           114:        int pos_lo;
        !           115:        POP();
        !           116:        pos_lo = POP();
        !           117: 
        !           118:        if( pb->fd >= 0 ) {
        !           119:                if( pos_lo == -1 )
        !           120:                        pos_lo = pb->size;
        !           121:        }
        !           122: 
        !           123:        pb->seekpos = pos_lo;
        !           124: 
        !           125:        PUSH(0);        /* ??? */
        !           126: }
        !           127: 
        !           128: /* ( -- pos.d ) */
        !           129: static void
        !           130: pdisk_tell( pdisk_data_t *pb )
        !           131: {
        !           132:        DPUSH( pb->seekpos );
        !           133: }
        !           134: 
        !           135: /* ( -- cstr ) */
        !           136: static void
        !           137: pdisk_get_path( pdisk_data_t *pb )
        !           138: {
        !           139:        PUSH( (int)pb->name );
        !           140: }
        !           141: 
        !           142: /* ( -- cstr ) */
        !           143: static void
        !           144: pdisk_get_fstype( pdisk_data_t *pb )
        !           145: {
        !           146:        PUSH( (int)"PSEUDO" );
        !           147: }
        !           148: 
        !           149: /* ( -- cstr ) */
        !           150: static void
        !           151: pdisk_volume_name( pdisk_data_t *pb )
        !           152: {
        !           153:        PUSH( (int)"Virtual Volume" );
        !           154: }
        !           155: 
        !           156: static void
        !           157: pdisk_block_size( pdisk_data_t *pb )
        !           158: {
        !           159:        PUSH(1);
        !           160: }
        !           161: 
        !           162: NODE_METHODS( pdisk ) = {
        !           163:        { "open",               pdisk_open              },
        !           164:        { "read",               pdisk_read              },
        !           165:        { "write",              pdisk_write             },
        !           166:        { "seek",               pdisk_seek              },
        !           167:        { "tell",               pdisk_tell              },
        !           168:        { "block-size",         pdisk_block_size        },
        !           169:        { "get-path",           pdisk_get_path          },
        !           170:        { "get-fstype",         pdisk_get_fstype        },
        !           171:        { "volume-name",        pdisk_volume_name       },
        !           172: };
        !           173: 
        !           174: void
        !           175: pseudodisk_init( void )
        !           176: {
        !           177:        REGISTER_NODE( pdisk );
        !           178: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.