source: mainline/uspace/lib/libblock/libblock.c@ 00b1d20e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 00b1d20e was 00b1d20e, checked in by Jiri Svoboda <jiri@…>, 16 years ago

Add PC MBR partition driver (mbr_part). Only supports primary partitions a.t.m.

  • Property mode set to 100644
File size: 19.1 KB
Line 
1/*
2 * Copyright (c) 2008 Jakub Jermar
3 * Copyright (c) 2008 Martin Decky
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libblock
31 * @{
32 */
33/**
34 * @file
35 * @brief
36 */
37
38#include "libblock.h"
39#include "../../srv/vfs/vfs.h"
40#include <ipc/devmap.h>
41#include <ipc/bd.h>
42#include <ipc/services.h>
43#include <errno.h>
44#include <sys/mman.h>
45#include <async.h>
46#include <ipc/ipc.h>
47#include <as.h>
48#include <assert.h>
49#include <fibril_sync.h>
50#include <adt/list.h>
51#include <adt/hash_table.h>
52#include <macros.h>
53#include <mem.h>
54
55/** Lock protecting the device connection list */
56static FIBRIL_MUTEX_INITIALIZE(dcl_lock);
57/** Device connection list head. */
58static LIST_INITIALIZE(dcl_head);
59
60#define CACHE_BUCKETS_LOG2 10
61#define CACHE_BUCKETS (1 << CACHE_BUCKETS_LOG2)
62
63typedef struct {
64 fibril_mutex_t lock;
65 size_t lblock_size; /**< Logical block size. */
66 unsigned block_count; /**< Total number of blocks. */
67 unsigned blocks_cached; /**< Number of cached blocks. */
68 hash_table_t block_hash;
69 link_t free_head;
70 enum cache_mode mode;
71} cache_t;
72
73typedef struct {
74 link_t link;
75 dev_handle_t dev_handle;
76 int dev_phone;
77 fibril_mutex_t comm_area_lock;
78 void *comm_area;
79 size_t comm_size;
80 void *bb_buf;
81 bn_t bb_addr;
82 size_t pblock_size; /**< Physical block size. */
83 cache_t *cache;
84} devcon_t;
85
86static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt);
87static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt);
88static int get_block_size(int dev_phone, size_t *bsize);
89
90static devcon_t *devcon_search(dev_handle_t dev_handle)
91{
92 link_t *cur;
93
94 fibril_mutex_lock(&dcl_lock);
95 for (cur = dcl_head.next; cur != &dcl_head; cur = cur->next) {
96 devcon_t *devcon = list_get_instance(cur, devcon_t, link);
97 if (devcon->dev_handle == dev_handle) {
98 fibril_mutex_unlock(&dcl_lock);
99 return devcon;
100 }
101 }
102 fibril_mutex_unlock(&dcl_lock);
103 return NULL;
104}
105
106static int devcon_add(dev_handle_t dev_handle, int dev_phone, size_t bsize,
107 void *comm_area, size_t comm_size)
108{
109 link_t *cur;
110 devcon_t *devcon;
111
112 if (comm_size < bsize)
113 return EINVAL;
114
115 devcon = malloc(sizeof(devcon_t));
116 if (!devcon)
117 return ENOMEM;
118
119 link_initialize(&devcon->link);
120 devcon->dev_handle = dev_handle;
121 devcon->dev_phone = dev_phone;
122 fibril_mutex_initialize(&devcon->comm_area_lock);
123 devcon->comm_area = comm_area;
124 devcon->comm_size = comm_size;
125 devcon->bb_buf = NULL;
126 devcon->bb_addr = 0;
127 devcon->pblock_size = bsize;
128 devcon->cache = NULL;
129
130 fibril_mutex_lock(&dcl_lock);
131 for (cur = dcl_head.next; cur != &dcl_head; cur = cur->next) {
132 devcon_t *d = list_get_instance(cur, devcon_t, link);
133 if (d->dev_handle == dev_handle) {
134 fibril_mutex_unlock(&dcl_lock);
135 free(devcon);
136 return EEXIST;
137 }
138 }
139 list_append(&devcon->link, &dcl_head);
140 fibril_mutex_unlock(&dcl_lock);
141 return EOK;
142}
143
144static void devcon_remove(devcon_t *devcon)
145{
146 fibril_mutex_lock(&dcl_lock);
147 list_remove(&devcon->link);
148 fibril_mutex_unlock(&dcl_lock);
149}
150
151int block_init(dev_handle_t dev_handle, size_t comm_size)
152{
153 int rc;
154 int dev_phone;
155 void *comm_area;
156 size_t bsize;
157
158 comm_area = mmap(NULL, comm_size, PROTO_READ | PROTO_WRITE,
159 MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
160 if (!comm_area) {
161 return ENOMEM;
162 }
163
164 dev_phone = devmap_device_connect(dev_handle, IPC_FLAG_BLOCKING);
165 if (dev_phone < 0) {
166 munmap(comm_area, comm_size);
167 return dev_phone;
168 }
169
170 rc = ipc_share_out_start(dev_phone, comm_area,
171 AS_AREA_READ | AS_AREA_WRITE);
172 if (rc != EOK) {
173 munmap(comm_area, comm_size);
174 ipc_hangup(dev_phone);
175 return rc;
176 }
177
178 if (get_block_size(dev_phone, &bsize) != EOK) {
179 munmap(comm_area, comm_size);
180 ipc_hangup(dev_phone);
181 return rc;
182 }
183
184 rc = devcon_add(dev_handle, dev_phone, bsize, comm_area, comm_size);
185 if (rc != EOK) {
186 munmap(comm_area, comm_size);
187 ipc_hangup(dev_phone);
188 return rc;
189 }
190
191 return EOK;
192}
193
194void block_fini(dev_handle_t dev_handle)
195{
196 devcon_t *devcon = devcon_search(dev_handle);
197 assert(devcon);
198
199 devcon_remove(devcon);
200
201 if (devcon->bb_buf)
202 free(devcon->bb_buf);
203
204 if (devcon->cache) {
205 hash_table_destroy(&devcon->cache->block_hash);
206 free(devcon->cache);
207 }
208
209 munmap(devcon->comm_area, devcon->comm_size);
210 ipc_hangup(devcon->dev_phone);
211
212 free(devcon);
213}
214
215int block_bb_read(dev_handle_t dev_handle, bn_t ba)
216{
217 void *bb_buf;
218 int rc;
219
220 devcon_t *devcon = devcon_search(dev_handle);
221 if (!devcon)
222 return ENOENT;
223 if (devcon->bb_buf)
224 return EEXIST;
225 bb_buf = malloc(devcon->pblock_size);
226 if (!bb_buf)
227 return ENOMEM;
228
229 fibril_mutex_lock(&devcon->comm_area_lock);
230 rc = read_blocks(devcon, 0, 1);
231 if (rc != EOK) {
232 fibril_mutex_unlock(&devcon->comm_area_lock);
233 free(bb_buf);
234 return rc;
235 }
236 memcpy(bb_buf, devcon->comm_area, devcon->pblock_size);
237 fibril_mutex_unlock(&devcon->comm_area_lock);
238
239 devcon->bb_buf = bb_buf;
240 devcon->bb_addr = ba;
241
242 return EOK;
243}
244
245void *block_bb_get(dev_handle_t dev_handle)
246{
247 devcon_t *devcon = devcon_search(dev_handle);
248 assert(devcon);
249 return devcon->bb_buf;
250}
251
252static hash_index_t cache_hash(unsigned long *key)
253{
254 return *key & (CACHE_BUCKETS - 1);
255}
256
257static int cache_compare(unsigned long *key, hash_count_t keys, link_t *item)
258{
259 block_t *b = hash_table_get_instance(item, block_t, hash_link);
260 return b->boff == *key;
261}
262
263static void cache_remove_callback(link_t *item)
264{
265}
266
267static hash_table_operations_t cache_ops = {
268 .hash = cache_hash,
269 .compare = cache_compare,
270 .remove_callback = cache_remove_callback
271};
272
273int block_cache_init(dev_handle_t dev_handle, size_t size, unsigned blocks,
274 enum cache_mode mode)
275{
276 devcon_t *devcon = devcon_search(dev_handle);
277 cache_t *cache;
278 if (!devcon)
279 return ENOENT;
280 if (devcon->cache)
281 return EEXIST;
282 cache = malloc(sizeof(cache_t));
283 if (!cache)
284 return ENOMEM;
285
286 fibril_mutex_initialize(&cache->lock);
287 list_initialize(&cache->free_head);
288 cache->lblock_size = size;
289 cache->block_count = blocks;
290 cache->blocks_cached = 0;
291 cache->mode = mode;
292
293 /* No block size translation a.t.m. */
294 assert(cache->lblock_size == devcon->pblock_size);
295
296 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1,
297 &cache_ops)) {
298 free(cache);
299 return ENOMEM;
300 }
301
302 devcon->cache = cache;
303 return EOK;
304}
305
306#define CACHE_LO_WATERMARK 10
307#define CACHE_HI_WATERMARK 20
308static bool cache_can_grow(cache_t *cache)
309{
310 if (cache->blocks_cached < CACHE_LO_WATERMARK)
311 return true;
312 if (!list_empty(&cache->free_head))
313 return false;
314 return true;
315}
316
317static void block_initialize(block_t *b)
318{
319 fibril_mutex_initialize(&b->lock);
320 b->refcnt = 1;
321 b->dirty = false;
322 b->toxic = false;
323 fibril_rwlock_initialize(&b->contents_lock);
324 link_initialize(&b->free_link);
325 link_initialize(&b->hash_link);
326}
327
328/** Instantiate a block in memory and get a reference to it.
329 *
330 * @param block Pointer to where the function will store the
331 * block pointer on success.
332 * @param dev_handle Device handle of the block device.
333 * @param boff Block offset.
334 * @param flags If BLOCK_FLAGS_NOREAD is specified, block_get()
335 * will not read the contents of the block from the
336 * device.
337 *
338 * @return EOK on success or a negative error code.
339 */
340int block_get(block_t **block, dev_handle_t dev_handle, bn_t boff, int flags)
341{
342 devcon_t *devcon;
343 cache_t *cache;
344 block_t *b;
345 link_t *l;
346 unsigned long key = boff;
347 int rc = EOK;
348
349 devcon = devcon_search(dev_handle);
350
351 assert(devcon);
352 assert(devcon->cache);
353
354 cache = devcon->cache;
355
356retry:
357 fibril_mutex_lock(&cache->lock);
358 l = hash_table_find(&cache->block_hash, &key);
359 if (l) {
360 /*
361 * We found the block in the cache.
362 */
363 b = hash_table_get_instance(l, block_t, hash_link);
364 fibril_mutex_lock(&b->lock);
365 if (b->refcnt++ == 0)
366 list_remove(&b->free_link);
367 if (b->toxic)
368 rc = EIO;
369 fibril_mutex_unlock(&b->lock);
370 fibril_mutex_unlock(&cache->lock);
371 } else {
372 /*
373 * The block was not found in the cache.
374 */
375 if (cache_can_grow(cache)) {
376 /*
377 * We can grow the cache by allocating new blocks.
378 * Should the allocation fail, we fail over and try to
379 * recycle a block from the cache.
380 */
381 b = malloc(sizeof(block_t));
382 if (!b)
383 goto recycle;
384 b->data = malloc(cache->lblock_size);
385 if (!b->data) {
386 free(b);
387 goto recycle;
388 }
389 cache->blocks_cached++;
390 } else {
391 /*
392 * Try to recycle a block from the free list.
393 */
394 unsigned long temp_key;
395recycle:
396 assert(!list_empty(&cache->free_head));
397 l = cache->free_head.next;
398 b = list_get_instance(l, block_t, free_link);
399
400 fibril_mutex_lock(&b->lock);
401 if (b->dirty) {
402 /*
403 * The block needs to be written back to the
404 * device before it changes identity. Do this
405 * while not holding the cache lock so that
406 * concurrency is not impeded. Also move the
407 * block to the end of the free list so that we
408 * do not slow down other instances of
409 * block_get() draining the free list.
410 */
411 list_remove(&b->free_link);
412 list_append(&b->free_link, &cache->free_head);
413 fibril_mutex_unlock(&cache->lock);
414 fibril_mutex_lock(&devcon->comm_area_lock);
415 memcpy(devcon->comm_area, b->data, b->size);
416 rc = write_blocks(devcon, b->boff, 1);
417 fibril_mutex_unlock(&devcon->comm_area_lock);
418 if (rc != EOK) {
419 /*
420 * We did not manage to write the block
421 * to the device. Keep it around for
422 * another try. Hopefully, we will grab
423 * another block next time.
424 */
425 fibril_mutex_unlock(&b->lock);
426 goto retry;
427 }
428 b->dirty = false;
429 if (!fibril_mutex_trylock(&cache->lock)) {
430 /*
431 * Somebody is probably racing with us.
432 * Unlock the block and retry.
433 */
434 fibril_mutex_unlock(&b->lock);
435 goto retry;
436 }
437
438 }
439 fibril_mutex_unlock(&b->lock);
440
441 /*
442 * Unlink the block from the free list and the hash
443 * table.
444 */
445 list_remove(&b->free_link);
446 temp_key = b->boff;
447 hash_table_remove(&cache->block_hash, &temp_key, 1);
448 }
449
450 block_initialize(b);
451 b->dev_handle = dev_handle;
452 b->size = cache->lblock_size;
453 b->boff = boff;
454 hash_table_insert(&cache->block_hash, &key, &b->hash_link);
455
456 /*
457 * Lock the block before releasing the cache lock. Thus we don't
458 * kill concurrent operations on the cache while doing I/O on
459 * the block.
460 */
461 fibril_mutex_lock(&b->lock);
462 fibril_mutex_unlock(&cache->lock);
463
464 if (!(flags & BLOCK_FLAGS_NOREAD)) {
465 /*
466 * The block contains old or no data. We need to read
467 * the new contents from the device.
468 */
469 fibril_mutex_lock(&devcon->comm_area_lock);
470 rc = read_blocks(devcon, b->boff, 1);
471 memcpy(b->data, devcon->comm_area, cache->lblock_size);
472 fibril_mutex_unlock(&devcon->comm_area_lock);
473 if (rc != EOK)
474 b->toxic = true;
475 } else
476 rc = EOK;
477
478 fibril_mutex_unlock(&b->lock);
479 }
480 *block = b;
481 return rc;
482}
483
484/** Release a reference to a block.
485 *
486 * If the last reference is dropped, the block is put on the free list.
487 *
488 * @param block Block of which a reference is to be released.
489 *
490 * @return EOK on success or a negative error code.
491 */
492int block_put(block_t *block)
493{
494 devcon_t *devcon = devcon_search(block->dev_handle);
495 cache_t *cache;
496 unsigned blocks_cached;
497 enum cache_mode mode;
498 int rc = EOK;
499
500 assert(devcon);
501 assert(devcon->cache);
502
503 cache = devcon->cache;
504
505retry:
506 fibril_mutex_lock(&cache->lock);
507 blocks_cached = cache->blocks_cached;
508 mode = cache->mode;
509 fibril_mutex_unlock(&cache->lock);
510
511 /*
512 * Determine whether to sync the block. Syncing the block is best done
513 * when not holding the cache lock as it does not impede concurrency.
514 * Since the situation may have changed when we unlocked the cache, the
515 * blocks_cached and mode variables are mere hints. We will recheck the
516 * conditions later when the cache lock is held again.
517 */
518 fibril_mutex_lock(&block->lock);
519 if (block->toxic)
520 block->dirty = false; /* will not write back toxic block */
521 if (block->dirty && (block->refcnt == 1) &&
522 (blocks_cached > CACHE_HI_WATERMARK || mode != CACHE_MODE_WB)) {
523 fibril_mutex_lock(&devcon->comm_area_lock);
524 memcpy(devcon->comm_area, block->data, block->size);
525 rc = write_blocks(devcon, block->boff, 1);
526 fibril_mutex_unlock(&devcon->comm_area_lock);
527 block->dirty = false;
528 }
529 fibril_mutex_unlock(&block->lock);
530
531 fibril_mutex_lock(&cache->lock);
532 fibril_mutex_lock(&block->lock);
533 if (!--block->refcnt) {
534 /*
535 * Last reference to the block was dropped. Either free the
536 * block or put it on the free list. In case of an I/O error,
537 * free the block.
538 */
539 if ((cache->blocks_cached > CACHE_HI_WATERMARK) ||
540 (rc != EOK)) {
541 /*
542 * Currently there are too many cached blocks or there
543 * was an I/O error when writing the block back to the
544 * device.
545 */
546 if (block->dirty) {
547 /*
548 * We cannot sync the block while holding the
549 * cache lock. Release everything and retry.
550 */
551 block->refcnt++;
552 fibril_mutex_unlock(&block->lock);
553 fibril_mutex_unlock(&cache->lock);
554 goto retry;
555 }
556 /*
557 * Take the block out of the cache and free it.
558 */
559 unsigned long key = block->boff;
560 hash_table_remove(&cache->block_hash, &key, 1);
561 free(block);
562 free(block->data);
563 cache->blocks_cached--;
564 fibril_mutex_unlock(&cache->lock);
565 return rc;
566 }
567 /*
568 * Put the block on the free list.
569 */
570 if (cache->mode != CACHE_MODE_WB && block->dirty) {
571 /*
572 * We cannot sync the block while holding the cache
573 * lock. Release everything and retry.
574 */
575 block->refcnt++;
576 fibril_mutex_unlock(&block->lock);
577 fibril_mutex_unlock(&cache->lock);
578 goto retry;
579 }
580 list_append(&block->free_link, &cache->free_head);
581 }
582 fibril_mutex_unlock(&block->lock);
583 fibril_mutex_unlock(&cache->lock);
584
585 return rc;
586}
587
588/** Read sequential data from a block device.
589 *
590 * @param dev_handle Device handle of the block device.
591 * @param bufpos Pointer to the first unread valid offset within the
592 * communication buffer.
593 * @param buflen Pointer to the number of unread bytes that are ready in
594 * the communication buffer.
595 * @param pos Device position to be read.
596 * @param dst Destination buffer.
597 * @param size Size of the destination buffer.
598 * @param block_size Block size to be used for the transfer.
599 *
600 * @return EOK on success or a negative return code on failure.
601 */
602int block_seqread(dev_handle_t dev_handle, off_t *bufpos, size_t *buflen,
603 off_t *pos, void *dst, size_t size)
604{
605 off_t offset = 0;
606 size_t left = size;
607 size_t block_size;
608 devcon_t *devcon;
609
610 devcon = devcon_search(dev_handle);
611 assert(devcon);
612 block_size = devcon->pblock_size;
613
614 fibril_mutex_lock(&devcon->comm_area_lock);
615 while (left > 0) {
616 size_t rd;
617
618 if (*bufpos + left < *buflen)
619 rd = left;
620 else
621 rd = *buflen - *bufpos;
622
623 if (rd > 0) {
624 /*
625 * Copy the contents of the communication buffer to the
626 * destination buffer.
627 */
628 memcpy(dst + offset, devcon->comm_area + *bufpos, rd);
629 offset += rd;
630 *bufpos += rd;
631 *pos += rd;
632 left -= rd;
633 }
634
635 if (*bufpos == (off_t) *buflen) {
636 /* Refill the communication buffer with a new block. */
637 int rc;
638
639 rc = read_blocks(devcon, *pos / block_size, 1);
640 if (rc != EOK) {
641 fibril_mutex_unlock(&devcon->comm_area_lock);
642 return rc;
643 }
644
645 *bufpos = 0;
646 *buflen = block_size;
647 }
648 }
649 fibril_mutex_unlock(&devcon->comm_area_lock);
650
651 return EOK;
652}
653
654/** Read blocks directly from device (bypass cache).
655 *
656 * @param dev_handle Device handle of the block device.
657 * @param ba Address of first block.
658 * @param cnt Number of blocks.
659 * @param src Buffer for storing the data.
660 *
661 * @return EOK on success or negative error code on failure.
662 */
663int block_read_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt, void *buf)
664{
665 devcon_t *devcon;
666 int rc;
667
668 devcon = devcon_search(dev_handle);
669 assert(devcon);
670
671 fibril_mutex_lock(&devcon->comm_area_lock);
672
673 rc = read_blocks(devcon, ba, cnt);
674 if (rc == EOK)
675 memcpy(buf, devcon->comm_area, devcon->pblock_size * cnt);
676
677 fibril_mutex_unlock(&devcon->comm_area_lock);
678
679 return rc;
680}
681
682/** Write blocks directly to device (bypass cache).
683 *
684 * @param dev_handle Device handle of the block device.
685 * @param ba Address of first block.
686 * @param cnt Number of blocks.
687 * @param src The data to be written.
688 *
689 * @return EOK on success or negative error code on failure.
690 */
691int block_write_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt,
692 const void *data)
693{
694 devcon_t *devcon;
695 int rc;
696
697 devcon = devcon_search(dev_handle);
698 assert(devcon);
699
700 fibril_mutex_lock(&devcon->comm_area_lock);
701
702 memcpy(devcon->comm_area, data, devcon->pblock_size * cnt);
703 rc = read_blocks(devcon, ba, cnt);
704
705 fibril_mutex_unlock(&devcon->comm_area_lock);
706
707 return rc;
708}
709
710/** Get device block size.
711 *
712 * @param dev_handle Device handle of the block device.
713 * @param bsize Output block size.
714 *
715 * @return EOK on success or negative error code on failure.
716 */
717int block_get_bsize(dev_handle_t dev_handle, size_t *bsize)
718{
719 devcon_t *devcon;
720
721 devcon = devcon_search(dev_handle);
722 assert(devcon);
723
724 return get_block_size(devcon->dev_phone, bsize);
725}
726
727/** Read blocks from block device.
728 *
729 * @param devcon Device connection.
730 * @param ba Address of first block.
731 * @param cnt Number of blocks.
732 * @param src Buffer for storing the data.
733 *
734 * @return EOK on success or negative error code on failure.
735 */
736static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt)
737{
738 int rc;
739
740 assert(devcon);
741 rc = async_req_3_0(devcon->dev_phone, BD_READ_BLOCKS, LOWER32(ba),
742 UPPER32(ba), cnt);
743 return rc;
744}
745
746/** Write block to block device.
747 *
748 * @param devcon Device connection.
749 * @param ba Address of first block.
750 * @param cnt Number of blocks.
751 * @param src Buffer containing the data to write.
752 *
753 * @return EOK on success or negative error code on failure.
754 */
755static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt)
756{
757 int rc;
758
759 assert(devcon);
760 rc = async_req_3_0(devcon->dev_phone, BD_WRITE_BLOCKS, LOWER32(ba),
761 UPPER32(ba), cnt);
762 return rc;
763}
764
765/** Get block size used by the device. */
766static int get_block_size(int dev_phone, size_t *bsize)
767{
768 ipcarg_t bs;
769 int rc;
770
771 rc = async_req_0_1(dev_phone, BD_GET_BLOCK_SIZE, &bs);
772 if (rc == EOK)
773 *bsize = (size_t) bs;
774
775 return rc;
776}
777
778/** @}
779 */
Note: See TracBrowser for help on using the repository browser.