2 * Bacula File Daemon verify-vol.c Verify files on a Volume
3 * versus attributes in Catalog
5 * Kern Sibbald, July MMII
11 Copyright (C) 2000-2003 Kern Sibbald and John Walker
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of
16 the License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public
24 License along with this program; if not, write to the Free
25 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
33 /* Data received from Storage Daemon */
34 static char rec_header[] = "rechdr %ld %ld %ld %ld %ld";
36 /* Forward referenced functions */
40 * Verify attributes of the requested files on the Volume
43 void do_verify_volume(JCR *jcr)
46 POOLMEM *fname; /* original file name */
47 POOLMEM *lname; /* link name */
50 uint32_t VolSessionId, VolSessionTime, file_index;
51 uint32_t record_file_index;
54 sd = jcr->store_bsock;
56 Jmsg(jcr, M_FATAL, 0, _("Storage command not issued before Verify.\n"));
57 set_jcr_job_status(jcr, JS_FatalError);
61 set_jcr_job_status(jcr, JS_Running);
63 if (!bnet_set_buffer_size(sd, MAX_NETWORK_BUFFER_SIZE, BNET_SETBUF_READ)) {
64 set_jcr_job_status(jcr, JS_FatalError);
67 jcr->buf_size = sd->msglen;
69 fname = get_pool_memory(PM_FNAME);
70 lname = get_pool_memory(PM_FNAME);
73 * Get a record from the Storage daemon
75 while (bget_msg(sd) >= 0 && !job_canceled(jcr)) {
77 * First we expect a Stream Record Header
79 if (sscanf(sd->msg, rec_header, &VolSessionId, &VolSessionTime, &file_index,
80 &stream, &size) != 5) {
81 Jmsg1(jcr, M_FATAL, 0, _("Record header scan error: %s\n"), sd->msg);
84 Dmsg2(30, "Got hdr: FilInx=%d Stream=%d.\n", file_index, stream);
87 * Now we expect the Stream Data
89 if (bget_msg(sd) < 0) {
90 Jmsg1(jcr, M_FATAL, 0, _("Data record error. ERR=%s\n"), bnet_strerror(sd));
93 if (size != ((uint32_t)sd->msglen)) {
94 Jmsg2(jcr, M_FATAL, 0, _("Actual data size %d not same as header %d\n"), sd->msglen, size);
97 Dmsg1(30, "Got stream data, len=%d\n", sd->msglen);
99 /* File Attributes stream */
101 case STREAM_UNIX_ATTRIBUTES:
102 case STREAM_UNIX_ATTRIBUTES_EX:
105 Dmsg0(400, "Stream=Unix Attributes.\n");
107 if ((int)sizeof_pool_memory(fname) < sd->msglen) {
108 fname = realloc_pool_memory(fname, sd->msglen + 1);
111 if ((int)sizeof_pool_memory(lname) < sd->msglen) {
112 lname = realloc_pool_memory(lname, sd->msglen + 1);
118 * An Attributes record consists of:
123 * Link name (if file linked i.e. FT_LNK)
124 * Extended Attributes (if Win32)
126 if (sscanf(sd->msg, "%d %d", &record_file_index, &type) != 2) {
127 Jmsg(jcr, M_FATAL, 0, _("Error scanning record header: %s\n"), sd->msg);
128 Dmsg0(0, "\nError scanning header\n");
131 Dmsg2(30, "Got Attr: FilInx=%d type=%d\n", record_file_index, type);
132 if (record_file_index != file_index) {
133 Jmsg(jcr, M_FATAL, 0, _("Record header file index %ld not equal record index %ld\n"),
134 file_index, record_file_index);
135 Dmsg0(0, "File index error\n");
139 while (*ap++ != ' ') /* skip record file index */
141 while (*ap++ != ' ') /* skip type */
143 /* Save filename and position to attributes */
146 *fp++ = *ap++; /* copy filename to fname */
148 *fp = *ap++; /* terminate filename & point to attribs */
150 Dmsg1(200, "Attr=%s\n", ap);
151 /* Skip to Link name */
152 if (type == FT_LNK || type == FT_LNKSAVED) {
157 strcat(lname, lp); /* "save" link name */
163 jcr->num_files_examined++;
164 pm_strcpy(&jcr->last_fname, fname); /* last file examined */
168 * Send file attributes to Director
172 * Filename (full path)
174 * Link name (if type==FT_LNK)
175 * For a directory, link is the same as fname, but with trailing
176 * slash. For a linked file, link is the link.
178 /* Send file attributes to Director */
179 Dmsg2(200, "send ATTR inx=%d fname=%s\n", jcr->JobFiles, fname);
180 if (type == FT_LNK || type == FT_LNKSAVED) {
181 stat = bnet_fsend(dir, "%d %d %s %s%c%s%c%s%c", jcr->JobFiles,
182 STREAM_UNIX_ATTRIBUTES, "pinsug5", fname,
185 stat = bnet_fsend(dir,"%d %d %s %s%c%s%c%c", jcr->JobFiles,
186 STREAM_UNIX_ATTRIBUTES, "pinsug5", fname,
189 Dmsg2(200, "bfiled>bdird: attribs len=%d: msg=%s\n", dir->msglen, dir->msg);
191 Jmsg(jcr, M_FATAL, 0, _("Network error in send to Director: ERR=%s\n"), bnet_strerror(dir));
196 /* Data streams to ignore */
197 case STREAM_FILE_DATA:
198 case STREAM_SPARSE_DATA:
199 case STREAM_WIN32_DATA:
200 case STREAM_WIN32_GZIP_DATA:
201 case STREAM_GZIP_DATA:
202 case STREAM_SPARSE_GZIP_DATA:
207 case STREAM_MD5_SIGNATURE:
209 bin_to_base64(MD5buf, (char *)sd->msg, 16); /* encode 16 bytes */
210 Dmsg2(400, "send inx=%d MD5=%s\n", jcr->JobFiles, MD5buf);
211 bnet_fsend(dir, "%d %d %s *MD5-%d*", jcr->JobFiles, STREAM_MD5_SIGNATURE, MD5buf,
213 Dmsg2(20, "bfiled>bdird: MD5 len=%d: msg=%s\n", dir->msglen, dir->msg);
216 case STREAM_SHA1_SIGNATURE:
218 bin_to_base64(SHA1buf, (char *)sd->msg, 20); /* encode 20 bytes */
219 Dmsg2(400, "send inx=%d SHA1=%s\n", jcr->JobFiles, SHA1buf);
220 bnet_fsend(dir, "%d %d %s *SHA1-%d*", jcr->JobFiles, STREAM_SHA1_SIGNATURE,
221 SHA1buf, jcr->JobFiles);
222 Dmsg2(20, "bfiled>bdird: SHA1 len=%d: msg=%s\n", dir->msglen, dir->msg);
226 Pmsg2(0, "None of above!!! stream=%d data=%s\n", stream,sd->msg);
229 } /* end while bnet_get */
230 set_jcr_job_status(jcr, JS_Terminated);
234 set_jcr_job_status(jcr, JS_ErrorTerminated);
237 if (jcr->compress_buf) {
238 free(jcr->compress_buf);
239 jcr->compress_buf = NULL;
241 free_pool_memory(fname);
242 free_pool_memory(lname);
243 Dmsg2(050, "End Verify-Vol. Files=%d Bytes=%" lld "\n", jcr->JobFiles,