diff options
author | Zheng Da <zhengda1936@gmail.com> | 2010-06-04 16:51:24 +0200 |
---|---|---|
committer | Zheng Da <zhengda1936@gmail.com> | 2010-06-04 16:51:24 +0200 |
commit | 21bf6f025d94c2987dfe30a0b327b6dfab7a8bff (patch) | |
tree | ca347da12bdeaf33ae9db843df3943791d2db84b /libdde_linux26/lib/src | |
parent | 2d2c99a2d22d53343e3ea39368201d2e316c5aa8 (diff) |
support block devices in the DDE library.
Diffstat (limited to 'libdde_linux26/lib/src')
-rw-r--r-- | libdde_linux26/lib/src/Makefile | 3 | ||||
-rw-r--r-- | libdde_linux26/lib/src/mach_glue/block.c | 77 | ||||
-rw-r--r-- | libdde_linux26/lib/src/mach_glue/net.c (renamed from libdde_linux26/lib/src/arch/l4/mach_glue.c) | 0 |
3 files changed, 79 insertions, 1 deletions
diff --git a/libdde_linux26/lib/src/Makefile b/libdde_linux26/lib/src/Makefile index 3743f91b..947f11b9 100644 --- a/libdde_linux26/lib/src/Makefile +++ b/libdde_linux26/lib/src/Makefile @@ -150,7 +150,7 @@ SRC_C_libdde_linux26.o.a += \ ################################################################## SRC_C_libdde_linux26_net.a += \ arch/l4/net.c \ - arch/l4/mach_glue.c \ + mach_glue/net.c \ drivers/net/mii.c \ net/core/dev.c \ net/core/dev_mcast.c \ @@ -180,6 +180,7 @@ SRC_C_libdde_linux26_sound.a += \ # SRC_C_libdde_linux26_block.a += \ arch/l4/inodes.c \ + mach_glue/block.c \ block/blk-barrier.c \ block/blk-core.c \ block/blk-exec.c \ diff --git a/libdde_linux26/lib/src/mach_glue/block.c b/libdde_linux26/lib/src/mach_glue/block.c new file mode 100644 index 00000000..7eac7e46 --- /dev/null +++ b/libdde_linux26/lib/src/mach_glue/block.c @@ -0,0 +1,77 @@ +#include <linux/fs.h> +#include <linux/genhd.h> +#include <linux/bio.h> +#include <ddekit/assert.h> + +struct gendisk *find_disk_by_name (char *); +void dde_page_cache_add (struct page *); + +struct block_device *open_block_dev (char *name, int part, fmode_t mode) +{ + struct gendisk *disk = find_disk_by_name (name); + dev_t devid = MKDEV (disk->major, disk->first_minor + part); + return open_by_devnum (devid, mode); +} + +/* write a piece of data to a block device. + * DATA must be in one page. + * SECTORNR: the writing location in sectors. */ +int block_dev_write (struct block_device *dev, int sectornr, + char *data, int count, void (*write_done (int err))) +{ + int err = 0; + struct bio *bio; + struct page *page; + int i; + + void end_bio (struct bio *bio, int err) + { + write_done (err); + } + + assert (count <= PAGE_SIZE); + bio = bio_alloc (GFP_NOIO, 1); + if (bio == NULL) + { + err = ENOMEM; + goto out; + } + + page = kmalloc (sizeof (*page), GFP_KERNEL); + if (page == NULL) + { + err = ENOMEM; + goto out; + } + + bio->bi_sector = sectornr; + bio->bi_bdev = dev; + page->virtual = data; + dde_page_cache_add (page); + bio->bi_io_vec[0].bv_page = page; + bio->bi_io_vec[0].bv_len = count; + bio->bi_io_vec[0].bv_offset = (int) data & ~PAGE_MASK; + + bio->bi_vcnt = 1; + bio->bi_idx = 0; + bio->bi_size = count; + + bio->bi_end_io = end_bio; + bio->bi_private = NULL; + bio_get (bio); + submit_bio (WRITE, bio); + if (bio_flagged (bio, BIO_EOPNOTSUPP)) + { + err = -EOPNOTSUPP; + goto out; + } + bio_put (bio); +out: + if (err) + { + if (bio) + bio_put (bio); + kfree (page); + } + return err; +} diff --git a/libdde_linux26/lib/src/arch/l4/mach_glue.c b/libdde_linux26/lib/src/mach_glue/net.c index 48373a90..48373a90 100644 --- a/libdde_linux26/lib/src/arch/l4/mach_glue.c +++ b/libdde_linux26/lib/src/mach_glue/net.c |