bool is_fs_nearly_full(uint64_t threshold);
int rehydrate_record(DCR *dcr, DEV_RECORD *rec);
- int set_writable(int fd, const char *vol_name);
- int set_readonly(int fd, const char *vol_name);
- int set_atime(int fd, const char *vol_name, btime_t val);
+ int set_writable(int fd, const char *vol_name, POOLMEM **error);
+ int set_readonly(int fd, const char *vol_name, POOLMEM **error);
+ int set_atime(int fd, const char *vol_name, btime_t val, POOLMEM **error);
/*
* Locking and blocking calls
if (dev->device->set_vol_immutable || dev->device->set_vol_read_only) {
uint32_t when = MAX(dev->device->min_volume_protection_time, dev->VolCatInfo.VolRetention);
btime_t now = time(NULL);
- if (dev->set_atime(-1, dev->getVolCatName(), now + when) < 0) {
- Jmsg(dcr->jcr, M_WARNING, 0, _(" Failed to set the volume %s on device %s in atime retention, ERR=%s.\n"),
+ if (dev->set_atime(-1, dev->getVolCatName(), now + when, &dev->errmsg) < 0) {
+ Jmsg(dcr->jcr, M_WARNING, 0, _(" Failed to set the atime retention on volume %s on device %s. %s.\n"),
dev->getVolCatName(), dev->print_name(), dev->errmsg);
}
bstrftime(buf2, sizeof(buf2), now+when);
if (dev->device->set_vol_read_only) {
/* Set volume as immutable/read only */
- if (dev->set_readonly(dev->m_fd, dev->getVolCatName()) < 0) {
- berrno be;
+ if (dev->set_readonly(dev->m_fd, dev->getVolCatName(), &dev->errmsg) < 0) {
/* We may proceed with that but warn the user */
- Jmsg(dcr->jcr, M_WARNING, 0, _("Failed to set the volume %s on device %s in read-only, ERR=%s.\n"),
- dev->getVolCatName(), dev->print_name(), be.bstrerror());
+ Jmsg(dcr->jcr, M_WARNING, 0, _("Failed to set the volume %s on device %s in read-only. %s.\n"),
+ dev->getVolCatName(), dev->print_name(), dev->errmsg);
} else {
Jmsg(dcr->jcr, M_INFO, 0, _("Marking Volume \"%s\" as read-only. Retention set to %s (%s).\n"),
dev->getVolCatName(), buf2, buf);
/* Set volume as immutable */
if (!dev->set_immutable(dev->getVolCatName(), &dev->errmsg)) {
/* We may proceed with that but warn the user */
- Jmsg(dcr->jcr, M_WARNING, 0, _("Failed to set the volume %s on device %s as immutable, ERR=%s.\n"),
+ Jmsg(dcr->jcr, M_WARNING, 0, _("Failed to set the volume %s on device %s as immutable, %s.\n"),
dev->getVolCatName(), dev->print_name(), dev->errmsg);
} else {
Jmsg(dcr->jcr, M_INFO, 0, _("Marking Volume \"%s\" as immutable. Retention set to %s (%s).\n"),
virtual bool check_volume_protection_time(const char *vol_name) { return true; };
virtual bool check_for_immutable(const char *vol_name) { return false; };
virtual bool check_for_read_only(int fd, const char *vol_name) { return false; };
- virtual int set_writable(int fd, const char *vol_name) { errno=ENOSYS; return -1;};
- virtual int set_readonly(int fd, const char *vol_name) { errno=ENOSYS; return -1;};
- virtual int set_atime(int fd, const char *vol_name, btime_t val) { errno=ENOSYS; return -1;};
+ virtual int set_writable(int fd, const char *vol_name, POOLMEM **error) { pm_strcpy(error, "Not implemented"); errno=ENOSYS; return -1;};
+ virtual int set_readonly(int fd, const char *vol_name, POOLMEM **error) { pm_strcpy(error, "Not implemented"); errno=ENOSYS; return -1;};
+ virtual int set_atime(int fd, const char *vol_name, btime_t val, POOLMEM **error) { pm_strcpy(error, "Not implemented"); errno=ENOSYS; return -1;};
virtual int use_protect() { return 0; };
virtual int use_volume_encryption();
virtual const char *print_type() = 0; /* in dev.c */
BSOCK *dir = jcr->dir_bsock;
char mediatype[MAX_NAME_LENGTH];
char volume[MAX_NAME_LENGTH];
- POOL_MEM device, tmp;
+ POOL_MEM device, tmp, error;
uint32_t retention;
int32_t drive;
bool ok;
if (dev->device->set_vol_immutable || dev->device->set_vol_read_only) {
uint32_t when = MAX(dev->device->min_volume_protection_time, retention);
btime_t now = time(NULL);
- if (dev->set_atime(-1, volume, now + when) < 0) {
- berrno be;
- Mmsg(tmp, _(" Failed to set the volume %s on device %s in atime retention, ERR=%s.\n"),
- volume, dev->print_name(), be.bstrerror());
+ if (dev->set_atime(-1, volume, now + when, error.handle()) < 0) {
+ MmsgD3(DT_VOLUME|50, tmp,
+ _(" Failed to set the volume %s on device %s in atime retention, ERR=%s.\n"),
+ volume, dev->print_name(), error.c_str());
}
pm_strcpy(tmp, "");
bstrftime(buf2, sizeof(buf2), now+when);
}
if (dev->device->set_vol_immutable) {
/* Set volume as immutable */
- if (!dev->set_immutable(volume, tmp.handle())) {
+ if (!dev->set_immutable(volume, error.handle())) {
/* We may proceed with that but warn the user */
- dir->fsend(_("3900 Unable to set immutable flag %s\n"), tmp.c_str());
+ dir->fsend(_("3900 Unable to set immutable flag %s\n"), error.c_str());
} else {
dir->fsend(_("3000 Mark volume \"%s\" as immutable. Retention set to %s (%s).\n"), volume, buf2, buf);
} else if (dev->device->set_vol_read_only) {
/* Set volume as immutable/read only */
- if (dev->set_readonly(-1, volume) < 0) {
- berrno be;
+ if (dev->set_readonly(-1, volume, error.handle()) < 0) {
/* We may proceed with that but warn the user */
dir->fsend(_("3900 Failed to set the volume %s on device %s in read-only, ERR=%s.%s\n"),
- volume, dev->print_name(), be.bstrerror(), tmp.c_str());
+ volume, dev->print_name(), error.c_str(), tmp.c_str());
} else {
dir->fsend(_("3000 Marking volume \"%s\" as read-only. Retention set to %s (%s).\n"),
volume,buf2, buf);
if (immutable && clear_immutable(getVolCatName(), &errmsg)) {
tryopen = true;
}
- if (readonly && set_writable(-1, getVolCatName()) == 0) {
+ if (readonly && set_writable(-1, getVolCatName(), &errmsg) == 0) {
tryopen = true;
}
if (tryopen) { /* It should be now possible to open the device with desired mode */
return m_fd >= 0;
}
-int file_dev::set_writable(int fd, const char *vol_name)
+int file_dev::set_writable(int fd, const char *vol_name, POOLMEM **error)
{
POOL_MEM fname;
get_volume_fpath(vol_name, fname.handle());
int ret = bchmod(fd, fname.c_str(), 0600);
if (ret < 0) {
berrno be;
- Dmsg1(DT_VOLUME|50, _("Unable to change permission to 0600. ERR=%s\n"), be.bstrerror());
+ MmsgD1(DT_VOLUME|50, error, _("Unable to change permission to 0600. ERR=%s\n"), be.bstrerror());
}
return ret;
}
-int file_dev::set_readonly(int fd, const char *vol_name)
+int file_dev::set_readonly(int fd, const char *vol_name, POOLMEM **error)
{
POOL_MEM fname;
get_volume_fpath(vol_name, fname.handle());
int ret = bchmod(fd, fname.c_str(), 0400);
if (ret < 0) {
berrno be;
- Dmsg1(DT_VOLUME|50, _("Unable to change permission to 0400. ERR=%s\n"), be.bstrerror());
+ MmsgD1(DT_VOLUME|50, error, _("Unable to change permission to 0400. ERR=%s\n"), be.bstrerror());
}
return ret;
}
-int file_dev::set_atime(int fd, const char *vol_name, btime_t val)
+int file_dev::set_atime(int fd, const char *vol_name, btime_t val, POOLMEM **error)
{
struct stat sp;
int ret;
get_volume_fpath(vol_name, fname.handle());
if (bstat(fd, fname.c_str(), &sp) < 0) {
berrno be;
- Dmsg2(DT_VOLUME|50, _("Unable to stat %s. ERR=%s\n"), fname.c_str(), be.bstrerror());
+ MmsgD2(DT_VOLUME|50, error, _("Unable to stat %s. ERR=%s\n"), fname.c_str(), be.bstrerror());
return -1;
}
ret = set_own_time(fd, fname.c_str(), val, sp.st_mtime);
if (ret < 0) {
berrno be;
- Dmsg2(DT_VOLUME|50, _("Unable to set atime/mtime to %s. ERR=%s\n"), fname.c_str(), be.bstrerror());
+ MmsgD2(DT_VOLUME|50, error, _("Unable to set atime/mtime to %s. ERR=%s\n"), fname.c_str(), be.bstrerror());
}
return ret;
}
}
if (dev->device->set_vol_read_only) {
- if (set_writable(dev->m_fd, dcr->VolumeName) < 0) {
- berrno be;
+ if (set_writable(dev->m_fd, dcr->VolumeName, &errmsg) < 0) {
Mmsg3(errmsg, _("Unable to set write permission for volume %s on device %s. %s\n"),
- dcr->VolumeName, print_name(), be.bstrerror());
+ dcr->VolumeName, print_name(), errmsg);
return false;
}
}
bool check_for_read_only(int fd, const char *vol_name);
bool get_os_device_freespace();
bool is_fs_nearly_full(uint64_t threshold);
- int set_writable(int fd, const char *vol_name);
- int set_readonly(int fd, const char *vol_name);
- int set_atime(int fd, const char *vol_name, btime_t val);
+ int set_writable(int fd, const char *vol_name, POOLMEM **error);
+ int set_readonly(int fd, const char *vol_name, POOLMEM **error);
+ int set_atime(int fd, const char *vol_name, btime_t val, POOLMEM **error);
int use_protect();
};