Annotation of src/usr.bin/rsync/extern.h, Revision 1.12
1.12 ! florian 1: /* $Id: extern.h,v 1.11 2019/02/16 10:46:22 florian 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 {
1.12 ! florian 74: mode_t mode; /* mode */
! 75: uid_t uid; /* user */
! 76: gid_t gid; /* group */
! 77: dev_t rdev; /* device type */
! 78: off_t size; /* size */
! 79: time_t mtime; /* modification */
1.1 benno 80: unsigned int flags;
1.12 ! florian 81: #define FLSTAT_TOP_DIR 0x01 /* a top-level directory */
1.1 benno 82:
83: };
84:
85: /*
86: * A list of files with their statistics.
87: */
88: struct flist {
89: char *path; /* path relative to root */
90: const char *wpath; /* "working" path for receiver */
91: struct flstat st; /* file information */
92: char *link; /* symlink target or NULL */
93: };
94:
95: /*
96: * Options passed into the command line.
97: * See struct fargs.
98: */
99: struct opts {
1.3 deraadt 100: int sender; /* --sender */
101: int server; /* --server */
102: int recursive; /* -r */
103: int verbose; /* -v */
104: int dry_run; /* -n */
105: int preserve_times; /* -t */
106: int preserve_perms; /* -p */
107: int preserve_links; /* -l */
1.5 benno 108: int preserve_gids; /* -g */
1.9 florian 109: int preserve_uids; /* -u */
1.3 deraadt 110: int del; /* --delete */
1.12 ! florian 111: int devices; /* --devices */
! 112: int specials; /* --specials */
1.3 deraadt 113: char *rsync_path; /* --rsync-path */
1.4 deraadt 114: char *ssh_prog; /* --rsh or -e */
1.1 benno 115: };
116:
117: /*
118: * An individual block description for a file.
119: * See struct blkset.
120: */
121: struct blk {
122: off_t offs; /* offset in file */
123: size_t idx; /* block index */
124: size_t len; /* bytes in block */
125: uint32_t chksum_short; /* fast checksum */
126: unsigned char chksum_long[CSUM_LENGTH_PHASE2]; /* slow checksum */
127: };
128:
129: /*
130: * When transferring file contents, we break the file down into blocks
131: * and work with those.
132: */
133: struct blkset {
134: off_t size; /* file size */
135: size_t rem; /* terminal block length if non-zero */
136: size_t len; /* block length */
137: size_t csum; /* checksum length */
138: struct blk *blks; /* all blocks */
139: size_t blksz; /* number of blks */
140: };
141:
142: /*
143: * Values required during a communication session.
144: */
145: struct sess {
146: const struct opts *opts; /* system options */
147: int32_t seed; /* checksum seed */
148: int32_t lver; /* local version */
149: int32_t rver; /* remote version */
150: uint64_t total_read; /* non-logging wire/reads */
151: uint64_t total_size; /* total file size */
152: uint64_t total_write; /* non-logging wire/writes */
153: int mplex_reads; /* multiplexing reads? */
154: size_t mplex_read_remain; /* remaining bytes */
155: int mplex_writes; /* multiplexing writes? */
156: };
157:
1.6 benno 158: /*
159: * Combination of name and numeric id for groups and users.
160: */
161: struct ident {
162: int32_t id; /* the gid_t or uid_t */
163: int32_t mapped; /* if receiving, the mapped gid */
164: char *name; /* resolved name */
165: };
166:
1.1 benno 167: struct download;
168: struct upload;
169:
170: #define LOG0(_sess, _fmt, ...) \
171: rsync_log((_sess), __FILE__, __LINE__, -1, (_fmt), ##__VA_ARGS__)
172: #define LOG1(_sess, _fmt, ...) \
173: rsync_log((_sess), __FILE__, __LINE__, 0, (_fmt), ##__VA_ARGS__)
174: #define LOG2(_sess, _fmt, ...) \
175: rsync_log((_sess), __FILE__, __LINE__, 1, (_fmt), ##__VA_ARGS__)
176: #define LOG3(_sess, _fmt, ...) \
177: rsync_log((_sess), __FILE__, __LINE__, 2, (_fmt), ##__VA_ARGS__)
178: #define LOG4(_sess, _fmt, ...) \
179: rsync_log((_sess), __FILE__, __LINE__, 3, (_fmt), ##__VA_ARGS__)
180: #define ERRX1(_sess, _fmt, ...) \
181: rsync_errx1((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
182: #define WARNX(_sess, _fmt, ...) \
183: rsync_warnx((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
184: #define WARN(_sess, _fmt, ...) \
185: rsync_warn((_sess), 0, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
186: #define WARN1(_sess, _fmt, ...) \
187: rsync_warn((_sess), 1, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
188: #define WARN2(_sess, _fmt, ...) \
189: rsync_warn((_sess), 2, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
190: #define ERR(_sess, _fmt, ...) \
191: rsync_err((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
192: #define ERRX(_sess, _fmt, ...) \
193: rsync_errx((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
194:
195: __BEGIN_DECLS
196:
197: void rsync_log(struct sess *,
198: const char *, size_t, int, const char *, ...)
199: __attribute__((format(printf, 5, 6)));
200: void rsync_warnx1(struct sess *,
201: const char *, size_t, const char *, ...)
202: __attribute__((format(printf, 4, 5)));
203: void rsync_warn(struct sess *, int,
204: const char *, size_t, const char *, ...)
205: __attribute__((format(printf, 5, 6)));
206: void rsync_warnx(struct sess *, const char *,
207: size_t, const char *, ...)
208: __attribute__((format(printf, 4, 5)));
209: void rsync_err(struct sess *, const char *,
210: size_t, const char *, ...)
211: __attribute__((format(printf, 4, 5)));
212: void rsync_errx(struct sess *, const char *,
213: size_t, const char *, ...)
214: __attribute__((format(printf, 4, 5)));
215: void rsync_errx1(struct sess *, const char *,
216: size_t, const char *, ...)
217: __attribute__((format(printf, 4, 5)));
218:
1.2 benno 219: int flist_del(struct sess *, int,
1.1 benno 220: const struct flist *, size_t);
221: int flist_gen(struct sess *, size_t, char **,
222: struct flist **, size_t *);
223: int flist_gen_local(struct sess *, const char *,
224: struct flist **, size_t *);
225: void flist_free(struct flist *, size_t);
226: int flist_recv(struct sess *, int,
227: struct flist **, size_t *);
228: int flist_send(struct sess *, int, int,
229: const struct flist *, size_t);
1.2 benno 230: int flist_gen_dels(struct sess *, const char *,
1.1 benno 231: struct flist **, size_t *,
232: const struct flist *, size_t);
233:
234: char **fargs_cmdline(struct sess *, const struct fargs *);
235:
236: int io_read_buf(struct sess *, int, void *, size_t);
237: int io_read_byte(struct sess *, int, uint8_t *);
238: int io_read_check(struct sess *, int);
239: int io_read_flush(struct sess *, int);
240: int io_read_int(struct sess *, int, int32_t *);
241: int io_read_long(struct sess *, int, int64_t *);
242: int io_read_size(struct sess *, int, size_t *);
243: int io_read_ulong(struct sess *, int, uint64_t *);
244: int io_write_buf(struct sess *, int, const void *, size_t);
245: int io_write_byte(struct sess *, int, uint8_t);
246: int io_write_int(struct sess *, int, int32_t);
247: int io_write_line(struct sess *, int, const char *);
248: int io_write_long(struct sess *, int, int64_t);
249:
1.2 benno 250: void io_buffer_int(struct sess *, void *,
1.1 benno 251: size_t *, size_t, int32_t);
1.2 benno 252: void io_buffer_buf(struct sess *, void *,
1.1 benno 253: size_t *, size_t, const void *, size_t);
254:
1.2 benno 255: void io_unbuffer_int(struct sess *, const void *,
1.1 benno 256: size_t *, size_t, int32_t *);
1.2 benno 257: int io_unbuffer_size(struct sess *, const void *,
1.1 benno 258: size_t *, size_t, size_t *);
1.2 benno 259: void io_unbuffer_buf(struct sess *, const void *,
1.1 benno 260: size_t *, size_t, void *, size_t);
261:
262: void rsync_child(const struct opts *, int, const struct fargs *)
263: __attribute__((noreturn));
264: int rsync_receiver(struct sess *, int, int, const char *);
265: int rsync_sender(struct sess *, int, int, size_t, char **);
266: int rsync_client(const struct opts *, int, const struct fargs *);
267: int rsync_socket(const struct opts *, const struct fargs *);
268: int rsync_server(const struct opts *, size_t, char *[]);
269: int rsync_downloader(struct download *, struct sess *, int *);
1.10 florian 270: int rsync_set_metadata(struct sess *, int, int,
271: const struct flist *, const char *);
1.12 ! florian 272: int rsync_set_metadata_at(struct sess *, int, int,
! 273: const struct flist *, const char *);
1.2 benno 274: int rsync_uploader(struct upload *,
1.1 benno 275: int *, struct sess *, int *);
276: int rsync_uploader_tail(struct upload *, struct sess *);
277:
278: struct download *download_alloc(struct sess *, int,
279: const struct flist *, size_t, int);
280: void download_free(struct download *);
1.12 ! florian 281: struct upload *upload_alloc(struct sess *, const char *, int, int, size_t,
1.1 benno 282: const struct flist *, size_t, mode_t);
283: void upload_free(struct upload *);
284:
285: struct blkset *blk_recv(struct sess *, int, const char *);
286: int blk_recv_ack(struct sess *,
287: int, const struct blkset *, int32_t);
288: int blk_match(struct sess *, int,
289: const struct blkset *, const char *);
290: int blk_send(struct sess *, int, size_t,
291: const struct blkset *, const char *);
292: int blk_send_ack(struct sess *, int, struct blkset *);
293: int blk_merge(struct sess *, int, int,
294: const struct blkset *, int, const char *,
295: const void *, size_t, float *);
296: void blkset_free(struct blkset *);
297:
298: uint32_t hash_fast(const void *, size_t);
299: void hash_slow(const void *, size_t,
300: unsigned char *, const struct sess *);
301: void hash_file(const void *, size_t,
302: unsigned char *, const struct sess *);
303:
304: int mkpath(struct sess *, char *);
1.11 florian 305:
306: int mkstempat(int, char *);
307: char *mkstemplinkat(char*, int, char *);
1.12 ! florian 308: char *mkstempfifoat(int, char *);
! 309: char *mkstempnodat(int, char *, mode_t, dev_t);
! 310: char *mkstempsock(const char *, char *);
1.11 florian 311: int mktemplate(char **, const char *, int);
1.1 benno 312:
313: char *symlink_read(struct sess *, const char *);
314: char *symlinkat_read(struct sess *, int, const char *);
315:
316: int sess_stats_send(struct sess *, int);
317: int sess_stats_recv(struct sess *, int);
1.6 benno 318:
1.9 florian 319: int idents_add(struct sess *, int, struct ident **, size_t *,
320: int32_t);
321: void idents_assign_gid(struct sess *,
322: struct flist *, size_t, const struct ident *, size_t);
323: void idents_assign_uid(struct sess *,
324: struct flist *, size_t, const struct ident *, size_t);
1.6 benno 325: void idents_free(struct ident *, size_t);
1.7 benno 326: int idents_recv(struct sess *, int, struct ident **, size_t *);
1.9 florian 327: void idents_remap(struct sess *, int, struct ident *, size_t);
1.6 benno 328: int idents_send(struct sess *, int, const struct ident *, size_t);
1.1 benno 329:
330: __END_DECLS
331:
332: #endif /*!EXTERN_H*/