本文整理汇总了C++中DEVICE::weof方法的典型用法代码示例。如果您正苦于以下问题:C++ DEVICE::weof方法的具体用法?C++ DEVICE::weof怎么用?C++ DEVICE::weof使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DEVICE
的用法示例。
在下文中一共展示了DEVICE::weof方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: release_device
/*
* This job is done, so release the device. From a Unix standpoint,
* the device remains open.
*
* Note, if we were spooling, we may enter with the device blocked.
* We unblock at the end, only if it was us who blocked the
* device.
*
*/
bool release_device(DCR *dcr)
{
utime_t now;
JCR *jcr = dcr->jcr;
DEVICE *dev = dcr->dev;
bool ok = true;
char tbuf[100];
int was_blocked = BST_NOT_BLOCKED;
/*
* Capture job statistics now that we are done using this device.
*/
now = (utime_t)time(NULL);
update_job_statistics(jcr, now);
dev->Lock();
if (!dev->is_blocked()) {
block_device(dev, BST_RELEASING);
} else {
was_blocked = dev->blocked();
dev->set_blocked(BST_RELEASING);
}
lock_volumes();
Dmsg2(100, "release_device device %s is %s\n", dev->print_name(), dev->is_tape() ? "tape" : "disk");
/*
* If device is reserved, job never started, so release the reserve here
*/
dcr->clear_reserved();
if (dev->can_read()) {
VOLUME_CAT_INFO *vol = &dev->VolCatInfo;
dev->clear_read(); /* clear read bit */
Dmsg2(150, "dir_update_vol_info. label=%d Vol=%s\n",
dev->is_labeled(), vol->VolCatName);
if (dev->is_labeled() && vol->VolCatName[0] != 0) {
dcr->dir_update_volume_info(false, false); /* send Volume info to Director */
remove_read_volume(jcr, dcr->VolumeName);
volume_unused(dcr);
}
} else if (dev->num_writers > 0) {
/*
* Note if WEOT is set, we are at the end of the tape and may not be positioned correctly,
* so the job_media_record and update_vol_info have already been done,
* which means we skip them here.
*/
dev->num_writers--;
Dmsg1(100, "There are %d writers in release_device\n", dev->num_writers);
if (dev->is_labeled()) {
Dmsg2(200, "dir_create_jobmedia. Release vol=%s dev=%s\n",
dev->getVolCatName(), dev->print_name());
if (!dev->at_weot() && !dcr->dir_create_jobmedia_record(false)) {
Jmsg2(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
dcr->getVolCatName(), jcr->Job);
}
/*
* If no more writers, and no errors, and wrote something, write an EOF
*/
if (!dev->num_writers && dev->can_write() && dev->block_num > 0) {
dev->weof(1);
write_ansi_ibm_labels(dcr, ANSI_EOF_LABEL, dev->VolHdr.VolumeName);
}
if (!dev->at_weot()) {
dev->VolCatInfo.VolCatFiles = dev->file; /* set number of files */
/*
* Note! do volume update before close, which zaps VolCatInfo
*/
dcr->dir_update_volume_info(false, false); /* send Volume info to Director */
Dmsg2(200, "dir_update_vol_info. Release vol=%s dev=%s\n",
dev->getVolCatName(), dev->print_name());
}
if (dev->num_writers == 0) { /* if not being used */
volume_unused(dcr); /* we obviously are not using the volume */
}
}
} else {
/*
* If we reach here, it is most likely because the job has failed,
* since the device is not in read mode and there are no writers.
* It was probably reserved.
*/
volume_unused(dcr);
}
Dmsg3(100, "%d writers, %d reserve, dev=%s\n", dev->num_writers, dev->num_reserved(), dev->print_name());
/*
* If no writers, close if file or !CAP_ALWAYS_OPEN
//.........这里部分代码省略.........
示例2: write_ansi_ibm_labels
//.........这里部分代码省略.........
ser_begin(label, sizeof(label));
ser_bytes("VOL1", 4);
ser_bytes(ansi_volname, 6);
/* Write VOL1 label */
if (label_type == B_IBM_LABEL) {
ascii_to_ebcdic(label, label, sizeof(label));
} else {
label[79] = '3'; /* ANSI label flag */
}
stat = dev->write(label, sizeof(label));
if (stat != sizeof(label)) {
berrno be;
Jmsg1(jcr, M_FATAL, 0, _("Could not write ANSI VOL1 label. ERR=%s\n"),
be.bstrerror());
return false;
}
}
/* Now construct HDR1 label */
memset(label, ' ', sizeof(label));
ser_begin(label, sizeof(label));
ser_bytes(labels[type], 3);
ser_bytes("1", 1);
ser_bytes("BACULA.DATA", 11); /* Filename field */
ser_begin(&label[21], sizeof(label)-21); /* fileset field */
ser_bytes(ansi_volname, 6); /* write Vol Ser No. */
ser_begin(&label[27], sizeof(label)-27);
ser_bytes("00010001000100", 14); /* File section, File seq no, Generation no */
now = time(NULL);
ser_bytes(ansi_date(now, date), 6); /* current date */
ser_bytes(ansi_date(now - 24 * 3600, date), 6); /* created yesterday */
ser_bytes(" 000000Bacula ", 27);
/* Write HDR1 label */
if (label_type == B_IBM_LABEL) {
ascii_to_ebcdic(label, label, sizeof(label));
}
/*
* This could come at the end of a tape, ignore
* EOT errors.
*/
stat = dev->write(label, sizeof(label));
if (stat != sizeof(label)) {
berrno be;
if (stat == -1) {
dev->clrerror(-1);
if (dev->dev_errno == 0) {
dev->dev_errno = ENOSPC; /* out of space */
}
if (dev->dev_errno != ENOSPC) {
Jmsg1(jcr, M_FATAL, 0, _("Could not write ANSI HDR1 label. ERR=%s\n"),
be.bstrerror());
return false;
}
} else {
Jmsg(jcr, M_FATAL, 0, _("Could not write ANSI HDR1 label.\n"));
return false;
}
}
/* Now construct HDR2 label */
memset(label, ' ', sizeof(label));
ser_begin(label, sizeof(label));
ser_bytes(labels[type], 3);
ser_bytes("2D3200032000", 12);
/* Write HDR2 label */
if (label_type == B_IBM_LABEL) {
label[4] = 'V';
ascii_to_ebcdic(label, label, sizeof(label));
}
stat = dev->write(label, sizeof(label));
if (stat != sizeof(label)) {
berrno be;
if (stat == -1) {
dev->clrerror(-1);
if (dev->dev_errno == 0) {
dev->dev_errno = ENOSPC; /* out of space */
}
if (dev->dev_errno != ENOSPC) {
Jmsg1(jcr, M_FATAL, 0, _("Could not write ANSI HDR1 label. ERR=%s\n"),
be.bstrerror());
return false;
}
dev->weof(1);
return true;
} else {
Jmsg(jcr, M_FATAL, 0, _("Could not write ANSI HDR1 label.\n"));
return false;
}
}
if (!dev->weof(1)) {
Jmsg(jcr, M_FATAL, 0, _("Error writing EOF to tape. ERR=%s"), dev->errmsg);
return false;
}
return true;
default:
Jmsg0(jcr, M_ABORT, 0, _("write_ansi_ibm_label called for non-ANSI/IBM type\n"));
return false; /* should not get here */
}
}
示例3: write_new_volume_label_to_dev
//.........这里部分代码省略.........
/* Set the new filename for open, ... */
dev->setVolCatName(VolName);
dcr->setVolCatName(VolName);
Dmsg1(150, "New VolName=%s\n", VolName);
if (!dev->open(dcr, OPEN_READ_WRITE)) {
/* If device is not tape, attempt to create it */
if (dev->is_tape() || !dev->open(dcr, CREATE_READ_WRITE)) {
Jmsg3(jcr, M_WARNING, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"),
dev->print_name(), dcr->VolumeName, dev->bstrerror());
goto bail_out;
}
}
Dmsg1(150, "Label type=%d\n", dev->label_type);
/*
* Let any stored plugin know that we are about to write a new label to the volume.
*/
if (generate_plugin_event(jcr, bsdEventLabelWrite, dcr) != bRC_OK) {
Dmsg0(200, "Error from bsdEventLabelWrite plugin event.\n");
goto bail_out;
}
for ( ;; ) {
empty_block(block);
if (!dev->rewind(dcr)) {
Dmsg2(130, "Bad status on %s from rewind: ERR=%s\n", dev->print_name(), dev->print_errmsg());
if (!forge_on) {
goto bail_out;
}
}
/* Temporarily mark in append state to enable writing */
dev->set_append();
/* Create PRE_LABEL */
create_volume_label(dev, VolName, PoolName);
/*
* If we have already detected an ANSI label, re-read it
* to skip past it. Otherwise, we write a new one if
* so requested.
*/
if (dev->label_type != B_BAREOS_LABEL) {
if (read_ansi_ibm_label(dcr) != VOL_OK) {
dev->rewind(dcr);
goto bail_out;
}
} else if (!write_ansi_ibm_labels(dcr, ANSI_VOL_LABEL, VolName)) {
goto bail_out;
}
create_volume_label_record(dcr, dev, dcr->rec);
dcr->rec->Stream = 0;
dcr->rec->maskedStream = 0;
if (!write_record_to_block(dcr, dcr->rec)) {
Dmsg2(130, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->print_errmsg());
goto bail_out;
} else {
Dmsg2(130, "Wrote label of %d bytes to %s\n", dcr->rec->data_len, dev->print_name());
}
Dmsg0(130, "Call write_block_to_dev()\n");
if (!dcr->write_block_to_dev()) {
Dmsg2(130, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->print_errmsg());
goto bail_out;
}
break;
}
dev = dcr->dev;
Dmsg0(130, " Wrote block to device\n");
if (dev->weof(1)) {
dev->set_labeled();
write_ansi_ibm_labels(dcr, ANSI_EOF_LABEL, dev->VolHdr.VolumeName);
}
if (debug_level >= 20) {
dump_volume_label(dev);
}
Dmsg0(100, "Call reserve_volume\n");
if (reserve_volume(dcr, VolName) == NULL) {
Mmsg2(jcr->errmsg, _("Could not reserve volume %s on %s\n"),
dev->VolHdr.VolumeName, dev->print_name());
Dmsg1(100, "%s", jcr->errmsg);
goto bail_out;
}
dev = dcr->dev; /* may have changed in reserve_volume */
dev->clear_append(); /* remove append since this is PRE_LABEL */
return true;
bail_out:
volume_unused(dcr);
dev->clear_volhdr();
dev->clear_append(); /* remove append since this is PRE_LABEL */
return false;
}