+#define LINELEN 256 /**< Size of static buffer used to read the
+ authorization file (yuck) */
+#define BUFSIZE (1024*1024) /**< Size of buffer that can hold requests */
+#define GIGA (1*1024*1024*1024) /**< 1 Gigabyte. Used as hunksize when doing
+ the multiple file thingy */
+#define DIFFPAGESIZE 4096 /**< diff file uses those chunks */
+#define F_READONLY 1 /**< flag to tell us a file is readonly */
+#define F_MULTIFILE 2 /**< flag to tell us a file is exported using -m */
+#define F_COPYONWRITE 4 /**< flag to tell us a file is exported using copyonwrite */
+char difffilename[256]; /**< filename of the copy-on-write file. Doesn't belong here! */
+unsigned int timeout = 0; /**< disconnect timeout */
+int autoreadonly = 0; /**< 1 = switch to readonly if opening readwrite isn't
+ possible */
+char *auth_file="nbd_server.allow"; /**< authorization file */
+char exportname2[1024]; /**< File I'm exporting, with virtualhost resolved */
+off_t lastpoint = (off_t)-1; /**< keep track of where we are in the file, to
+ avoid an lseek if possible */
+char pagebuf[DIFFPAGESIZE]; /**< when doing copyonwrite, this is
+ used as a temporary buffer to store
+ the exported block in. @todo this is
+ a great example of namespace
+ pollution. Throw it out. */
+unsigned int port; /**< Port I'm listening at */
+char *exportname; /**< File I'm exporting */
+off_t exportsize = OFFT_MAX; /**< length of file I'm exporting */
+off_t hunksize = OFFT_MAX; /**< size of each exported file in case of -m */
+int flags = 0; /**< flags associated with this exported file */
+int export[1024];/**< array of filedescriptors of exported files; only first is
+ used unless -m option is activated */
+int difffile=-1; /**< filedescriptor for copyonwrite file */
+u32 difffilelen=0 ; /**< number of pages in difffile */
+u32 *difmap=NULL ; /**< Determine whether a block is in the original file
+ (difmap[block]==-1) or in the copyonwrite file (in which
+ case it contains the offset where it is to be found in the
+ copyonwrite file). @todo the kernel knows about sparse
+ files, we should use those instead. Should also be off_t
+ instead of u32; copyonwrite is probably broken wrt LFS */
+char clientname[256] ;
+int child_arraysize=DEFAULT_CHILD_ARRAY; /**< number of available slots for
+ child array */
+pid_t *children; /**< child array */
+char pidfname[256]; /**< name of our PID file */
+
+/**
+ * Variables associated with a copyonwrite server. Not yet used.
+ **/
+typedef struct __cow_opts {
+ char* difffilename; /**< filename of the copy-on-write file */
+ int difffile; /**< filedescriptor of copyonwrite file. @todo
+ shouldn't this be an array too? (cfr
+ nbd_server_opts::export) Or make -m and -c
+ mutually exclusive */
+ u32 difffilelen; /**< number of pages in difffile */
+ u32 *difmap; /**< see comment on the global difmap for this one */
+} cow_opts;
+
+/**
+ * Variables associated with a server. Not yet used.
+ **/
+typedef struct __nbd_server_opts {
+ char* exportname; /**< filename of the file we're exporting */
+ unsigned int port; /**< port we're exporting this file at */
+ char* authname; /**< filename of the authorization file */
+ off_t exportsize; /**< size of the file we're exporting */
+ off_t hunksize; /**< size of a hunk of an exported file */
+ int flags; /**< flags associated with this exported file */
+ char* clientname; /**< peer */
+ unsigned int timeout;/**< how long a connection may be idle
+ (0=forever) */
+ int export[1024]; /**< array of filedescriptors of exported files;
+ only the first is actually used unless we're
+ doing the multiple file option */
+ cow_opts* cow; /**< only used if (flags | F_COPYONWRITE) */
+} nbd_server_opts;
+
+/**
+ * Check whether a client is allowed to connect. Works with an
+ * authorization file which contains one line per machine, no
+ * wildcards.
+ * @param name IP address of client trying to connect (in human-readable form)
+ * @return 0 - authorization refused, 1 - OK
+ **/