Structures.cpp 11.5 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
using namespace castor::tape;

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

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

  /* now we verify all other fields which must be spaces */
  if (cmpString(accessibility, ""))
57
    throw Exceptions::Errnum("accessibility is not empty");
58
  if (cmpString(reserved1, ""))
59
    throw Exceptions::Errnum("reserved1 is not empty");
60
  if (cmpString(implID, ""))
61
    throw Exceptions::Errnum("implID is not empty");
62
  if (cmpString(reserved2, ""))
63
    throw Exceptions::Errnum("reserved2 is not empty");
64
65
}

66
void AULFile::HDR1EOF1::fillCommon(
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  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 */
}

88
89
void AULFile::HDR1EOF1::verifyCommon()
  const throw (Exceptions::Errnum) {
90
91

  if (!cmpString(fileId, ""))
92
    throw Exceptions::Errnum(
93
          std::string("Failed verify for the fileId: ") +
94
          AULFile::toString(fileId));
95
  if (!cmpString(VSN, ""))
96
97
    throw Exceptions::Errnum(std::string("Failed verify for the VSN: ") +
          AULFile::toString(VSN));
98
  if (cmpString(fSec, "0001"))
99
    throw Exceptions::Errnum(
100
          std::string("Failed verify for the fSec: ") +
101
          AULFile::toString(fSec));
102
  if (!cmpString(fSeq, ""))
103
    throw Exceptions::Errnum(
104
          std::string("Failed verify for the fSeq: ") +
105
          AULFile::toString(fSeq));
106
  if (cmpString(genNum, "0001"))
107
    throw Exceptions::Errnum(
108
          std::string("Failed verify for the genNum: ") +
109
          AULFile::toString(genNum));
110
  if (cmpString(verNumOfGen, "00"))
111
    throw Exceptions::Errnum(
112
          std::string("Failed verify for the verNumOfGen: ") +
113
          AULFile::toString(verNumOfGen));
114
  if (!cmpString(creationDate, ""))
115
    throw Exceptions::Errnum(
116
          std::string("Failed verify for the creationDate: ") +
117
          AULFile::toString(creationDate));
118
  if (!cmpString(expirationDate, ""))
119
    throw Exceptions::Errnum(
120
          std::string("Failed verify for the expirationDate: ") +
121
          AULFile::toString(expirationDate));
122
  if (cmpString(accessibility, ""))
123
    throw Exceptions::Errnum("accessibility is not empty");
124
  if (!cmpString(sysCode, ""))
125
    throw Exceptions::Errnum(
126
          std::string("Failed verify for the sysCode: ") +
127
          AULFile::toString(sysCode));
128
  if (cmpString(reserved, ""))
129
    throw Exceptions::Errnum("reserved is not empty");
130
131
}

132
void AULFile::HDR1::fill(
133
134
135
136
137
138
139
140
141
142
  std::string _fileId,
  std::string _VSN,
  int _fSeq) {

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

  fillCommon(_fileId, _VSN, _fSeq);
}

143
void AULFile::HDR1::verify() const throw (Exceptions::Errnum) {
144
  if (cmpString(label, "HDR1"))
145
146
    throw Exceptions::Errnum(std::string("Failed verify for the HDR1: ") +
          AULFile::toString(label));
147
  if (cmpString(blockCount, "000000"))
148
    throw Exceptions::Errnum(
149
          std::string("Failed verify for the blockCount: ") +
150
          AULFile::toString(blockCount));
151
152
153
154

  verifyCommon();
}

155
void AULFile::HDR1PRELABEL::fill(std::string _VSN) {
156
157
158
159
160
161
  setString(label, "HDR1");
  setString(blockCount, "000000");

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

162
163
void AULFile::HDR1PRELABEL::verify()
  const throw (Exceptions::Errnum) {
164
165

  if (cmpString(label, "HDR1"))
166
167
    throw Exceptions::Errnum(std::string("Failed verify for the HDR1: ") +
          AULFile::toString(label));
168
  if (cmpString(blockCount, "000000"))
169
    throw Exceptions::Errnum(
170
          std::string("Failed verify for the blockCount: ") +
171
          AULFile::toString(blockCount));
172
  if (cmpString(fileId, "PRELABEL"))
173
    throw Exceptions::Errnum(
174
          std::string("Failed verify for the PRELABEL: ") +
175
          AULFile::toString(fileId));
176
177
178
179

  verifyCommon();
}

180
void AULFile::EOF1::fill(
181
182
183
184
185
186
187
188
  std::string _fileId, std::string _VSN, int _fSeq, int _blockCount) {

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

  fillCommon(_fileId, _VSN, _fSeq);
}

189
void AULFile::EOF1::verify() const throw (Exceptions::Errnum) {
190
  if (cmpString(label, "EOF1"))
191
192
    throw Exceptions::Errnum(std::string("Failed verify for the EOF1: ") +
          AULFile::toString(label));
193
  if (!cmpString(blockCount, ""))
194
    throw Exceptions::Errnum(
195
          std::string("Failed verify for the blockCount: ") +
196
          AULFile::toString(blockCount));
197
198
199
200

  verifyCommon();
}

201
void AULFile::HDR2EOF2::fillCommon(int _blockLength, bool driveHasCompression) {
202
203
204
205
206
207
208
209
210
211
212
213
  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");
}

214
215
void AULFile::HDR2EOF2::verifyCommon() 
  const throw (Exceptions::Errnum) {
216
217

  if (cmpString(recordFormat, "F"))
218
    throw Exceptions::Errnum(
219
          std::string("Failed verify for the recordFormat: ") +
220
          AULFile::toString(recordFormat));
221
  if (!cmpString(blockLength, ""))
222
    throw Exceptions::Errnum(
223
          std::string("Failed verify for the blockLength: ") +
224
          AULFile::toString(blockLength));
225
  if (!cmpString(recordLength, ""))
226
    throw Exceptions::Errnum(
227
          std::string("Failed verify for the recordLength: ") +
228
          AULFile::toString(recordLength));
229
  if (cmpString(aulId, "00"))
230
    throw Exceptions::Errnum(
231
          std::string("Failed verify for the aulId: ") +
232
          AULFile::toString(aulId));
233
  if (cmpString(reserved1, ""))
234
    throw Exceptions::Errnum("reserved1 is not empty");
235
  if (cmpString(reserved2, ""))
236
    throw Exceptions::Errnum("reserved2 is not empty");
237
  if (cmpString(reserved3, ""))
238
    throw Exceptions::Errnum("reserved2 is not empty");
239
240
}

241
void AULFile::HDR2::fill(int _blockLength, bool driveHasCompression) {
242
243
244
245
  setString(label, "HDR2");
  
  fillCommon(_blockLength, driveHasCompression);
}
246
void AULFile::HDR2::verify() const throw (Exceptions::Errnum) {
247
  if (cmpString(label, "HDR2"))
248
249
    throw Exceptions::Errnum(std::string("Failed verify for the HDR2: ") +
          AULFile::toString(label));
250
251

  verifyCommon();
252
}
253

254
void AULFile::EOF2::fill(int _blockLength, bool driveHasCompression) {
255
256
257
258
259
  setString(label, "EOF2");

  fillCommon(_blockLength, driveHasCompression);
}

260
void AULFile::EOF2::verify() const throw (Exceptions::Errnum) {
261
  if (cmpString(label, "EOF2"))
262
263
    throw Exceptions::Errnum(std::string("Failed verify for the EOF2: ") +
          AULFile::toString(label));
264
265
266
267

  verifyCommon();
}

268
void AULFile::UHL1UTL1::fillCommon(int fSeq,
269
270
271
  int blockSize,
  std::string siteName,
  std::string hostName,
272
  drives::deviceInfo deviceInfo) {
273
274
275
276
277
278
279
280
281
282
283

  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);
}

284
285
void AULFile::UHL1UTL1::verifyCommon() 
  const throw (Exceptions::Errnum){  
286
287

  if (!cmpString(actualfSeq, ""))
288
    throw Exceptions::Errnum(
289
          std::string("Failed verify for the actualfSeq: ") +
290
          AULFile::toString(actualfSeq));
291
  if (!cmpString(actualBlockSize, ""))
292
    throw Exceptions::Errnum(
293
          std::string("Failed verify for the actualBlockSize: ") +
294
          AULFile::toString(actualBlockSize));
295
  if (!cmpString(actualRecordLength, ""))
296
    throw Exceptions::Errnum(
297
          std::string("Failed verify for the actualRecordLength: ") +
298
          AULFile::toString(actualRecordLength));
299
  if (!cmpString(site, ""))
300
    throw Exceptions::Errnum(
301
          std::string("Failed verify for site: ") +
302
          AULFile::toString(site));
303
  if (!cmpString(moverHost, ""))
304
    throw Exceptions::Errnum(
305
          std::string("Failed verify for moverHost: ") +
306
          AULFile::toString(moverHost));
307
  if (!cmpString(driveVendor, ""))
308
    throw Exceptions::Errnum(
309
          std::string("Failed verify for driveVendor: ") +
310
          AULFile::toString(driveVendor));
311
  if (!cmpString(driveModel, ""))
312
    throw Exceptions::Errnum(
313
          std::string("Failed verify for driveModel: ") +
314
          AULFile::toString(driveModel));
315
  if (!cmpString(serialNumber, ""))
316
    throw Exceptions::Errnum(
317
          std::string("Failed verify for serialNumber: ") +
318
          AULFile::toString(serialNumber));
319
320
}

321
void AULFile::UHL1::fill(int fSeq,
322
323
324
  int blockSize,
  std::string siteName,
  std::string hostName,
325
  drives::deviceInfo deviceInfo) {
326
327
328
329
330
331

  setString(label, "UHL1");

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

332
void AULFile::UHL1::verify() const throw (Exceptions::Errnum) {
333
  if (cmpString(label, "UHL1"))
334
335
    throw Exceptions::Errnum(std::string("Failed verify for the UHL1: ") +
          AULFile::toString(label));
336
337
338
339

  verifyCommon();
}

340
void AULFile::UTL1::fill(int fSeq,
341
342
343
  int blockSize,
  std::string siteName,
  std::string hostName,
344
  drives::deviceInfo deviceInfo) {
345
346
347
348
349
350

  setString(label, "UTL1");

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

351
void AULFile::UTL1::verify() const throw (Exceptions::Errnum) {
352
  if (cmpString(label, "UTL1"))
353
354
    throw Exceptions::Errnum(std::string("Failed verify for the UTL1: ") +
          AULFile::toString(label));
355
356
357
358

  verifyCommon();
}