From: Kern Sibbald Date: Thu, 14 Sep 2006 09:51:10 +0000 (+0000) Subject: kes Create lseek() method for DEVICE that takes dcr as an X-Git-Tag: Release-2.0.0~450 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b0969e8bfce6949454474960dacb214644123881;p=bacula%2Fbacula kes Create lseek() method for DEVICE that takes dcr as an argument. This is to eliminate the use of attached_dcrs in lseek(). The calls to lseek_dev() must still be changed. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3467 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 331e7a5faa..7413106d58 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -1848,7 +1848,16 @@ void DEVICE::close_part(DCR *dcr) memcpy(&dcr->VolCatInfo, &saveVolCatInfo, sizeof(dcr->VolCatInfo)); } - +off_t DEVICE::lseek(DCR *dcr, off_t offset, int whence) +{ + if (is_dvd()) { + return lseek_dvd(dcr, offset, whence); + } + if (is_file()) { + return ::lseek(fd, offset, whence); + } + return -1; +} bool DEVICE::truncate(DCR *dcr) /* We need the DCR for DVD-writing */ diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index a7b775a3ad..ebb0cc592f 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -363,6 +363,7 @@ public: bool scan_dir_for_volume(DCR *dcr); /* in scan.c */ bool reposition(uint32_t rfile, uint32_t rblock); /* in dev.c */ void clrerror(int func); /* in dev.c */ + off_t lseek(DCR *dcr, off_t offset, int whence); /* in dev.c */ void set_blocked(int block) { dev_blocked = block; }; int get_blocked() const { return dev_blocked; }; diff --git a/bacula/src/stored/dvd.c b/bacula/src/stored/dvd.c index beb9c7de71..64c3c3414b 100644 --- a/bacula/src/stored/dvd.c +++ b/bacula/src/stored/dvd.c @@ -592,22 +592,33 @@ int dvd_open_first_part(DCR *dcr, int mode) return dev->fd; } - -/* Protected version of lseek, which opens the right part if necessary */ +/* Deprecated */ off_t lseek_dev(DEVICE *dev, off_t offset, int whence) { DCR *dcr; - off_t pos; - char ed1[50], ed2[50]; - Dmsg5(400, "Enter lseek_dev fd=%d off=%s w=%d part=%d nparts=%d\n", dev->fd, - edit_int64(offset, ed1), whence, dev->part, dev->num_dvd_parts); if (!dev->is_dvd()) { Dmsg0(400, "Using sys lseek\n"); return lseek(dev->fd, offset, whence); } dcr = (DCR *)dev->attached_dcrs->first(); /* any dcr will do */ + return lseek_dvd(dcr, offset, whence); +} + + +/* + * Do an lseek on a DVD handling all the different parts + */ +off_t lseek_dvd(DCR *dcr, off_t offset, int whence) +{ + DEVICE *dev = dcr->dev; + off_t pos; + char ed1[50], ed2[50]; + + Dmsg5(400, "Enter lseek_dev fd=%d off=%s w=%d part=%d nparts=%d\n", dev->fd, + edit_int64(offset, ed1), whence, dev->part, dev->num_dvd_parts); + switch(whence) { case SEEK_SET: Dmsg2(400, "lseek_dev SEEK_SET to %s (part_start=%s)\n", diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index e6b97fa760..e2dac7df15 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -165,7 +165,7 @@ mount_next_vol: mode = OPEN_READ_WRITE; } while (dev->open(dcr, mode) < 0) { - Dmsg0(150, "open_device failed\n"); + Dmsg1(150, "open_device failed: ERR=%s\n", dev->bstrerror()); if (dev->is_file() && dev->is_removable()) { Dmsg0(150, "call scan_dir_for_vol\n"); if (dev->scan_dir_for_volume(dcr)) { diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 10b82cf1d8..83b8231106 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -82,7 +82,6 @@ void display_tape_error_status(JCR *jcr, DEVICE *dev); /* From dev.c */ DEVICE *init_dev(JCR *jcr, DEVRES *device); -off_t lseek_dev(DEVICE *dev, off_t offset, int whence); bool can_open_mounted_dev(DEVICE *dev); bool truncate_dev(DCR *dcr); void term_dev(DEVICE *dev); @@ -120,6 +119,8 @@ void make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name); bool truncate_dvd(DCR *dcr); bool check_can_write_on_non_blank_dvd(DCR *dcr); int find_num_dvd_parts(DCR *dcr); +off_t lseek_dvd(DCR *dcr, off_t offset, int whence); +off_t lseek_dev(DEVICE *dev, off_t offset, int whence); /* deprecated */ /* From device.c */ bool open_device(DCR *dcr); diff --git a/bacula/technotes-1.39 b/bacula/technotes-1.39 index 28ed985244..b0f42d957c 100644 --- a/bacula/technotes-1.39 +++ b/bacula/technotes-1.39 @@ -1,6 +1,10 @@ Technical notes on version 1.39 General: +14Sep06 +kes Create lseek() method for DEVICE that takes dcr as an + argument. This is to eliminate the use of attached_dcrs in + lseek(). The calls to lseek_dev() must still be changed. 13Sep06 kes Apply Richard Mortimer's patches for printing an error message in btape when a DVD is used, and to initialize traceback.