static int local_renameat(FsContext *ctx, V9fsPath *olddir,

                          const char *old_name, V9fsPath *newdir,

                          const char *new_name)

{

    int ret;

    int odirfd, ndirfd;



    odirfd = local_opendir_nofollow(ctx, olddir->data);

    if (odirfd == -1) {

        return -1;

    }



    ndirfd = local_opendir_nofollow(ctx, newdir->data);

    if (ndirfd == -1) {

        close_preserve_errno(odirfd);

        return -1;

    }



    ret = renameat(odirfd, old_name, ndirfd, new_name);

    if (ret < 0) {

        goto out;

    }



    if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {

        int omap_dirfd, nmap_dirfd;



        ret = mkdirat(ndirfd, VIRTFS_META_DIR, 0700);

        if (ret < 0 && errno != EEXIST) {

            goto err_undo_rename;

        }



        omap_dirfd = openat(odirfd, VIRTFS_META_DIR,

                            O_RDONLY | O_DIRECTORY | O_NOFOLLOW);

        if (omap_dirfd == -1) {

            goto err;

        }



        nmap_dirfd = openat(ndirfd, VIRTFS_META_DIR,

                            O_RDONLY | O_DIRECTORY | O_NOFOLLOW);

        if (nmap_dirfd == -1) {

            close_preserve_errno(omap_dirfd);

            goto err;

        }



        /* rename the .virtfs_metadata files */

        ret = renameat(omap_dirfd, old_name, nmap_dirfd, new_name);

        close_preserve_errno(nmap_dirfd);

        close_preserve_errno(omap_dirfd);

        if (ret < 0 && errno != ENOENT) {

            goto err_undo_rename;

        }



        ret = 0;

    }

    goto out;



err:

    ret = -1;

err_undo_rename:

    renameat_preserve_errno(ndirfd, new_name, odirfd, old_name);

out:

    close_preserve_errno(ndirfd);

    close_preserve_errno(odirfd);

    return ret;

}

static int local_renameat(FsContext *ctx, V9fsPath *olddir,

                          const char *old_name, V9fsPath *newdir,

                          const char *new_name)

{

    int ret;

    int odirfd, ndirfd;



    odirfd = local_opendir_nofollow(ctx, olddir->data);

    if (odirfd == -1) {

        return -1;

    }



    ndirfd = local_opendir_nofollow(ctx, newdir->data);

    if (ndirfd == -1) {

        close_preserve_errno(odirfd);

        return -1;

    }



    ret = renameat(odirfd, old_name, ndirfd, new_name);

    if (ret < 0) {

        goto out;

    }



    if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {

        int omap_dirfd, nmap_dirfd;



        ret = mkdirat(ndirfd, VIRTFS_META_DIR, 0700);

        if (ret < 0 && errno != EEXIST) {

            goto err_undo_rename;

        }



        omap_dirfd = openat(odirfd, VIRTFS_META_DIR,

                            O_RDONLY | O_DIRECTORY | O_NOFOLLOW);

        if (omap_dirfd == -1) {

            goto err;

        }



        nmap_dirfd = openat(ndirfd, VIRTFS_META_DIR,

                            O_RDONLY | O_DIRECTORY | O_NOFOLLOW);

        if (nmap_dirfd == -1) {

            close_preserve_errno(omap_dirfd);

            goto err;

        }



        

        ret = renameat(omap_dirfd, old_name, nmap_dirfd, new_name);

        close_preserve_errno(nmap_dirfd);

        close_preserve_errno(omap_dirfd);

        if (ret < 0 && errno != ENOENT) {

            goto err_undo_rename;

        }



        ret = 0;

    }

    goto out;



err:

    ret = -1;

err_undo_rename:

    renameat_preserve_errno(ndirfd, new_name, odirfd, old_name);

out:

    close_preserve_errno(ndirfd);

    close_preserve_errno(odirfd);

    return ret;

}

        omap_dirfd = openat(odirfd, VIRTFS_META_DIR,                             O_RDONLY | O_DIRECTORY | O_NOFOLLOW);         nmap_dirfd = openat(ndirfd, VIRTFS_META_DIR,                             O_RDONLY | O_DIRECTORY | O_NOFOLLOW);
static int FUNC_0(FsContext *VAR_0, V9fsPath *VAR_1,

                          const char *VAR_2, V9fsPath *VAR_3,

                          const char *VAR_4)

{

    int VAR_5;

    int VAR_6, VAR_7;



    VAR_6 = local_opendir_nofollow(VAR_0, VAR_1->data);

    if (VAR_6 == -1) {

        return -1;

    }



    VAR_7 = local_opendir_nofollow(VAR_0, VAR_3->data);

    if (VAR_7 == -1) {

        close_preserve_errno(VAR_6);

        return -1;

    }



    VAR_5 = renameat(VAR_6, VAR_2, VAR_7, VAR_4);

    if (VAR_5 < 0) {

        goto out;

    }



    if (VAR_0->export_flags & V9FS_SM_MAPPED_FILE) {

        int VAR_8, VAR_9;



        VAR_5 = mkdirat(VAR_7, VIRTFS_META_DIR, 0700);

        if (VAR_5 < 0 && errno != EEXIST) {

            goto err_undo_rename;

        }



        VAR_8 = openat(VAR_6, VIRTFS_META_DIR,

                            O_RDONLY | O_DIRECTORY | O_NOFOLLOW);

        if (VAR_8 == -1) {

            goto err;

        }



        VAR_9 = openat(VAR_7, VIRTFS_META_DIR,

                            O_RDONLY | O_DIRECTORY | O_NOFOLLOW);

        if (VAR_9 == -1) {

            close_preserve_errno(VAR_8);

            goto err;

        }



        

        VAR_5 = renameat(VAR_8, VAR_2, VAR_9, VAR_4);

        close_preserve_errno(VAR_9);

        close_preserve_errno(VAR_8);

        if (VAR_5 < 0 && errno != ENOENT) {

            goto err_undo_rename;

        }



        VAR_5 = 0;

    }

    goto out;



err:

    VAR_5 = -1;

err_undo_rename:

    renameat_preserve_errno(VAR_7, VAR_4, VAR_6, VAR_2);

out:

    close_preserve_errno(VAR_7);

    close_preserve_errno(VAR_6);

    return VAR_5;

}

static int FUNC_0(FsContext *VAR_0, V9fsPath *VAR_1,
const char *VAR_2, V9fsPath *VAR_3,
const char *VAR_4)
{ int VAR_5; int VAR_6, VAR_7; VAR_6 = local_opendir_nofollow(VAR_0, VAR_1->data); if (VAR_6 == -1) { return -1; } VAR_7 = local_opendir_nofollow(VAR_0, VAR_3->data); if (VAR_7 == -1) { close_preserve_errno(VAR_6); return -1; } VAR_5 = renameat(VAR_6, VAR_2, VAR_7, VAR_4); if (VAR_5 < 0) { goto out; } if (VAR_0->export_flags & V9FS_SM_MAPPED_FILE) { int VAR_8, VAR_9; VAR_5 = mkdirat(VAR_7, VIRTFS_META_DIR, 0700); if (VAR_5 < 0 && errno != EEXIST) { goto err_undo_rename; } VAR_8 = openat(VAR_6, VIRTFS_META_DIR,
O_RDONLY | O_DIRECTORY | O_NOFOLLOW); if (VAR_8 == -1) { goto err; } VAR_9 = openat(VAR_7, VIRTFS_META_DIR,
O_RDONLY | O_DIRECTORY | O_NOFOLLOW); if (VAR_9 == -1) { close_preserve_errno(VAR_8); goto err; } VAR_5 = renameat(VAR_8, VAR_2, VAR_9, VAR_4); close_preserve_errno(VAR_9); close_preserve_errno(VAR_8); if (VAR_5 < 0 && errno != ENOENT) { goto err_undo_rename; } VAR_5 = 0; } goto out; err:
VAR_5 = -1; err_undo_rename:
renameat_preserve_errno(VAR_7, VAR_4, VAR_6, VAR_2); out:
close_preserve_errno(VAR_7); close_preserve_errno(VAR_6); return VAR_5; }