kernel - TMPFS - Bug fixing pass - fsync, vnode locks
[dragonfly.git] / bin / cpdup / hclink.h
blob0428ee3c5f92884f8cdf1069cf231f4bf9709c0f
1 /*
2 * HCLINK.H
4 * $DragonFly: src/bin/cpdup/hclink.h,v 1.7 2008/05/24 17:21:36 dillon Exp $
5 */
7 #ifndef _HCLINK_H_
8 #define _HCLINK_H_
10 struct HCHostDesc {
11 struct HCHostDesc *next;
12 int desc;
13 int type;
14 void *data;
17 struct HostConf;
19 typedef struct HCTransaction {
20 struct HCTransaction *next;
21 struct HostConf *hc;
22 u_int16_t id; /* assigned transaction id */
23 int windex; /* output buffer index */
24 enum { HCT_IDLE, HCT_SENT, HCT_REPLIED, HCT_DONE } state;
25 char rbuf[65536]; /* input buffer */
26 char wbuf[65536]; /* output buffer */
27 } *hctransaction_t;
29 struct HostConf {
30 char *host; /* [user@]host */
31 int fdin; /* pipe */
32 int fdout; /* pipe */
33 int error; /* permanent failure code */
34 pid_t pid;
35 int version; /* cpdup protocol version */
36 struct HCHostDesc *hostdescs;
37 struct HCTransaction trans;
40 struct HCHead {
41 int32_t magic; /* magic number / byte ordering */
42 int32_t bytes; /* size of packet */
43 int16_t cmd; /* command code */
44 u_int16_t id; /* transaction id */
45 int32_t error; /* error code (response) */
48 #define HCMAGIC 0x48435052 /* compatible byte ordering */
49 #define HCMAGIC_REV 0x52504348 /* reverse byte ordering */
50 #define HCC_ALIGN(bytes) (((bytes) + 7) & ~7)
52 struct HCLeaf {
53 int16_t leafid;
54 int16_t reserved; /* reserved must be 0 */
55 int32_t bytes;
58 #define HCF_REPLY 0x8000 /* reply */
60 #define LCF_TYPEMASK 0x0F00
61 #define LCF_INT32 0x0100 /* 4 byte integer */
62 #define LCF_INT64 0x0200 /* 8 byte integer */
63 #define LCF_STRING 0x0300 /* string, must be 0-terminated */
64 #define LCF_BINARY 0x0F00 /* binary data */
66 #define LCF_NESTED 0x8000
68 struct HCDesc {
69 int16_t cmd;
70 int (*func)(hctransaction_t, struct HCHead *);
74 * Item extraction macros
76 #define HCC_STRING(item) ((const char *)((item) + 1))
77 #define HCC_INT32(item) (*(int32_t *)((item) + 1))
78 #define HCC_INT64(item) (*(int64_t *)((item) + 1))
79 #define HCC_BINARYDATA(item) ((void *)((item) + 1))
82 * Prototypes
84 int hcc_connect(struct HostConf *hc);
85 int hcc_slave(int fdin, int fdout, struct HCDesc *descs, int count);
87 hctransaction_t hcc_start_command(struct HostConf *hc, int16_t cmd);
88 struct HCHead *hcc_finish_command(hctransaction_t trans);
89 void hcc_leaf_string(hctransaction_t trans, int16_t leafid, const char *str);
90 void hcc_leaf_data(hctransaction_t trans, int16_t leafid, const void *ptr, int bytes);
91 void hcc_leaf_int32(hctransaction_t trans, int16_t leafid, int32_t value);
92 void hcc_leaf_int64(hctransaction_t trans, int16_t leafid, int64_t value);
94 int hcc_alloc_descriptor(struct HostConf *hc, void *ptr, int type);
95 void *hcc_get_descriptor(struct HostConf *hc, int desc, int type);
96 void hcc_set_descriptor(struct HostConf *hc, int desc, void *ptr, int type);
98 struct HCLeaf *hcc_firstitem(struct HCHead *head);
99 struct HCLeaf *hcc_nextitem(struct HCHead *head, struct HCLeaf *item);
101 void hcc_debug_dump(struct HCHead *head);
102 void hcc_free_trans(struct HostConf *hc);
104 #endif