SVN_SILENT made messages (.desktop file)
[kdeadmin.git] / kdat / TapeDrive.h
blob4709eeda60c86b48e2e6edf967a5166175cdb8be
1 // KDat - a tar-based DAT archiver
2 // Copyright (C) 1998-2000 Sean Vyain, svyain@mail.tds.net
3 // Copyright (C) 2001-2002 Lawrence Widman, kdat@cardiothink.com
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef _TapeDrive_h_
20 #define _TapeDrive_h_
22 #include <qobject.h>
24 class Tape;
26 /**
27 * @short An OO interface to the tape drive.
29 class TapeDrive : public QObject {
30 Q_OBJECT
31 int _fd;
32 bool _readOnly;
33 Tape* _tape;
34 char* _writeBuf;
35 char* _readBuf;
36 int _writeBufIdx;
37 int _readBufIdx;
39 static TapeDrive* _instance;
41 TapeDrive();
42 public:
43 /**
44 * Destroy the tape drive (figuratively speaking, of course).
46 ~TapeDrive();
48 /**
49 * Get a reference to the single instance of the tape drive object.
51 * @return A pointer to the tape drive object.
53 static TapeDrive* instance();
55 /**
56 * Close the tape device. If data was written to the tape drive, then this
57 * will also cause a single end-of-file marker to be written out. This is
58 * the preferred way to write an end-of-file marker to the tape.
60 void close();
62 /**
63 * Physically eject the tape from the drive. Some tape drives do not
64 * support this operation well.
66 void eject();
68 /**
69 * If there is unwritten data in the buffer, it will be flushed out. This
70 * method is called when necessary by the other tape drive methods.
72 void flush();
74 /**
75 * Get the current tape file number. The first tape file is number 0.
77 * @return >= 0 on success, -1 on failure.
79 int getFile();
81 /**
82 * Get the current tape block number within the current file. The first
83 * tape block number within a file is 0.
85 * @return >= 0 on success, -1 on failure.
87 int getBlock();
89 /**
90 * Determine whether the tape can be written to.
92 * @return TRUE if the tape cannot be written to, otherwise FALSE.
94 bool isReadOnly();
96 /**
97 * Determine whether there is a tape in the drive.
99 * @return TRUE if there is a tape, otherwise FALSE.
101 bool isTapePresent();
104 * Load the tape into the drive.
106 * @return TRUE on success, otherwise FALSE.
108 bool load();
111 * Lock the tape in the drive, so that it cannot be ejected manually by the
112 * user. Not all tape drives support this operation.
114 * @return TRUE on success, otherwise FALSE.
116 bool lock();
119 * Skip over one or more end-of-file markers on the tape. The tape is
120 * positioned just after the last skipped end-of-file marker.
122 * @param count The number of end-of-file markers to skip over.
124 * @return TRUE on success, otherwise FALSE.
126 bool nextFile( int count );
129 * Skip over one or more tape blocks within the current tape file.
131 * @param count The number of tape blocks to skip over.
133 * @return TRUE on success, otherwise FALSE.
135 bool nextRecord( int count );
138 * Open the tape device for reading and writing. If this fails, try
139 * opening the tape device for reading only. Check isReadOnly() to see
140 * if the tape device was opened for reading and writing.
142 * @return TRUE if the tape device was opened for reading and/or writing,
143 * otherwise FALSE.
145 void open();
148 * Determine wether the tape is positioned just after an end-of-file
149 * marker.
151 * @return TRUE if the tape is positioned after an end-of-file marker,
152 * otherwise FALSE.
154 bool pastEOF();
157 * Backspace over one or more end-of-file markers. The tape is positioned
158 * just before the last end-of-file marker.
160 * @param count The number of end-of-file markers to backspace over.
162 * @return TRUE on success, otherwise FALSE.
164 bool prevFile( int count );
167 * Backspace over one or more tape blocks.
169 * @param count The number of tape block to backspace over.
171 * @return TRUE on success, otherwise FALSE.
173 bool prevRecord( int count );
176 * Read data from the tape.
178 * @param buf The buffer to read into.
179 * @param len The number of bytes to read.
181 * @return The actual number of bytes read, or -1 on failure.
183 int read( char* buf, int len );
186 * Read the KDat tape header (if there is one), and get the index
187 * associated with the tape.
189 * @return A pointer to the tape index, or NULL if the tape does not have
190 * a KDat header.
192 Tape* readHeader();
195 * Rewind the tape.
197 * @return TRUE on success, otherwise FALSE.
199 bool rewind();
202 * Move the tape to the given tar block within the given tape file. This
203 * method will intelligently move the tape to the desired position.
205 * @param file The tape file number.
206 * @param tarBlock The desired tar block (NOT tape block).
208 * @return TRUE on success, otherwise FALSE.
210 bool seek( int file, int tarBlock );
213 * Set the hardware tape block size.
215 * @param blockSize The new tape block size in bytes.
217 * @return TRUE on success, otherwise FALSE.
219 bool setBlockSize( int blockSize );
222 * Unlock the tape in the drive, so that it can be ejected manually by the
223 * user. Not all tape drives support this operation.
225 * @return TRUE on success, otherwise FALSE.
227 bool unlock();
230 * Write data to the tape.
232 * @param buf The buffer to write from.
233 * @param len The number of bytes to write.
235 * @return The actual number of bytes written, or -1 on failure.
237 int write( const char* buf, int len );
238 signals:
240 * This signal is emitted for one-line, informational messages.
242 * @param msg The informational message.
244 void sigStatus( const QString & msg );
247 #endif