Network Block Device @PACKAGE_VERSION@

cliserv.h

Go to the documentation of this file.
00001 /* This header file is shared by client & server. They really have
00002  * something to share...
00003  * */
00004 
00005 /* Client/server protocol is as follows:
00006    Send INIT_PASSWD
00007    Send 64-bit cliserv_magic
00008    Send 64-bit size of exported device
00009    Send 128 bytes of zeros (reserved for future use)
00010  */
00011 
00012 #include <errno.h>
00013 #include <string.h>
00014 #include <netdb.h>
00015 #include <netinet/tcp.h>
00016 #include <netinet/in.h>
00017 #include <stdlib.h>
00018 
00019 #if SIZEOF_UNSIGNED_SHORT_INT==4
00020 typedef unsigned short u32;
00021 #elif SIZEOF_UNSIGNED_INT==4
00022 typedef unsigned int u32;
00023 #elif SIZEOF_UNSIGNED_LONG_INT==4
00024 typedef unsigned long u32;
00025 #else
00026 #error I need at least some 32-bit type
00027 #endif
00028 
00029 #if SIZEOF_UNSIGNED_INT==8
00030 typedef unsigned int u64;
00031 #elif SIZEOF_UNSIGNED_LONG_INT==8
00032 typedef unsigned long u64;
00033 #elif SIZEOF_UNSIGNED_LONG_LONG_INT==8
00034 typedef unsigned long long u64;
00035 #else
00036 #error I need at least some 64-bit type
00037 #endif
00038 
00039 #define __be32 u32
00040 #define __be64 u64
00041 #include "nbd.h"
00042 
00043 #ifndef HAVE_FDATASYNC
00044 #define fdatasync(arg) fsync(arg)
00045 #endif
00046 
00047 #if NBD_LFS==1
00048 /* /usr/include/features.h (included from /usr/include/sys/types.h)
00049    defines this when _GNU_SOURCE is defined
00050  */
00051 #ifndef _LARGEFILE_SOURCE
00052 #define _LARGEFILE_SOURCE
00053 #endif
00054 #define _FILE_OFFSET_BITS 64
00055 #endif
00056 
00057 #ifndef G_GNUC_NORETURN
00058 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
00059 #define G_GNUC_NORETURN __attribute__((__noreturn__))
00060 #define G_GNUC_UNUSED __attribute__((unused))
00061 #else
00062 #define G_GNUC_NORETURN
00063 #define G_GNUC_UNUSED
00064 #endif
00065 #endif
00066 
00067 extern const u64 cliserv_magic;
00068 extern const u64 opts_magic;
00069 extern const u64 rep_magic;
00070 
00071 #define INIT_PASSWD "NBDMAGIC"
00072 
00073 #define INFO(a) do { } while(0)
00074 
00075 void setmysockopt(int sock);
00076 void err_nonfatal(const char *s);
00077 
00078 void err(const char *s) G_GNUC_NORETURN;
00079 
00080 void logging(const char* name);
00081 
00082 #ifndef ntohll
00083 uint64_t ntohll(uint64_t a);
00084 #endif
00085 #ifndef htonll
00086 #define htonll ntohll
00087 #endif
00088 
00089 void readit(int f, void *buf, size_t len);
00090 
00091 #define NBD_DEFAULT_PORT        "10809" /* Port on which named exports are
00092                                          * served */
00093 
00094 /* Options that the client can select to the server */
00095 #define NBD_OPT_EXPORT_NAME     (1)     /** Client wants to select a named export (is followed by name of export) */
00096 #define NBD_OPT_ABORT           (2)     /** Client wishes to abort negotiation */
00097 #define NBD_OPT_LIST            (3)     /** Client request list of supported exports (not followed by data) */
00098 
00099 /* Replies the server can send during negotiation */
00100 #define NBD_REP_ACK             (1)     /** ACK a request. Data: option number to be acked */
00101 #define NBD_REP_SERVER          (2)     /** Reply to NBD_OPT_LIST (one of these per server; must be followed by NBD_REP_ACK to signal the end of the list */
00102 #define NBD_REP_FLAG_ERROR      (1 << 31)       /** If the high bit is set, the reply is an error */
00103 #define NBD_REP_ERR_UNSUP       (1 | NBD_REP_FLAG_ERROR)        /** Client requested an option not understood by this version of the server */
00104 #define NBD_REP_ERR_POLICY      (2 | NBD_REP_FLAG_ERROR)        /** Client requested an option not allowed by server configuration. (e.g., the option was disabled) */
00105 #define NBD_REP_ERR_INVALID     (3 | NBD_REP_FLAG_ERROR)        /** Client issued an invalid request */
00106 #define NBD_REP_ERR_PLATFORM    (4 | NBD_REP_FLAG_ERROR)        /** Option not supported on this platform */
00107 
00108 /* Global flags */
00109 #define NBD_FLAG_FIXED_NEWSTYLE (1 << 0)        /* new-style export that actually supports extending */
00110 #define NBD_FLAG_NO_ZEROES      (1 << 1)        /* we won't send the 128 bits of zeroes if the client sends NBD_FLAG_C_NO_ZEROES */
00111 /* Flags from client to server. Only one such option currently. */
00112 #define NBD_FLAG_C_FIXED_NEWSTYLE NBD_FLAG_FIXED_NEWSTYLE
00113 #define NBD_FLAG_C_NO_ZEROES    NBD_FLAG_NO_ZEROES