Index: uspace/drv/bus/usb/usbmast/main.c
===================================================================
--- uspace/drv/bus/usb/usbmast/main.c	(revision ea8b91df4038cc5ddcc2fb20431672c304c62ba9)
+++ uspace/drv/bus/usb/usbmast/main.c	(revision 4802dd7d8d17cb02ec8f79547ffde538bb8c6736)
@@ -37,5 +37,5 @@
 #include <as.h>
 #include <async.h>
-#include <ipc/bd.h>
+#include <bd_srv.h>
 #include <macros.h>
 #include <usb/dev/driver.h>
@@ -82,4 +82,25 @@
     void *arg);
 
+static int usbmast_bd_open(bd_srv_t *);
+static int usbmast_bd_close(bd_srv_t *);
+static int usbmast_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t);
+static int usbmast_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t);
+static int usbmast_bd_get_block_size(bd_srv_t *, size_t *);
+static int usbmast_bd_get_num_blocks(bd_srv_t *, aoff64_t *);
+
+static bd_ops_t usbmast_bd_ops = {
+	.open = usbmast_bd_open,
+	.close = usbmast_bd_close,
+	.read_blocks = usbmast_bd_read_blocks,
+	.write_blocks = usbmast_bd_write_blocks,
+	.get_block_size = usbmast_bd_get_block_size,
+	.get_num_blocks = usbmast_bd_get_num_blocks
+};
+
+static usbmast_fun_t *bd_srv_usbmast(bd_srv_t *bd)
+{
+	return (usbmast_fun_t *)bd->arg;
+}
+
 /** Callback when a device is removed from the system.
  *
@@ -219,4 +240,8 @@
 	mfun->lun = lun;
 
+	bd_srv_init(&mfun->bd);
+	mfun->bd.ops = &usbmast_bd_ops;
+	mfun->bd.arg = mfun;
+
 	/* Set up a connection handler. */
 	fun->conn_handler = usbmast_bd_connection;
@@ -284,64 +309,61 @@
 {
 	usbmast_fun_t *mfun;
-	void *comm_buf = NULL;
-	size_t comm_size;
-	ipc_callid_t callid;
-	ipc_call_t call;
-	unsigned int flags;
-	sysarg_t method;
-	uint64_t ba;
-	size_t cnt;
-	int retval;
-
-	async_answer_0(iid, EOK);
-
-	if (!async_share_out_receive(&callid, &comm_size, &flags)) {
-		async_answer_0(callid, EHANGUP);
-		return;
-	}
-	
-	(void) async_share_out_finalize(callid, &comm_buf);
-	if (comm_buf == AS_MAP_FAILED) {
-		async_answer_0(callid, EHANGUP);
-		return;
-	}
-	
+
 	mfun = (usbmast_fun_t *) ((ddf_fun_t *)arg)->driver_data;
-
-	while (true) {
-		callid = async_get_call(&call);
-		method = IPC_GET_IMETHOD(call);
-
-		if (!method) {
-			/* The other side hung up. */
-			async_answer_0(callid, EOK);
-			return;
-		}
-
-		switch (method) {
-		case BD_GET_BLOCK_SIZE:
-			async_answer_1(callid, EOK, mfun->block_size);
-			break;
-		case BD_GET_NUM_BLOCKS:
-			async_answer_2(callid, EOK, LOWER32(mfun->nblocks),
-			    UPPER32(mfun->nblocks));
-			break;
-		case BD_READ_BLOCKS:
-			ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
-			cnt = IPC_GET_ARG3(call);
-			retval = usbmast_read(mfun, ba, cnt, comm_buf);
-			async_answer_0(callid, retval);
-			break;
-		case BD_WRITE_BLOCKS:
-			ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
-			cnt = IPC_GET_ARG3(call);
-			retval = usbmast_write(mfun, ba, cnt, comm_buf);
-			async_answer_0(callid, retval);
-			break;
-		default:
-			async_answer_0(callid, EINVAL);
-		}
-	}
-}
+	bd_conn(iid, icall, &mfun->bd);
+}
+
+/** Open device. */
+static int usbmast_bd_open(bd_srv_t *bd)
+{
+	return EOK;
+}
+
+/** Close device. */
+static int usbmast_bd_close(bd_srv_t *bd)
+{
+	return EOK;
+}
+
+/** Read blocks from the device. */
+static int usbmast_bd_read_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt, void *buf,
+    size_t size)
+{
+	usbmast_fun_t *mfun = bd_srv_usbmast(bd);
+
+	if (size < cnt * mfun->block_size)
+		return EINVAL;
+
+	return usbmast_read(mfun, ba, cnt, buf);
+}
+
+/** Write blocks to the device. */
+static int usbmast_bd_write_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt,
+    const void *buf, size_t size)
+{
+	usbmast_fun_t *mfun = bd_srv_usbmast(bd);
+
+	if (size < cnt * mfun->block_size)
+		return EINVAL;
+
+	return usbmast_write(mfun, ba, cnt, buf);
+}
+
+/** Get device block size. */
+static int usbmast_bd_get_block_size(bd_srv_t *bd, size_t *rsize)
+{
+	usbmast_fun_t *mfun = bd_srv_usbmast(bd);
+	*rsize = mfun->block_size;
+	return EOK;
+}
+
+/** Get number of blocks on device. */
+static int usbmast_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb)
+{
+	usbmast_fun_t *mfun = bd_srv_usbmast(bd);
+	*rnb = mfun->nblocks;
+	return EOK;
+}
+
 
 /** USB mass storage driver ops. */
Index: uspace/drv/bus/usb/usbmast/usbmast.h
===================================================================
--- uspace/drv/bus/usb/usbmast/usbmast.h	(revision ea8b91df4038cc5ddcc2fb20431672c304c62ba9)
+++ uspace/drv/bus/usb/usbmast/usbmast.h	(revision 4802dd7d8d17cb02ec8f79547ffde538bb8c6736)
@@ -37,4 +37,5 @@
 #define USBMAST_H_
 
+#include <bd_srv.h>
 #include <sys/types.h>
 #include <usb/usb.h>
@@ -68,4 +69,6 @@
 	/** Block size in bytes */
 	size_t block_size;
+	/** Block device server structure */
+	bd_srv_t bd;
 } usbmast_fun_t;
 
