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

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