Skip to content

Commit

Permalink
[EROFS]: cleanup: report error when encountering bad mapfile
Browse files Browse the repository at this point in the history
Return an error code when encountering a bad map file.

Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
  • Loading branch information
salvete committed Nov 13, 2024
1 parent 2fed67e commit 8ce880b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/overlaybd/tar/erofs/liberofs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ static int erofs_write_map_file(photon::fs::IFile *fout, uint64_t blksz, FILE *f
uint32_t nblocks, zeroedlen;
char *line = NULL;
size_t len = 0;
int cnt;
int cnt, err = 0;

if (fp == NULL) {
LOG_ERROR("unable to get upper.map, ignored");
Expand All @@ -597,6 +597,7 @@ static int erofs_write_map_file(photon::fs::IFile *fout, uint64_t blksz, FILE *f
cnt = sscanf(line, "%" PRIx64" %x%" PRIx64 "%u", &blkaddr, &nblocks, &toff, &zeroedlen);
if (cnt < 3) {
LOG_ERROR("Bad formatted map file.");
err = -EINVAL;
break;
}

Expand All @@ -608,12 +609,15 @@ static int erofs_write_map_file(photon::fs::IFile *fout, uint64_t blksz, FILE *f

int nwrite = fout->ioctl(LSMT::IFileRW::RemoteData, lba);
if ((unsigned) nwrite != lba.count) {
LOG_ERRNO_RETURN(0, -1, "failed to write lba");
LOG_ERROR("failed to write lba");
err = -EINVAL;
break;
}
}
free(line);
if (line)
free(line);

return 0;
return err;
}

static int erofs_close_sbi(struct erofs_sb_info *sbi, ErofsCache *cache)
Expand Down

0 comments on commit 8ce880b

Please sign in to comment.