3 #define WRAP_INVALID_FHINFO (-1ull)
4 #define WRAP_MAX_PATH (1024+512)
5 #define WRAP_MAX_NAME 256
6 #define WRAP_MAX_ENV 100
7 #define WRAP_MAX_FILE 100
8 #define WRAP_MAX_COMMAND (20*1024)
9 #define WRAP_MAX_O_OPTION 100
17 ****************************************************************
20 extern int wrap_main (int ac, char *av[], struct wrap_ccb *wccb);
21 extern int wrap_main_start_index_file (struct wrap_ccb *wccb);
22 extern int wrap_main_start_image_file (struct wrap_ccb *wccb);
24 extern void wrap_log (struct wrap_ccb *wccb, char *fmt, ...);
26 extern int wrap_set_error (struct wrap_ccb *wccb, int error);
33 ****************************************************************
35 * This wrapper will spawn (fork/exec) a subprocess to do
36 * the real work. These help form the sh(1) command line,
37 * create the pipe fittings, and spawn the subprocess.
39 * The fdmap[3] corresponds to the subprocess stdin, stdout,
40 * and stderr. A value >= 0 is assumed to be an inherited
41 * file descriptor. A value < 0 is one of the special codes
42 * WRAP_FDMAP_xxx. On return, the _PIPE special codes are
43 * replaced with the file descriptor for the parent process
47 #define WRAP_FDMAP_INPUT_PIPE -2 /* input to child, parent writes */
48 #define WRAP_FDMAP_OUTPUT_PIPE -3 /* output from child, parent reads */
49 #define WRAP_FDMAP_DEV_NULL -4 /* /dev/null */
51 extern int wrap_cmd_add_with_escapes (char *cmd, char *word,
53 extern int wrap_cmd_add_with_sh_escapes (char *cmd, char *word);
54 extern int wrap_cmd_add_allow_file_wildcards (char *cmd, char *word);
55 extern int wrap_pipe_fork_exec (char *cmd, int fdmap[3]);
61 * CCB -- Command Control Block
62 ****************************************************************
64 * A digested form of command line arguments
69 WRAP_CCB_OP_BACKUP = 1, /* -c */
70 WRAP_CCB_OP_RECOVER = 2, /* -x */
71 WRAP_CCB_OP_RECOVER_FILEHIST = 3 /* -t */
80 unsigned long long fhinfo;
81 char * original_name; /* relative to backup root */
82 char * save_to_name; /* relative to file system */
88 char errmsg[WRAP_MAX_NAME];
91 char * B_butype; /* -B TYPE */
92 int d_debug; /* -d N */
93 struct wrap_env env[WRAP_MAX_ENV]; /* -E NAME=VALUE */
95 char * f_file_name; /* -f FILE */
96 char * I_index_file_name; /* -I FILE */
97 char * o_option[WRAP_MAX_O_OPTION]; /* -o OPTION */
100 struct wrap_file file[WRAP_MAX_FILE]; /* recovery only */
103 /* derived from arguments */
109 /* Common interprettations of the env */
115 * Recovery variables.
117 * All offset/length pairs refer to a portion of the
120 * have The portion currently in the buffer.
121 * want The portion wanted by the formatter
123 * reading The portion immediately after what we
124 * "have" (in the buffer) still coming due
125 * to the last NDMP_NOTIFY_DATA_READ.
126 * last_read The portion requested by the last
127 * NDMP_NOTIFY_DATA_READ.
128 * expect Composite of have and reading.
131 unsigned long n_iobuf;
134 unsigned long long have_offset;
135 unsigned long have_length; /* never bigger than iobuf */
136 unsigned long long want_offset;
137 unsigned long long want_length;
138 unsigned long long reading_offset;
139 unsigned long long reading_length;
140 unsigned long long last_read_offset;
141 unsigned long long last_read_length;
142 unsigned long long expect_offset;
143 unsigned long long expect_length;
147 extern int wrap_process_args (int argc, char *argv[],
148 struct wrap_ccb *wccb);
149 extern char * wrap_find_env (struct wrap_ccb *wccb, char *name);
152 extern int wrap_reco_seek (struct wrap_ccb *wccb,
153 unsigned long long want_offset,
154 unsigned long long want_length,
155 unsigned long must_have_length);
156 extern int wrap_reco_must_have (struct wrap_ccb *wccb,
157 unsigned long length);
158 extern int wrap_reco_pass (struct wrap_ccb *wccb, int write_fd,
159 unsigned long long length, unsigned write_bsize);
160 extern int wrap_reco_align_to_wanted (struct wrap_ccb *wccb);
161 extern int wrap_reco_receive (struct wrap_ccb *wccb);
162 extern int wrap_reco_consume (struct wrap_ccb *wccb,
163 unsigned long length);
164 extern int wrap_reco_issue_read (struct wrap_ccb *wccb);
172 ****************************************************************
174 * A message is simply one text line following a format.
175 * These structures are used to buffer incoming messages.
178 struct wrap_log_message { /* Lx */
179 char message[WRAP_MAX_PATH];
183 WRAP_FTYPE_INVALID = 0,
184 WRAP_FTYPE_DIR = 1, /* d */
185 WRAP_FTYPE_FIFO = 2, /* p */
186 WRAP_FTYPE_CSPEC = 3, /* c */
187 WRAP_FTYPE_BSPEC = 4, /* b */
188 WRAP_FTYPE_REG = 5, /* - */
189 WRAP_FTYPE_SLINK = 6, /* l */
190 WRAP_FTYPE_SOCK = 7, /* s */
191 WRAP_FTYPE_REGISTRY = 8, /* R */
192 WRAP_FTYPE_OTHER = 9 /* o */
197 #define WRAP_FSTAT_VALID_FTYPE (1ul<<0u)
198 #define WRAP_FSTAT_VALID_MODE (1ul<<1u)
199 #define WRAP_FSTAT_VALID_LINKS (1ul<<2u)
200 #define WRAP_FSTAT_VALID_SIZE (1ul<<3u)
201 #define WRAP_FSTAT_VALID_UID (1ul<<4u)
202 #define WRAP_FSTAT_VALID_GID (1ul<<5u)
203 #define WRAP_FSTAT_VALID_ATIME (1ul<<6u)
204 #define WRAP_FSTAT_VALID_MTIME (1ul<<7u)
205 #define WRAP_FSTAT_VALID_CTIME (1ul<<8u)
206 #define WRAP_FSTAT_VALID_FILENO (1ul<<9u)
208 enum wrap_ftype ftype; /* f%s */
209 unsigned short mode; /* m%04o */
210 unsigned long links; /* l%lu */
211 unsigned long long size; /* s%llu */
212 unsigned long uid; /* u%lu */
213 unsigned long gid; /* g%lu */
214 unsigned long atime; /* ta%lu */
215 unsigned long mtime; /* tm%lu */
216 unsigned long ctime; /* tc%lu */
217 unsigned long long fileno; /* i%llu */
221 * HF path [@fhinfo] [stats]
223 * History File -- Corresponds to NDMPv?_FH_ADD_FILE
225 struct wrap_add_file {
226 unsigned long long fhinfo; /* @%llu */
227 struct wrap_fstat fstat;
228 char path[WRAP_MAX_PATH];
232 * HD dir_fileno name fileno [@fhinfo]
234 * History Directory entry -- Corresponds to NDMPv?_FH_ADD_DIR
236 struct wrap_add_dirent {
237 unsigned long long fhinfo; /* @%llu */
238 unsigned long long dir_fileno; /* %llu */
239 unsigned long long fileno; /* %llu */
240 char name[WRAP_MAX_NAME];
244 * HN [@fhinfo] [stats] -- iFILENO must be present
246 * History Node -- Corresponds to NDMPv?_FH_ADD_NODE
248 struct wrap_add_node { /* HN */
249 unsigned long long fhinfo; /* @%llu */
250 struct wrap_fstat fstat;
256 * Data Env -- Corresponds to NDMPv?_DATA_GET_ENV
257 * This is used for the post backup processing env[].
259 struct wrap_add_env {
260 char name[WRAP_MAX_NAME];
261 char value[WRAP_MAX_PATH];
267 * Data Read -- Corresponds to NDMPv?_NOTIFY_DATA_READ
268 * This is used during recovery operations to retrieve
269 * portions of the backup image.
271 struct wrap_data_read { /* DR */
272 unsigned long long offset; /* %llu */
273 unsigned long long length; /* %llu */
277 * DS s{r|d|f} [wN] [etN] [ebN]
279 * Data Stats -- Supplemental info for NDMPv?_DATA_GET_STATE
280 * Sent periodically to update certain fields of the
281 * DATA_GET_STATE reply.
284 enum wrap_data_status {
286 WRAP_DS_RUNNING = 1, /* sr */
287 WRAP_DS_DONE_OK = 2, /* sd */
288 WRAP_DS_DONE_FAILED = 3 /* sf */
291 struct wrap_data_stats { /* DS */
293 #define WRAP_DATASTATS_VALID_BYTES_WRITTEN (1ul<<0u)
294 #define WRAP_DATASTATS_VALID_EST_TIME_REMAINING (1ul<<1u)
295 #define WRAP_DATASTATS_VALID_EST_BYTES_REMAINING (1ul<<2u)
297 enum wrap_data_status status; /* s{r|d|f} */
298 unsigned long long bytes_written; /* w%llu */
299 unsigned long long est_time_remaining; /* et%llu */
300 unsigned long long est_bytes_remaining; /* eb%llu */
306 * Recovery Result -- Corresponds to NDMPv?_LOG_FILE
307 * Sent during recovery operations to report the
308 * success or failure of recovery.
310 struct wrap_recovery_result { /* RR */
311 int rr_errno; /* sys/errno.h */
312 char path[WRAP_MAX_PATH];
316 WRAP_MSGTYPE_LOG_MESSAGE = 1,
317 WRAP_MSGTYPE_ADD_FILE = 2,
318 WRAP_MSGTYPE_ADD_DIRENT = 3,
319 WRAP_MSGTYPE_ADD_NODE = 4,
320 WRAP_MSGTYPE_ADD_ENV = 5,
321 WRAP_MSGTYPE_DATA_READ = 6,
322 WRAP_MSGTYPE_DATA_STATS = 7,
323 WRAP_MSGTYPE_RECOVERY_RESULT = 8,
326 struct wrap_msg_buf {
327 enum wrap_msg_type msg_type;
329 struct wrap_log_message log_message;
330 struct wrap_add_file add_file;
331 struct wrap_add_dirent add_dirent;
332 struct wrap_add_node add_node;
333 struct wrap_add_env add_env;
334 struct wrap_data_read data_read;
335 struct wrap_data_stats data_stats;
336 struct wrap_recovery_result recovery_result;
340 extern int wrap_parse_msg (char *buf, struct wrap_msg_buf *wmsg);
341 extern int wrap_parse_log_message_msg (char *buf, struct wrap_msg_buf *wmsg);
342 extern int wrap_send_log_message (FILE *fp, char *message);
343 extern int wrap_parse_add_file_msg (char *buf, struct wrap_msg_buf *wmsg);
344 extern int wrap_send_add_file (FILE *fp, char *path, unsigned long long fhinfo,
345 struct wrap_fstat *fstat);
346 extern int wrap_parse_add_dirent_msg (char *buf, struct wrap_msg_buf *wmsg);
347 extern int wrap_send_add_dirent (FILE *fp, char *name,
348 unsigned long long fhinfo,
349 unsigned long long dir_fileno,
350 unsigned long long fileno);
351 extern int wrap_parse_add_node_msg (char *buf, struct wrap_msg_buf *wmsg);
352 extern int wrap_send_add_node (FILE *fp, unsigned long long fhinfo,
353 struct wrap_fstat *fstat);
354 extern int wrap_parse_fstat_subr (char **scanp, struct wrap_fstat *fstat);
355 extern int wrap_send_fstat_subr (FILE *fp, struct wrap_fstat *fstat);
356 extern int wrap_parse_add_env_msg (char *buf, struct wrap_msg_buf *wmsg);
357 extern int wrap_send_add_env (FILE *fp, char *name, char *value);
358 extern int wrap_parse_data_read_msg (char *buf, struct wrap_msg_buf *wmsg);
359 extern int wrap_send_data_read (FILE *fp, unsigned long long offset,
360 unsigned long long length);
367 ****************************************************************
368 * Convert strings to/from HTTP-like canonical strings (%xx).
369 * Example "a b%c" --> "a%20b%25c"
372 #define NDMCSTR_WARN '%'
373 extern int wrap_cstr_from_str (char *src, char *dst, unsigned dst_max);
374 extern int wrap_cstr_to_str (char *src, char *dst, unsigned dst_max);
375 extern int wrap_cstr_from_hex (int c);