FakeDrive.hpp 5.01 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/******************************************************************************
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * 
 *
 * @author Castor Dev team, castor-dev@cern.ch
 *****************************************************************************/
#pragma once

#include "castor/tape/tapeserver/drive/DriveInterface.hpp"

namespace castor {
namespace tape {
29
namespace tapeserver {
30
namespace drive {
31
32
33
34
35
/**
   * Fake drive class used for unit testing
  */
  class FakeDrive : public DriveInterface {
  private:
36
37
38
39
40
41
42
    struct tapeBlock {
      std::string data;
      uint64_t remainingSpaceAfter;
    };
    std::vector<tapeBlock> m_tape;
    uint32_t m_currentPosition;
    uint64_t m_tapeCapacity;
43
    int m_beginOfCompressStats;
44
    uint64_t getRemaingSpace(uint32_t currentPosition);
45
46
47
48
49
  public:
    enum FailureMoment { OnWrite, OnFlush } ;
  private:
    const enum FailureMoment m_failureMoment;
    bool m_tapeOverflow;
50
    bool m_failToMount;
51
    lbpToUse m_lbpToUse;
52
53
  public:
    std::string contentToString() throw();
54
55

    FakeDrive(uint64_t capacity=std::numeric_limits<uint64_t>::max(),
56
57
58
      enum FailureMoment failureMoment=OnWrite,
      bool failOnMount = false) throw();
    FakeDrive(bool failOnMount) throw ();
59
60
    virtual ~FakeDrive() throw(){}
    virtual compressionStats getCompression() ;
61
62
63
    virtual void clearCompressionStats();
    virtual std::map<std::string,uint64_t> getTapeWriteErrors();
    virtual std::map<std::string,uint64_t> getTapeReadErrors();
64
65
66
67
68
    virtual std::map<std::string,uint32_t> getTapeNonMediumErrors();
    virtual std::map<std::string,float> getQualityStats();
    virtual std::map<std::string,uint32_t> getDriveStats();
    virtual std::map<std::string,uint32_t> getVolumeStats();
    virtual std::string getDriveFirmwareVersion();
69
    virtual deviceInfo getDeviceInfo() ;
70
    virtual std::string getGenericSCSIPath() ;
71
72
73
    virtual std::string getSerialNumber() ;
    virtual void positionToLogicalObject(uint32_t blockId) ;
    virtual positionInfo getPositionInfo() ;
74
    virtual physicalPositionInfo getPhysicalPositionInfo();
75
    virtual std::vector<endOfWrapPosition> getEndOfWrapPositions();
76
77
78
    virtual std::vector<uint16_t> getTapeAlertCodes();
    virtual std::vector<std::string> getTapeAlerts(const std::vector<uint16_t>&) ;
    virtual std::vector<std::string> getTapeAlertsCompact(const std::vector<uint16_t>&) ;
79
    virtual bool tapeAlertsCriticalForWrite(const std::vector<uint16_t> & codes);
80
81
    virtual void setDensityAndCompression(bool compression = true, 
    unsigned char densityCode = 0) ;
82
83
84
85
86
87
    virtual void enableCRC32CLogicalBlockProtectionReadOnly() ;
    virtual void enableCRC32CLogicalBlockProtectionReadWrite() ;
    virtual void disableLogicalBlockProtection() ;
    virtual drive::LBPInfo getLBPInfo();
    virtual void setLogicalBlockProtection(const unsigned char method,
      unsigned char methodLength, const bool enableLPBforRead, 
88
89
90
91
      const bool enableLBBforWrite);
    virtual void setEncryptionKey(const std::string &encryption_key);
    virtual bool clearEncryptionKey();
    virtual bool isEncryptionCapEnabled();
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    virtual driveStatus getDriveStatus() ;
    virtual void setSTBufferWrite(bool bufWrite) ;
    virtual void fastSpaceToEOM(void) ;
    virtual void rewind(void) ;
    virtual void spaceToEOM(void) ;
    virtual void spaceFileMarksBackwards(size_t count) ;
    virtual void spaceFileMarksForward(size_t count) ;
    virtual void unloadTape(void) ;
    virtual void flush(void) ;
    virtual void writeSyncFileMarks(size_t count) ;
    virtual void writeImmediateFileMarks(size_t count) ;
    virtual void writeBlock(const void * data, size_t count) ;
    virtual ssize_t readBlock(void * data, size_t count) ;
    virtual void readExactBlock(void * data, size_t count, std::string context) ;
    virtual void readFileMark(std::string context) ;
107
    virtual void waitUntilReady(const uint32_t timeoutSecond) ;    
108
109
110
111
    virtual bool isWriteProtected() ;
    virtual bool isAtBOT() ;
    virtual bool isAtEOD() ;
    virtual bool isTapeBlank();
112
    virtual lbpToUse getLbpToUse();
113
    virtual bool hasTapeInPlace();
Cristina Moraru's avatar
Cristina Moraru committed
114
    virtual castor::tape::SCSI::Structures::RAO::udsLimits getLimitUDS();
115
    virtual void queryRAO(std::list<SCSI::Structures::RAO::blockLims> &files, int maxSupported,const std::string & raoAlgorithm);
116
117
  };
  
118
}}}}