Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Bacula® is a registered trademark of John Walker.
+ Bacula® is a registered trademark of Kern Sibbald.
The licensor of Bacula is the Free Software Foundation Europe
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
#include "bacula.h"
#include "find.h"
-int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode) = NULL;
-int (*plugin_bclose)(JCR *jcr) = NULL;
-ssize_t (*plugin_bread)(JCR *jcr, void *buf, size_t count) = NULL;
-ssize_t (*plugin_bwrite)(JCR *jcr, void *buf, size_t count) = NULL;
-boffset_t (*plugin_blseek)(JCR *jcr, boffset_t offset, int whence) = NULL;
+const int dbglvl = 200;
+
+int (*plugin_bopen)(BFILE *bfd, const char *fname, int flags, mode_t mode) = NULL;
+int (*plugin_bclose)(BFILE *bfd) = NULL;
+ssize_t (*plugin_bread)(BFILE *bfd, void *buf, size_t count) = NULL;
+ssize_t (*plugin_bwrite)(BFILE *bfd, void *buf, size_t count) = NULL;
+boffset_t (*plugin_blseek)(BFILE *bfd, boffset_t offset, int whence) = NULL;
#ifdef HAVE_DARWIN_OS
if (bfd->cmd_plugin && plugin_bopen) {
int rtnstat;
- Dmsg1(000, "call plugin_bopen fname=%s\n", fname);
- rtnstat = plugin_bopen(bfd->jcr, fname, flags, mode);
+ Dmsg1(50, "call plugin_bopen fname=%s\n", fname);
+ rtnstat = plugin_bopen(bfd, fname, flags, mode);
+ Dmsg1(50, "return from plugin_bopen status=%d\n", rtnstat);
+ if (rtnstat >= 0) {
+ if (flags & O_CREAT || flags & O_WRONLY) { /* Open existing for write */
+ Dmsg1(50, "plugin_open for write OK file=%s.\n", fname);
+ bfd->mode = BF_WRITE;
+ } else {
+ Dmsg1(50, "plugin_open for read OK file=%s.\n", fname);
+ bfd->mode = BF_READ;
+ }
+ } else {
+ bfd->mode = BF_CLOSED;
+ Dmsg1(000, "==== plugin_bopen returned bad status=%d\n", rtnstat);
+ }
free_pool_memory(win32_fname_wchar);
free_pool_memory(win32_fname);
- return rtnstat;
+ return bfd->mode == BF_CLOSED ? -1 : 1;
}
+ Dmsg0(50, "=== NOT plugin\n");
if (!(p_CreateFileA || p_CreateFileW))
return 0;
bfd->errmsg = NULL;
}
if (bfd->mode == BF_CLOSED) {
+ Dmsg0(50, "=== BFD already closed.\n");
return 0;
}
if (bfd->cmd_plugin && plugin_bclose) {
- stat = plugin_bclose(bfd->jcr);
+ stat = plugin_bclose(bfd);
+ Dmsg0(50, "==== BFD closed!!!\n");
goto all_done;
}
bfd->rw_bytes = 0;
if (bfd->cmd_plugin && plugin_bread) {
- return plugin_bread(bfd->jcr, buf, count);
+ return plugin_bread(bfd, buf, count);
}
if (bfd->use_backup_api) {
bfd->rw_bytes = 0;
if (bfd->cmd_plugin && plugin_bwrite) {
- return plugin_bwrite(bfd->jcr, buf, count);
+ return plugin_bwrite(bfd, buf, count);
}
if (bfd->use_backup_api) {
LONG offset_high = (LONG)(offset >> 32);
DWORD dwResult;
- if (bfd->cmd_plugin && plugin_bwrite) {
- return plugin_blseek(bfd->jcr, offset, whence);
+ if (bfd->cmd_plugin && plugin_blseek) {
+ return plugin_blseek(bfd, offset, whence);
}
dwResult = SetFilePointer(bfd->fh, offset_low, &offset_high, whence);
int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode)
{
if (bfd->cmd_plugin && plugin_bopen) {
- Dmsg1(000, "call plugin_bopen fname=%s\n", fname);
- return plugin_bopen(bfd->jcr, fname, flags, mode);
+ Dmsg1(50, "call plugin_bopen fname=%s\n", fname);
+ bfd->fid = plugin_bopen(bfd, fname, flags, mode);
+ Dmsg1(50, "Plugin bopen stat=%d\n", bfd->fid);
+ return bfd->fid;
}
/* Normal file open */
- Dmsg1(100, "open file %s\n", fname);
+ Dmsg1(dbglvl, "open file %s\n", fname);
/* We use fnctl to set O_NOATIME if requested to avoid open error */
bfd->fid = open(fname, flags & ~O_NOATIME, mode);
Dmsg1(400, "Close file %d\n", bfd->fid);
if (bfd->cmd_plugin && plugin_bclose) {
- stat = plugin_bclose(bfd->jcr);
+ stat = plugin_bclose(bfd);
bfd->fid = -1;
bfd->cmd_plugin = false;
}
ssize_t stat;
if (bfd->cmd_plugin && plugin_bread) {
- return plugin_bread(bfd->jcr, buf, count);
+ return plugin_bread(bfd, buf, count);
}
stat = read(bfd->fid, buf, count);
ssize_t stat;
if (bfd->cmd_plugin && plugin_bwrite) {
- return plugin_bwrite(bfd->jcr, buf, count);
+ return plugin_bwrite(bfd, buf, count);
}
stat = write(bfd->fid, buf, count);
bfd->berrno = errno;
boffset_t pos;
if (bfd->cmd_plugin && plugin_bwrite) {
- return plugin_blseek(bfd->jcr, offset, whence);
+ return plugin_blseek(bfd, offset, whence);
}
- pos = (boffset_t)lseek(bfd->fid, (off_t)offset, whence);
+ pos = (boffset_t)lseek(bfd->fid, offset, whence);
bfd->berrno = errno;
return pos;
}