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

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