149
151
static part_t *mbr_part_new(void);
150
152
static void mbr_pte_to_part(uint32_t base, const pt_entry_t *pte, part_t *part);
151
153
static void mbr_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg);
152
static int mbr_bd_read(part_t *p, uint64_t ba, size_t cnt, void *buf);
153
static int mbr_bd_write(part_t *p, uint64_t ba, size_t cnt, const void *buf);
154
154
static int mbr_bsa_translate(part_t *p, uint64_t ba, size_t cnt, uint64_t *gba);
156
static int mbr_bd_open(bd_srvs_t *, bd_srv_t *);
157
static int mbr_bd_close(bd_srv_t *);
158
static int mbr_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t);
159
static int mbr_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t);
160
static int mbr_bd_get_block_size(bd_srv_t *, size_t *);
161
static int mbr_bd_get_num_blocks(bd_srv_t *, aoff64_t *);
163
static bd_ops_t mbr_bd_ops = {
165
.close = mbr_bd_close,
166
.read_blocks = mbr_bd_read_blocks,
167
.write_blocks = mbr_bd_write_blocks,
168
.get_block_size = mbr_bd_get_block_size,
169
.get_num_blocks = mbr_bd_get_num_blocks
172
static part_t *bd_srv_part(bd_srv_t *bd)
174
return (part_t *)bd->srvs->sarg;
156
177
int main(int argc, char **argv)
158
179
printf(NAME ": PC MBR partition driver\n");
418
434
assert(part->present == true);
420
/* Answer the IPC_M_CONNECT_ME_TO call. */
421
async_answer_0(iid, EOK);
423
if (!async_share_out_receive(&callid, &comm_size, &flags)) {
424
async_answer_0(callid, EHANGUP);
428
(void) async_share_out_finalize(callid, &fs_va);
429
if (fs_va == AS_MAP_FAILED) {
430
async_answer_0(callid, EHANGUP);
435
callid = async_get_call(&call);
436
method = IPC_GET_IMETHOD(call);
439
/* The other side has hung up. */
440
async_answer_0(callid, EOK);
446
ba = MERGE_LOUP32(IPC_GET_ARG1(call),
448
cnt = IPC_GET_ARG3(call);
449
if (cnt * block_size > comm_size) {
453
retval = mbr_bd_read(part, ba, cnt, fs_va);
455
case BD_WRITE_BLOCKS:
456
ba = MERGE_LOUP32(IPC_GET_ARG1(call),
458
cnt = IPC_GET_ARG3(call);
459
if (cnt * block_size > comm_size) {
463
retval = mbr_bd_write(part, ba, cnt, fs_va);
465
case BD_GET_BLOCK_SIZE:
466
async_answer_1(callid, EOK, block_size);
468
case BD_GET_NUM_BLOCKS:
469
async_answer_2(callid, EOK, LOWER32(part->length),
470
UPPER32(part->length));
476
async_answer_0(callid, retval);
435
bd_conn(iid, icall, &part->bds);
439
static int mbr_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
445
static int mbr_bd_close(bd_srv_t *bd)
480
450
/** Read blocks from partition. */
481
static int mbr_bd_read(part_t *p, uint64_t ba, size_t cnt, void *buf)
451
static int mbr_bd_read_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, void *buf,
454
part_t *p = bd_srv_part(bd);
457
if (cnt * block_size < size)
485
460
if (mbr_bsa_translate(p, ba, cnt, &gba) != EOK)
488
return block_read_direct(indef_sid, gba, cnt, buf);
463
return block_read_direct(indev_sid, gba, cnt, buf);
491
466
/** Write blocks to partition. */
492
static int mbr_bd_write(part_t *p, uint64_t ba, size_t cnt, const void *buf)
467
static int mbr_bd_write_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt,
468
const void *buf, size_t size)
470
part_t *p = bd_srv_part(bd);
473
if (cnt * block_size < size)
496
476
if (mbr_bsa_translate(p, ba, cnt, &gba) != EOK)
499
return block_write_direct(indef_sid, gba, cnt, buf);
479
return block_write_direct(indev_sid, gba, cnt, buf);
482
/** Get device block size. */
483
static int mbr_bd_get_block_size(bd_srv_t *bd, size_t *rsize)
489
/** Get number of blocks on device. */
490
static int mbr_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb)
492
part_t *part = bd_srv_part(bd);
502
498
/** Translate block segment address with range checking. */