9os

Experimental kernel using plan9 ideas for embedded device
git clone git://git.simple-cc.org/9os
Log | Files | Refs | README | LICENSE

dummyblk.c (820B)


      1 #include <os9/os9.h>
      2 
      3 #include "../src/libc/syscall.h"
      4 #include "dev.h"
      5 #include "blk.h"
      6 
      7 /*
      8  * A block file filled with zeros can be created with:
      9  * dd bs=512 count=2 if=/dev/zero of=blkfile
     10  */
     11 
     12 void
     13 dummyblkinit(Blk *dev, Attr *attr)
     14 {
     15 	static char filename[] = "blkfile";
     16 	int fd;
     17 
     18 	if ((fd = _open(filename, 0x2)) < 0)
     19 		panic("blkinit");
     20 	dev->data = alloc(sizeof(fd));
     21 	*(int *)dev->data = fd;
     22 }
     23 
     24 int
     25 dummyblkbread(Blk *dev, long blkno, void *buf)
     26 {
     27 	int fd;
     28 
     29 	fd = *(int *) dev->data;
     30 	_lseek(fd, blkno * BLKSIZ, 0);
     31 	return _read(fd, buf, BLKSIZ);
     32 }
     33 
     34 int
     35 dummyblkbwrite(Blk *dev, long blkno, void *buf)
     36 {
     37 	int fd;
     38 
     39 	fd = *(int *) dev->data;
     40 	_lseek(fd, blkno * BLKSIZ, 0);
     41 	return _write(fd, buf, BLKSIZ);
     42 }
     43 
     44 Blkphy dummyblkphy = {
     45 	.init = dummyblkinit,
     46 	.bread  = dummyblkbread,
     47 	.bwrite = dummyblkbwrite
     48 };