]> git.sur5r.net Git - bacula/bacula/commitdiff
kes Create lseek() method for DEVICE that takes dcr as an
authorKern Sibbald <kern@sibbald.com>
Thu, 14 Sep 2006 09:51:10 +0000 (09:51 +0000)
committerKern Sibbald <kern@sibbald.com>
Thu, 14 Sep 2006 09:51:10 +0000 (09:51 +0000)
     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

bacula/src/stored/dev.c
bacula/src/stored/dev.h
bacula/src/stored/dvd.c
bacula/src/stored/mount.c
bacula/src/stored/protos.h
bacula/technotes-1.39

index 331e7a5faa3947f6d2aa6abc19b6c79472f2d8f9..7413106d58a047e9e547b1f32c9d52bbc8ecc1fb 100644 (file)
@@ -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 */
index a7b775a3ad444e39eeb1075b8e68a033f8de1eb6..ebb0cc592f7624a2a5e3ca3efa5ead1af36f1670 100644 (file)
@@ -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; };
index beb9c7de71223932d3f12962704213adff68747e..64c3c3414b45d74fddf867197ac9790a903ffd03 100644 (file)
@@ -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",
index e6b97fa76026728417e313ba9b61a481d0370dea..e2dac7df15d979dcac9fb5a37a10ab5e237e82df 100644 (file)
@@ -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)) {
index 10b82cf1d8eeb5c4e08e97dd782dfa48370a45c0..83b8231106941346743687d1007743c476b4bbec 100644 (file)
@@ -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);
index 28ed9852447f888e976bdc18f8ad67277fe86bb3..b0f42d957c69b338177e00bd6ff0264237441108 100644 (file)
@@ -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.