56
58
* Iff there is no header, returns DSERR_MAGIC and leaves us
57
59
* positioned where we started.
59
afs_uint32 ParseStageHdr(XFILE *X, unsigned char *tag, backup_system_header *hdr)
62
ParseStageHdr(XFILE * X, unsigned char *tag, backup_system_header * hdr)
61
char buf[STAGE_HDRLEN];
62
struct stage_header *bckhdr = (struct stage_header *)buf;
66
if (r = xftell(X, &where)) return r;
67
if (hdr) memset(hdr, 0, sizeof(*hdr));
69
if (*tag != STAGE_VERSMIN) return DSERR_MAGIC;
71
r = xfread(X, buf + 1, STAGE_HDRLEN - 1);
73
r = xfread(X, buf, STAGE_HDRLEN);
76
if (r == ERROR_XFILE_EOF) {
77
r = xfseek(X, &where);
78
return r ? r : DSERR_MAGIC;
79
} else if (r) return r;
81
if (bckhdr->c_vers < STAGE_VERSMIN
82
|| ntohl(bckhdr->c_magic) != STAGE_MAGIC
83
|| hdr_checksum(buf, STAGE_HDRLEN) != STAGE_CHECKSUM) {
84
r = xfseek(X, &where);
85
return r ? r : DSERR_MAGIC;
89
hdr->version = bckhdr->c_vers;
90
hdr->from_date = ntohl(bckhdr->c_fdate);
91
hdr->to_date = ntohl(bckhdr->c_tdate);
92
hdr->dump_date = ntohl(bckhdr->c_time);
93
hdr->filenum = ntohl(bckhdr->c_filenum);
94
hdr->volid = ntohl(bckhdr->c_id);
95
hdr->dumplen = ntohl(bckhdr->c_length);
96
hdr->level = ntohl(bckhdr->c_level);
97
hdr->magic = ntohl(bckhdr->c_magic);
98
hdr->cksum = ntohl(bckhdr->c_checksum);
99
hdr->flags = ntohl(bckhdr->c_flags);
100
hdr->server = malloc(strlen(bckhdr->c_host) + 1);
101
hdr->part = malloc(strlen(bckhdr->c_disk) + 1);
102
hdr->volname = malloc(strlen(bckhdr->c_name) + 1);
104
if (!hdr->server || !hdr->part || !hdr->volname) {
105
if (hdr->server) free(hdr->server);
106
if (hdr->part) free(hdr->part);
107
if (hdr->volname) free(hdr->volname);
110
strcpy(hdr->server, bckhdr->c_host);
111
strcpy(hdr->part, bckhdr->c_disk);
112
strcpy(hdr->volname, bckhdr->c_name);
115
if (tag) return ReadByte(X, tag);
64
char buf[STAGE_HDRLEN];
65
struct stage_header *bckhdr = (struct stage_header *)buf;
69
if (r = xftell(X, &where))
72
memset(hdr, 0, sizeof(*hdr));
74
if (*tag != STAGE_VERSMIN)
77
r = xfread(X, buf + 1, STAGE_HDRLEN - 1);
79
r = xfread(X, buf, STAGE_HDRLEN);
82
if (r == ERROR_XFILE_EOF) {
83
r = xfseek(X, &where);
84
return r ? r : DSERR_MAGIC;
88
if (bckhdr->c_vers < STAGE_VERSMIN
89
|| ntohl(bckhdr->c_magic) != STAGE_MAGIC
90
|| hdr_checksum(buf, STAGE_HDRLEN) != STAGE_CHECKSUM) {
91
r = xfseek(X, &where);
92
return r ? r : DSERR_MAGIC;
96
hdr->version = bckhdr->c_vers;
97
hdr->from_date = ntohl(bckhdr->c_fdate);
98
hdr->to_date = ntohl(bckhdr->c_tdate);
99
hdr->dump_date = ntohl(bckhdr->c_time);
100
hdr->filenum = ntohl(bckhdr->c_filenum);
101
hdr->volid = ntohl(bckhdr->c_id);
102
hdr->dumplen = ntohl(bckhdr->c_length);
103
hdr->level = ntohl(bckhdr->c_level);
104
hdr->magic = ntohl(bckhdr->c_magic);
105
hdr->cksum = ntohl(bckhdr->c_checksum);
106
hdr->flags = ntohl(bckhdr->c_flags);
107
hdr->server = malloc(strlen(bckhdr->c_host) + 1);
108
hdr->part = malloc(strlen(bckhdr->c_disk) + 1);
109
hdr->volname = malloc(strlen(bckhdr->c_name) + 1);
111
if (!hdr->server || !hdr->part || !hdr->volname) {
120
strcpy(hdr->server, bckhdr->c_host);
121
strcpy(hdr->part, bckhdr->c_disk);
122
strcpy(hdr->volname, bckhdr->c_name);
126
return ReadByte(X, tag);
120
132
/* Dump a stage backup header */
121
afs_uint32 DumpStageHdr(XFILE *OX, backup_system_header *hdr)
134
DumpStageHdr(XFILE * OX, backup_system_header * hdr)
123
char buf[STAGE_HDRLEN];
124
struct stage_header *bckhdr = (struct stage_header *)buf;
128
memset(buf, 0, STAGE_HDRLEN);
129
bckhdr->c_vers = hdr->version;
130
bckhdr->c_fdate = htonl(hdr->from_date);
131
bckhdr->c_tdate = htonl(hdr->to_date);
132
bckhdr->c_filenum = htonl(hdr->filenum);
133
bckhdr->c_time = htonl(hdr->dump_date);
134
bckhdr->c_id = htonl(hdr->volid);
135
bckhdr->c_length = htonl(hdr->dumplen);
136
bckhdr->c_level = htonl(hdr->level);
137
bckhdr->c_magic = htonl(STAGE_MAGIC);
138
bckhdr->c_flags = htonl(hdr->flags);
140
strcpy(bckhdr->c_host, hdr->server);
141
strcpy(bckhdr->c_disk, hdr->part);
142
strcpy(bckhdr->c_name, hdr->volname);
144
/* Now, compute the checksum */
145
checksum = hdr_checksum(buf, STAGE_HDRLEN);
146
bckhdr->c_checksum = htonl(STAGE_CHECKSUM - checksum);
148
if (r = xfwrite(OX, buf, STAGE_HDRLEN)) return r;
136
char buf[STAGE_HDRLEN];
137
struct stage_header *bckhdr = (struct stage_header *)buf;
141
memset(buf, 0, STAGE_HDRLEN);
142
bckhdr->c_vers = hdr->version;
143
bckhdr->c_fdate = htonl(hdr->from_date);
144
bckhdr->c_tdate = htonl(hdr->to_date);
145
bckhdr->c_filenum = htonl(hdr->filenum);
146
bckhdr->c_time = htonl(hdr->dump_date);
147
bckhdr->c_id = htonl(hdr->volid);
148
bckhdr->c_length = htonl(hdr->dumplen);
149
bckhdr->c_level = htonl(hdr->level);
150
bckhdr->c_magic = htonl(STAGE_MAGIC);
151
bckhdr->c_flags = htonl(hdr->flags);
153
strcpy(bckhdr->c_host, hdr->server);
154
strcpy(bckhdr->c_disk, hdr->part);
155
strcpy(bckhdr->c_name, hdr->volname);
157
/* Now, compute the checksum */
158
checksum = hdr_checksum(buf, STAGE_HDRLEN);
159
bckhdr->c_checksum = htonl(STAGE_CHECKSUM - checksum);
161
if (r = xfwrite(OX, buf, STAGE_HDRLEN))