Skip to content

Commit 45f769a

Browse files
committed
tar/multitape: add clarifying comments
1 parent da3ccaa commit 45f769a

6 files changed

Lines changed: 28 additions & 1 deletion

File tree

tar/multitape/multitape_fsck.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ phase1(uint64_t machinenum, STORAGE_D * SD, STORAGE_R * SR,
176176
if ((mdat = malloc(sizeof(struct tapemetadata))) == NULL)
177177
goto err2;
178178

179+
/* Get the next metadata file. */
179180
switch (multitape_metadata_get_byhash(SR, NULL, mdat,
180181
&flist[file * 32], 1)) {
181182
case -1:

tar/multitape/multitape_metadata.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,12 @@ multitape_metadata_delete(STORAGE_D * S, CHUNKS_D * C,
506506
{
507507
uint8_t hbuf[32];
508508

509+
/* Compute the hash of the tape name. */
509510
if (crypto_hash_data(CRYPTO_KEY_HMAC_NAME,
510511
(uint8_t *)mdat->name, strlen(mdat->name), hbuf))
511512
goto err0;
513+
514+
/* Delete the file and update the stats. */
512515
if (storage_delete_file(S, 'm', hbuf))
513516
goto err0;
514517
chunks_delete_extrastats(C, mdat->metadatalen);

tar/multitape/multitape_metaindex.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ multitape_metaindex_fragname(const uint8_t namehash[32], uint32_t fragnum,
3838
{
3939
uint8_t fragnum_le[4];
4040

41+
/* Use a platform-agnostic format for fragnum. */
4142
le32enc(fragnum_le, fragnum);
43+
44+
/* SHA256(namehash || fragnum). */
4245
if (crypto_hash_data_2(CRYPTO_KEY_HMAC_SHA256, namehash, 32,
4346
fragnum_le, 4, fraghash)) {
4447
warn0("Programmer error: "
@@ -90,19 +93,21 @@ multitape_metaindex_put(STORAGE_W * S, CHUNKS_W * C,
9093
if ((p = buf = malloc(buflen)) == NULL)
9194
goto err0;
9295

93-
/* Copy values into buffer. */
96+
/* Copy the header index into the buffer. */
9497
le32enc(p, (uint32_t)mind->hindexlen);
9598
p += 4;
9699
if (mind->hindexlen > 0)
97100
memcpy(p, mind->hindex, mind->hindexlen);
98101
p += mind->hindexlen;
99102

103+
/* Copy the chunk index into the buffer. */
100104
le32enc(p, (uint32_t)mind->cindexlen);
101105
p += 4;
102106
if (mind->cindexlen > 0)
103107
memcpy(p, mind->cindex, mind->cindexlen);
104108
p += mind->cindexlen;
105109

110+
/* Copy the trailer index into the buffer. */
106111
le32enc(p, (uint32_t)mind->tindexlen);
107112
p += 4;
108113
if (mind->tindexlen > 0)
@@ -231,8 +236,11 @@ multitape_metaindex_get(STORAGE_R * S, CHUNKS_S * C,
231236
buf += 4;
232237
buflen -= 4;
233238

239+
/* Sanity check. */
234240
if (buflen < mind->hindexlen)
235241
goto corrupt0;
242+
243+
/* Copy the header index into a new buffer. */
236244
if (((mind->hindex = malloc(mind->hindexlen)) == NULL) &&
237245
(mind->hindexlen > 0))
238246
goto err1;
@@ -248,8 +256,11 @@ multitape_metaindex_get(STORAGE_R * S, CHUNKS_S * C,
248256
buf += 4;
249257
buflen -= 4;
250258

259+
/* Sanity check. */
251260
if (buflen < mind->cindexlen)
252261
goto corrupt1;
262+
263+
/* Copy the chunk index into a new buffer. */
253264
if (((mind->cindex = malloc(mind->cindexlen)) == NULL) &&
254265
(mind->cindexlen > 0))
255266
goto err2;
@@ -265,8 +276,11 @@ multitape_metaindex_get(STORAGE_R * S, CHUNKS_S * C,
265276
buf += 4;
266277
buflen -= 4;
267278

279+
/* Sanity check. */
268280
if (buflen < mind->tindexlen)
269281
goto corrupt2;
282+
283+
/* Copy the trailer index into a new buffer. */
270284
if (((mind->tindex = malloc(mind->tindexlen)) == NULL) &&
271285
(mind->tindexlen > 0))
272286
goto err3;
@@ -275,6 +289,7 @@ multitape_metaindex_get(STORAGE_R * S, CHUNKS_S * C,
275289
buf += mind->tindexlen;
276290
buflen -= mind->tindexlen;
277291

292+
/* Sanity check. */
278293
if (buflen != 0)
279294
goto corrupt3;
280295

@@ -331,6 +346,7 @@ multitape_metaindex_free(struct tapemetaindex * mind)
331346
if (mind == NULL)
332347
return;
333348

349+
/* Clean up. */
334350
free(mind->tindex);
335351
free(mind->cindex);
336352
free(mind->hindex);
@@ -351,6 +367,7 @@ multitape_metaindex_delete(STORAGE_D * S, CHUNKS_D * C,
351367
size_t fraglen;
352368
uint8_t fraghash[32];
353369

370+
/* Compute the hash of the tape name. */
354371
if (crypto_hash_data(CRYPTO_KEY_HMAC_NAME,
355372
(uint8_t *)mdat->name, strlen(mdat->name), hbuf))
356373
goto err0;

tar/multitape/multitape_read.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ stream_get_chunk(struct stream * S, const uint8_t ** buf, size_t * clen,
127127

128128
/* Skip part of the current chunk if appropriate. */
129129
if (S->skiplen) {
130+
/* How many bytes should we skip? */
130131
skip = (off_t)(S->chunklen - S->chunkpos);
131132
if (skip > S->skiplen)
132133
skip = S->skiplen;
133134

135+
/* Skip bytes. */
134136
S->skiplen -= skip;
135137
S->chunkpos += (size_t)skip;
136138
}
@@ -377,11 +379,13 @@ readtape_read(TAPE_R * d, const void ** buffer)
377379
continue;
378380
}
379381

382+
/* Read data. */
380383
if (stream_get_chunk(readstream, buf, &clen, d->C))
381384
goto err0;
382385
if ((off_t)clen > *readmaxlen)
383386
clen = (size_t)(*readmaxlen);
384387

388+
/* Update position and length. */
385389
readstream->chunkpos += clen;
386390
*readmaxlen -= clen;
387391

tar/multitape/multitape_stats.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ statstape_print(TAPE_S * d, const char * tapename, const char * csv_filename,
401401
goto err0;
402402
}
403403

404+
/* Compute statistics. */
404405
if (multitape_chunkiter_tmd(d->SR, d->C, &tmd,
405406
callback_print, d->C, 0))
406407
goto err2;

tar/multitape/multitape_write.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,7 @@ writetape_free(TAPE_W * d)
10541054
if (d == NULL)
10551055
return;
10561056

1057+
/* Clean up. */
10571058
chunks_write_free(d->C);
10581059
storage_write_free(d->S);
10591060
if ((d->lockfd != -1) && close(d->lockfd))

0 commit comments

Comments
 (0)