Skip to content

Commit

Permalink
fix: improve block calculation for directory contents
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Sep 28, 2023
1 parent ca109b3 commit fa945bf
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions xgenext2fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,18 @@ add2fs_from_tarball(filesystem *fs, uint32 this_nod, FILE * fh, int squash_uids,
mode = archive_entry_mode(entry);
if (stats)
{
filepath = archive_entry_pathname(entry);
if (filepath == NULL) {
error_msg("invalid filename %s\n", filepath);
continue;
}
curdirbytes = align(sizeof(directory) + strlen(filepath), 4);
if (dirbytes + curdirbytes > BLOCKSIZE) {
dirbytes = curdirbytes;
stats->nblocks++;
} else {
dirbytes += curdirbytes;
}
// depending on the archive, the entry size might not
// be set in the first place in which case the
// estimate might be totally off
Expand All @@ -2398,18 +2410,6 @@ add2fs_from_tarball(filesystem *fs, uint32 this_nod, FILE * fh, int squash_uids,
stats->ninodes++;
break;
case S_IFDIR:
filepath = archive_entry_pathname(entry);
if (filepath == NULL) {
error_msg("invalid filename %s\n", filepath);
continue;
}
curdirbytes = align(sizeof(directory) + strlen(filepath), 4);
if (dirbytes + curdirbytes > BLOCKSIZE) {
dirbytes = curdirbytes;
stats->nblocks++;
} else {
dirbytes += curdirbytes;
}
stats->nblocks++;
stats->ninodes++;
break;
Expand Down Expand Up @@ -2687,7 +2687,14 @@ add2fs_from_dir(filesystem *fs, uint32 this_nod, int squash_uids, int squash_per
uid = gid = squash_uids;
if(squash_perms)
mode &= ~(FM_IRWXG | FM_IRWXO);
if(stats)
if(stats) {
curdirbytes = align(sizeof(directory) + strlen(dent->d_name), 4);
if (dirbytes + curdirbytes > BLOCKSIZE) {
dirbytes = curdirbytes;
stats->nblocks++;
} else {
dirbytes += curdirbytes;
}
switch(st.st_mode & S_IFMT)
{
case S_IFLNK:
Expand All @@ -2704,13 +2711,6 @@ add2fs_from_dir(filesystem *fs, uint32 this_nod, int squash_uids, int squash_per
stats->ninodes++;
break;
case S_IFDIR:
curdirbytes = align(sizeof(directory) + strlen(dent->d_name), 4);
if (dirbytes + curdirbytes > BLOCKSIZE) {
dirbytes = curdirbytes;
stats->nblocks++;
} else {
dirbytes += curdirbytes;
}
stats->nblocks++;
stats->ninodes++;
if(chdir(dent->d_name) < 0)
Expand All @@ -2723,6 +2723,7 @@ add2fs_from_dir(filesystem *fs, uint32 this_nod, int squash_uids, int squash_per
default:
break;
}
}
else
{
if((nod = find_dir(fs, this_nod, name)))
Expand Down

0 comments on commit fa945bf

Please sign in to comment.