本文整理汇总了C++中DEVICE::set_mode方法的典型用法代码示例。如果您正苦于以下问题:C++ DEVICE::set_mode方法的具体用法?C++ DEVICE::set_mode怎么用?C++ DEVICE::set_mode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DEVICE
的用法示例。
在下文中一共展示了DEVICE::set_mode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: truncate
/*
* Truncate a volume. If this is aligned disk, we
* truncate both volumes.
*/
bool DEVICE::truncate(DCR *dcr) /* We need the DCR for DVD-writing */
{
struct stat st;
DEVICE *dev = this;
Dmsg1(100, "truncate %s\n", print_name());
switch (dev_type) {
case B_VTL_DEV:
case B_VTAPE_DEV:
case B_TAPE_DEV:
/* maybe we should rewind and write and eof ???? */
return true; /* we don't really truncate tapes */
case B_FILE_DEV:
Dmsg1(100, "Truncate fd=%d\n", dev->m_fd);
if (ftruncate(dev->m_fd, 0) != 0) {
berrno be;
Mmsg2(errmsg, _("Unable to truncate device %s. ERR=%s\n"),
print_name(), be.bstrerror());
return false;
}
/*
* Check for a successful ftruncate() and issue a work-around for devices
* (mostly cheap NAS) that don't support truncation.
* Workaround supplied by Martin Schmid as a solution to bug #1011.
* 1. close file
* 2. delete file
* 3. open new file with same mode
* 4. change ownership to original
*/
if (fstat(dev->m_fd, &st) != 0) {
berrno be;
Mmsg2(errmsg, _("Unable to stat device %s. ERR=%s\n"),
print_name(), be.bstrerror());
return false;
}
if (st.st_size != 0) { /* ftruncate() didn't work */
POOL_MEM archive_name(PM_FNAME);
pm_strcpy(archive_name, dev_name);
if (!IsPathSeparator(archive_name.c_str()[strlen(archive_name.c_str())-1])) {
pm_strcat(archive_name, "/");
}
pm_strcat(archive_name, dcr->VolumeName);
Mmsg2(errmsg, _("Device %s doesn't support ftruncate(). Recreating file %s.\n"),
print_name(), archive_name.c_str());
/* Close file and blow it away */
::close(dev->m_fd);
::unlink(archive_name.c_str());
/* Recreate the file -- of course, empty */
dev->set_mode(CREATE_READ_WRITE);
if ((dev->m_fd = ::open(archive_name.c_str(), mode, st.st_mode)) < 0) {
berrno be;
dev_errno = errno;
Mmsg2(errmsg, _("Could not reopen: %s, ERR=%s\n"), archive_name.c_str(),
be.bstrerror());
Dmsg1(40, "reopen failed: %s", errmsg);
Emsg0(M_FATAL, 0, errmsg);
return false;
}
/* Reset proper owner */
chown(archive_name.c_str(), st.st_uid, st.st_gid);
}
return true;
}
return false;
}