1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LINUX_NBD_H
16#define LINUX_NBD_H
17
18#include <linux/types.h>
19
20#define NBD_SET_SOCK _IO( 0xab, 0 )
21#define NBD_SET_BLKSIZE _IO( 0xab, 1 )
22#define NBD_SET_SIZE _IO( 0xab, 2 )
23#define NBD_DO_IT _IO( 0xab, 3 )
24#define NBD_CLEAR_SOCK _IO( 0xab, 4 )
25#define NBD_CLEAR_QUE _IO( 0xab, 5 )
26#define NBD_PRINT_DEBUG _IO( 0xab, 6 )
27#define NBD_SET_SIZE_BLOCKS _IO( 0xab, 7 )
28#define NBD_DISCONNECT _IO( 0xab, 8 )
29#define NBD_SET_TIMEOUT _IO( 0xab, 9 )
30
31enum {
32 NBD_CMD_READ = 0,
33 NBD_CMD_WRITE = 1,
34 NBD_CMD_DISC = 2
35};
36
37#define nbd_cmd(req) ((req)->cmd[0])
38
39
40#ifdef __KERNEL__
41
42#include <linux/wait.h>
43#include <linux/mutex.h>
44
45
46#define NBD_READ_ONLY 0x0001
47#define NBD_WRITE_NOCHK 0x0002
48
49struct request;
50
51struct nbd_device {
52 int flags;
53 int harderror;
54 struct socket * sock;
55 struct file * file;
56 int magic;
57
58 spinlock_t queue_lock;
59 struct list_head queue_head;
60 struct request *active_req;
61 wait_queue_head_t active_wq;
62 struct list_head waiting_queue;
63 wait_queue_head_t waiting_wq;
64
65 struct mutex tx_lock;
66 struct gendisk *disk;
67 int blksize;
68 u64 bytesize;
69 pid_t pid;
70 int xmit_timeout;
71};
72
73#endif
74
75
76
77#define NBD_REQUEST_MAGIC 0x25609513
78#define NBD_REPLY_MAGIC 0x67446698
79
80
81
82
83
84
85struct nbd_request {
86 __be32 magic;
87 __be32 type;
88 char handle[8];
89 __be64 from;
90 __be32 len;
91} __attribute__((packed));
92
93
94
95
96
97struct nbd_reply {
98 __be32 magic;
99 __be32 error;
100 char handle[8];
101};
102#endif
103