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

1.42    ! claudio     1: /*     $OpenBSD: extern.h,v 1.41 2021/09/01 09:48:08 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: /*
1.42    ! claudio    37:  * Maximum number of base directories that can be used.
        !            38:  */
        !            39: #define MAX_BASEDIR    20
        !            40:
        !            41: #define BASE_MODE_COMPARE      1
        !            42: #define BASE_MODE_COPY         2
        !            43: #define BASE_MODE_LINK         3
        !            44:
        !            45: /*
1.1       benno      46:  * The sender and receiver use a two-phase synchronisation process.
                     47:  * The first uses two-byte hashes; the second, 16-byte.
                     48:  * (The second must hold a full MD4 digest.)
                     49:  */
                     50: #define        CSUM_LENGTH_PHASE1 (2)
                     51: #define        CSUM_LENGTH_PHASE2 (16)
1.37      claudio    52:
                     53: /*
                     54:  * Rsync error codes.
                     55:  */
                     56: #define ERR_SYNTAX     1
                     57: #define ERR_PROTOCOL   2
                     58: #define ERR_SOCK_IO    10
                     59: #define ERR_FILE_IO    11
                     60: #define ERR_WIREPROTO  12
                     61: #define ERR_IPC                14      /* catchall for any kind of syscall error */
                     62: #define ERR_TERMIMATED 16
                     63: #define ERR_WAITPID    21
                     64: #define ERR_NOMEM      22
1.1       benno      65:
1.14      florian    66: /*
1.34      claudio    67:  * Use this for --timeout.
1.14      florian    68:  * All poll events will use it and catch time-outs.
                     69:  */
1.34      claudio    70: extern int poll_timeout;
1.13      florian    71:
1.1       benno      72: /*
                     73:  * Operating mode for a client or a server.
                     74:  * Sender means we synchronise local files with those from remote.
                     75:  * Receiver is the opposite.
                     76:  * This is relative to which host we're running on.
                     77:  */
                     78: enum   fmode {
                     79:        FARGS_SENDER,
                     80:        FARGS_RECEIVER
                     81: };
                     82:
                     83: /*
                     84:  * File arguments given on the command line.
                     85:  * See struct opts.
                     86:  */
                     87: struct fargs {
                     88:        char      *host; /* hostname or NULL if local */
                     89:        char     **sources; /* transfer source */
                     90:        size_t     sourcesz; /* number of sources */
                     91:        char      *sink; /* transfer endpoint */
                     92:        enum fmode mode; /* mode of operation */
                     93:        int        remote; /* uses rsync:// or :: for remote */
                     94:        char      *module; /* if rsync://, the module */
                     95: };
                     96:
                     97: /*
                     98:  * The subset of stat(2) information that we need.
                     99:  * (There are some parts we don't use yet.)
                    100:  */
                    101: struct flstat {
1.12      florian   102:        mode_t           mode;  /* mode */
                    103:        uid_t            uid;   /* user */
                    104:        gid_t            gid;   /* group */
                    105:        dev_t            rdev;  /* device type */
                    106:        off_t            size;  /* size */
                    107:        time_t           mtime; /* modification */
1.1       benno     108:        unsigned int     flags;
1.12      florian   109: #define        FLSTAT_TOP_DIR   0x01   /* a top-level directory */
1.1       benno     110:
                    111: };
                    112:
                    113: /*
                    114:  * A list of files with their statistics.
                    115:  */
                    116: struct flist {
                    117:        char            *path; /* path relative to root */
                    118:        const char      *wpath; /* "working" path for receiver */
                    119:        struct flstat    st; /* file information */
                    120:        char            *link; /* symlink target or NULL */
                    121: };
                    122:
                    123: /*
                    124:  * Options passed into the command line.
                    125:  * See struct fargs.
                    126:  */
                    127: struct opts {
1.3       deraadt   128:        int              sender;                /* --sender */
                    129:        int              server;                /* --server */
                    130:        int              recursive;             /* -r */
                    131:        int              dry_run;               /* -n */
                    132:        int              preserve_times;        /* -t */
                    133:        int              preserve_perms;        /* -p */
                    134:        int              preserve_links;        /* -l */
1.5       benno     135:        int              preserve_gids;         /* -g */
1.9       florian   136:        int              preserve_uids;         /* -u */
1.3       deraadt   137:        int              del;                   /* --delete */
1.12      florian   138:        int              devices;               /* --devices */
                    139:        int              specials;              /* --specials */
1.36      job       140:        int              no_motd;               /* --no-motd */
1.22      benno     141:        int              numeric_ids;           /* --numeric-ids */
1.28      bket      142:        int              one_file_system;       /* -x */
1.42    ! claudio   143:        int              alt_base_mode;
1.3       deraadt   144:        char            *rsync_path;            /* --rsync-path */
1.4       deraadt   145:        char            *ssh_prog;              /* --rsh or -e */
1.18      deraadt   146:        char            *port;                  /* --port */
1.32      claudio   147:        char            *address;               /* --address */
1.42    ! claudio   148:        char            *basedir[MAX_BASEDIR];
1.1       benno     149: };
                    150:
1.40      claudio   151: enum rule_type {
                    152:        RULE_NONE,
                    153:        RULE_EXCLUDE,
                    154:        RULE_INCLUDE,
                    155:        RULE_CLEAR,
                    156: #ifdef NOTYET
                    157:        RULE_MERGE,
                    158:        RULE_DIR_MERGE,
                    159:        RULE_SHOW,
                    160:        RULE_HIDE,
                    161:        RULE_PROTECT,
                    162:        RULE_RISK,
                    163: #endif
                    164: };
                    165:
1.1       benno     166: /*
                    167:  * An individual block description for a file.
                    168:  * See struct blkset.
                    169:  */
                    170: struct blk {
                    171:        off_t            offs; /* offset in file */
                    172:        size_t           idx; /* block index */
                    173:        size_t           len; /* bytes in block */
                    174:        uint32_t         chksum_short; /* fast checksum */
                    175:        unsigned char    chksum_long[CSUM_LENGTH_PHASE2]; /* slow checksum */
                    176: };
                    177:
1.14      florian   178: enum   blkstatst {
                    179:        BLKSTAT_NONE = 0,
1.21      benno     180:        BLKSTAT_NEXT,
1.14      florian   181:        BLKSTAT_DATA,
                    182:        BLKSTAT_TOK,
                    183:        BLKSTAT_HASH,
1.21      benno     184:        BLKSTAT_DONE,
                    185:        BLKSTAT_PHASE,
1.14      florian   186: };
                    187:
1.1       benno     188: /*
1.13      florian   189:  * Information for the sender updating receiver blocks reentrantly.
                    190:  */
                    191: struct blkstat {
1.14      florian   192:        off_t            offs; /* position in sender file */
                    193:        off_t            total; /* total amount processed */
                    194:        off_t            dirty; /* total amount sent */
                    195:        size_t           hint; /* optimisation: next probable match */
                    196:        void            *map; /* mapped file or MAP_FAILED otherwise */
                    197:        size_t           mapsz; /* size of file or zero */
                    198:        int              fd; /* descriptor girding the map */
                    199:        enum blkstatst   curst; /* FSM for sending file blocks */
                    200:        off_t            curpos; /* sending: position in file to send */
                    201:        off_t            curlen; /* sending: length of send */
                    202:        int32_t          curtok; /* sending: next matching token or zero */
1.31      florian   203:        struct blktab   *blktab; /* hashtable of blocks */
                    204:        uint32_t         s1; /* partial sum for computing fast hash */
                    205:        uint32_t         s2; /* partial sum for computing fast hash */
1.13      florian   206: };
                    207:
                    208: /*
1.1       benno     209:  * When transferring file contents, we break the file down into blocks
                    210:  * and work with those.
                    211:  */
                    212: struct blkset {
                    213:        off_t            size; /* file size */
                    214:        size_t           rem; /* terminal block length if non-zero */
                    215:        size_t           len; /* block length */
                    216:        size_t           csum; /* checksum length */
                    217:        struct blk      *blks; /* all blocks */
                    218:        size_t           blksz; /* number of blks */
                    219: };
                    220:
                    221: /*
                    222:  * Values required during a communication session.
                    223:  */
                    224: struct sess {
                    225:        const struct opts *opts; /* system options */
                    226:        int32_t            seed; /* checksum seed */
                    227:        int32_t            lver; /* local version */
                    228:        int32_t            rver; /* remote version */
                    229:        uint64_t           total_read; /* non-logging wire/reads */
                    230:        uint64_t           total_size; /* total file size */
                    231:        uint64_t           total_write; /* non-logging wire/writes */
                    232:        int                mplex_reads; /* multiplexing reads? */
                    233:        size_t             mplex_read_remain; /* remaining bytes */
                    234:        int                mplex_writes; /* multiplexing writes? */
                    235: };
                    236:
1.6       benno     237: /*
                    238:  * Combination of name and numeric id for groups and users.
                    239:  */
                    240: struct ident {
                    241:        int32_t  id; /* the gid_t or uid_t */
                    242:        int32_t  mapped; /* if receiving, the mapped gid */
                    243:        char    *name; /* resolved name */
                    244: };
1.27      deraadt   245:
                    246: typedef struct arglist arglist;
                    247: struct arglist {
                    248:        char    **list;
                    249:        u_int   num;
                    250:        u_int   nalloc;
                    251: };
1.35      claudio   252: void   addargs(arglist *, const char *, ...)
1.27      deraadt   253:            __attribute__((format(printf, 2, 3)));
                    254: void   freeargs(arglist *);
1.6       benno     255:
1.1       benno     256: struct download;
                    257: struct upload;
                    258:
1.29      benno     259: extern int verbose;
                    260:
1.17      deraadt   261: #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
1.14      florian   262:
1.29      benno     263: #define LOG0(_fmt, ...) \
1.33      deraadt   264:        rsync_log( -1, (_fmt), ##__VA_ARGS__)
1.29      benno     265: #define LOG1(_fmt, ...) \
1.33      deraadt   266:        rsync_log( 0, (_fmt), ##__VA_ARGS__)
1.29      benno     267: #define LOG2(_fmt, ...) \
1.33      deraadt   268:        rsync_log( 1, (_fmt), ##__VA_ARGS__)
1.29      benno     269: #define LOG3(_fmt, ...) \
1.33      deraadt   270:        rsync_log( 2, (_fmt), ##__VA_ARGS__)
1.29      benno     271: #define LOG4(_fmt, ...) \
1.33      deraadt   272:        rsync_log( 3, (_fmt), ##__VA_ARGS__)
1.29      benno     273: #define ERRX1(_fmt, ...) \
1.33      deraadt   274:        rsync_errx1( (_fmt), ##__VA_ARGS__)
1.29      benno     275: #define WARNX(_fmt, ...) \
1.33      deraadt   276:        rsync_warnx( (_fmt), ##__VA_ARGS__)
1.29      benno     277: #define WARN(_fmt, ...) \
1.33      deraadt   278:        rsync_warn(0,  (_fmt), ##__VA_ARGS__)
1.29      benno     279: #define WARN1(_fmt, ...) \
1.33      deraadt   280:        rsync_warn(1,  (_fmt), ##__VA_ARGS__)
1.29      benno     281: #define WARN2(_fmt, ...) \
1.33      deraadt   282:        rsync_warn(2,  (_fmt), ##__VA_ARGS__)
1.29      benno     283: #define ERR(_fmt, ...) \
1.33      deraadt   284:        rsync_err( (_fmt), ##__VA_ARGS__)
1.29      benno     285: #define ERRX(_fmt, ...) \
1.33      deraadt   286:        rsync_errx( (_fmt), ##__VA_ARGS__)
1.29      benno     287:
1.39      claudio   288: void   rsync_log(int, const char *, ...)
1.33      deraadt   289:                        __attribute__((format(printf, 2, 3)));
1.39      claudio   290: void   rsync_warnx1(const char *, ...)
1.33      deraadt   291:                        __attribute__((format(printf, 1, 2)));
1.39      claudio   292: void   rsync_warn(int, const char *, ...)
1.33      deraadt   293:                        __attribute__((format(printf, 2, 3)));
1.39      claudio   294: void   rsync_warnx(const char *, ...)
1.33      deraadt   295:                        __attribute__((format(printf, 1, 2)));
1.39      claudio   296: void   rsync_err(const char *, ...)
1.33      deraadt   297:                        __attribute__((format(printf, 1, 2)));
1.39      claudio   298: void   rsync_errx(const char *, ...)
1.33      deraadt   299:                        __attribute__((format(printf, 1, 2)));
1.39      claudio   300: void   rsync_errx1(const char *, ...)
1.33      deraadt   301:                        __attribute__((format(printf, 1, 2)));
1.1       benno     302:
1.39      claudio   303: int    flist_del(struct sess *, int, const struct flist *, size_t);
                    304: int    flist_gen(struct sess *, size_t, char **, struct flist **, size_t *);
                    305: int    flist_gen_local(struct sess *, const char *, struct flist **, size_t *);
                    306: void   flist_free(struct flist *, size_t);
                    307: int    flist_recv(struct sess *, int, struct flist **, size_t *);
                    308: int    flist_send(struct sess *, int, int, const struct flist *, size_t);
                    309: int    flist_gen_dels(struct sess *, const char *, struct flist **, size_t *,
                    310:            const struct flist *, size_t);
                    311:
1.42    ! claudio   312: const char      *alt_base_mode(int);
        !           313: char           **fargs_cmdline(struct sess *, const struct fargs *, size_t *);
1.39      claudio   314:
                    315: int    io_read_buf(struct sess *, int, void *, size_t);
                    316: int    io_read_byte(struct sess *, int, uint8_t *);
                    317: int    io_read_check(int);
                    318: int    io_read_flush(struct sess *, int);
                    319: int    io_read_int(struct sess *, int, int32_t *);
                    320: int    io_read_uint(struct sess *, int, uint32_t *);
                    321: int    io_read_long(struct sess *, int, int64_t *);
                    322: int    io_read_size(struct sess *, int, size_t *);
                    323: int    io_read_ulong(struct sess *, int, uint64_t *);
                    324: int    io_write_buf(struct sess *, int, const void *, size_t);
                    325: int    io_write_byte(struct sess *, int, uint8_t);
                    326: int    io_write_int(struct sess *, int, int32_t);
                    327: int    io_write_uint(struct sess *, int, uint32_t);
                    328: int    io_write_line(struct sess *, int, const char *);
                    329: int    io_write_long(struct sess *, int, int64_t);
                    330: int    io_write_ulong(struct sess *, int, uint64_t);
                    331:
                    332: int    io_lowbuffer_alloc(struct sess *, void **, size_t *, size_t *, size_t);
                    333: void   io_lowbuffer_int(struct sess *, void *, size_t *, size_t, int32_t);
                    334: void   io_lowbuffer_buf(struct sess *, void *, size_t *, size_t, const void *,
                    335:            size_t);
                    336:
                    337: void   io_buffer_int(void *, size_t *, size_t, int32_t);
                    338: void   io_buffer_buf(void *, size_t *, size_t, const void *, size_t);
                    339:
                    340: void   io_unbuffer_int(const void *, size_t *, size_t, int32_t *);
                    341: int    io_unbuffer_size(const void *, size_t *, size_t, size_t *);
                    342: void   io_unbuffer_buf(const void *, size_t *, size_t, void *, size_t);
                    343:
                    344: int    rsync_receiver(struct sess *, int, int, const char *);
                    345: int    rsync_sender(struct sess *, int, int, size_t, char **);
                    346: int    rsync_client(const struct opts *, int, const struct fargs *);
                    347: int    rsync_connect(const struct opts *, int *, const struct fargs *);
                    348: int    rsync_socket(const struct opts *, int, const struct fargs *);
                    349: int    rsync_server(const struct opts *, size_t, char *[]);
                    350: int    rsync_downloader(struct download *, struct sess *, int *);
                    351: int    rsync_set_metadata(struct sess *, int, int, const struct flist *,
                    352:            const char *);
                    353: int    rsync_set_metadata_at(struct sess *, int, int, const struct flist *,
                    354:            const char *);
                    355: int    rsync_uploader(struct upload *, int *, struct sess *, int *);
                    356: int    rsync_uploader_tail(struct upload *, struct sess *);
                    357:
                    358: struct download        *download_alloc(struct sess *, int, const struct flist *,
                    359:                    size_t, int);
                    360: void            download_free(struct download *);
                    361: struct upload  *upload_alloc(const char *, int, int, size_t,
                    362:                    const struct flist *, size_t, mode_t);
                    363: void           upload_free(struct upload *);
1.31      florian   364:
                    365: struct blktab  *blkhash_alloc(void);
                    366: int             blkhash_set(struct blktab *, const struct blkset *);
                    367: void            blkhash_free(struct blktab *);
1.1       benno     368:
1.39      claudio   369: struct blkset  *blk_recv(struct sess *, int, const char *);
                    370: void            blk_recv_ack(char [20], const struct blkset *, int32_t);
                    371: void            blk_match(struct sess *, const struct blkset *,
                    372:                    const char *, struct blkstat *);
                    373: int             blk_send(struct sess *, int, size_t, const struct blkset *,
                    374:                    const char *);
                    375: int             blk_send_ack(struct sess *, int, struct blkset *);
                    376:
                    377: uint32_t        hash_fast(const void *, size_t);
                    378: void            hash_slow(const void *, size_t, unsigned char *,
                    379:                    const struct sess *);
                    380: void            hash_file(const void *, size_t, unsigned char *,
                    381:                    const struct sess *);
1.42    ! claudio   382:
        !           383: void            copy_file(int, const char *, const struct flist *);
1.39      claudio   384:
                    385: int             mkpath(char *);
                    386:
                    387: int             mkstempat(int, char *);
                    388: char           *mkstemplinkat(char*, int, char *);
                    389: char           *mkstempfifoat(int, char *);
                    390: char           *mkstempnodat(int, char *, mode_t, dev_t);
                    391: char           *mkstempsock(const char *, char *);
                    392: int             mktemplate(char **, const char *, int);
1.40      claudio   393:
                    394: int             parse_rule(char *line, enum rule_type);
1.41      claudio   395: void            parse_file(const char *, enum rule_type);
1.40      claudio   396: void            send_rules(struct sess *, int);
                    397: void            recv_rules(struct sess *, int);
                    398: int             rules_match(const char *, int);
                    399:
                    400: int             rmatch(const char *, const char *, int);
1.39      claudio   401:
                    402: char           *symlink_read(const char *);
                    403: char           *symlinkat_read(int, const char *);
                    404:
                    405: int             sess_stats_send(struct sess *, int);
                    406: int             sess_stats_recv(struct sess *, int);
                    407:
                    408: int             idents_add(int, struct ident **, size_t *, int32_t);
                    409: void            idents_assign_gid(struct sess *, struct flist *, size_t,
                    410:                    const struct ident *, size_t);
                    411: void            idents_assign_uid(struct sess *, struct flist *, size_t,
                    412:                    const struct ident *, size_t);
                    413: void            idents_free(struct ident *, size_t);
                    414: int             idents_recv(struct sess *, int, struct ident **, size_t *);
                    415: void            idents_remap(struct sess *, int, struct ident *, size_t);
                    416: int             idents_send(struct sess *, int, const struct ident *, size_t);
1.1       benno     417:
                    418: #endif /*!EXTERN_H*/