# Path: remount_union.py
# def remount_union(ctx, rotate_upper=False):
#     cfg = ctx.config()
#     union_mntroot = cfg.union_mntroot()
# 
#     if cfg.testing_overlayfs():
#         system("umount " + cfg.union_mntroot())
#         system("echo 3 > /proc/sys/vm/drop_caches")
#         check_not_tainted()
# 
#         upper_mntroot = cfg.upper_mntroot()
#         if rotate_upper and ctx.have_more_layers():
#             lowerlayers = ctx.upper_layer() + ":" + ctx.lower_layers()
#             layer_mntroot = upper_mntroot + "/" + ctx.next_layer()
#             upperdir = layer_mntroot + "/u"
#             workdir = layer_mntroot + "/w"
#             os.mkdir(layer_mntroot)
#             # Create unique fs for upper/N if N < maxfs
#             if ctx.have_more_fs():
#                 system("mount -t tmpfs " + ctx.curr_layer() + "_layer " + layer_mntroot)
#             os.mkdir(upperdir)
#             os.mkdir(workdir)
#             # Create pure upper file
#             write_file(upperdir + "/f", "pure");
#         else:
#             lowerlayers = ctx.lower_layers()
#             layer_mntroot = upper_mntroot + "/" + ctx.curr_layer()
#             upperdir = layer_mntroot + "/u"
#             workdir = layer_mntroot + "/w"
# 
#         mnt = union_mntroot
#         mntopt = cfg.mntopts()
#         cmd = "mount -t " + cfg.fstype() + " " + cfg.fsname() + " " + mnt + " " + mntopt + " -olowerdir=" + lowerlayers + ",upperdir=" + upperdir + ",workdir=" + workdir
#         system(cmd)
#         if cfg.is_verbose():
#             write_kmsg(cmd);
#         # Record st_dev of merge dir and pure upper file
#         ctx.note_upper_fs(upper_mntroot, cfg.testdir(), union_mntroot + "/f")
#         ctx.note_lower_layers(lowerlayers)
#         ctx.note_upper_layer(upperdir)


from tool_box import *
from remount_union import remount_union
from stat import *
from enum import IntEnum
import sys, os, errno
                return errno.ENOTDIR
            if dentry2.is_reg_or_sym_to_reg():
                return errno.EISDIR
            return None

        line = "rename " + filename + " " + filename2
        (dentry, dentry2) = self.vfs_op_prelude(
            line, filename, args, filename2,
            no_follow=True,
            guess=guess_error,
            create=True)

        try:
            self.verbosef("os.rename({:s},{:s})\n", filename, filename2)
            filetype = dentry.filetype()
            dev = self.get_dev_id(filename)
            ino = self.get_file_ino(filename)
            layer = self.layers_nr()
            os.rename(filename, filename2)
            if dentry != dentry2:
                dentry.copied_up(layer)
                dentry2.replace_with(dentry)
            self.vfs_op_success(filename, dentry, args)
            self.vfs_op_success(filename2, dentry2, args, create=True, filetype=filetype,
                                hardlink_to=dentry)
            recycle = self.__recycle
            if "recycle" in args:
                recycle = args["recycle"]
            if recycle:
                # Cycle mount and possibly rotate upper after rename

# Path: remount_union.py
# def remount_union(ctx, rotate_upper=False):
#     cfg = ctx.config()
#     union_mntroot = cfg.union_mntroot()
# 
#     if cfg.testing_overlayfs():
#         system("umount " + cfg.union_mntroot())
#         system("echo 3 > /proc/sys/vm/drop_caches")
#         check_not_tainted()
# 
#         upper_mntroot = cfg.upper_mntroot()
#         if rotate_upper and ctx.have_more_layers():
#             lowerlayers = ctx.upper_layer() + ":" + ctx.lower_layers()
#             layer_mntroot = upper_mntroot + "/" + ctx.next_layer()
#             upperdir = layer_mntroot + "/u"
#             workdir = layer_mntroot + "/w"
#             os.mkdir(layer_mntroot)
#             # Create unique fs for upper/N if N < maxfs
#             if ctx.have_more_fs():
#                 system("mount -t tmpfs " + ctx.curr_layer() + "_layer " + layer_mntroot)
#             os.mkdir(upperdir)
#             os.mkdir(workdir)
#             # Create pure upper file
#             write_file(upperdir + "/f", "pure");
#         else:
#             lowerlayers = ctx.lower_layers()
#             layer_mntroot = upper_mntroot + "/" + ctx.curr_layer()
#             upperdir = layer_mntroot + "/u"
#             workdir = layer_mntroot + "/w"
# 
#         mnt = union_mntroot
#         mntopt = cfg.mntopts()
#         cmd = "mount -t " + cfg.fstype() + " " + cfg.fsname() + " " + mnt + " " + mntopt + " -olowerdir=" + lowerlayers + ",upperdir=" + upperdir + ",workdir=" + workdir
#         system(cmd)
#         if cfg.is_verbose():
#             write_kmsg(cmd);
#         # Record st_dev of merge dir and pure upper file
#         ctx.note_upper_fs(upper_mntroot, cfg.testdir(), union_mntroot + "/f")
#         ctx.note_lower_layers(lowerlayers)
#         ctx.note_upper_layer(upperdir)


# Path: context.py
from tool_box import *
from remount_union import remount_union
from stat import *
from enum import IntEnum
import sys, os, errno

                return errno.ENOTDIR
            if dentry2.is_reg_or_sym_to_reg():
                return errno.EISDIR
            return None

        line = "rename " + filename + " " + filename2
        (dentry, dentry2) = self.vfs_op_prelude(
            line, filename, args, filename2,
            no_follow=True,
            guess=guess_error,
            create=True)

        try:
            self.verbosef("os.rename({:s},{:s})\n", filename, filename2)
            filetype = dentry.filetype()
            dev = self.get_dev_id(filename)
            ino = self.get_file_ino(filename)
            layer = self.layers_nr()
            os.rename(filename, filename2)
            if dentry != dentry2:
                dentry.copied_up(layer)
                dentry2.replace_with(dentry)
            self.vfs_op_success(filename, dentry, args)
            self.vfs_op_success(filename2, dentry2, args, create=True, filetype=filetype,
                                hardlink_to=dentry)
            recycle = self.__recycle
            if "recycle" in args:
                recycle = args["recycle"]
            if recycle:
                # Cycle mount and possibly rotate upper after rename

                remount_union(self, rotate_upper=True)