Annotation of src/usr.bin/rsync/extern.h, Revision 1.9
1.9 ! florian 1: /* $Id: extern.h,v 1.8 2019/02/12 19:39:57 benno Exp $ */
1.1 benno 2: /*
3: * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
4: *
5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16: */
17: #ifndef EXTERN_H
18: #define EXTERN_H
19:
20: /*
21: * This is the rsync protocol version that we support.
22: */
23: #define RSYNC_PROTOCOL (27)
24:
25: /*
26: * Maximum amount of file data sent over the wire at once.
27: */
28: #define MAX_CHUNK (32 * 1024)
29:
30: /*
31: * This is the minimum size for a block of data not including those in
32: * the remainder block.
33: */
34: #define BLOCK_SIZE_MIN (700)
35:
36: /*
37: * The sender and receiver use a two-phase synchronisation process.
38: * The first uses two-byte hashes; the second, 16-byte.
39: * (The second must hold a full MD4 digest.)
40: */
41: #define CSUM_LENGTH_PHASE1 (2)
42: #define CSUM_LENGTH_PHASE2 (16)
43:
44: /*
45: * Operating mode for a client or a server.
46: * Sender means we synchronise local files with those from remote.
47: * Receiver is the opposite.
48: * This is relative to which host we're running on.
49: */
50: enum fmode {
51: FARGS_SENDER,
52: FARGS_RECEIVER
53: };
54:
55: /*
56: * File arguments given on the command line.
57: * See struct opts.
58: */
59: struct fargs {
60: char *host; /* hostname or NULL if local */
61: char **sources; /* transfer source */
62: size_t sourcesz; /* number of sources */
63: char *sink; /* transfer endpoint */
64: enum fmode mode; /* mode of operation */
65: int remote; /* uses rsync:// or :: for remote */
66: char *module; /* if rsync://, the module */
67: };
68:
69: /*
70: * The subset of stat(2) information that we need.
71: * (There are some parts we don't use yet.)
72: */
73: struct flstat {
74: mode_t mode; /* mode */
75: uid_t uid; /* user */
76: gid_t gid; /* group */
77: off_t size; /* size */
78: time_t mtime; /* modification */
79: unsigned int flags;
80: #define FLSTAT_TOP_DIR 0x01 /* a top-level directory */
81:
82: };
83:
84: /*
85: * A list of files with their statistics.
86: */
87: struct flist {
88: char *path; /* path relative to root */
89: const char *wpath; /* "working" path for receiver */
90: struct flstat st; /* file information */
91: char *link; /* symlink target or NULL */
92: };
93:
94: /*
95: * Options passed into the command line.
96: * See struct fargs.
97: */
98: struct opts {
1.3 deraadt 99: int sender; /* --sender */
100: int server; /* --server */
101: int recursive; /* -r */
102: int verbose; /* -v */
103: int dry_run; /* -n */
104: int preserve_times; /* -t */
105: int preserve_perms; /* -p */
106: int preserve_links; /* -l */
1.5 benno 107: int preserve_gids; /* -g */
1.9 ! florian 108: int preserve_uids; /* -u */
1.3 deraadt 109: int del; /* --delete */
110: char *rsync_path; /* --rsync-path */
1.4 deraadt 111: char *ssh_prog; /* --rsh or -e */
1.1 benno 112: };
113:
114: /*
115: * An individual block description for a file.
116: * See struct blkset.
117: */
118: struct blk {
119: off_t offs; /* offset in file */
120: size_t idx; /* block index */
121: size_t len; /* bytes in block */
122: uint32_t chksum_short; /* fast checksum */
123: unsigned char chksum_long[CSUM_LENGTH_PHASE2]; /* slow checksum */
124: };
125:
126: /*
127: * When transferring file contents, we break the file down into blocks
128: * and work with those.
129: */
130: struct blkset {
131: off_t size; /* file size */
132: size_t rem; /* terminal block length if non-zero */
133: size_t len; /* block length */
134: size_t csum; /* checksum length */
135: struct blk *blks; /* all blocks */
136: size_t blksz; /* number of blks */
137: };
138:
139: /*
140: * Values required during a communication session.
141: */
142: struct sess {
143: const struct opts *opts; /* system options */
144: int32_t seed; /* checksum seed */
145: int32_t lver; /* local version */
146: int32_t rver; /* remote version */
147: uint64_t total_read; /* non-logging wire/reads */
148: uint64_t total_size; /* total file size */
149: uint64_t total_write; /* non-logging wire/writes */
150: int mplex_reads; /* multiplexing reads? */
151: size_t mplex_read_remain; /* remaining bytes */
152: int mplex_writes; /* multiplexing writes? */
153: };
154:
1.6 benno 155: /*
156: * Combination of name and numeric id for groups and users.
157: */
158: struct ident {
159: int32_t id; /* the gid_t or uid_t */
160: int32_t mapped; /* if receiving, the mapped gid */
161: char *name; /* resolved name */
162: };
163:
1.1 benno 164: struct download;
165: struct upload;
166:
167: #define LOG0(_sess, _fmt, ...) \
168: rsync_log((_sess), __FILE__, __LINE__, -1, (_fmt), ##__VA_ARGS__)
169: #define LOG1(_sess, _fmt, ...) \
170: rsync_log((_sess), __FILE__, __LINE__, 0, (_fmt), ##__VA_ARGS__)
171: #define LOG2(_sess, _fmt, ...) \
172: rsync_log((_sess), __FILE__, __LINE__, 1, (_fmt), ##__VA_ARGS__)
173: #define LOG3(_sess, _fmt, ...) \
174: rsync_log((_sess), __FILE__, __LINE__, 2, (_fmt), ##__VA_ARGS__)
175: #define LOG4(_sess, _fmt, ...) \
176: rsync_log((_sess), __FILE__, __LINE__, 3, (_fmt), ##__VA_ARGS__)
177: #define ERRX1(_sess, _fmt, ...) \
178: rsync_errx1((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
179: #define WARNX(_sess, _fmt, ...) \
180: rsync_warnx((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
181: #define WARN(_sess, _fmt, ...) \
182: rsync_warn((_sess), 0, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
183: #define WARN1(_sess, _fmt, ...) \
184: rsync_warn((_sess), 1, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
185: #define WARN2(_sess, _fmt, ...) \
186: rsync_warn((_sess), 2, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
187: #define ERR(_sess, _fmt, ...) \
188: rsync_err((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
189: #define ERRX(_sess, _fmt, ...) \
190: rsync_errx((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
191:
192: __BEGIN_DECLS
193:
194: void rsync_log(struct sess *,
195: const char *, size_t, int, const char *, ...)
196: __attribute__((format(printf, 5, 6)));
197: void rsync_warnx1(struct sess *,
198: const char *, size_t, const char *, ...)
199: __attribute__((format(printf, 4, 5)));
200: void rsync_warn(struct sess *, int,
201: const char *, size_t, const char *, ...)
202: __attribute__((format(printf, 5, 6)));
203: void rsync_warnx(struct sess *, const char *,
204: size_t, const char *, ...)
205: __attribute__((format(printf, 4, 5)));
206: void rsync_err(struct sess *, const char *,
207: size_t, const char *, ...)
208: __attribute__((format(printf, 4, 5)));
209: void rsync_errx(struct sess *, const char *,
210: size_t, const char *, ...)
211: __attribute__((format(printf, 4, 5)));
212: void rsync_errx1(struct sess *, const char *,
213: size_t, const char *, ...)
214: __attribute__((format(printf, 4, 5)));
215:
1.2 benno 216: int flist_del(struct sess *, int,
1.1 benno 217: const struct flist *, size_t);
218: int flist_gen(struct sess *, size_t, char **,
219: struct flist **, size_t *);
220: int flist_gen_local(struct sess *, const char *,
221: struct flist **, size_t *);
222: void flist_free(struct flist *, size_t);
223: int flist_recv(struct sess *, int,
224: struct flist **, size_t *);
225: int flist_send(struct sess *, int, int,
226: const struct flist *, size_t);
1.2 benno 227: int flist_gen_dels(struct sess *, const char *,
1.1 benno 228: struct flist **, size_t *,
229: const struct flist *, size_t);
230:
231: char **fargs_cmdline(struct sess *, const struct fargs *);
232:
233: int io_read_buf(struct sess *, int, void *, size_t);
234: int io_read_byte(struct sess *, int, uint8_t *);
235: int io_read_check(struct sess *, int);
236: int io_read_flush(struct sess *, int);
237: int io_read_int(struct sess *, int, int32_t *);
238: int io_read_long(struct sess *, int, int64_t *);
239: int io_read_size(struct sess *, int, size_t *);
240: int io_read_ulong(struct sess *, int, uint64_t *);
241: int io_write_buf(struct sess *, int, const void *, size_t);
242: int io_write_byte(struct sess *, int, uint8_t);
243: int io_write_int(struct sess *, int, int32_t);
244: int io_write_line(struct sess *, int, const char *);
245: int io_write_long(struct sess *, int, int64_t);
246:
1.2 benno 247: void io_buffer_int(struct sess *, void *,
1.1 benno 248: size_t *, size_t, int32_t);
1.2 benno 249: void io_buffer_buf(struct sess *, void *,
1.1 benno 250: size_t *, size_t, const void *, size_t);
251:
1.2 benno 252: void io_unbuffer_int(struct sess *, const void *,
1.1 benno 253: size_t *, size_t, int32_t *);
1.2 benno 254: int io_unbuffer_size(struct sess *, const void *,
1.1 benno 255: size_t *, size_t, size_t *);
1.2 benno 256: void io_unbuffer_buf(struct sess *, const void *,
1.1 benno 257: size_t *, size_t, void *, size_t);
258:
259: void rsync_child(const struct opts *, int, const struct fargs *)
260: __attribute__((noreturn));
261: int rsync_receiver(struct sess *, int, int, const char *);
262: int rsync_sender(struct sess *, int, int, size_t, char **);
263: int rsync_client(const struct opts *, int, const struct fargs *);
264: int rsync_socket(const struct opts *, const struct fargs *);
265: int rsync_server(const struct opts *, size_t, char *[]);
266: int rsync_downloader(struct download *, struct sess *, int *);
1.2 benno 267: int rsync_uploader(struct upload *,
1.1 benno 268: int *, struct sess *, int *);
269: int rsync_uploader_tail(struct upload *, struct sess *);
270:
271: struct download *download_alloc(struct sess *, int,
272: const struct flist *, size_t, int);
273: void download_free(struct download *);
1.2 benno 274: struct upload *upload_alloc(struct sess *, int, int, size_t,
1.1 benno 275: const struct flist *, size_t, mode_t);
276: void upload_free(struct upload *);
277:
278: struct blkset *blk_recv(struct sess *, int, const char *);
279: int blk_recv_ack(struct sess *,
280: int, const struct blkset *, int32_t);
281: int blk_match(struct sess *, int,
282: const struct blkset *, const char *);
283: int blk_send(struct sess *, int, size_t,
284: const struct blkset *, const char *);
285: int blk_send_ack(struct sess *, int, struct blkset *);
286: int blk_merge(struct sess *, int, int,
287: const struct blkset *, int, const char *,
288: const void *, size_t, float *);
289: void blkset_free(struct blkset *);
290:
291: uint32_t hash_fast(const void *, size_t);
292: void hash_slow(const void *, size_t,
293: unsigned char *, const struct sess *);
294: void hash_file(const void *, size_t,
295: unsigned char *, const struct sess *);
296:
297: int mkpath(struct sess *, char *);
298:
299: char *symlink_read(struct sess *, const char *);
300: char *symlinkat_read(struct sess *, int, const char *);
301:
302: int sess_stats_send(struct sess *, int);
303: int sess_stats_recv(struct sess *, int);
1.6 benno 304:
1.9 ! florian 305: int idents_add(struct sess *, int, struct ident **, size_t *,
! 306: int32_t);
! 307: void idents_assign_gid(struct sess *,
! 308: struct flist *, size_t, const struct ident *, size_t);
! 309: void idents_assign_uid(struct sess *,
! 310: struct flist *, size_t, const struct ident *, size_t);
1.6 benno 311: void idents_free(struct ident *, size_t);
1.7 benno 312: int idents_recv(struct sess *, int, struct ident **, size_t *);
1.9 ! florian 313: void idents_remap(struct sess *, int, struct ident *, size_t);
1.6 benno 314: int idents_send(struct sess *, int, const struct ident *, size_t);
1.1 benno 315:
316: __END_DECLS
317:
318: #endif /*!EXTERN_H*/