00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef NBD_H
00021 #define NBD_H
00022
00023 #include <sys/types.h>
00024 #include <stdbool.h>
00025
00026 #include <qemu-common.h>
00027 #include "block_int.h"
00028
00029 struct nbd_request {
00030 uint32_t type;
00031 uint64_t handle;
00032 uint64_t from;
00033 uint32_t len;
00034 };
00035
00036 struct nbd_reply {
00037 uint32_t error;
00038 uint64_t handle;
00039 };
00040
00041 enum {
00042 NBD_CMD_READ = 0,
00043 NBD_CMD_WRITE = 1,
00044 NBD_CMD_DISC = 2
00045 };
00046
00047 size_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read);
00048 int tcp_socket_outgoing(const char *address, uint16_t port);
00049 int tcp_socket_incoming(const char *address, uint16_t port);
00050 int unix_socket_outgoing(const char *path);
00051 int unix_socket_incoming(const char *path);
00052
00053 int nbd_negotiate(int csock, off_t size);
00054 int nbd_receive_negotiate(int csock, off_t *size, size_t *blocksize);
00055 int nbd_init(int fd, int csock, off_t size, size_t blocksize);
00056 int nbd_send_request(int csock, struct nbd_request *request);
00057 int nbd_receive_reply(int csock, struct nbd_reply *reply);
00058 int nbd_trip(BlockDriverState *bs, int csock, off_t size, uint64_t dev_offset,
00059 off_t *offset, bool readonly, uint8_t *data, int data_size);
00060 int nbd_client(int fd, int csock);
00061 int nbd_disconnect(int fd);
00062
00063 #endif