本文整理汇总了C++中DEVICE::close_part方法的典型用法代码示例。如果您正苦于以下问题:C++ DEVICE::close_part方法的具体用法?C++ DEVICE::close_part怎么用?C++ DEVICE::close_part使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DEVICE
的用法示例。
在下文中一共展示了DEVICE::close_part方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dvd_open_first_part
/*
* Open the first part file.
* - Close the fd
* - Reopen the device
*/
static bool dvd_open_first_part(DCR *dcr, int mode)
{
DEVICE *dev = dcr->dev;
Dmsg5(29, "Enter: ==== open_first_part dev=%s Vol=%s mode=%d num_dvd_parts=%d append=%d\n", dev->print_name(),
dev->getVolCatName(), dev->openmode, dev->num_dvd_parts, dev->can_append());
dev->close_part(dcr);
Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->getVolCatName(),
mode);
Dmsg0(100, "Set part=1\n");
dev->part = 1;
dev->part_start = 0;
if (dev->open(dcr, mode) < 0) {
Dmsg0(400, "open dev() failed\n");
return false;
}
Dmsg2(400, "Leave open_first_part state=%s append=%d\n", dev->is_open()?"open":"not open", dev->can_append());
return true;
}
示例2: truncate_dvd
bool truncate_dvd(DCR *dcr)
{
DEVICE* dev = dcr->dev;
dev->clear_freespace_ok(); /* need to update freespace */
dev->close_part(dcr);
if (!dev->unmount(1)) {
Dmsg0(400, "truncate_dvd: Failed to unmount DVD\n");
return false;
}
/* If necessary, delete its spool file. */
if (dev->is_part_spooled()) {
POOL_MEM archive_name(PM_FNAME);
/* Delete spool file */
make_spooled_dvd_filename(dev, archive_name);
unlink(archive_name.c_str());
dev->set_part_spooled(false);
}
/* Set num_dvd_parts to zero (on disk) */
dev->part = 0;
dev->num_dvd_parts = 0;
dcr->VolCatInfo.VolCatParts = 0;
dev->VolCatInfo.VolCatParts = 0;
Dmsg0(400, "truncate_dvd: Opening first part (1)...\n");
dev->truncating = true;
/* This creates a zero length spool file and sets part=1 */
if (!dvd_open_first_part(dcr, CREATE_READ_WRITE)) {
Dmsg0(400, "truncate_dvd: Error while opening first part (1).\n");
dev->truncating = false;
return false;
}
dev->close_part(dcr);
Dmsg0(400, "truncate_dvd: Opening first part (2)...\n");
/*
* Now actually truncate the DVD which is done by writing
* a zero length part to the DVD/
*/
if (!dvd_write_part(dcr)) {
Dmsg0(400, "truncate_dvd: Error while writing to DVD.\n");
dev->truncating = false;
return false;
}
dev->truncating = false;
/* Set num_dvd_parts to zero (on disk) */
dev->part = 0;
dev->num_dvd_parts = 0;
dcr->VolCatInfo.VolCatParts = 0;
dev->VolCatInfo.VolCatParts = 0;
/* Clear the size of the volume */
dev->VolCatInfo.VolCatBytes = 0;
dcr->VolCatInfo.VolCatBytes = 0;
/* Update catalog */
if (!dir_update_volume_info(dcr, false, true)) {
return false;
}
return true;
}
示例3: dvd_open_next_part
/*
* Open the next part file.
* - Close the fd
* - Increment part number
* - Reopen the device
*/
int dvd_open_next_part(DCR *dcr)
{
DEVICE *dev = dcr->dev;
Dmsg6(29, "Enter: == open_next_part part=%d npart=%d dev=%s vol=%s mode=%d file_addr=%d\n",
dev->part, dev->num_dvd_parts, dev->print_name(),
dev->getVolCatName(), dev->openmode, dev->file_addr);
if (!dev->is_dvd()) {
Dmsg1(100, "Device %s is not dvd!!!!\n", dev->print_name());
return -1;
}
/* When appending, do not open a new part if the current is empty */
if (dev->can_append() && (dev->part > dev->num_dvd_parts) &&
(dev->part_size == 0)) {
Dmsg0(29, "open_next_part exited immediately (dev->part_size == 0).\n");
return dev->fd();
}
dev->close_part(dcr); /* close current part */
/*
* If we have a spooled part open, write it to the
* DVD before opening the next part.
*/
if (dev->is_part_spooled()) {
Dmsg2(100, "Before open next write previous. part=%d num_parts=%d\n",
dev->part, dev->num_dvd_parts);
if (!dvd_write_part(dcr)) {
Dmsg0(29, "Error in dvd_write part.\n");
return -1;
}
}
dev->part_start += dev->part_size;
dev->part++;
Dmsg2(29, "Inc part=%d num_dvd_parts=%d\n", dev->part, dev->num_dvd_parts);
/* Are we working on a part past what is written in the DVD? */
if (dev->num_dvd_parts < dev->part) {
POOL_MEM archive_name(PM_FNAME);
struct stat buf;
/*
* First check what is on DVD. If our part is there, we
* are in trouble, so bail out.
* NB: This is however not a problem if we are writing the first part.
* It simply means that we are over writing an existing volume...
*/
if (dev->num_dvd_parts > 0) {
make_mounted_dvd_filename(dev, archive_name); /* makes dvd name */
Dmsg1(100, "Check if part on DVD: %s\n", archive_name.c_str());
if (stat(archive_name.c_str(), &buf) == 0) {
/* bad news bail out */
dev->set_part_spooled(false);
Mmsg1(&dev->errmsg, _("Next Volume part already exists on DVD. Cannot continue: %s\n"),
archive_name.c_str());
return -1;
}
}
#ifdef neeeded
Dmsg2(400, "num_dvd_parts=%d part=%d\n", dev->num_dvd_parts, dev->part);
make_spooled_dvd_filename(dev, archive_name); /* makes spool name */
/* Check if the next part exists in spool directory . */
Dmsg1(100, "Check if part on spool: %s\n", archive_name.c_str());
if ((stat(archive_name.c_str(), &buf) == 0) || (errno != ENOENT)) {
Dmsg1(29, "======= Part %s is in the way, deleting it...\n", archive_name.c_str());
/* Then try to unlink it */
if (unlink(archive_name.c_str()) < 0) {
berrno be;
dev->set_part_spooled(false);
dev->dev_errno = errno;
Mmsg2(dev->errmsg, _("open_next_part can't unlink existing part %s, ERR=%s\n"),
archive_name.c_str(), be.bstrerror());
return -1;
}
}
#endif
}
Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->getVolCatName(),
dev->openmode);
/* Open next part. Note, this sets part_size for part opened. */
if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
return -1;
}
dev->set_labeled(); /* all next parts are "labeled" */
return dev->fd();
}