2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Read code for Storage daemon
31 * Kern Sibbald, November MM
39 /* Forward referenced subroutines */
40 static bool record_cb(DCR *dcr, DEV_RECORD *rec);
43 /* Responses sent to the File daemon */
44 static char OK_data[] = "3000 OK data\n";
45 static char FD_error[] = "3000 error\n";
46 static char rec_header[] = "rechdr %ld %ld %ld %ld %ld";
49 * Read Data and send to File Daemon
50 * Returns: false on failure
53 bool do_read_data(JCR *jcr)
55 BSOCK *fd = jcr->file_bsock;
57 DCR *dcr = jcr->read_dcr;
59 Dmsg0(20, "Start read data.\n");
61 if (!bnet_set_buffer_size(fd, dcr->device->max_network_buffer_size, BNET_SETBUF_WRITE)) {
65 if (jcr->NumReadVolumes == 0) {
66 Jmsg(jcr, M_FATAL, 0, _("No Volume names found for restore.\n"));
71 Dmsg2(200, "Found %d volumes names to restore. First=%s\n", jcr->NumReadVolumes,
72 jcr->VolList->VolumeName);
74 /* Ready device for reading */
75 if (!acquire_device_for_read(dcr)) {
80 /* Tell File daemon we will send data */
82 ok = read_records(dcr, record_cb, mount_next_read_volume);
84 /* Send end of data to FD */
87 if (!release_device(jcr->read_dcr)) {
91 Dmsg0(30, "Done reading.\n");
96 * Called here for each record from read_records()
100 static bool record_cb(DCR *dcr, DEV_RECORD *rec)
103 BSOCK *fd = jcr->file_bsock;
106 char ec1[50], ec2[50];
108 if (rec->FileIndex < 0) {
111 Dmsg5(400, "Send to FD: SessId=%u SessTim=%u FI=%s Strm=%s, len=%d\n",
112 rec->VolSessionId, rec->VolSessionTime,
113 FI_to_ascii(ec1, rec->FileIndex),
114 stream_to_ascii(ec2, rec->Stream, rec->FileIndex),
117 /* Send record header to File daemon */
118 if (!fd->fsend(rec_header, rec->VolSessionId, rec->VolSessionTime,
119 rec->FileIndex, rec->Stream, rec->data_len)) {
120 Pmsg1(000, _(">filed: Error Hdr=%s\n"), fd->msg);
121 Jmsg1(jcr, M_FATAL, 0, _("Error sending to File daemon. ERR=%s\n"),
125 Dmsg1(400, ">filed: Hdr=%s\n", fd->msg);
129 /* Send data record to File daemon */
130 save_msg = fd->msg; /* save fd message pointer */
131 fd->msg = rec->data; /* pass data directly to the FD */
132 fd->msglen = rec->data_len;
133 Dmsg1(400, ">filed: send %d bytes data.\n", fd->msglen);
135 Pmsg1(000, _("Error sending to FD. ERR=%s\n"), fd->bstrerror());
136 Jmsg1(jcr, M_FATAL, 0, _("Error sending to File daemon. ERR=%s\n"),
141 fd->msg = save_msg; /* restore fd message pointer */