-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstdlabel.c
More file actions
125 lines (110 loc) · 3.75 KB
/
stdlabel.c
File metadata and controls
125 lines (110 loc) · 3.75 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
/* vtapeutils - Virtual tape management utilities
STDLABEL.C - Processes ANSI standard tape labels in EBCDIC or ASCII
This file is part of the vtapeutils package of virtual tape management
utilities. The package is hosted at Github. Complete information may be
found at the summary page, https://github.com/jmaynard/vtapeutils .
Copyright James R. Maynard, III
All rights reserved.
See the file LICENSE in this distribution for license terms.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "vtape.h"
#include "stdlabel.h"
#include "ebcdic.h"
int do_standard_label(VTAPE_FILE *tape_file, unsigned char *label)
{
ansi_label translated_label;
if (memcmp(label,"VOL1",4) == 0) {
memcpy(translated_label.raw_label,label,80);
print_volume_label(translated_label);
return TRUE;
} else {
if (memcmp(label,"HDR1",4) == 0) {
memcpy(translated_label.raw_label,label,80);
print_header1_label(translated_label);
return TRUE;
} else {
if ((memcmp(label,"EOF1",4) == 0) ||
(memcmp(label,"EOV1",4) == 0)) {
memcpy(translated_label.raw_label,label,80);
print_trailer1_label(tape_file, translated_label);
return TRUE;
} else {
if ((memcmp(label,"HDR2",4) == 0)) {
memcpy(translated_label.raw_label,label,80);
print_hdrtlr2_label(translated_label);
return TRUE;
}
}
}
}
ebcdic_to_ascii(label,translated_label.raw_label,80);
if (memcmp(translated_label.raw_label,"VOL1",4) == 0) {
print_volume_label(translated_label);
return TRUE;
} else {
if (memcmp(translated_label.raw_label,"HDR1",4) == 0) {
print_header1_label(translated_label);
return TRUE;
} else {
if ((memcmp(translated_label.raw_label,"EOF1",4) == 0) ||
(memcmp(translated_label.raw_label,"EOV1",4) == 0)) {
print_trailer1_label(tape_file, translated_label);
return TRUE;
} else {
if ((memcmp(translated_label.raw_label,"HDR2",4) == 0)) {
print_hdrtlr2_label(translated_label);
return TRUE;
}
}
}
}
return FALSE;
}
void print_volume_label(ansi_label label)
{
printf("Standard labeled tape, volume %.6s, owner %.17s\n",
label.vol1.volser, label.vol1.owner);
}
void print_header1_label(ansi_label label)
{
printf("Begin dataset %.17s, number %.4s, created %.6s, expires %.6s\n",
label.hdr1.dataset_name, label.hdr1.dataset_seq,
label.hdr1.creation_date, label.hdr1.expiration_date);
}
void print_trailer1_label(VTAPE_FILE *tape_file, ansi_label label)
{
int label_block_count;
char block_count_buffer[11];
printf("End dataset %.17s, %.4s%.6s blocks, written on %.13s\n",
label.eof1.dataset_name, label.eof1.block_count_high,
label.eof1.block_count, label.eof1.system_type);
memcpy(block_count_buffer,label.eof1.block_count_high,4);
memcpy(block_count_buffer+4,label.eof1.block_count,6);
block_count_buffer[10] = '\0';
label_block_count = strtol(block_count_buffer,(char **)NULL,10);
if (label_block_count != tape_file->fileblkcnt) {
printf("** WARNING ** Actual number of blocks in file is %d\n",
tape_file->fileblkcnt);
}
}
void print_hdrtlr2_label(ansi_label label)
{
char blocking[3];
if (label.hdr2.block_attr[0] == 'R') {
strcpy(blocking,"BS");
} else {
blocking[0] = label.hdr2.block_attr[0];
if (blocking[0] == ' ')
blocking[0] = '\0';
else
blocking[1] = '\0';
}
printf(" blocksize %.5s, lrecl %.5s, record format %.1s%s%.1s, ",
label.hdr2.block_length, label.hdr2.record_length,
label.hdr2.record_format, blocking, label.hdr2.control_char);
printf("written by %.17s\n", label.hdr2.creating_job);
}