[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.17

1.17    ! deraadt     1: /*     $Id: extern.h,v 1.16 2019/02/16 17:59:33 deraadt 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:
1.14      florian    44: /*
                     45:  * Use this for debugging deadlocks.
                     46:  * All poll events will use it and catch time-outs.
                     47:  */
                     48: #define POLL_TIMEOUT   (INFTIM)
1.13      florian    49:
1.1       benno      50: /*
                     51:  * Operating mode for a client or a server.
                     52:  * Sender means we synchronise local files with those from remote.
                     53:  * Receiver is the opposite.
                     54:  * This is relative to which host we're running on.
                     55:  */
                     56: enum   fmode {
                     57:        FARGS_SENDER,
                     58:        FARGS_RECEIVER
                     59: };
                     60:
                     61: /*
                     62:  * File arguments given on the command line.
                     63:  * See struct opts.
                     64:  */
                     65: struct fargs {
                     66:        char      *host; /* hostname or NULL if local */
                     67:        char     **sources; /* transfer source */
                     68:        size_t     sourcesz; /* number of sources */
                     69:        char      *sink; /* transfer endpoint */
                     70:        enum fmode mode; /* mode of operation */
                     71:        int        remote; /* uses rsync:// or :: for remote */
                     72:        char      *module; /* if rsync://, the module */
                     73: };
                     74:
                     75: /*
                     76:  * The subset of stat(2) information that we need.
                     77:  * (There are some parts we don't use yet.)
                     78:  */
                     79: struct flstat {
1.12      florian    80:        mode_t           mode;  /* mode */
                     81:        uid_t            uid;   /* user */
                     82:        gid_t            gid;   /* group */
                     83:        dev_t            rdev;  /* device type */
                     84:        off_t            size;  /* size */
                     85:        time_t           mtime; /* modification */
1.1       benno      86:        unsigned int     flags;
1.12      florian    87: #define        FLSTAT_TOP_DIR   0x01   /* a top-level directory */
1.1       benno      88:
                     89: };
                     90:
                     91: /*
                     92:  * A list of files with their statistics.
                     93:  */
                     94: struct flist {
                     95:        char            *path; /* path relative to root */
                     96:        const char      *wpath; /* "working" path for receiver */
                     97:        struct flstat    st; /* file information */
                     98:        char            *link; /* symlink target or NULL */
                     99: };
                    100:
                    101: /*
                    102:  * Options passed into the command line.
                    103:  * See struct fargs.
                    104:  */
                    105: struct opts {
1.3       deraadt   106:        int              sender;                /* --sender */
                    107:        int              server;                /* --server */
                    108:        int              recursive;             /* -r */
                    109:        int              verbose;               /* -v */
                    110:        int              dry_run;               /* -n */
                    111:        int              preserve_times;        /* -t */
                    112:        int              preserve_perms;        /* -p */
                    113:        int              preserve_links;        /* -l */
1.5       benno     114:        int              preserve_gids;         /* -g */
1.9       florian   115:        int              preserve_uids;         /* -u */
1.3       deraadt   116:        int              del;                   /* --delete */
1.12      florian   117:        int              devices;               /* --devices */
                    118:        int              specials;              /* --specials */
1.3       deraadt   119:        char            *rsync_path;            /* --rsync-path */
1.4       deraadt   120:        char            *ssh_prog;              /* --rsh or -e */
1.1       benno     121: };
                    122:
                    123: /*
                    124:  * An individual block description for a file.
                    125:  * See struct blkset.
                    126:  */
                    127: struct blk {
                    128:        off_t            offs; /* offset in file */
                    129:        size_t           idx; /* block index */
                    130:        size_t           len; /* bytes in block */
                    131:        uint32_t         chksum_short; /* fast checksum */
                    132:        unsigned char    chksum_long[CSUM_LENGTH_PHASE2]; /* slow checksum */
                    133: };
                    134:
1.14      florian   135: enum   blkstatst {
                    136:        BLKSTAT_NONE = 0,
                    137:        BLKSTAT_DATASZ,
                    138:        BLKSTAT_DATA,
                    139:        BLKSTAT_TOK,
                    140:        BLKSTAT_HASH,
                    141:        BLKSTAT_DONE
                    142: };
                    143:
1.1       benno     144: /*
1.13      florian   145:  * Information for the sender updating receiver blocks reentrantly.
                    146:  */
                    147: struct blkstat {
1.14      florian   148:        off_t            offs; /* position in sender file */
                    149:        off_t            total; /* total amount processed */
                    150:        off_t            dirty; /* total amount sent */
                    151:        size_t           hint; /* optimisation: next probable match */
                    152:        void            *map; /* mapped file or MAP_FAILED otherwise */
                    153:        size_t           mapsz; /* size of file or zero */
                    154:        int              fd; /* descriptor girding the map */
                    155:        enum blkstatst   curst; /* FSM for sending file blocks */
                    156:        off_t            curpos; /* sending: position in file to send */
                    157:        off_t            curlen; /* sending: length of send */
                    158:        int32_t          curtok; /* sending: next matching token or zero */
1.13      florian   159: };
                    160:
                    161: /*
1.1       benno     162:  * When transferring file contents, we break the file down into blocks
                    163:  * and work with those.
                    164:  */
                    165: struct blkset {
                    166:        off_t            size; /* file size */
                    167:        size_t           rem; /* terminal block length if non-zero */
                    168:        size_t           len; /* block length */
                    169:        size_t           csum; /* checksum length */
                    170:        struct blk      *blks; /* all blocks */
                    171:        size_t           blksz; /* number of blks */
                    172: };
                    173:
                    174: /*
                    175:  * Values required during a communication session.
                    176:  */
                    177: struct sess {
                    178:        const struct opts *opts; /* system options */
                    179:        int32_t            seed; /* checksum seed */
                    180:        int32_t            lver; /* local version */
                    181:        int32_t            rver; /* remote version */
                    182:        uint64_t           total_read; /* non-logging wire/reads */
                    183:        uint64_t           total_size; /* total file size */
                    184:        uint64_t           total_write; /* non-logging wire/writes */
                    185:        int                mplex_reads; /* multiplexing reads? */
                    186:        size_t             mplex_read_remain; /* remaining bytes */
                    187:        int                mplex_writes; /* multiplexing writes? */
                    188: };
                    189:
1.6       benno     190: /*
                    191:  * Combination of name and numeric id for groups and users.
                    192:  */
                    193: struct ident {
                    194:        int32_t  id; /* the gid_t or uid_t */
                    195:        int32_t  mapped; /* if receiving, the mapped gid */
                    196:        char    *name; /* resolved name */
                    197: };
                    198:
1.1       benno     199: struct download;
                    200: struct upload;
                    201:
1.17    ! deraadt   202: #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
1.14      florian   203:
1.1       benno     204: #define LOG0(_sess, _fmt, ...) \
                    205:        rsync_log((_sess), __FILE__, __LINE__, -1, (_fmt), ##__VA_ARGS__)
                    206: #define LOG1(_sess, _fmt, ...) \
                    207:        rsync_log((_sess), __FILE__, __LINE__, 0, (_fmt), ##__VA_ARGS__)
                    208: #define LOG2(_sess, _fmt, ...) \
                    209:        rsync_log((_sess), __FILE__, __LINE__, 1, (_fmt), ##__VA_ARGS__)
                    210: #define LOG3(_sess, _fmt, ...) \
                    211:        rsync_log((_sess), __FILE__, __LINE__, 2, (_fmt), ##__VA_ARGS__)
                    212: #define LOG4(_sess, _fmt, ...) \
                    213:        rsync_log((_sess), __FILE__, __LINE__, 3, (_fmt), ##__VA_ARGS__)
                    214: #define ERRX1(_sess, _fmt, ...) \
                    215:        rsync_errx1((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    216: #define WARNX(_sess, _fmt, ...) \
                    217:        rsync_warnx((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    218: #define WARN(_sess, _fmt, ...) \
                    219:        rsync_warn((_sess), 0, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    220: #define WARN1(_sess, _fmt, ...) \
                    221:        rsync_warn((_sess), 1, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    222: #define WARN2(_sess, _fmt, ...) \
                    223:        rsync_warn((_sess), 2, __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    224: #define ERR(_sess, _fmt, ...) \
                    225:        rsync_err((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    226: #define ERRX(_sess, _fmt, ...) \
                    227:        rsync_errx((_sess), __FILE__, __LINE__, (_fmt), ##__VA_ARGS__)
                    228:
                    229: __BEGIN_DECLS
                    230:
                    231: void             rsync_log(struct sess *,
                    232:                        const char *, size_t, int, const char *, ...)
                    233:                        __attribute__((format(printf, 5, 6)));
                    234: void             rsync_warnx1(struct sess *,
                    235:                        const char *, size_t, const char *, ...)
                    236:                        __attribute__((format(printf, 4, 5)));
                    237: void             rsync_warn(struct sess *, int,
                    238:                        const char *, size_t, const char *, ...)
                    239:                        __attribute__((format(printf, 5, 6)));
                    240: void             rsync_warnx(struct sess *, const char *,
                    241:                        size_t, const char *, ...)
                    242:                        __attribute__((format(printf, 4, 5)));
                    243: void             rsync_err(struct sess *, const char *,
                    244:                        size_t, const char *, ...)
                    245:                        __attribute__((format(printf, 4, 5)));
                    246: void             rsync_errx(struct sess *, const char *,
                    247:                        size_t, const char *, ...)
                    248:                        __attribute__((format(printf, 4, 5)));
                    249: void             rsync_errx1(struct sess *, const char *,
                    250:                        size_t, const char *, ...)
                    251:                        __attribute__((format(printf, 4, 5)));
                    252:
1.2       benno     253: int              flist_del(struct sess *, int,
1.1       benno     254:                        const struct flist *, size_t);
                    255: int              flist_gen(struct sess *, size_t, char **,
                    256:                        struct flist **, size_t *);
                    257: int              flist_gen_local(struct sess *, const char *,
                    258:                        struct flist **, size_t *);
                    259: void             flist_free(struct flist *, size_t);
                    260: int              flist_recv(struct sess *, int,
                    261:                        struct flist **, size_t *);
                    262: int              flist_send(struct sess *, int, int,
                    263:                        const struct flist *, size_t);
1.2       benno     264: int              flist_gen_dels(struct sess *, const char *,
1.1       benno     265:                        struct flist **, size_t *,
                    266:                        const struct flist *, size_t);
                    267:
                    268: char           **fargs_cmdline(struct sess *, const struct fargs *);
                    269:
                    270: int              io_read_buf(struct sess *, int, void *, size_t);
                    271: int              io_read_byte(struct sess *, int, uint8_t *);
                    272: int              io_read_check(struct sess *, int);
                    273: int              io_read_flush(struct sess *, int);
                    274: int              io_read_int(struct sess *, int, int32_t *);
                    275: int              io_read_long(struct sess *, int, int64_t *);
                    276: int              io_read_size(struct sess *, int, size_t *);
                    277: int              io_read_ulong(struct sess *, int, uint64_t *);
                    278: int              io_write_buf(struct sess *, int, const void *, size_t);
                    279: int              io_write_byte(struct sess *, int, uint8_t);
                    280: int              io_write_int(struct sess *, int, int32_t);
                    281: int              io_write_line(struct sess *, int, const char *);
                    282: int              io_write_long(struct sess *, int, int64_t);
                    283:
1.14      florian   284: int              io_lowbuffer_alloc(struct sess *, void **,
                    285:                        size_t *, size_t *, size_t);
                    286: void             io_lowbuffer_int(struct sess *, void *,
                    287:                        size_t *, size_t, int32_t);
                    288: void             io_lowbuffer_buf(struct sess *, void *,
                    289:                        size_t *, size_t, const void *, size_t);
                    290:
1.2       benno     291: void             io_buffer_int(struct sess *, void *,
1.1       benno     292:                        size_t *, size_t, int32_t);
1.2       benno     293: void             io_buffer_buf(struct sess *, void *,
1.1       benno     294:                        size_t *, size_t, const void *, size_t);
                    295:
1.2       benno     296: void             io_unbuffer_int(struct sess *, const void *,
1.1       benno     297:                        size_t *, size_t, int32_t *);
1.2       benno     298: int              io_unbuffer_size(struct sess *, const void *,
1.1       benno     299:                        size_t *, size_t, size_t *);
1.2       benno     300: void             io_unbuffer_buf(struct sess *, const void *,
1.1       benno     301:                        size_t *, size_t, void *, size_t);
                    302:
                    303: void             rsync_child(const struct opts *, int, const struct fargs *)
                    304:                        __attribute__((noreturn));
                    305: int              rsync_receiver(struct sess *, int, int, const char *);
                    306: int              rsync_sender(struct sess *, int, int, size_t, char **);
                    307: int              rsync_client(const struct opts *, int, const struct fargs *);
                    308: int              rsync_socket(const struct opts *, const struct fargs *);
                    309: int              rsync_server(const struct opts *, size_t, char *[]);
                    310: int              rsync_downloader(struct download *, struct sess *, int *);
1.15      florian   311: int              rsync_set_metadata(struct sess *, int, int,
1.10      florian   312:                        const struct flist *, const char *);
1.16      deraadt   313: int              rsync_set_metadata_at(struct sess *, int, int,
1.12      florian   314:                        const struct flist *, const char *);
1.2       benno     315: int              rsync_uploader(struct upload *,
1.1       benno     316:                        int *, struct sess *, int *);
                    317: int              rsync_uploader_tail(struct upload *, struct sess *);
                    318:
                    319: struct download         *download_alloc(struct sess *, int,
                    320:                        const struct flist *, size_t, int);
                    321: void             download_free(struct download *);
1.12      florian   322: struct upload   *upload_alloc(struct sess *, const char *, int, int, size_t,
1.1       benno     323:                        const struct flist *, size_t, mode_t);
                    324: void             upload_free(struct upload *);
                    325:
                    326: struct blkset   *blk_recv(struct sess *, int, const char *);
                    327: int              blk_recv_ack(struct sess *,
                    328:                        int, const struct blkset *, int32_t);
1.14      florian   329: void             blk_match(struct sess *, const struct blkset *,
1.13      florian   330:                        const char *, struct blkstat *);
1.1       benno     331: int              blk_send(struct sess *, int, size_t,
                    332:                        const struct blkset *, const char *);
                    333: int              blk_send_ack(struct sess *, int, struct blkset *);
                    334:
                    335: uint32_t         hash_fast(const void *, size_t);
                    336: void             hash_slow(const void *, size_t,
                    337:                        unsigned char *, const struct sess *);
                    338: void             hash_file(const void *, size_t,
                    339:                        unsigned char *, const struct sess *);
                    340:
                    341: int              mkpath(struct sess *, char *);
1.11      florian   342:
                    343: int              mkstempat(int, char *);
                    344: char            *mkstemplinkat(char*, int, char *);
1.12      florian   345: char            *mkstempfifoat(int, char *);
                    346: char            *mkstempnodat(int, char *, mode_t, dev_t);
                    347: char            *mkstempsock(const char *, char *);
1.11      florian   348: int              mktemplate(char **, const char *, int);
1.1       benno     349:
                    350: char            *symlink_read(struct sess *, const char *);
                    351: char            *symlinkat_read(struct sess *, int, const char *);
                    352:
                    353: int              sess_stats_send(struct sess *, int);
                    354: int              sess_stats_recv(struct sess *, int);
1.6       benno     355:
1.9       florian   356: int              idents_add(struct sess *, int, struct ident **, size_t *,
                    357:                        int32_t);
                    358: void             idents_assign_gid(struct sess *,
                    359:                        struct flist *, size_t, const struct ident *, size_t);
                    360: void             idents_assign_uid(struct sess *,
                    361:                        struct flist *, size_t, const struct ident *, size_t);
1.6       benno     362: void             idents_free(struct ident *, size_t);
1.7       benno     363: int              idents_recv(struct sess *, int, struct ident **, size_t *);
1.9       florian   364: void             idents_remap(struct sess *, int, struct ident *, size_t);
1.6       benno     365: int              idents_send(struct sess *, int, const struct ident *, size_t);
1.1       benno     366:
                    367: __END_DECLS
                    368:
                    369: #endif /*!EXTERN_H*/