[BACK]Return to extern.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / rsync

Annotation of src/usr.bin/rsync/extern.h, Revision 1.3

1.3     ! deraadt     1: /*     $Id: extern.h,v 1.2 2019/02/10 23:24:14 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 */
        !           107:        int              del;                   /* --delete */
        !           108:        char            *rsync_path;            /* --rsync-path */
1.1       benno     109: };
                    110:
                    111: /*
                    112:  * An individual block description for a file.
                    113:  * See struct blkset.
                    114:  */
                    115: struct blk {
                    116:        off_t            offs; /* offset in file */
                    117:        size_t           idx; /* block index */
                    118:        size_t           len; /* bytes in block */
                    119:        uint32_t         chksum_short; /* fast checksum */
                    120:        unsigned char    chksum_long[CSUM_LENGTH_PHASE2]; /* slow checksum */
                    121: };
                    122:
                    123: /*
                    124:  * When transferring file contents, we break the file down into blocks
                    125:  * and work with those.
                    126:  */
                    127: struct blkset {
                    128:        off_t            size; /* file size */
                    129:        size_t           rem; /* terminal block length if non-zero */
                    130:        size_t           len; /* block length */
                    131:        size_t           csum; /* checksum length */
                    132:        struct blk      *blks; /* all blocks */
                    133:        size_t           blksz; /* number of blks */
                    134: };
                    135:
                    136: /*
                    137:  * Values required during a communication session.
                    138:  */
                    139: struct sess {
                    140:        const struct opts *opts; /* system options */
                    141:        int32_t            seed; /* checksum seed */
                    142:        int32_t            lver; /* local version */
                    143:        int32_t            rver; /* remote version */
                    144:        uint64_t           total_read; /* non-logging wire/reads */
                    145:        uint64_t           total_size; /* total file size */
                    146:        uint64_t           total_write; /* non-logging wire/writes */
                    147:        int                mplex_reads; /* multiplexing reads? */
                    148:        size_t             mplex_read_remain; /* remaining bytes */
                    149:        int                mplex_writes; /* multiplexing writes? */
                    150: };
                    151:
                    152: struct download;
                    153: struct upload;
                    154:
                    155: #define LOG0(_sess, _fmt, ...) \
                    156:        rsync_log((_sess), __FILE__, __LINE__, -1, (_fmt), ##__VA_ARGS__)
                    157: #define LOG1(_sess, _fmt, ...) \
                    158:        rsync_log((_sess), __FILE__, __LINE__, 0, (_fmt), ##__VA_ARGS__)
                    159: #define LOG2(_sess, _fmt, ...) \
                    160:        rsync_log((_sess), __FILE__, __LINE__, 1, (_fmt), ##__VA_ARGS__)
                    161: #define LOG3(_sess, _fmt, ...) \
                    162:        rsync_log((_sess), __FILE__, __LINE__, 2, (_fmt), ##__VA_ARGS__)
                    163: #define LOG4(_sess, _fmt, ...) \
                    164:        rsync_log((_sess), __FILE__, __LINE__, 3, (_fmt), ##__VA_ARGS__)
                    165: #define ERRX1(_sess, _fmt, ...) \
                    166:        rsync_errx1((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    167: #define WARNX(_sess, _fmt, ...) \
                    168:        rsync_warnx((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    169: #define WARN(_sess, _fmt, ...) \
                    170:        rsync_warn((_sess), 0, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    171: #define WARN1(_sess, _fmt, ...) \
                    172:        rsync_warn((_sess), 1, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    173: #define WARN2(_sess, _fmt, ...) \
                    174:        rsync_warn((_sess), 2, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    175: #define ERR(_sess, _fmt, ...) \
                    176:        rsync_err((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    177: #define ERRX(_sess, _fmt, ...) \
                    178:        rsync_errx((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    179:
                    180: __BEGIN_DECLS
                    181:
                    182: void             rsync_log(struct sess *,
                    183:                        const char *, size_t, int, const char *, ...)
                    184:                        __attribute__((format(printf, 5, 6)));
                    185: void             rsync_warnx1(struct sess *,
                    186:                        const char *, size_t, const char *, ...)
                    187:                        __attribute__((format(printf, 4, 5)));
                    188: void             rsync_warn(struct sess *, int,
                    189:                        const char *, size_t, const char *, ...)
                    190:                        __attribute__((format(printf, 5, 6)));
                    191: void             rsync_warnx(struct sess *, const char *,
                    192:                        size_t, const char *, ...)
                    193:                        __attribute__((format(printf, 4, 5)));
                    194: void             rsync_err(struct sess *, const char *,
                    195:                        size_t, const char *, ...)
                    196:                        __attribute__((format(printf, 4, 5)));
                    197: void             rsync_errx(struct sess *, const char *,
                    198:                        size_t, const char *, ...)
                    199:                        __attribute__((format(printf, 4, 5)));
                    200: void             rsync_errx1(struct sess *, const char *,
                    201:                        size_t, const char *, ...)
                    202:                        __attribute__((format(printf, 4, 5)));
                    203:
1.2       benno     204: int              flist_del(struct sess *, int,
1.1       benno     205:                        const struct flist *, size_t);
                    206: int              flist_gen(struct sess *, size_t, char **,
                    207:                        struct flist **, size_t *);
                    208: int              flist_gen_local(struct sess *, const char *,
                    209:                        struct flist **, size_t *);
                    210: void             flist_free(struct flist *, size_t);
                    211: int              flist_recv(struct sess *, int,
                    212:                        struct flist **, size_t *);
                    213: int              flist_send(struct sess *, int, int,
                    214:                        const struct flist *, size_t);
1.2       benno     215: int              flist_gen_dels(struct sess *, const char *,
1.1       benno     216:                        struct flist **, size_t *,
                    217:                        const struct flist *, size_t);
                    218:
                    219: char           **fargs_cmdline(struct sess *, const struct fargs *);
                    220:
                    221: int              io_read_buf(struct sess *, int, void *, size_t);
                    222: int              io_read_byte(struct sess *, int, uint8_t *);
                    223: int              io_read_check(struct sess *, int);
                    224: int              io_read_flush(struct sess *, int);
                    225: int              io_read_int(struct sess *, int, int32_t *);
                    226: int              io_read_long(struct sess *, int, int64_t *);
                    227: int              io_read_size(struct sess *, int, size_t *);
                    228: int              io_read_ulong(struct sess *, int, uint64_t *);
                    229: int              io_write_buf(struct sess *, int, const void *, size_t);
                    230: int              io_write_byte(struct sess *, int, uint8_t);
                    231: int              io_write_int(struct sess *, int, int32_t);
                    232: int              io_write_line(struct sess *, int, const char *);
                    233: int              io_write_long(struct sess *, int, int64_t);
                    234:
1.2       benno     235: void             io_buffer_int(struct sess *, void *,
1.1       benno     236:                        size_t *, size_t, int32_t);
1.2       benno     237: void             io_buffer_buf(struct sess *, void *,
1.1       benno     238:                        size_t *, size_t, const void *, size_t);
                    239:
1.2       benno     240: void             io_unbuffer_int(struct sess *, const void *,
1.1       benno     241:                        size_t *, size_t, int32_t *);
1.2       benno     242: int              io_unbuffer_size(struct sess *, const void *,
1.1       benno     243:                        size_t *, size_t, size_t *);
1.2       benno     244: void             io_unbuffer_buf(struct sess *, const void *,
1.1       benno     245:                        size_t *, size_t, void *, size_t);
                    246:
                    247: void             rsync_child(const struct opts *, int, const struct fargs *)
                    248:                        __attribute__((noreturn));
                    249: int              rsync_receiver(struct sess *, int, int, const char *);
                    250: int              rsync_sender(struct sess *, int, int, size_t, char **);
                    251: int              rsync_client(const struct opts *, int, const struct fargs *);
                    252: int              rsync_socket(const struct opts *, const struct fargs *);
                    253: int              rsync_server(const struct opts *, size_t, char *[]);
                    254: int              rsync_downloader(struct download *, struct sess *, int *);
1.2       benno     255: int              rsync_uploader(struct upload *,
1.1       benno     256:                        int *, struct sess *, int *);
                    257: int              rsync_uploader_tail(struct upload *, struct sess *);
                    258:
                    259: struct download         *download_alloc(struct sess *, int,
                    260:                        const struct flist *, size_t, int);
                    261: void             download_free(struct download *);
1.2       benno     262: struct upload   *upload_alloc(struct sess *, int, int, size_t,
1.1       benno     263:                        const struct flist *, size_t, mode_t);
                    264: void             upload_free(struct upload *);
                    265:
                    266: struct blkset   *blk_recv(struct sess *, int, const char *);
                    267: int              blk_recv_ack(struct sess *,
                    268:                        int, const struct blkset *, int32_t);
                    269: int              blk_match(struct sess *, int,
                    270:                        const struct blkset *, const char *);
                    271: int              blk_send(struct sess *, int, size_t,
                    272:                        const struct blkset *, const char *);
                    273: int              blk_send_ack(struct sess *, int, struct blkset *);
                    274: int              blk_merge(struct sess *, int, int,
                    275:                        const struct blkset *, int, const char *,
                    276:                        const void *, size_t, float *);
                    277: void             blkset_free(struct blkset *);
                    278:
                    279: uint32_t         hash_fast(const void *, size_t);
                    280: void             hash_slow(const void *, size_t,
                    281:                        unsigned char *, const struct sess *);
                    282: void             hash_file(const void *, size_t,
                    283:                        unsigned char *, const struct sess *);
                    284:
                    285: int              mkpath(struct sess *, char *);
                    286:
                    287: char            *symlink_read(struct sess *, const char *);
                    288: char            *symlinkat_read(struct sess *, int, const char *);
                    289:
                    290: int              sess_stats_send(struct sess *, int);
                    291: int              sess_stats_recv(struct sess *, int);
                    292:
                    293: __END_DECLS
                    294:
                    295: #endif /*!EXTERN_H*/