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

1.36    ! job         1: /*     $Id: extern.h,v 1.35 2021/03/22 11:14:42 claudio 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: /*
1.34      claudio    45:  * Use this for --timeout.
1.14      florian    46:  * All poll events will use it and catch time-outs.
                     47:  */
1.34      claudio    48: extern int poll_timeout;
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              dry_run;               /* -n */
                    110:        int              preserve_times;        /* -t */
                    111:        int              preserve_perms;        /* -p */
                    112:        int              preserve_links;        /* -l */
1.5       benno     113:        int              preserve_gids;         /* -g */
1.9       florian   114:        int              preserve_uids;         /* -u */
1.3       deraadt   115:        int              del;                   /* --delete */
1.12      florian   116:        int              devices;               /* --devices */
                    117:        int              specials;              /* --specials */
1.36    ! job       118:        int              no_motd;               /* --no-motd */
1.22      benno     119:        int              numeric_ids;           /* --numeric-ids */
1.28      bket      120:        int              one_file_system;       /* -x */
1.3       deraadt   121:        char            *rsync_path;            /* --rsync-path */
1.4       deraadt   122:        char            *ssh_prog;              /* --rsh or -e */
1.18      deraadt   123:        char            *port;                  /* --port */
1.32      claudio   124:        char            *address;               /* --address */
1.1       benno     125: };
                    126:
                    127: /*
                    128:  * An individual block description for a file.
                    129:  * See struct blkset.
                    130:  */
                    131: struct blk {
                    132:        off_t            offs; /* offset in file */
                    133:        size_t           idx; /* block index */
                    134:        size_t           len; /* bytes in block */
                    135:        uint32_t         chksum_short; /* fast checksum */
                    136:        unsigned char    chksum_long[CSUM_LENGTH_PHASE2]; /* slow checksum */
                    137: };
                    138:
1.14      florian   139: enum   blkstatst {
                    140:        BLKSTAT_NONE = 0,
1.21      benno     141:        BLKSTAT_NEXT,
1.14      florian   142:        BLKSTAT_DATA,
                    143:        BLKSTAT_TOK,
                    144:        BLKSTAT_HASH,
1.21      benno     145:        BLKSTAT_DONE,
                    146:        BLKSTAT_PHASE,
1.14      florian   147: };
                    148:
1.1       benno     149: /*
1.13      florian   150:  * Information for the sender updating receiver blocks reentrantly.
                    151:  */
                    152: struct blkstat {
1.14      florian   153:        off_t            offs; /* position in sender file */
                    154:        off_t            total; /* total amount processed */
                    155:        off_t            dirty; /* total amount sent */
                    156:        size_t           hint; /* optimisation: next probable match */
                    157:        void            *map; /* mapped file or MAP_FAILED otherwise */
                    158:        size_t           mapsz; /* size of file or zero */
                    159:        int              fd; /* descriptor girding the map */
                    160:        enum blkstatst   curst; /* FSM for sending file blocks */
                    161:        off_t            curpos; /* sending: position in file to send */
                    162:        off_t            curlen; /* sending: length of send */
                    163:        int32_t          curtok; /* sending: next matching token or zero */
1.31      florian   164:        struct blktab   *blktab; /* hashtable of blocks */
                    165:        uint32_t         s1; /* partial sum for computing fast hash */
                    166:        uint32_t         s2; /* partial sum for computing fast hash */
1.13      florian   167: };
                    168:
                    169: /*
1.1       benno     170:  * When transferring file contents, we break the file down into blocks
                    171:  * and work with those.
                    172:  */
                    173: struct blkset {
                    174:        off_t            size; /* file size */
                    175:        size_t           rem; /* terminal block length if non-zero */
                    176:        size_t           len; /* block length */
                    177:        size_t           csum; /* checksum length */
                    178:        struct blk      *blks; /* all blocks */
                    179:        size_t           blksz; /* number of blks */
                    180: };
                    181:
                    182: /*
                    183:  * Values required during a communication session.
                    184:  */
                    185: struct sess {
                    186:        const struct opts *opts; /* system options */
                    187:        int32_t            seed; /* checksum seed */
                    188:        int32_t            lver; /* local version */
                    189:        int32_t            rver; /* remote version */
                    190:        uint64_t           total_read; /* non-logging wire/reads */
                    191:        uint64_t           total_size; /* total file size */
                    192:        uint64_t           total_write; /* non-logging wire/writes */
                    193:        int                mplex_reads; /* multiplexing reads? */
                    194:        size_t             mplex_read_remain; /* remaining bytes */
                    195:        int                mplex_writes; /* multiplexing writes? */
                    196: };
                    197:
1.6       benno     198: /*
                    199:  * Combination of name and numeric id for groups and users.
                    200:  */
                    201: struct ident {
                    202:        int32_t  id; /* the gid_t or uid_t */
                    203:        int32_t  mapped; /* if receiving, the mapped gid */
                    204:        char    *name; /* resolved name */
                    205: };
1.27      deraadt   206:
                    207: typedef struct arglist arglist;
                    208: struct arglist {
                    209:        char    **list;
                    210:        u_int   num;
                    211:        u_int   nalloc;
                    212: };
1.35      claudio   213: void   addargs(arglist *, const char *, ...)
1.27      deraadt   214:            __attribute__((format(printf, 2, 3)));
                    215: void   freeargs(arglist *);
1.6       benno     216:
1.1       benno     217: struct download;
                    218: struct upload;
                    219:
1.29      benno     220: extern int verbose;
                    221:
1.17      deraadt   222: #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
1.14      florian   223:
1.29      benno     224: #define LOG0(_fmt, ...) \
1.33      deraadt   225:        rsync_log( -1, (_fmt), ##__VA_ARGS__)
1.29      benno     226: #define LOG1(_fmt, ...) \
1.33      deraadt   227:        rsync_log( 0, (_fmt), ##__VA_ARGS__)
1.29      benno     228: #define LOG2(_fmt, ...) \
1.33      deraadt   229:        rsync_log( 1, (_fmt), ##__VA_ARGS__)
1.29      benno     230: #define LOG3(_fmt, ...) \
1.33      deraadt   231:        rsync_log( 2, (_fmt), ##__VA_ARGS__)
1.29      benno     232: #define LOG4(_fmt, ...) \
1.33      deraadt   233:        rsync_log( 3, (_fmt), ##__VA_ARGS__)
1.29      benno     234: #define ERRX1(_fmt, ...) \
1.33      deraadt   235:        rsync_errx1( (_fmt), ##__VA_ARGS__)
1.29      benno     236: #define WARNX(_fmt, ...) \
1.33      deraadt   237:        rsync_warnx( (_fmt), ##__VA_ARGS__)
1.29      benno     238: #define WARN(_fmt, ...) \
1.33      deraadt   239:        rsync_warn(0,  (_fmt), ##__VA_ARGS__)
1.29      benno     240: #define WARN1(_fmt, ...) \
1.33      deraadt   241:        rsync_warn(1,  (_fmt), ##__VA_ARGS__)
1.29      benno     242: #define WARN2(_fmt, ...) \
1.33      deraadt   243:        rsync_warn(2,  (_fmt), ##__VA_ARGS__)
1.29      benno     244: #define ERR(_fmt, ...) \
1.33      deraadt   245:        rsync_err( (_fmt), ##__VA_ARGS__)
1.29      benno     246: #define ERRX(_fmt, ...) \
1.33      deraadt   247:        rsync_errx( (_fmt), ##__VA_ARGS__)
1.29      benno     248:
1.33      deraadt   249: void             rsync_log(int, const char *, ...)
                    250:                        __attribute__((format(printf, 2, 3)));
                    251: void             rsync_warnx1(const char *, ...)
                    252:                        __attribute__((format(printf, 1, 2)));
                    253: void             rsync_warn(int, const char *, ...)
                    254:                        __attribute__((format(printf, 2, 3)));
                    255: void             rsync_warnx(const char *, ...)
                    256:                        __attribute__((format(printf, 1, 2)));
                    257: void             rsync_err(const char *, ...)
                    258:                        __attribute__((format(printf, 1, 2)));
                    259: void             rsync_errx(const char *, ...)
                    260:                        __attribute__((format(printf, 1, 2)));
                    261: void             rsync_errx1(const char *, ...)
                    262:                        __attribute__((format(printf, 1, 2)));
1.1       benno     263:
1.2       benno     264: int              flist_del(struct sess *, int,
1.1       benno     265:                        const struct flist *, size_t);
                    266: int              flist_gen(struct sess *, size_t, char **,
                    267:                        struct flist **, size_t *);
                    268: int              flist_gen_local(struct sess *, const char *,
                    269:                        struct flist **, size_t *);
                    270: void             flist_free(struct flist *, size_t);
                    271: int              flist_recv(struct sess *, int,
                    272:                        struct flist **, size_t *);
                    273: int              flist_send(struct sess *, int, int,
                    274:                        const struct flist *, size_t);
1.2       benno     275: int              flist_gen_dels(struct sess *, const char *,
1.1       benno     276:                        struct flist **, size_t *,
                    277:                        const struct flist *, size_t);
                    278:
1.25      naddy     279: char           **fargs_cmdline(struct sess *, const struct fargs *, size_t *);
1.1       benno     280:
                    281: int              io_read_buf(struct sess *, int, void *, size_t);
                    282: int              io_read_byte(struct sess *, int, uint8_t *);
1.30      benno     283: int              io_read_check(int);
1.1       benno     284: int              io_read_flush(struct sess *, int);
                    285: int              io_read_int(struct sess *, int, int32_t *);
1.26      deraadt   286: int              io_read_uint(struct sess *, int, uint32_t *);
1.1       benno     287: int              io_read_long(struct sess *, int, int64_t *);
                    288: int              io_read_size(struct sess *, int, size_t *);
                    289: int              io_read_ulong(struct sess *, int, uint64_t *);
                    290: int              io_write_buf(struct sess *, int, const void *, size_t);
                    291: int              io_write_byte(struct sess *, int, uint8_t);
                    292: int              io_write_int(struct sess *, int, int32_t);
1.26      deraadt   293: int              io_write_uint(struct sess *, int, uint32_t);
1.1       benno     294: int              io_write_line(struct sess *, int, const char *);
                    295: int              io_write_long(struct sess *, int, int64_t);
1.26      deraadt   296: int              io_write_ulong(struct sess *, int, uint64_t);
1.1       benno     297:
1.14      florian   298: int              io_lowbuffer_alloc(struct sess *, void **,
                    299:                        size_t *, size_t *, size_t);
                    300: void             io_lowbuffer_int(struct sess *, void *,
                    301:                        size_t *, size_t, int32_t);
                    302: void             io_lowbuffer_buf(struct sess *, void *,
                    303:                        size_t *, size_t, const void *, size_t);
                    304:
1.30      benno     305: void             io_buffer_int(void *, size_t *, size_t, int32_t);
                    306: void             io_buffer_buf(void *, size_t *, size_t, const void *, size_t);
1.1       benno     307:
1.30      benno     308: void             io_unbuffer_int(const void *,
1.1       benno     309:                        size_t *, size_t, int32_t *);
1.30      benno     310: int              io_unbuffer_size(const void *, size_t *, size_t, size_t *);
                    311: void             io_unbuffer_buf(const void *, size_t *, size_t, void *, size_t);
1.1       benno     312:
                    313: int              rsync_receiver(struct sess *, int, int, const char *);
                    314: int              rsync_sender(struct sess *, int, int, size_t, char **);
                    315: int              rsync_client(const struct opts *, int, const struct fargs *);
1.25      naddy     316: int              rsync_connect(const struct opts *, int *,
                    317:                        const struct fargs *);
                    318: int              rsync_socket(const struct opts *, int, const struct fargs *);
1.1       benno     319: int              rsync_server(const struct opts *, size_t, char *[]);
                    320: int              rsync_downloader(struct download *, struct sess *, int *);
1.15      florian   321: int              rsync_set_metadata(struct sess *, int, int,
1.10      florian   322:                        const struct flist *, const char *);
1.16      deraadt   323: int              rsync_set_metadata_at(struct sess *, int, int,
1.12      florian   324:                        const struct flist *, const char *);
1.2       benno     325: int              rsync_uploader(struct upload *,
1.1       benno     326:                        int *, struct sess *, int *);
                    327: int              rsync_uploader_tail(struct upload *, struct sess *);
                    328:
                    329: struct download         *download_alloc(struct sess *, int,
                    330:                        const struct flist *, size_t, int);
                    331: void             download_free(struct download *);
1.30      benno     332: struct upload   *upload_alloc(const char *, int, int, size_t,
1.1       benno     333:                        const struct flist *, size_t, mode_t);
                    334: void             upload_free(struct upload *);
1.31      florian   335:
                    336: struct blktab  *blkhash_alloc(void);
                    337: int             blkhash_set(struct blktab *, const struct blkset *);
                    338: void            blkhash_free(struct blktab *);
1.1       benno     339:
                    340: struct blkset   *blk_recv(struct sess *, int, const char *);
1.30      benno     341: void             blk_recv_ack(char [20], const struct blkset *, int32_t);
1.14      florian   342: void             blk_match(struct sess *, const struct blkset *,
1.13      florian   343:                        const char *, struct blkstat *);
1.1       benno     344: int              blk_send(struct sess *, int, size_t,
                    345:                        const struct blkset *, const char *);
                    346: int              blk_send_ack(struct sess *, int, struct blkset *);
                    347:
                    348: uint32_t         hash_fast(const void *, size_t);
                    349: void             hash_slow(const void *, size_t,
                    350:                        unsigned char *, const struct sess *);
                    351: void             hash_file(const void *, size_t,
                    352:                        unsigned char *, const struct sess *);
                    353:
1.30      benno     354: int              mkpath(char *);
1.11      florian   355:
                    356: int              mkstempat(int, char *);
                    357: char            *mkstemplinkat(char*, int, char *);
1.12      florian   358: char            *mkstempfifoat(int, char *);
                    359: char            *mkstempnodat(int, char *, mode_t, dev_t);
                    360: char            *mkstempsock(const char *, char *);
1.30      benno     361: int              mktemplate(char **, const char *, int);
1.1       benno     362:
1.30      benno     363: char            *symlink_read(const char *);
                    364: char            *symlinkat_read(int, const char *);
1.1       benno     365:
                    366: int              sess_stats_send(struct sess *, int);
                    367: int              sess_stats_recv(struct sess *, int);
1.6       benno     368:
1.30      benno     369: int              idents_add(int, struct ident **, size_t *, int32_t);
1.9       florian   370: void             idents_assign_gid(struct sess *,
                    371:                        struct flist *, size_t, const struct ident *, size_t);
                    372: void             idents_assign_uid(struct sess *,
                    373:                        struct flist *, size_t, const struct ident *, size_t);
1.6       benno     374: void             idents_free(struct ident *, size_t);
1.7       benno     375: int              idents_recv(struct sess *, int, struct ident **, size_t *);
1.9       florian   376: void             idents_remap(struct sess *, int, struct ident *, size_t);
1.6       benno     377: int              idents_send(struct sess *, int, const struct ident *, size_t);
1.1       benno     378:
                    379: #endif /*!EXTERN_H*/