4 * block device emulation for unix hosts
6 * Copyright (C) 2004 Stefan Reinauer <stepan@openbios.org>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
15 #include "libopenbios/bindings.h"
24 DECLARE_NODE( blk, INSTALL_OPEN, sizeof(blk_data_t), "+/unix/block/disk" );
27 blk_open( blk_data_t *pb )
34 pb->channel = 0; /* FIXME */
36 selfword("open-deblocker");
38 /* interpose disk-label */
39 ph = find_dev("/packages/disk-label");
44 /* printk("osi-blk: open %d\n", pb->unit ); */
50 blk_close( __attribute__((unused)) blk_data_t *pb )
52 selfword("close-deblocker");
56 /* ( buf blk nblks -- actual ) */
58 blk_read_blocks( blk_data_t *pb )
62 char *dest = (char*)POP();
64 // printk("blk_read_blocks %x block=%d n=%d\n", (ucell)dest, blk, n );
68 ucell m = MIN( n-i, sizeof(buf)/512 );
70 if( read_from_disk(pb->channel, pb->unit, blk+i, (ucell)buf, m*512) < 0 ) {
71 printk("read_from_disk: error\n");
74 memcpy( dest, buf, m * 512 );
83 blk_block_size( __attribute__((unused)) blk_data_t *pb )
90 blk_max_transfer( __attribute__((unused)) blk_data_t *pb )
96 blk_initialize( __attribute__((unused)) blk_data_t *pb )
98 fword("is-deblocker");
102 NODE_METHODS( blk ) = {
103 { NULL, blk_initialize },
104 { "open", blk_open },
105 { "close", blk_close },
106 { "read-blocks", blk_read_blocks },
107 { "block-size", blk_block_size },
108 { "max-transfer", blk_max_transfer},
114 REGISTER_NODE( blk );