Structures.cpp 12.2 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
/******************************************************************************
 *                      Structures.cpp
 *
 * 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
 *****************************************************************************/
24

25
26
#include "Structures.hpp"
#include "../Exception/Exception.hpp"
27
28
#include <time.h>
#include <stdio.h>
29
30
31
32

void Tape::AULFile::VOL1::fill(std::string vsn) {
  setString(label, "VOL1");
  setString(VSN, vsn);
33
  setString(lblStandard, "3");
34
35
36
37
  setString(ownerID, "CASTOR"); /* TODO: check do we need CASTOR's STAGERSUPERUSER */
}

void Tape::AULFile::VOL1::verify() {
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  if (cmpString(label, "VOL1"))
    throw Tape::Exceptions::Errnum(std::string("Failed verify for the VOL1: ") +
          Tape::AULFile::toString(label));
  if (!cmpString(VSN, ""))
    throw Tape::Exceptions::Errnum(std::string("Failed verify for the VSN: ") +
          Tape::AULFile::toString(VSN));
  if (cmpString(lblStandard, "3"))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the label standard: ") +
          Tape::AULFile::toString(lblStandard));
  if (cmpString(ownerID, "CASTOR"))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the ownerID: ") +
          Tape::AULFile::toString(ownerID));

  /* now we verify all other fields which must be spaces */
  if (cmpString(accessibility, ""))
    throw Tape::Exceptions::Errnum("accessibility is not empty");
  if (cmpString(reserved1, ""))
57
    throw Tape::Exceptions::Errnum("reserved1 is not empty");
58
  if (cmpString(implID, ""))
59
    throw Tape::Exceptions::Errnum("implID is not empty");
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
  if (cmpString(reserved2, ""))
    throw Tape::Exceptions::Errnum("reserved2 is not empty");
}

void Tape::AULFile::HDR1EOF1::fillCommon(
  std::string _fileId, std::string _VSN, int _fSeq) {

  setString(fileId, _fileId);
  setString(VSN, _VSN);
  setInt(fSeq, _fSeq);

  // fill the predefined values
  setString(fSec, "0001");
  setString(genNum, "0001");
  setString(verNumOfGen, "00");
  setDate(creationDate);
  /**
   * TODO:   current_time += (retentd * 86400); to check do we really need
   * retend retention period in days which means a file may be overwritten only
   * if it is  expired.   Default  is  0,  which means that the file may be
   * overwritten immediately.
   */
  setDate(expirationDate);
  setString(sysCode, "CASTOR 7.7.77"); /* TODO: CASTOR BASEVERSION */
}

void Tape::AULFile::HDR1EOF1::verifyCommon()
  const throw (Tape::Exceptions::Errnum) {

  if (!cmpString(fileId, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the fileId: ") +
          Tape::AULFile::toString(fileId));
  if (!cmpString(VSN, ""))
    throw Tape::Exceptions::Errnum(std::string("Failed verify for the VSN: ") +
          Tape::AULFile::toString(VSN));
  if (cmpString(fSec, "0001"))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the fSec: ") +
          Tape::AULFile::toString(fSec));
  if (!cmpString(fSeq, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the fSeq: ") +
          Tape::AULFile::toString(fSeq));
  if (cmpString(genNum, "0001"))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the genNum: ") +
          Tape::AULFile::toString(genNum));
  if (cmpString(verNumOfGen, "00"))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the verNumOfGen: ") +
          Tape::AULFile::toString(verNumOfGen));
  if (!cmpString(creationDate, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the creationDate: ") +
          Tape::AULFile::toString(creationDate));
  if (!cmpString(expirationDate, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the expirationDate: ") +
          Tape::AULFile::toString(expirationDate));
  if (cmpString(accessibility, ""))
    throw Tape::Exceptions::Errnum("accessibility is not empty");
  if (!cmpString(sysCode, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the sysCode: ") +
          Tape::AULFile::toString(sysCode));
  if (cmpString(reserved, ""))
    throw Tape::Exceptions::Errnum("reserved is not empty");
}

void Tape::AULFile::HDR1::fill(
  std::string _fileId,
  std::string _VSN,
  int _fSeq) {

  setString(label, "HDR1");
  setString(blockCount, "000000");

  fillCommon(_fileId, _VSN, _fSeq);
}

void Tape::AULFile::HDR1::verify() const throw (Tape::Exceptions::Errnum) {
  if (cmpString(label, "HDR1"))
    throw Tape::Exceptions::Errnum(std::string("Failed verify for the HDR1: ") +
          Tape::AULFile::toString(label));
  if (cmpString(blockCount, "000000"))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the blockCount: ") +
          Tape::AULFile::toString(blockCount));

  verifyCommon();
}

void Tape::AULFile::HDR1PRELABEL::fill(std::string _VSN) {
  setString(label, "HDR1");
  setString(blockCount, "000000");

  fillCommon(std::string("PRELABEL"), _VSN, 1);
}

void Tape::AULFile::HDR1PRELABEL::verify()
  const throw (Tape::Exceptions::Errnum) {

  if (cmpString(label, "HDR1"))
    throw Tape::Exceptions::Errnum(std::string("Failed verify for the HDR1: ") +
          Tape::AULFile::toString(label));
  if (cmpString(blockCount, "000000"))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the blockCount: ") +
          Tape::AULFile::toString(blockCount));
  if (cmpString(fileId, "PRELABEL"))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the PRELABEL: ") +
          Tape::AULFile::toString(fileId));

  verifyCommon();
}

void Tape::AULFile::EOF1::fill(
  std::string _fileId, std::string _VSN, int _fSeq, int _blockCount) {

  setString(label, "EOF1");
  setInt(blockCount, _blockCount);

  fillCommon(_fileId, _VSN, _fSeq);
}

void Tape::AULFile::EOF1::verify() const throw (Tape::Exceptions::Errnum) {
  if (cmpString(label, "EOF1"))
    throw Tape::Exceptions::Errnum(std::string("Failed verify for the EOF1: ") +
          Tape::AULFile::toString(label));
  if (!cmpString(blockCount, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the blockCount: ") +
          Tape::AULFile::toString(blockCount));

  verifyCommon();
}

void Tape::AULFile::HDR2EOF2::fillCommon(int _blockLength, bool driveHasCompression) {
  setString(recordFormat, "F");
  if (_blockLength < 100000) {
    setInt(blockLength, _blockLength);
    setInt(recordLength, _blockLength);
  } else {
    setInt(blockLength, 0);
    setInt(recordLength, 0);
  }
  if (driveHasCompression) setString(recTechnique,"P ");
  setString(aulId, "00");
}

void Tape::AULFile::HDR2EOF2::verifyCommon() 
  const throw (Tape::Exceptions::Errnum) {

  if (cmpString(recordFormat, "F"))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the recordFormat: ") +
          Tape::AULFile::toString(recordFormat));
  if (!cmpString(blockLength, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the blockLength: ") +
          Tape::AULFile::toString(blockLength));
  if (!cmpString(recordLength, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the recordLength: ") +
          Tape::AULFile::toString(recordLength));
  if (cmpString(aulId, "00"))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the aulId: ") +
          Tape::AULFile::toString(aulId));
  if (cmpString(reserved1, ""))
    throw Tape::Exceptions::Errnum("reserved1 is not empty");
  if (cmpString(reserved2, ""))
    throw Tape::Exceptions::Errnum("reserved2 is not empty");
  if (cmpString(reserved3, ""))
    throw Tape::Exceptions::Errnum("reserved2 is not empty");
}

void Tape::AULFile::HDR2::fill(int _blockLength, bool driveHasCompression) {
  setString(label, "HDR2");
  
  fillCommon(_blockLength, driveHasCompression);
}
void Tape::AULFile::HDR2::verify() const throw (Tape::Exceptions::Errnum) {
  if (cmpString(label, "HDR2"))
    throw Tape::Exceptions::Errnum(std::string("Failed verify for the HDR2: ") +
          Tape::AULFile::toString(label));

  verifyCommon();
250
}
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356

void Tape::AULFile::EOF2::fill(int _blockLength, bool driveHasCompression) {
  setString(label, "EOF2");

  fillCommon(_blockLength, driveHasCompression);
}

void Tape::AULFile::EOF2::verify() const throw (Tape::Exceptions::Errnum) {
  if (cmpString(label, "EOF2"))
    throw Tape::Exceptions::Errnum(std::string("Failed verify for the EOF2: ") +
          Tape::AULFile::toString(label));

  verifyCommon();
}

void Tape::AULFile::UHL1UTL1::fillCommon(int fSeq,
  int blockSize,
  std::string siteName,
  std::string hostName,
  Tape::deviceInfo deviceInfo) {

  setInt(actualfSeq, fSeq);
  setInt(actualBlockSize, blockSize);
  setInt(actualRecordLength, blockSize);
  setString(site, siteName);
  setString(moverHost, hostName);
  setString(driveVendor, deviceInfo.vendor);
  setString(driveModel, deviceInfo.product);
  setString(serialNumber, deviceInfo.serialNumber);
}

void Tape::AULFile::UHL1UTL1::verifyCommon() 
  const throw (Tape::Exceptions::Errnum){  

  if (!cmpString(actualfSeq, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the actualfSeq: ") +
          Tape::AULFile::toString(actualfSeq));
  if (!cmpString(actualBlockSize, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the actualBlockSize: ") +
          Tape::AULFile::toString(actualBlockSize));
  if (!cmpString(actualRecordLength, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for the actualRecordLength: ") +
          Tape::AULFile::toString(actualRecordLength));
  if (!cmpString(site, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for site: ") +
          Tape::AULFile::toString(site));
  if (!cmpString(moverHost, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for moverHost: ") +
          Tape::AULFile::toString(moverHost));
  if (!cmpString(driveVendor, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for driveVendor: ") +
          Tape::AULFile::toString(driveVendor));
  if (!cmpString(driveModel, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for driveModel: ") +
          Tape::AULFile::toString(driveModel));
  if (!cmpString(serialNumber, ""))
    throw Tape::Exceptions::Errnum(
          std::string("Failed verify for serialNumber: ") +
          Tape::AULFile::toString(serialNumber));
}

void Tape::AULFile::UHL1::fill(int fSeq,
  int blockSize,
  std::string siteName,
  std::string hostName,
  Tape::deviceInfo deviceInfo) {

  setString(label, "UHL1");

  fillCommon(fSeq, blockSize, siteName, hostName, deviceInfo);
}

void Tape::AULFile::UHL1::verify() const throw (Tape::Exceptions::Errnum) {
  if (cmpString(label, "UHL1"))
    throw Tape::Exceptions::Errnum(std::string("Failed verify for the UHL1: ") +
          Tape::AULFile::toString(label));

  verifyCommon();
}

void Tape::AULFile::UTL1::fill(int fSeq,
  int blockSize,
  std::string siteName,
  std::string hostName,
  Tape::deviceInfo deviceInfo) {

  setString(label, "UTL1");

  fillCommon(fSeq, blockSize, siteName, hostName, deviceInfo);
}

void Tape::AULFile::UTL1::verify() const throw (Tape::Exceptions::Errnum) {
  if (cmpString(label, "UTL1"))
    throw Tape::Exceptions::Errnum(std::string("Failed verify for the UTL1: ") +
          Tape::AULFile::toString(label));

  verifyCommon();
}