tarfs: Correctly track link count.
Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D39019
This commit is contained in:
parent
144e0f1f0c
commit
f4f2dfc1dc
@ -384,6 +384,18 @@ tarfs_free_node(struct tarfs_node *tnp)
|
||||
tmp = tnp->tmp;
|
||||
|
||||
switch (tnp->type) {
|
||||
case VREG:
|
||||
if (tnp->nlink-- > 1)
|
||||
return;
|
||||
if (tnp->other != NULL)
|
||||
tarfs_free_node(tnp->other);
|
||||
break;
|
||||
case VDIR:
|
||||
if (tnp->nlink-- > 2)
|
||||
return;
|
||||
if (tnp->parent != NULL && tnp->parent != tnp)
|
||||
tarfs_free_node(tnp->parent);
|
||||
break;
|
||||
case VLNK:
|
||||
if (tnp->link.name)
|
||||
free(tnp->link.name, M_TARFSNAME);
|
||||
@ -397,6 +409,7 @@ tarfs_free_node(struct tarfs_node *tnp)
|
||||
free(tnp->blk, M_TARFSBLK);
|
||||
if (tnp->ino >= TARFS_MININO)
|
||||
free_unr(tmp->ino_unr, tnp->ino);
|
||||
TAILQ_REMOVE(&tmp->allnodes, tnp, entries);
|
||||
free(tnp, M_TARFSNODE);
|
||||
tmp->nfiles--;
|
||||
}
|
||||
|
@ -406,16 +406,14 @@ static void
|
||||
tarfs_free_mount(struct tarfs_mount *tmp)
|
||||
{
|
||||
struct mount *mp;
|
||||
struct tarfs_node *tnp;
|
||||
struct tarfs_node *tnp, *tnp_next;
|
||||
|
||||
MPASS(tmp != NULL);
|
||||
|
||||
TARFS_DPF(ALLOC, "%s: Freeing mount structure %p\n", __func__, tmp);
|
||||
|
||||
TARFS_DPF(ALLOC, "%s: freeing tarfs_node structures\n", __func__);
|
||||
while (!TAILQ_EMPTY(&tmp->allnodes)) {
|
||||
tnp = TAILQ_FIRST(&tmp->allnodes);
|
||||
TAILQ_REMOVE(&tmp->allnodes, tnp, entries);
|
||||
TAILQ_FOREACH_SAFE(tnp, &tmp->allnodes, entries, tnp_next) {
|
||||
tarfs_free_node(tnp);
|
||||
}
|
||||
|
||||
@ -744,6 +742,7 @@ tarfs_alloc_one(struct tarfs_mount *tmp, off_t *blknump)
|
||||
error = EINVAL;
|
||||
goto bad;
|
||||
}
|
||||
tnp->other->nlink++;
|
||||
break;
|
||||
case TAR_TYPE_SYMLINK:
|
||||
if (link == NULL) {
|
||||
|
@ -59,6 +59,8 @@ tarfs_basic_body() {
|
||||
atf_check_equal "$(stat -f%d,%i "${mnt}"/sparse_file)" "$(stat -L -f%d,%i "${mnt}"/short_link)"
|
||||
atf_check_equal "$(stat -f%d,%i "${mnt}"/sparse_file)" "$(stat -L -f%d,%i "${mnt}"/long_link)"
|
||||
atf_check_equal "$(sha256 -q "${mnt}"/sparse_file)" ${sum}
|
||||
atf_check_equal "$(stat -f%l "${mnt}"/sparse_file)" 2
|
||||
atf_check_equal "$(stat -f%l "${mnt}"/hard_link)" 2
|
||||
}
|
||||
tarfs_basic_cleanup() {
|
||||
umount "${mnt}" || true
|
||||
|
Loading…
Reference in New Issue
Block a user