14d1cc41eSFrançois Revol/*
24d1cc41eSFrançois Revol * Network Block Device protocol
34d1cc41eSFrançois Revol * Copyright 2006-2007, Fran��ois Revol. All rights reserved.
44d1cc41eSFrançois Revol * Distributed under the terms of the MIT License.
54d1cc41eSFrançois Revol *
64d1cc41eSFrançois Revol * references:
74d1cc41eSFrançois Revol * include/linux/nbd.h
84d1cc41eSFrançois Revol */
94d1cc41eSFrançois Revol
104d1cc41eSFrançois Revolenum {
114d1cc41eSFrançois Revol	NBD_CMD_READ = 0,
124d1cc41eSFrançois Revol	NBD_CMD_WRITE,
134d1cc41eSFrançois Revol	NBD_CMD_DISC
144d1cc41eSFrançois Revol};
154d1cc41eSFrançois Revol
164d1cc41eSFrançois Revol#define NBD_REQUEST_MAGIC 0x25609513
174d1cc41eSFrançois Revol#define NBD_REPLY_MAGIC 0x67446698
184d1cc41eSFrançois Revol
194d1cc41eSFrançois Revol/* in network byte order */
204d1cc41eSFrançois Revolstruct nbd_request {
214d1cc41eSFrançois Revol	uint32 magic; /* REQUEST_MAGIC */
224d1cc41eSFrançois Revol	uint32 type;
234d1cc41eSFrançois Revol	uint64 handle; //char handle[8];
244d1cc41eSFrançois Revol	uint64 from;
254d1cc41eSFrançois Revol	uint32 len;
264d1cc41eSFrançois Revol} _PACKED;
274d1cc41eSFrançois Revol
284d1cc41eSFrançois Revol/* in network byte order */
294d1cc41eSFrançois Revolstruct nbd_reply {
304d1cc41eSFrançois Revol	uint32 magic; /* REPLY_MAGIC */
314d1cc41eSFrançois Revol	uint32 error;
324d1cc41eSFrançois Revol	uint64 handle; //char handle[8];
334d1cc41eSFrançois Revol} _PACKED;
344d1cc41eSFrançois Revol
354d1cc41eSFrançois Revol/* initialization protocol (ENBD ? or at least Linux specific ?) */
364d1cc41eSFrançois Revol
374d1cc41eSFrançois Revol#define NBD_INIT_PASSWD "NBDMAGIC"
384d1cc41eSFrançois Revol#define NBD_INIT_MAGIC 0x0000420281861253LL
394d1cc41eSFrançois Revol
404d1cc41eSFrançois Revol/* in network byte order */
414d1cc41eSFrançois Revolstruct nbd_init_packet {
424d1cc41eSFrançois Revol	uint8 passwd[8]; /* "NBDMAGIC" */
434d1cc41eSFrançois Revol	uint64 magic; /* INIT_MAGIC */
444d1cc41eSFrançois Revol	uint64 device_size; /* size in bytes */
454d1cc41eSFrançois Revol	uint8 dummy[128]; /* reserved for future use */
464d1cc41eSFrançois Revol} _PACKED;